移植到stm32f1,实现手动线赋码控制器功能
This commit is contained in:
@@ -158,6 +158,123 @@ commend_export(code,code,"write uidcode to slave,uid_len=8,pw_len=4")
|
||||
|
||||
|
||||
|
||||
// 检测赋码
|
||||
|
||||
|
||||
typedef struct{
|
||||
handle_def h;
|
||||
uint8_t uid_size;
|
||||
uint8_t pw_size;
|
||||
uint8_t data[24];
|
||||
}code2_def;
|
||||
|
||||
|
||||
static void code2_start(handle_def *h)
|
||||
{
|
||||
code2_def *c=(code2_def *)h;
|
||||
port_set_busy(h->p,1);
|
||||
array_def *a=arr_creat();
|
||||
arr_append(a,c->uid_size);
|
||||
arr_append(a,c->pw_size);
|
||||
arr_append(a,1);// 此项为1,检测中赋码
|
||||
arr_appends(a,c->data,c->uid_size+c->pw_size);
|
||||
|
||||
list_def *l=list_creat_int();
|
||||
int cmds[]={0x0b};
|
||||
list_appends(l,cmds,1);
|
||||
l=list_temp(l);
|
||||
emit port_send_signal(h->p,port_get_addr(h->p),0x0b,l,arr_temp(a),60,5);
|
||||
}
|
||||
|
||||
|
||||
static void code2_dolater(handle_def *h,uint8_t src,uint8_t cmd,array_def *data,char *err_str)
|
||||
{
|
||||
if(port_get_busy(h->p)==0) return;
|
||||
if(cmd==0x02)
|
||||
{
|
||||
if(arr_get(data,0)==0)
|
||||
{
|
||||
port_set_busy(h->p,0);
|
||||
port_timer_stop(h->p);
|
||||
DBG_LOG("slave:%d, recv check data",src);
|
||||
arr_remove(data,0,1);
|
||||
DBG_LOG("slave:%d, recv:%s",src,str_temp(arr_string(data)));
|
||||
//emit port_end_signal(h->p,h->p,tappend(scheme_check_returns(c->sch,data),0),0,"ok");
|
||||
// 直接返回原始数据
|
||||
emit port_end_signal(h->p,h->p,data,0,"ok");
|
||||
// }else if(arr_get(data,0)==2){
|
||||
}else{
|
||||
// 检测中则继续发送
|
||||
list_def *l=list_creat_int();
|
||||
int arr[]={0x02};
|
||||
list_appends(l,arr,1);
|
||||
emit port_send_signal(h->p,port_get_addr(h->p),0x02,list_temp(l),arr_temp(arr_creat()),60,130);
|
||||
}
|
||||
// else{
|
||||
// port_set_busy(h->p,0);
|
||||
// port_timer_stop(h->p);
|
||||
// DBG_WARN("slave:%d,get check_result err,%s",src,str_temp(arr_string(data)));
|
||||
// emit port_end_signal(h->p,h->p,0,arr_get(data,0),"get check_result err");
|
||||
// }
|
||||
}
|
||||
else if(cmd==0x0b)
|
||||
{
|
||||
if(arr_get(data,0)==0)
|
||||
{
|
||||
int timeout =h->interval;
|
||||
DBG_LOG("slave:%d, check first ack,timeout=%d",src,timeout);
|
||||
list_def *l=list_creat_int();
|
||||
int arr[]={0x02};
|
||||
list_appends(l,arr,1);
|
||||
emit port_send_signal(h->p,port_get_addr(h->p),0x02,list_temp(l),arr_temp(arr_creat()),60,timeout/60);
|
||||
}
|
||||
else{
|
||||
port_set_busy(h->p,0);
|
||||
port_timer_stop(h->p);
|
||||
DBG_WARN("slave:%d,get start_check err,%s",src,str_temp(arr_string(data)));
|
||||
emit port_end_signal(h->p,h->p,0,-1,"get start_check err");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void code2_timeout(handle_def *h)
|
||||
{
|
||||
// 从机没有指定数目时从这里返回
|
||||
port_timer_stop(h->p);
|
||||
port_set_busy(h->p,0);
|
||||
DBG_WARN("slave:%d,%s timeout.",port_get_addr(h->p), h->name);
|
||||
emit port_end_signal(h->p,h->p,0,-1,"timeout");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// uid_size+pw_size不应大于24
|
||||
handle_def *code2_creat(int uid_size,int pw_size,uint8_t *data)
|
||||
{
|
||||
code2_def *c=calloc(1,sizeof(code2_def));
|
||||
param_check(c);
|
||||
if(uid_size+pw_size>24)
|
||||
{
|
||||
free(c);
|
||||
return 0;
|
||||
}
|
||||
c->uid_size=uid_size;
|
||||
c->pw_size=pw_size;
|
||||
memcpy(c->data,data,c->uid_size+c->pw_size);
|
||||
|
||||
handle_def *h=(handle_def *)c;
|
||||
h->static_=0;// 动态内存这项设置为0
|
||||
h->start=code2_start;
|
||||
h->dolater=code2_dolater;
|
||||
h->del=(void (*)(handle_def *))free;
|
||||
h->timeout=code2_timeout;
|
||||
h->interval=10000;
|
||||
h->name="code2";
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user