赋码仪错误判断
This commit is contained in:
@@ -132,4 +132,8 @@
|
||||
2023.7.3
|
||||
检测错误码
|
||||
解决tcp下升级方案死机的问题,原因是内存没有回收导致的内存不足
|
||||
2023.7.6
|
||||
UID转存储码特征码从*10000改为*100000
|
||||
赋码仪接收上位机的0x81,0x82回复
|
||||
添加错误判断,未完成
|
||||
|
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;
|
||||
}
|
||||
|
@@ -85,9 +85,9 @@ const sys_param_def *sys_param(void);
|
||||
|
||||
__packed
|
||||
typedef struct{
|
||||
uint32_t max;
|
||||
uint32_t min;
|
||||
uint32_t err;
|
||||
uint32_t max;
|
||||
uint32_t min;
|
||||
uint32_t err;
|
||||
}scheme_range_def;
|
||||
|
||||
|
||||
@@ -95,9 +95,11 @@ typedef struct{
|
||||
__packed
|
||||
typedef struct
|
||||
{
|
||||
uint32_t item_num;
|
||||
uint32_t err;
|
||||
scheme_range_def range[16];
|
||||
uint32_t taskid;
|
||||
uint32_t taskindex;
|
||||
uint32_t item_num;
|
||||
uint32_t err;
|
||||
scheme_range_def range[16];
|
||||
}scheme_task_def;
|
||||
|
||||
// 方案参数
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
|
||||
#define BUILD_DATE "2023-07-04 09:17:01"
|
||||
#define BUILD_DATE "2023-07-06 19:01:21"
|
||||
#define SOFT_VERSION "0.10"
|
||||
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "coder_lib.h"
|
||||
#include "PSDGenerate.h"
|
||||
#include "mystring.h"
|
||||
#include "coder_judge.h"
|
||||
|
||||
// 这个文件解析跟赋码仪相关的命令
|
||||
|
||||
@@ -93,6 +94,8 @@ static void write_uid_end(ucport_def *u,port_mcu *src,void *data,int ack,char *e
|
||||
emit tran_send_signal(w->u.p,0x82,arr_temp(a));
|
||||
tran_set_busy(w->u.p,0);
|
||||
g_self.step=0;
|
||||
// 把命令字改为0x82用于接收主机应答
|
||||
w->u.cmd=0x82;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +126,14 @@ static void write_del(ucport_def *u)
|
||||
}
|
||||
|
||||
|
||||
static int write_uid_dolater(ucport_def *u,uint8_t cmd,array_def *data,char *err_str)
|
||||
{
|
||||
DBG_LOG("recv write_uid end signal.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ucport_def *write_uid(tran_def *t, uint8_t cmd,array_def *data)
|
||||
{
|
||||
if(arr_length(data)<140+4+1){
|
||||
@@ -134,6 +145,7 @@ static ucport_def *write_uid(tran_def *t, uint8_t cmd,array_def *data)
|
||||
u->u.p=t;
|
||||
u->u.del=write_del;
|
||||
u->u.doend=write_uid_end;
|
||||
u->u.dolater=write_uid_dolater;
|
||||
u->addrs_num=arr_get(data,0);
|
||||
memcpy(u->year,arr_data(data)+1,4);
|
||||
DBG_LOG("coder, year=%s",u->year);
|
||||
@@ -329,7 +341,13 @@ static void check_end(ucport_def *u,port_mcu *src,void *data,int ack,char *err_s
|
||||
ack_d[3]=(errcode>>8)&0xff;
|
||||
ack_d[4]=(errcode>>16)&0xff;
|
||||
ack_d[5]=(errcode>>24)&0xff;
|
||||
if(ack_d[1]==0) ack_d[1]=ack_d[2];
|
||||
if(ack_d[1]==0){
|
||||
// 先判断主要错误,如果没有主要错误,则填充为子错误
|
||||
ack_d[1]=coder_judge(arr_data(data));
|
||||
if(ack_d[1]==0){
|
||||
ack_d[1]=ack_d[2];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
}
|
||||
|
||||
@@ -342,6 +360,8 @@ static void check_end(ucport_def *u,port_mcu *src,void *data,int ack,char *err_s
|
||||
arr_appends(a,w->ack,(6)*10);
|
||||
emit tran_send_signal(w->u.p,0x81,arr_temp(a));
|
||||
tran_set_busy(w->u.p,0);
|
||||
// 把命令字改为0x81用于接收主机应答
|
||||
w->u.cmd=0x81;
|
||||
g_self.step=1;
|
||||
}
|
||||
}
|
||||
@@ -372,6 +392,11 @@ static void check_del(ucport_def *u)
|
||||
free(u);
|
||||
}
|
||||
|
||||
static int check_dolater(ucport_def *u,uint8_t cmd,array_def *data,char *err_str)
|
||||
{
|
||||
DBG_LOG("recv check end signal.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static ucport_def *check(tran_def *t, uint8_t cmd,array_def *data)
|
||||
@@ -384,6 +409,7 @@ static ucport_def *check(tran_def *t, uint8_t cmd,array_def *data)
|
||||
u->u.p=t;
|
||||
u->u.del=check_del;
|
||||
u->u.doend=check_end;
|
||||
u->u.dolater=check_dolater;
|
||||
u->addrs_num=arr_get(data,0);
|
||||
u->type=arr_get(data,0);
|
||||
// 默认失败
|
||||
|
Reference in New Issue
Block a user