赋码仪错误判断
This commit is contained in:
		
							
								
								
									
										215
									
								
								source/coder/coder_judge.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										215
									
								
								source/coder/coder_judge.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,215 @@ | ||||
| #include "coder_judge.h" | ||||
| #include "dev_flash.h" | ||||
| #include "string.h" | ||||
|  | ||||
|  | ||||
| // <20><>d<EFBFBD><64><EFBFBD><EFBFBD> a<>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD> | ||||
| static void c_insert(uint8_t *a,uint8_t d) | ||||
| { | ||||
|   int len=sizeof(uint8_t [6]); | ||||
|   for(int i=0;i<len;i++) | ||||
|   { | ||||
|     if(a[i]==d) | ||||
|       return; | ||||
|   } | ||||
|   for(int i=0;i<len;i++) | ||||
|   { | ||||
|     if(a[i]==0xff){ | ||||
|       a[i]=d; | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| // ɾ<><C9BE>a<EFBFBD>е<EFBFBD>ֵd | ||||
| static void c_del(uint8_t *a,uint8_t d) | ||||
| { | ||||
|   int len=sizeof(uint8_t [6]); | ||||
|   for(int i=0;i<len;i++) | ||||
|   { | ||||
|     if(a[i]==d){ | ||||
|       memcpy(&a[i],&a[i+1],len-i-1); | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| // ɾ<><C9BE>a<EFBFBD>г<EFBFBD>d֮<64><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ | ||||
| static void c_only(uint8_t *a,uint8_t d) | ||||
| { | ||||
|   int len=sizeof(uint8_t [6]); | ||||
|   for(int i=0;i<len;i++) | ||||
|   { | ||||
|     if(a[i]==d) | ||||
|     { | ||||
|       memset(a,0xff,len); | ||||
|       a[0]=d; | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
|   // <20><><EFBFBD><EFBFBD>û<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>ȫ<EFBFBD><C8AB>ɾ<EFBFBD><C9BE> | ||||
|   memset(a,0xff,len); | ||||
| } | ||||
|  | ||||
| // <20><>ʼ<EFBFBD><CABC>a | ||||
| static void c_init(uint8_t *a) | ||||
| { | ||||
|   int len=sizeof(uint8_t [6]); | ||||
|   memset(a,0xff,len); | ||||
| } | ||||
|  | ||||
|  | ||||
| // <20><><EFBFBD><EFBFBD>taskid<69>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD> | ||||
| const scheme_task_def *find_task_next(int index_now,int taskid) | ||||
| { | ||||
|   const scheme_def *s=check_scheme(); | ||||
|   const scheme_task_def *t; | ||||
|   for(int i=index_now;i<s->task_num;i++) | ||||
|   { | ||||
|     t=&s->task[i]; | ||||
|     if(t->taskid==taskid) | ||||
|       return t; | ||||
|   } | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>index<65>IJ<EFBFBD><C4B2><EFBFBD> | ||||
|  | ||||
|  | ||||
| // <20><>ȡ<EFBFBD><C8A1>index<65><78><EFBFBD><EFBFBD>Χ | ||||
| static int get_range(int index,int *min,int *max) | ||||
| { | ||||
|   const scheme_def *s=check_scheme(); | ||||
|   const scheme_task_def *t; | ||||
|   int index_p=0; | ||||
|   for(int i=0;i<s->task_num;i++) | ||||
|   { | ||||
|     t=&s->task[i]; | ||||
|     for(int j=0;j<t->item_num;j++) | ||||
|     { | ||||
|       if(index_p==index) | ||||
|       { | ||||
|         if(min) *min=t->range[j].min; | ||||
|         if(max) *max=t->range[j].max; | ||||
|         return index_p; | ||||
|       } | ||||
|       index_p++; | ||||
|     } | ||||
|   } | ||||
|   return index_p; | ||||
| } | ||||
|  | ||||
|  | ||||
| // <20><>ȡ<EFBFBD><C8A1>index<65><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
| static int get_data(const uint8_t *data,int index) | ||||
| { | ||||
|   data+=16; | ||||
|   return data[index*2]|(data[index*2+1]<<8); | ||||
| } | ||||
|  | ||||
| // <20><>ȡ<EFBFBD><C8A1>index<65><78><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>1<EFBFBD><31>ʧ<EFBFBD>ܣ<EFBFBD>0<EFBFBD>ɹ<EFBFBD> | ||||
| static int get_ack(const uint8_t *data,int index) | ||||
| { | ||||
|   if(data[index/8]&(1<<(index%8))) | ||||
|     return 1; | ||||
|   else | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| //-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣,1 | ||||
| //-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣,2 | ||||
| //-- <20>Ӵ<EFBFBD><D3B4>쳣,3 | ||||
| //-- <20><>˿<EFBFBD><CBBF>ֵ<EFBFBD>쳣,4 | ||||
| //-- оƬ<D0BE>쳣,5 | ||||
| //-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>7 | ||||
| //-- <20><>·<EFBFBD><C2B7>8 | ||||
|  | ||||
| #define  TASK_RETURN(task) {\ | ||||
|   if(task==0) return 6; \ | ||||
|   else index+=1;\ | ||||
| }// <20>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
|  | ||||
| uint8_t coder_judge(const uint8_t *data) | ||||
| { | ||||
|   int temp,temp2; | ||||
|   int index=0; | ||||
|   const scheme_task_def *task=0; | ||||
|    | ||||
|   // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
|   task=find_task_next(index,0); | ||||
|   TASK_RETURN(task); | ||||
|   { | ||||
|     if(get_ack(data,0)) | ||||
|     { | ||||
|       // <20>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><F3A3ACBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣 | ||||
|       return 1; | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   // <20>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD> | ||||
|   task=find_task_next(index,1); | ||||
|   TASK_RETURN(task); | ||||
|   { | ||||
|     temp=get_data(data,0); | ||||
|     if(temp<task->range[0].min) | ||||
|     { | ||||
|       // <20><>ѹ<EFBFBD><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣 | ||||
|       return 1; | ||||
|     } | ||||
|     temp=get_data(data,1); | ||||
|     if((temp>39000)||(temp<1)){ | ||||
|       // <20><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | ||||
|   task=find_task_next(index,4); | ||||
|   TASK_RETURN(task); | ||||
|   temp=get_data(data,5); | ||||
|   temp2=get_data(data,6); | ||||
|   if((temp<10)&&(temp2<20)) | ||||
|   { | ||||
|     // <20>Ӵ<EFBFBD><D3B4>쳣 | ||||
|     return 3; | ||||
|   } | ||||
|   else if(((temp>task->range[0].max)&&(temp<1500))|| | ||||
|     ((temp2>task->range[0].max)&&(temp2<1500))) | ||||
|   { | ||||
|     // <20><><EFBFBD><EFBFBD> | ||||
|     return 7; | ||||
|   }else if((temp>1500)&&(temp2>1500)) | ||||
|   { | ||||
|     // <20><>· | ||||
|     return 8; | ||||
|   } | ||||
|    | ||||
|    | ||||
|   // <20><><EFBFBD><EFBFBD>uid | ||||
|   task=find_task_next(index,5); | ||||
|   TASK_RETURN(task); | ||||
|   if(get_ack(data,task->taskindex)) | ||||
|   { | ||||
|     // оƬ<D0BE><C6AC><EFBFBD><EFBFBD> | ||||
|     return 5; | ||||
|   } | ||||
|    | ||||
|   // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ | ||||
|   task=find_task_next(index,6); | ||||
|   TASK_RETURN(task); | ||||
|   temp=get_data(data,7); | ||||
|   if((temp<task->range[0].min)||(temp>task->range[0].max)) | ||||
|   { | ||||
|     // <20><>˿<EFBFBD><CBBF><EFBFBD><EFBFBD> | ||||
|     return 4; | ||||
|   } | ||||
|    | ||||
|   // <20><><EFBFBD><EFBFBD> | ||||
|    | ||||
|    | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
							
								
								
									
										16
									
								
								source/coder/coder_judge.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								source/coder/coder_judge.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| #ifndef coder_judge_h__ | ||||
| #define coder_judge_h__ | ||||
|  | ||||
| #include "stdint.h" | ||||
|  | ||||
|  | ||||
|  | ||||
| uint8_t coder_judge(const uint8_t *data); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif | ||||
|  | ||||
| @@ -129,7 +129,8 @@ int coder_uid_to_save(const char *uid_code,uint8_t *save_code) | ||||
|   ymd|=coder_strint_to_byte(&uid_code[8],2); | ||||
|   save_code[2]=ymd>>8; | ||||
|   save_code[3]=ymd&0xff; | ||||
|   feature=uid_code[10]*10000; | ||||
|   // 文档 YM-UID设计V1.2 - 2023.xlsx 规定*10000,实际是*100000 | ||||
|   feature=uid_code[10]*100000; | ||||
|   feature+=coder_strint_to_byte(&uid_code[11],3)*100; | ||||
|   feature+=coder_strint_to_byte(&uid_code[14],2); | ||||
|   save_code[4]=feature>>16; | ||||
| @@ -174,8 +175,8 @@ int coder_save_to_uid(const uint8_t *save_code,char *uid_code) | ||||
|   ret|=coder_int_to_strint(ymd>>9,&uid_code[2],2); | ||||
|   ret|=coder_int_to_strint((ymd>>5)&0x0f,&uid_code[6],2); | ||||
|   ret|=coder_int_to_strint((ymd)&0x1f,&uid_code[8],2); | ||||
|   uid_code[10]=feature/10000; | ||||
|   ret|=coder_int_to_strint(feature%10000/100,&uid_code[11],3); | ||||
|   uid_code[10]=feature/100000; | ||||
|   ret|=coder_int_to_strint(feature%100000/100,&uid_code[11],3); | ||||
|   ret|=coder_int_to_strint(feature%100,&uid_code[14],2); | ||||
|   return ret; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ranchuan
					ranchuan