From 455f5a992d4e921e416b9ebf6e043d7dd0e37059 Mon Sep 17 00:00:00 2001 From: "mr.zhangsan" Date: Fri, 31 May 2024 02:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E4=BF=AE=E6=94=B9=E5=AE=8C?= =?UTF-8?q?=E6=AF=95=20AA=20id=20cmd=20num0=20num1=20data=20ocr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/app/app_weight.c | 71 +++++++++++++++++++++++++++++++++-------- source/app/app_weight.h | 43 +++++++++++++++++++++---- 2 files changed, 95 insertions(+), 19 deletions(-) diff --git a/source/app/app_weight.c b/source/app/app_weight.c index 46edc47..dcef016 100644 --- a/source/app/app_weight.c +++ b/source/app/app_weight.c @@ -370,6 +370,7 @@ void L3_weight_ONdebug(u8 filter)//// ON listen function L4_weight_out(); D_LED1_REV(); break; + case 0x20: ///// 校准 ////选择一个砝码,发送0x12指令,然后读取的数据 和砝码的重量使用 20 21 22参数来 @@ -384,26 +385,38 @@ void L3_weight_ONdebug(u8 filter)//// ON listen function /// Fe 01 00 00 c8 02 00 35 20kg 放置20kg 然后输入 /// Fe 02 00 01 d6 03 00 35 47kg 10个3kg砝码实际是27kg+20kg ////如果需要上位机设置 需要在上位机的串口 加上D4 D代表chuandi - if(pd->R1 < 3) + + //AA 02 20 00 03 pIndex kgx10_0 kgx10_1 ocr 对pIndex(0/1/2)点进行校准,校准值为kgx10 + if(pd485->buf[0] < 3) { - ts_weight_SPara.ts_WPoint[pd->R1].kg = D_2uc_u16(pd->R3,pd->R4); - ts_weight_SPara.ts_WPoint[pd->R1].adc = tst_weight.adc32;////使用当前采样值 + ts_weight_SPara.ts_WPoint[pd485->buf[0]].kg = D_2uc_u16(pd485->buf[1],pd485->buf[2]); + ts_weight_SPara.ts_WPoint[pd485->buf[0]].adc = tst_weight.adc32;////使用当前采样值 - printf5("\r\nset %d: %4x(%6d) %4x(%6d)\r\n",(int)pd->R1, - ts_weight_SPara.ts_WPoint[pd->R1].kg,ts_weight_SPara.ts_WPoint[pd->R1].kg, - ts_weight_SPara.ts_WPoint[pd->R1].adc,ts_weight_SPara.ts_WPoint[pd->R1].adc); + // printf5("\r\nset %d: %4x(%6d) %4x(%6d)\r\n",(int)pd->R1, + // ts_weight_SPara.ts_WPoint[pd->R1].kg,ts_weight_SPara.ts_WPoint[pd->R1].kg, + // ts_weight_SPara.ts_WPoint[pd->R1].adc,ts_weight_SPara.ts_WPoint[pd->R1].adc); + D_LED1_REV(); + L4_WPoint_out(); + D_LED1_REV(); + + //写入IAP + L3_R_2_S(); + L0_Iap_Program_array(D_EEP_BASE,D_struct2U8(S),D_S_LEN); } - - L3_R_2_S(); - L0_Iap_Program_array(D_EEP_BASE,D_struct2U8(S),D_S_LEN); + break; case 0x30: /// 清零指令 把当前的重量值作为0点; 可以在pad上配置参数 ////Fe 223344556677 21 - L4_weight_print(); + //L4_weight_print(); tst_weight.kgx10_zero = tst_weight.kgx10; - printf2("\r\n kgx10_zero= %4x(%4d)",tst_weight.kgx10_zero,tst_weight.kgx10_zero); + //printf2("\r\n kgx10_zero= %4x(%4d)",tst_weight.kgx10_zero,tst_weight.kgx10_zero); + + D_LED1_REV(); + L4_kgx10zero_out(); + D_LED1_REV(); + break; case 0x40: @@ -457,10 +470,11 @@ void L4_weight_print(void) printf2("out (%d)%4x\r\n", tst_weight.kgx10_out,tst_weight.kgx10_out); } -TS_weight_out_ ts_weight_out; + #if 0 +TS_weight_out_ ts_weight_out; void L4_weight_out(void) { ts_weight_out.fx = 0x55; @@ -485,9 +499,10 @@ void L4_weight_out(void) #else +TS_weight_out_ ts_weight_out; void L4_weight_out(void) { - U8 dnum = 12,total = 18; + U8 dnum = 12, total = 18; ts_weight_out.filter = 0xAA; ts_weight_out.slaveId = 0x02; ts_weight_out.cmd = 0x10; @@ -503,6 +518,36 @@ void L4_weight_out(void) L1_uartD_Array((u8 *)&ts_weight_out,total); } +TS_WPoint_out_ ts_wpoint_out; +void L4_WPoint_out(void) +{ + U8 dnum = 12, total = 18; + ts_wpoint_out.filter = 0xAA; + ts_wpoint_out.slaveId = 0x02; + ts_wpoint_out.cmd = 0x20; + ts_wpoint_out.num[0] = (dnum >> 8) & 0xFF; + ts_wpoint_out.num[1] = dnum & 0xFF; + Lc_buf_from_const_uc(ts_wpoint_out.wpoint, S.weight_SPara.ts_WPoint , sizeof(S.weight_SPara.ts_WPoint)); + ts_wpoint_out.ocr =0x33; + L1_uartD_Array((u8 *)&ts_wpoint_out,total); +} + + +TS_Kgx10zero_out_ ts_kgx10zero_out; +void L4_kgx10zero_out(void) +{ + U8 dnum = 2, total = 8; + ts_kgx10zero_out.filter = 0xAA; + ts_kgx10zero_out.slaveId = 0x02; + ts_kgx10zero_out.cmd = 0x30; + ts_kgx10zero_out.num[0] = (dnum >> 8) & 0xFF; + ts_kgx10zero_out.num[1] = dnum & 0xFF; + ts_kgx10zero_out.kgx10zero[0] = tst_weight.kgx10_zero >> 8 & 0xFF; + ts_kgx10zero_out.kgx10zero[1] = tst_weight.kgx10_zero >> 0 & 0xFF; + ts_kgx10zero_out.ocr =0x33; + L1_uartD_Array((u8 *)&ts_kgx10zero_out,total); +} + #endif diff --git a/source/app/app_weight.h b/source/app/app_weight.h index c04c4cd..2ac2196 100644 --- a/source/app/app_weight.h +++ b/source/app/app_weight.h @@ -58,6 +58,16 @@ Layer1: bsp: bsp_cs1232 最底层的adc的采样 #include "msp_uart1.h" #include "../bsp/bsp_cs1232.h" /////水一般是18-19升,再加上桶,就是大约20公斤 + + +typedef struct +{ + vU16 kg; + vU16 adc; ///kg 对应的adc的采样值 + +}TS_weight_point_;///8Bytes + + #if 0 typedef struct { @@ -76,7 +86,9 @@ typedef struct vU16 out6;//// 12 }TS_weight_out_; + #else + typedef struct { u8 filter; @@ -89,14 +101,31 @@ typedef struct u8 ocr; vU16 out6; }TS_weight_out_; -#endif -typedef struct +typedef struct { - vU16 kg; - vU16 adc; ///kg 对应的adc的采样值 + u8 filter; + u8 slaveId; + u8 cmd; + u8 num[2]; + TS_weight_point_ wpoint[3]; + u8 ocr; + vU16 out6; +}TS_WPoint_out_; + +typedef struct +{ + u8 filter; + u8 slaveId; + u8 cmd; + u8 num[2]; + u8 kgx10zero[2]; + u8 ocr; + vU16 out6; +}TS_Kgx10zero_out_; + +#endif -}TS_weight_point_;///8Bytes #define D_rev0x55aa55aa 0x55aa55aa @@ -198,7 +227,9 @@ extern void L3_task_weight_handler(TS_TASK_weight_ *s); ///extern void L3_weight_setPara(u8 filter); extern void L3_weight_ONdebug(u8 filter); extern void L4_weight_print(void); -void L4_weight_out(void); +extern void L4_weight_out(void); +extern void L4_WPoint_out(void); +extern void L4_kgx10zero_out(void); #define D_get_weight() tst_weight.kgx10