diff --git a/source/.vscode/settings.json b/source/.vscode/settings.json new file mode 100644 index 0000000..55b70af --- /dev/null +++ b/source/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "msp_uart1.h": "c" + } +} \ No newline at end of file diff --git a/source/app/app_weight.c b/source/app/app_weight.c index f11ceea..46edc47 100644 --- a/source/app/app_weight.c +++ b/source/app/app_weight.c @@ -251,6 +251,7 @@ void L3_task_weight_cal(void) */ +#if 0 void L3_weight_ONdebug(u8 filter)//// ON listen function { if(filter == pd->filter) @@ -351,6 +352,85 @@ void L3_weight_ONdebug(u8 filter)//// ON listen function printfs("333"); } } + +#else +void L3_weight_ONdebug(u8 filter)//// ON listen function +{ + // printf(" \r\n0->filter=%X ", (int)filter); + // printf(" \r\n1->filter=%X slaveId=%X cmd=%X len = %d ", (int)pd485->filter,(int)pd485->slaveId, (int)pd485->cmd, (int)ts_Urec[D_UART1].num); + // D_LED2_REV(); + if(filter == pd485->filter) + { + // L1_uartD_Arrayhex((u8*)pd,9); + switch (pd485->cmd) + { + case 0x10: + ////读取称重 + D_LED1_REV(); + L4_weight_out(); + D_LED1_REV(); + break; + case 0x20: + ///// 校准 + ////选择一个砝码,发送0x12指令,然后读取的数据 和砝码的重量使用 20 21 22参数来 + ///fx R1 R2 R3R4 R5R6 ocr + ///Fe ch 00 2233 4455 35 kg= 0x2233 + + ////校准20kg 输入 Fe 01 00 00 c8 02 00 35 + ///Fe 01 00 00 c8 02 00 35 kg= 0x00c8=200d///需要校准的重量的 20kg 200d=0xc8 + ///校准20kg 输入 Fe 01 00 00 c8 02 00 35 + + /// Fe 00 00 00 00 01 00 35 校准零点 不需要上电即可 + /// 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) + { + 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;////使用当前采样值 + + 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); + } + + 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(); + tst_weight.kgx10_zero = tst_weight.kgx10; + printf2("\r\n kgx10_zero= %4x(%4d)",tst_weight.kgx10_zero,tst_weight.kgx10_zero); + break; + + case 0x40: + ///Fe 11 22 33 44 55 66 23 + TTSS_run_times(3) + { + printf5("\r\n%d: %4x(%4d ) %4x(%6d)\r\n",(int)tst_v.i, + ts_weight_SPara.ts_WPoint[tst_v.i].kg,ts_weight_SPara.ts_WPoint[tst_v.i].kg, + ts_weight_SPara.ts_WPoint[tst_v.i].adc,ts_weight_SPara.ts_WPoint[tst_v.i].adc); + } + break; + + case 0x50: ///读取当前的重量和传感器数值 + ///Fe 223344556677 12 + printfs("\r\n "); + L4_weight_print(); + break; + + default: + printfs(" pp error\r\n "); + break; + }; + } +} +#endif + + void L4_weight_print(void) { L1_uartD_ushex(ts_adc_samples[0].out1_adc);L1_uartD_uc(' '); @@ -380,6 +460,7 @@ void L4_weight_print(void) TS_weight_out_ ts_weight_out; +#if 0 void L4_weight_out(void) { ts_weight_out.fx = 0x55; @@ -402,207 +483,26 @@ void L4_weight_out(void) } -#if 0 +#else -void L3_adc_zero(void) -{ - L3_out_zero(0); - L3_out_zero(1); - L3_out_zero(2); - L3_out_zero(3); - -// printf("\r\niapData.zeroout= %d = 0x%4x\r\n", iapData.zeroout, iapData.zeroout); -// printf("\r\nR.sd.zeroout= %d = 0x%4x offset %d = 0x%4x\r\n", R.sd.zeroout, R.sd.zeroout,ts_adc_samples[0].offset,ts_adc_samples[0].offset); -/* -S.sd.offset[0] = ts_adc_samples[0].offset; -S.sd.offset[1] = ts_adc_samples[1].offset; -S.sd.offset[2] = ts_adc_samples[2].offset; -S.sd.offset[3] = ts_adc_samples[3].offset; - -ts_weight_SPara.offset[0] = S.sd.offset[0]; -ts_weight_SPara.offset[1] = S.sd.offset[1]; -ts_weight_SPara.offset[2] = S.sd.offset[2]; -ts_weight_SPara.offset[3] = S.sd.offset[3]; -L0_waitFree_uartN(0); -printf("\r\nR.sd.offset 0x%4x,0x%4x,0x%4x,0x%4x,\r\n",S.sd.offset[0],S.sd.offset[1],S.sd.offset[2],S.sd.offset[3]); - -*/ - -/// L4_reg_2_iap();///写入iap -/// L4_iap_2_reg();///读取出来验证 -} - -void L3_task_weight_set(Ts_uart_rev_ *ph4) +void L4_weight_out(void) { - TS_P_debug *td; - if(ph4->debugok) - { ph4->debugok = 0; - td = (TS_P_debug *)ph4->buf; - - /// TS_PH4_modbus *ts_modbus = (TS_PH4_modbus *)ph4->buf; - - L0_uartN_uchexArray(0,ph4->buf, 8); - if(0xfd == td->filter) - { - if(0x04 == td->R1)///设置四个传感器的清零 - { //// fd 04 33 44 55 - L0_uart0_sendstr("\r\n 4sensor zero \r\n"); - L3_adc_zero(); - }else if(0x01 == td->R1)///设置重量的清零 - { //// fd 04 33 44 55 - L0_uart0_sendstr("\r\n--weight zero-- \r\na b= "); - - }else if(0x02 == td->R1)///读取 - { - if(0x00 == td->R2) - {//// fd 02 00 44 55 - L0_uart0_sendstr("\r\n--read iapData-- \r\n"); - L4_print_iap(&iapData); - }else - {//// fd 02 33 44 55 - L0_uart0_sendstr("\r\n--read R.sd-- \r\n"); - L4_print_iap(&R.sd); - } - } - - else - { - L0_uart0_sendstr("\r\n command error \r\n"); - - } - } - else if(0xf5 == td->filter) - {///设置重量 - if(td->R1 < 3)/// - { - //// R1 R2 R3 - //// f5 00 33 44 55 把当前的adc的值作为第R1个校准点的值 - R.sd.zerows[td->R1].adc = (vU16)tst_weight.out6; - - Lc_buf_copy_uc((u8 *)&R.sd.factory_ws,(u8 *)&R.sd.zerows,12); - L4_reg_2_iap();///写入iap - L4_iap_2_reg();///读取出来验证 - }else - { - - } - L0_waitFree_uartN(0); - printf("\r\n set[ %d].adc = 0x%04x\r\n",(int)td->R1, (vU16)tst_weight.out6); - } - - - else if(0xf6 == td->filter) - {///设置砝码 - if(td->R1 < 3)/// - { - //// R1 R2 R3 - //// f5 00 33 44 55 把当前第R1个校准曲线的点的kg的值 0x3344 - R.sd.zerows[td->R1].kg = D_2uc_u16(R2,R3); - - Lc_buf_copy_uc((u8 *)&R.sd.factory_ws,(u8 *)&R.sd.zerows,12); - L4_reg_2_iap();///写入iap - L4_iap_2_reg();///读取出来验证 - }else - { - - } - L0_waitFree_uartN(0); - printf("\r\nset [ %d],Kg = 0x%04x\r\n",(int)td->R1, R.sd.zerows[td->R1].kg ); - } - - - else - { - - } - } + U8 dnum = 12,total = 18; + ts_weight_out.filter = 0xAA; + ts_weight_out.slaveId = 0x02; + ts_weight_out.cmd = 0x10; + ts_weight_out.num[0] = (dnum >> 8) & 0xFF; + ts_weight_out.num[1] = dnum & 0xFF; + ts_weight_out.sensor_adc[0]=ts_adc_samples[0].out1_adc; + ts_weight_out.sensor_adc[1]=ts_adc_samples[1].out1_adc; + ts_weight_out.sensor_adc[2]=ts_adc_samples[2].out1_adc; + ts_weight_out.sensor_adc[3]=ts_adc_samples[3].out1_adc; + ts_weight_out.kgx10_out = tst_weight.kgx10_out; + ts_weight_out.adc32= tst_weight.adc32;////采样值用作校准时使用 + ts_weight_out.ocr =0x33; + L1_uartD_Array((u8 *)&ts_weight_out,total); } - -/////////cc 2023/04/06--7:3:24 协议解析 -void L3_weight_setPara(u8 filter) -{ - if(filter == Ts_debug.td->filter) - { - L1_uartD_uc('D'); - L0_uart0_0d0a(); - - - if(0x01 == Ts_debug.td->ocr) - { - if(0x04 == Ts_debug.td->R1)///设置四个传感器的清零 - { //// fd 04 33 44 01 - L0_uart0_sendstr("\r\n 4sensor zero \r\n"); - L3_adc_zero(); - }else if(0x01 == Ts_debug.td->R1)///设置重量的清零 - { //// fd 01 33 44 01 - L0_uart0_sendstr("\r\n--weight zero-- \r\na b= "); - - }else if(0x02 == Ts_debug.td->R1)///读取 - { - if(0x00 == Ts_debug.td->R2) - {//// fd 02 00 44 01 - L0_uart0_sendstr("\r\n--read ts_weight_save-- \r\n"); - L4_print_iap(&ts_weight_save); - }else - {//// fd 02 33 44 01 - L0_uart0_sendstr("\r\n--read R.sd-- \r\n"); - L4_print_iap(&R.sd); - } - } - - else - { - L0_uart0_sendstr("\r\n command error \r\n"); - - } - } - else if(0x02 == Ts_debug.td->ocr) - {///设置重量 - if(Ts_debug.td->R1 < 3)/// - { - //// R1 R2 R3 - //// fd 00 33 44 02 把当前的adc的值作为第R1个校准点的值 - R.sd.zerows[Ts_debug.td->R1].adc = (vU16)tst_weight.out6; - - Lc_buf_copy_uc((u8 *)&R.sd.factory_ws,(u8 *)&R.sd.zerows,12); - L4_reg_2_iap();///写入iap - L4_iap_2_reg();///读取出来验证 - }else - { - - } - L0_waitFree_uartN(0); - printf("\r\n set[ %d].adc = 0x%04x\r\n",(int)Ts_debug.td->R1, (vU16)tst_weight.out6); - } - - - else if(0x03 == Ts_debug.td->ocr) - {///设置砝码 - if(Ts_debug.td->R1 < 3)/// - { //200 - //// R1 R2 R3 - //// fd 00 33 44 03 把当前第R1个校准曲线的点的kg的值 0x3344 - R.sd.zerows[Ts_debug.td->R1].kg = D_2uc_u16(Ts_debug.td->R2,Ts_debug.td->R3); - Lc_buf_copy_uc((u8 *)&R.sd.factory_ws,(u8 *)&R.sd.zerows,12); - L4_reg_2_iap();///写入iap - L4_iap_2_reg();///读取出来验证 20 14 - }else - { - - } - L0_waitFree_uartN(0); - printf("\r\nset [ %d],Kg = 0x%04x\r\n",(int)Ts_debug.td->R1, R.sd.zerows[Ts_debug.td->R1].kg ); - } - - - else - { - - } - - } -} #endif diff --git a/source/app/app_weight.h b/source/app/app_weight.h index 7a8f9f0..c04c4cd 100644 --- a/source/app/app_weight.h +++ b/source/app/app_weight.h @@ -58,6 +58,7 @@ Layer1: bsp: bsp_cs1232 最底层的adc的采样 #include "msp_uart1.h" #include "../bsp/bsp_cs1232.h" /////水一般是18-19升,再加上桶,就是大约20公斤 +#if 0 typedef struct { ///40Bytes @@ -75,6 +76,20 @@ typedef struct vU16 out6;//// 12 }TS_weight_out_; +#else +typedef struct +{ + u8 filter; + u8 slaveId; + u8 cmd; + u8 num[2]; + vU16 sensor_adc[4]; + vU16 kgx10_out; + vU16 adc32; + u8 ocr; + vU16 out6; +}TS_weight_out_; +#endif typedef struct { diff --git a/source/app/main.c b/source/app/main.c index 1ebdc82..2cce03e 100644 --- a/source/app/main.c +++ b/source/app/main.c @@ -79,7 +79,8 @@ void L0_main_init(void) L3_debug_drv_init(); L1_task_tick_init(); - L0_timer0_Init();ET0 = 1; + L0_timer0_Init(); + ET0 = 1; printf1("\r\nD_sys_MainFre %ld",D_sys_MainFre); @@ -108,23 +109,18 @@ void main(void) { s_nos_tick.t1s_heartbeat = 0; ///L1_uartD_uc('.'); - D_LED2_REV(); + // D_LED2_REV(); } - TTSS_run_every(s_nos_tick.stamp,40) - D_LED1_REV(); - L4_weight_out(); - ///55 0D 0C 90 F5 77 FF 52 80 00 00 00 33 - TTSS_run_every_end + // TTSS_run_every(s_nos_tick.stamp,40) + // D_LED1_REV(); + // L4_weight_out(); + // ///55 0D 0C 90 F5 77 FF 52 80 00 00 00 33 + // TTSS_run_every_end if(L2_debug_ONcomand()) { - L3_test_ONdebug(D_cmd_filter_debug);///fd xx xx/// - L3_weight_ONdebug(D_cmd_filter_weight);///fe xx xx/// - // L3_ADC_debug(D_cmd_filter_adc);///fa xx xx - // L3_moto_debug(D_cmd_filter_moto);///f0 xx xx/ - // L3_lora_debug(D_cmd_filter_lora);// } L3_task_weight_handler(&tst_weight); } diff --git a/source/clib/c_lib.c.bak b/source/clib/c_lib.c.bak deleted file mode 100644 index de6111c..0000000 --- a/source/clib/c_lib.c.bak +++ /dev/null @@ -1,1787 +0,0 @@ -/***************************************************************************** - * uart.c: UART API file for NXP LPC17xx Family Microprocessors - * - * Copyright (c) 2023 CCSENS - * All rights reserved. - * - * History - * 2009.05.27 ver 1.00 Prelimnary version, first Release - * -******************************************************************************/ - - -#include "c_type51.h" -#include "c_lib.h" -///#include "../msp/msp_uart0.h" -////#include "../msp/time.h" -#include - - -code vU16 us2fun2[5] -={ -1, //0 -10,// 1 -100,// 2 -1000,// 3 -10000// 4 - -}; - - - -code vU32 ul2fun2[10] -={ -1, //0 -10,// 1 -100,// 2 -1000,// 3 -10000,// 4 -100000, -1000000, -10000000, -100000000, -1000000000,//9 -}; - -#if 0 - -同样是转义字符,\n 的作用相当于“Enter”键,而想退回去就可以用“Backspace”键,也就是\b -这里还有一个可能用到的转义字符是\r :使光标回退到本行开头 - \b 退格 - \n 换行 0x0A - \f 走纸 - \t 水平制表 - \v 垂直制表 - -\r 0x0d - -//如果追求内存紧张加上const INT32U ul2fun2[10] - - -void Lc_float2str(float f,U8 *str,U8 point_num); -{ - S32 i = 0; U32 u32i = 0; - U8 n = 0;U8 m = 0;U8 d = 0; - switch(point_num) - { - case 0: - - break; - case 1: - f *= 10.; - - break; - case 2: - f *= 100.; - - break; - case 3: - f *= 1000.; - - break; - default: - - break; - }; - i = (S32)f; -// Lc_float2str(1.23,&d,2) -// Lc_float2str(0.23,&d,2) -// Lc_float2str(23.4,&d,1) -// Lc_float2str(-12345.236,&d,2) - // 1,1.2 12.3 240 0.12 - if(i < 0) - { - str[n] = '-'; - n ++; - i *= -1; - } - u32i = (U32)i; - m = 4; - if(u32i >= ul2fun2[m]) u32i = ul2fun2[m] - 1; - for(m = 0;m > 4;m ++) - {// 43210 - d = (u32i /ul2fun2[m])%10; - if (d > 0) - str[n] = d; - n ++; - } - - if (n == point_num) - { - str[n] ='.'; - n ++; - } - - - str[n] = i%10 - -} - - -#endif - - -U32 Abs2(S32 a) -{ - if(a < 0) - { - a = -a; - } - return a; -} - -///despiking 削峰 -void Lc_despiking_shift3_U16(vU16 *m) -{///只要中间的数据同时大于或小于两边的数据,则去掉 - if(m[1] >= m[0]) - { - if(m[1] > m[2]) - { - m[1] = m[0]; - } - }else if(m[1] < m[0]) - { - if(m[1] < m[2]) - { - m[1] = m[0]; - } - }else - { - - } -} - -int libc_strlen(char *str) -{ - char *tmp = str; - while(*tmp++) - ; - return tmp - str - 1; -} - -U8* Lc_strcpy(U8* dst,const char* str) -{ - U8 *p = dst; - while(*dst++ = *str++); - return p; -} - - -U8 Lc_strStartsWith(U8 *s1,U8 *s2) -{ - while(*s1 && *s2) - { - if(*s1++ != *s2++) - { - return 0; - } - } - return (*s2 == 0); -} - - -int hexToDec(const char *source) -{ - int sum = 0; - long t = 1; - int i,len; - - len = Lc_strlen(source); - for(i=len-1; i>=0; i--) - { - sum += t * getIndexOfSigns(*(source + i)); - t *= 16; - } - - return sum; - -} -unsigned char hex_to_char(unsigned char hex) -{ - if((hex>=0x30)&&(hex<=0x39)) - hex = hex-0x30; - else if((hex>=0x41)&&(hex<=0x5A)) // capital - hex = 'A' + (hex - 0x41); - else if((hex>=0x61)&&(hex<=0x7A)) // little case - hex = 'a' + (hex - 0x61); - else - hex = 0xff; - return hex; -} - -int getIndexOfSigns(char ch) -{ - if(ch >= '0' && ch <= '9') - { - return ch - '0'; - } - if(ch >= 'A' && ch <='F') - { - return ch - 'A' + 10; - } - if(ch >= 'a' && ch <= 'f') - { - return ch - 'a' + 10; - } - return -1; -} - - -void Lc_buf_copy_uc(U8 *d,const U8 *s,U16 num) -{ - U16 i; - for(i = 0; i < num; i ++) - { - *(d+i) = *(s+i); - } - -} - -vU8 Lc_U8_media3(vU8 a,vU8 b,vU8 c) -{ - if(a > b) - { - if(b > c) - { - return b; - }else - {// b a) - {/// a a) - {// a b) - { - if(b > c) - { - return b; - } - else - {// b a) - {/// a a) - {// a arr[j+1]) - { - ok = 0; - tmp = arr[j]; - arr[j] = arr[j+1]; - arr[j+1] = tmp; - } - } - if(ok) - { - break; - } - } -} - -vS32 Lc_S32_media(vS32 val[],S16 num) -{ - if(num <= 1) - { - return val[0]; - } - else - { - Lc_array_sort(val,num); - return val[num/2]; - } -} -U32 Lc_vS32_media(U32 *d, U8 n) -{ - U8 i = 0,j = 0; - U32 h = 0; - if(n == 1) - { - return d[0]; - } - for(i=0;i d[j]) - { - h = d[i]; - d[i] = d[j]; - d[j] = h; - } - } - } - if(n%2 != 0) //奇数 - { - return d[n/2]; - } - else//偶数 - { - return ((d[n/2] + d[n/2-1])/2); - } -} - - -U32 Lc_vU32_avg(U32 *d, U8 n) -{ - U8 i = 0; - U32 sum = 0; - if(n == 1) - { - return d[0]; - } - for(i=0;i 0x31 0x31 0x32 0x32 '1' '1' '2' '2' -void Lc_hex2ascii(U8 *buf,U16 len,U8 *ascii) -{ - vU16 t = 0,m = 0; - for(t = 0;t < len;t ++) - { - - #if 1 - ascii[m] = cguHex2Char[D_uc_high(buf[t])][1]; - m ++; - ascii[m] = cguHex2Char[D_uc_low (buf[t])][1]; - m ++; - ascii[m] =0x20; - m ++; - #else - - ascii[m] = 0x30+m; - m++; - ascii[m] = 0x30+m; - m++; - ascii[m] = 0x30+m; - m++; - - - #endif - } -} - -/// cguHex2Char[0][0] = 0x00 cguHex2Char[0][1] = 0x30 -unsigned char code cguHex2Char[16][2] -={ - 0x00,'0', - 0x01,'1', - 0x02,'2', - 0x03,'3', - 0x04,'4', - 0x05,'5', - 0x06,'6', - 0x07,'7', - 0x08,'8', - 0x09,'9', - 0x0A,'A', - 0x0B,'B', - 0x0C,'C', - 0x0D,'D', - 0x0E,'E', - 0x0F,'F' -}; - - -void Lc_for_int16(U16 i) -{ - U16 m; - for(m=i;m>0;m--) - { - ///L0_Delay_1ms(); - } -} - -U32 Lc_abs(vS32 a,vS32 b) -{ - if(a >= b) - { - return a - b; - } - return b - a; -} - -void Lc_encrypt_id(U8 *enc_dst, U8 *enc_src, U32 enc_key, U8 src_len) -{ - U8 i = 0,key0,key1,key2,key3; - key0 = enc_key >> 24 & 0xFF; - key1 = enc_key >> 16 & 0xFF; - key2 = enc_key >> 8 & 0xFF; - key3 = enc_key >> 0 & 0xFF; - - for(i=0;i> 0) & 0xFF) << 24) | (((dat >> 8) & 0xFF) << 16) | (((dat >> 16) & 0xFF) << 8) | (((dat >> 24) & 0xFF) << 0); - } - return res; -} - -U32 htonl(U32 dat) -{ - U32 res = 0; - if(dat == 0 || isBigEndianOrder()){ - res = dat; - }else{ - res = (((dat >> 0) & 0xFF) << 24) | (((dat >> 8) & 0xFF) << 16) | (((dat >> 16) & 0xFF) << 8) | (((dat >> 24) & 0xFF) << 0); - } - return res; -} - -U16 ntohs(U16 dat) -{ - U16 res = 0; - if(dat == 0 || isBigEndianOrder()){ - res = dat; - }else{ - res = (((dat >> 0) & 0xFF) << 8) | (((dat >> 8) & 0xFF) << 0) ; - } - return res; -} - -U16 htons(U16 dat) -{ - U16 res = 0; - if(dat == 0 || isBigEndianOrder()){ - res = dat; - }else{ - res = (((dat >> 0) & 0xFF) << 8) | (((dat >> 8) & 0xFF) << 0) ; - } - return res; -} -#endif - -#if 0///#ifdef D_flash_max - - -// 0--9 '0' -// ABCEDF------0X41-- 87-6= 81 -U8 Lc_Hex2Char(U8 CharStr) -{ - U8 rd; - if (CharStr >9)//A 10-9+ - { - rd = (CharStr - 10 + 'A') ; - } - else - { - rd = (CharStr + '0') ; - } - return rd; -} -// 0x30'0'----'9'--> 0x0----0x09 -//0x61--'a'---'f'--> 0x0a---0x0f -//0x41 'A'--'F'--> 0x0a---0x0f -U8 Lc_Char2Hex(U8 CharStr) -{ - U8 rd; - if (CharStr >= 'a')//0x61--'a'---'f'--> 0x0a---0x0f - { - rd = (CharStr - 'a' + 0x0a) ; - } - else if (CharStr >= 'A')//0x61--'a'---'f'--> 0x0a---0x0f - { - rd = (CharStr - 'A' + 0x0a) ; - } - else - { - rd = (CharStr - '0') ; - } - return rd; -} -//catch_protocol(s,d); -// 从 d中提取出协议,一般用于协议打包后的调试和透传, -// *s="iicsend:12 34 56 78 9a \r\n"; -// i: 012345678 -// 返回协议字节数量 -// extern int strpos (const char *s, char c); -unsigned char catch_protocol (const char *d_src,char d_protocol[]) -{ - unsigned char n = 0,len = 0;//,i = 0; - int i = 0; - i = strpos(d_src, (char)':'); - i ++; - len = strlen (d_src) - 2; - while(i < len) - { - d_protocol[n] = Lc_Char2Hex(*(d_src+i))*16; - i ++; - d_protocol[n] += Lc_Char2Hex(*(d_src+i)); - i ++;i ++; - n ++; - } - return n; -} - -/* - * 函数名:itoa 不同类型的cpu不一样 并且支持的最大数据取决于i = 1000000;D_value_max - * 描述 :将整形数据转换成字符串 - * 输入 :-radix =10 表示10进制,其他结果为0 - * -value 要转换的整形数 - * -buf 转换后的字符串 - * -radix = 10 - * 输出 :无 - * 返回 :无 - * 调用 :被USART1_printf()调用 - - Lc_int2a - - - */ - #define D_value_max 100000 -char *Lc_int2a(vS32 value, char *string, UN_TYPE radix) -{ - vS32 i, d; - UN_TYPE flag = 0; - vU16 U16temp = 0; - char *ptr = string; - - /* This implementation only works for decimal numbers. */ - //value - if (!value) - { - *ptr++ = 0x30; - *ptr = 0; - return string; - } - U16temp = value; - switch(radix) - {//%X2 %X4 %X6 - case '2': - *ptr++ = Lc_Hex2Char((U16temp>>4)&0x0f); - *ptr++ = Lc_Hex2Char((U16temp)&0x0f); - *ptr = 0; - return string; - break; - case '4': - *ptr++ = Lc_Hex2Char((U16temp>>12)&0x0f); - *ptr++ = Lc_Hex2Char((U16temp>>8)&0x0f); - *ptr++ = Lc_Hex2Char((U16temp>>12)&0x0f); - *ptr++ = Lc_Hex2Char((U16temp>>8)&0x0f); - *ptr++ = Lc_Hex2Char((U16temp>>4)&0x0f); - *ptr++ = Lc_Hex2Char((U16temp)&0x0f); - *ptr = 0; - return string; - break; - #if 0 - case '8': - *ptr++ = Lc_HexToChar((value>>24)&0x0f); - *ptr++ = Lc_HexToChar((value>>20)&0x0f); - *ptr++ = Lc_HexToChar((value>>16)&0x0f); - *ptr++ = Lc_HexToChar((value>>12)&0x0f); - *ptr++ = Lc_HexToChar((value>>8 )&0x0f); - *ptr++ = Lc_HexToChar((value>>4 )&0x0f); - *ptr++ = Lc_HexToChar((value)&0x0f); - *ptr = 0; - return string; - break; - #endif - case 10: - /* if this is a negative value insert the minus sign. */ - if (value < 0) - { - *ptr++ = '-'; - - /* Make the value positive. */ - value *= -1; - } - i = D_value_max; - if (value > i) - { - value = i; - } - for (;i > 0; i /= 10) - { - d = value / i; - - if (d || flag) - { - *ptr++ = (char)(d + 0x30); - value -= (d * i); - flag = 1; - } - } - - /* Null terminate the string. */ - *ptr = 0; - - return string; - break; - default: - *ptr++ = 0x30; - *ptr = 0; - return string; - break; - } - - -} /* NCL_Itoa */ -/// bits:生成的字符共几位数据 -void Lc_int2D(vS16 value, char *string,char bits) -{ - vS16 i, d; - UN_TYPE flag = 0; -// vU16 U16temp = 0; - char *ptr = string; - - /* This implementation only works for decimal numbers. */ - //value - -// U16temp = value; - /* if this is a negative value insert the minus sign. */ - if (value < 0) - { - *ptr++ = '-'; - value *= -1; - }else - { - *ptr++ = ' '; - - } - - - - i = us2fun2[bits-1]; - for (;i > 0; i /= 10) - { - d = value / i; - if((0 == d)&&(0 == flag)&&(1 != i)) - {/// - *ptr++ = ' '; - - }else - { - flag = 1;///第一个非零的数据出现 - *ptr = (char)(d + 0x30); - *ptr++; - value -= (d * i); - } - } - -} /* NCL_Itoa */ - - -//void (*L0_uart0_uc)(U8 ww); - -// 带buf的printf fixme: 需要精简地方 -void Lc_print_buf(char *dat4,...) -{ - const char *s; - vS32 d; - char buf[64]; ///取决于cpu的内存大小,如果出现问题,请先定位到此处 -// char send[16]; - char n = 0; - char *dat = 0; - va_list ap;//va_list 是一个字符指针,可以理解为指向当前参数的一个指针, - //取参必须通过这个指针进行。 -// 在调用参数表之前,定义一个 va_list 类型的变量, -//(假设va_list 类型变量被定义为ap); - va_start(ap, dat); -// 然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数, -//这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在 -//变参表前面紧挨着的一个变量,即“...”之前的那个参数; - - dat = dat4; -// 然后是获取参数,调用va_arg,它的第一个参数是ap, -//第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值, -//并且把 ap 的位置指向变参表的下一个变量位置; - //"e645654675y73\0" - while ( *dat != 0) // 判断是否到达字符串结束符 - { - if ( *dat == 0x5c ) //'\' - { - switch ( *++dat ) - { - case 'r': //回车符 - ts_uart_send_depot.buf[n ++] = 0x0d;//L0pf_send_uc(0x0d); - dat ++; - break; - - case 'n': //换行符 - ts_uart_send_depot.buf[n ++] = 0x0a;//L0pf_send_uc(0x0a); - dat ++; - break; - - case 't': // - ts_uart_send_depot.buf[n ++] = 0x09;//L0pf_send_uc(0x09); - dat ++; - break; - default: - dat ++; - break; - } - } - else if ( *dat == '%') - { // - switch ( *++dat ) - { - case 'C': - case 'c': //字符 - //va_arg()里的任务就是根据指定的参数类型 - //取得本参数的值,并且把指针调到下一 - //个参数的起始地址 - //#define va_arg(ap,t) - //( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) - - //char *ap; %c " , 0x30, - s = va_arg(ap, const char *); // 0x30 - ts_uart_send_depot.buf[n ++] = (char)s;// L0pf_send_uc((char)s); // '0' - dat++; - break; - case 'd': //十进制 - //" %d",0x30, - //" %d",48, - // int i = 48; - //" %d",i, - - d = va_arg(ap, int); // 0x30 =48d - Lc_int2a(d, buf, 10); //"buf="48" buf[0]='4' buf[1]='8' - for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s - { //\0 - ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); - //printf("%c",*s); - } - dat++; - break; - case 'X': - case 'x': //字符串 - d = va_arg(ap, int); // 0x30 =48d - dat++;//%X2 %X4 %X8 - Lc_int2a(d, buf, *dat); //"buf="48" buf[0]='4' buf[1]='8' - for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s - { //\0 - ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); - } - dat++; - break; - case 'S': - case 's': //字符串 - s = va_arg(ap, const char *); - for ( ; *s; s++) - { - ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); - } - dat++; - break; - case 'f': //十进制 - d = va_arg(ap, int); - Lc_int2a(d, buf, 10); - for (s = buf; *s; s++) - { - ts_uart_send_depot.buf[n ++] = *s;//L0pf_send_uc(*s); - - } - dat++; - break; - default: - dat++; - break; - } - } /* end of else if */ - else - { - ts_uart_send_depot.buf[n ++] = (*dat++);//L0pf_send_uc( *dat++); - } - }//end while.... - ts_uart_send_depot.max = n; - ts_uart_send_depot.p = ts_uart_send_depot.buf; - L0_uart0_sendbuf(); -}// -#endif - -#if 0 //5436345673456 -/******************************************************************** -* -* 名称: L0_Usend_uc_hex -* 说明: 例如:L0_Usend_uc_hex(0x0c); output " 0c " -* 功能: 发送数据 -* 调用: SendHUc()Lc_HexToChar() -* 输入: -* 返回值: 无 -***********************************************************************/ -void Lc_uc_hex(char ww) -{ - L0_uart0_uc(Lc_Hex2Char((ww>>4)&0x0f)); - L0_uart0_uc(Lc_Hex2Char(ww&0x0f)); -} - -void Lc_us_hex(U16 ww) -{// - U8 t; - t = (U8)(((ww >> 8)&0x00ff)); - Lcp_uc_hex(t); - t = (U8)(((ww )&0x00ff)); - Lcp_uc_hex(t); -} - -void Lc_print_NC(char *dat,...) -{ - -} -// 非缓存模式的打印 fixme: 发送16进制数据时有bug -void Lc_print33333(char *dat4,...) -{ - const char *s; - vS32 d; - char buf[16];//char t; - char *dat = NULL; - va_list ap;//va_list 是一个字符指针,可以理解为指向当前参数的一个指针, - //取参必须通过这个指针进行。 -// 在调用参数表之前,定义一个 va_list 类型的变量, -//(假设va_list 类型变量被定义为ap); - va_start(ap, dat4); -// 然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数, -//这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在 -//变参表前面紧挨着的一个变量,即“...”之前的那个参数; -dat =dat4; -// 然后是获取参数,调用va_arg,它的第一个参数是ap, -//第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值, -//并且把 ap 的位置指向变参表的下一个变量位置; - //"e645654675y73\0" - while ( *dat != 0) // 判断是否到达字符串结束符 - { - if ( *dat == 0x5c ) //'\' - { - switch ( *++dat ) - { - case 'r': //回车符 - L0_uart0_uc(0x0d); - dat ++; - break; - - case 'n': //换行符 - L0_uart0_uc(0x0a); - dat ++; - break; - - case 't': // - L0_uart0_uc(0x09); - dat ++; - break; - default: - dat ++; - break; - } - } - else if ( *dat == '%') - { // - switch ( *++dat ) - { - case 'C': - case 'c': //字符 - //va_arg()里的任务就是根据指定的参数类型 - //取得本参数的值,并且把指针调到下一 - //个参数的起始地址 - //#define va_arg(ap,t) - //( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) - - //char *ap; %c " , 0x30, - s = va_arg(ap, const char *); // 0x30 - L0_uart0_uc((char)s); // '0' - dat++; - break; - case 'd': //十进制 - //" %d",0x30, - //" %d",48, - // int i = 48; - //" %d",i, //#define va_arg(ap,t) (((t *)ap)++[0]) //(((int *)ap)++[0]) - - d = va_arg(ap, int); // 0x30 =48d - d >>= 8; - Lc_int2a(d, buf, 10); //"buf="48" buf[0]='4' buf[1]='8' - for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s - { //\0 - L0_uart0_uc(*s); - //printf("%c",*s); - } - dat++; - break; - case 'X': - case 'x': //字符串 - d = va_arg(ap, int); // 0x30 =48d - d >>= 8; - dat++;//%X2 %X4 %X8 - Lc_int2a(d, buf, *dat); //"buf="48" buf[0]='4' buf[1]='8' - for (s = buf; *s; s++) // "48"----'4'--'8' '\0'--*s - { //\0 - L0_uart0_uc(*s); - } - dat++; - break; - case 'S': - case 's': //字符串 - s = va_arg(ap, const char *); - for ( ; *s; s++) - { - L0_uart0_uc(*s); - } - dat++; - break; - case 'f': //十进制 - d = va_arg(ap, int); - Lc_int2a(d, buf, 10); - for (s = buf; *s; s++) - { - L0_uart0_uc(*s); - - } - dat++; - break; - default: - dat++; - break; - } - } /* end of else if */ - else - { - L0_uart0_uc(*dat ++); - //t = *dat; - //L0pf_send_uc = L0_uart0_uc; - //L0pf_send_uc(t); - //L0_uart0_uc(t); - //dat++; - } - }//end while....斯蒂芬 -}// - - - - - -///计算CRC校验码 -unsigned int CRC16(unsigned char *ptr, unsigned char len) -{ - unsigned int crc=0xffff; - unsigned char i; - while(len--) - { - crc ^=*ptr++; - for(i=0;i<8;i++) - { - if(crc & 0x1) - { - crc>>=1; - crc^=0xa001; - } - else - { - crc>>=1; - } - } - } - return crc; -} - - - -///检测CRC校验码是否正确 -unsigned char CheckCRC(unsigned char *ptr,unsigned char len) -{ - unsigned int crc; - crc = (unsigned int)CRC16(ptr,(len-2)); - if(ptr[len-1]==(crc>>8) && ptr[len-2]==(crc & 0x00ff)) - { - return 0xff; - } - else - { - return 0x0; - } -} - - -char *strstr(const char *str1, const char *str2) -{ - char *cp = (char*)str1; - char *s1, *s2; - - if (!*str2) - return((char *)str1); - - while (*cp) - { - s1 = cp; - s2 = (char *)str2; - - while (*s1 && *s2 && !(*s1 - *s2)) - s1++, s2++; - - if (!*s2) - return(cp); - - cp++; - } - return(NULL); -} - - -//40 -void Lc_int2str_4(U32 ui_in,char *d) -{ - U8 m = 0;//,i; - - if (ui_in >= ul2fun2[3])// 1,000 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - *(d+m) = 0x30 + Lc_WEI(ui_in,0); -} - - -// 123 -void Lc_int2str_3(U32 ui_in,char *d) -{ - U8 m = 0;//,i; - - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - *(d+m) = 0x30 + Lc_WEI(ui_in,0); -} - - -//Lc_int2str(123456, 5,3,&str[0]'); -/* - - -blank 填充字符 ' '或者其他unsigned char *blank)//保留以后使用 - - -*/ - - - -void Lc_int2str(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d) -{ - U8 m = 0,i; - for(i = 0;i < len;i++) - { - if(point != 0) - { - if(point == (len-i+1)) - { - *(d+m) = '.'; - m ++; - } - } - if (ui_in>=ul2fun2[len-i]) - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(len-i));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - } - *(d+m) = 0x30 + Lc_WEI(ui_in,1); - m++; - *(d+m) = 0x00; - //*(d+m) = 'e'; -} - - -// input: 123456d -// output: '1' '2' '3'.... -//对应的点阵 为 0123456789. ,最后为空格,专为显示点阵类的数值使用 -void Lc_int2number(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d) -{ - U8 i,m = 0; //uc_temp, - for(i = len+1;i != 0;i--)// len + 1 point 占用一位 - { - if(point == (len-i)) - { - d[len-m] = '.';//'.' - m ++; - } - { - if (ui_in>=ul2fun2[i-1]) - { - d[len-m] = (U8)((ui_in/ul2fun2[i-1])%10); - - } - else - { - d[len-m] = ' ';//' ' - } - m ++; - } - } - d[len-m] = (U8)(ui_in%10); -} - -void Lc_Byte_cp(BYTE *src,BYTE *dis, int len) -{ - int i; - for(i = 0; i < len ;i ++) - { - *dis = *src; - dis ++; - src ++; - } - //return 0; -} -/* -void Lc_Byte_print(BYTE *src,int len) -{ - int i, d; - for(i = 0; i < len ;i ++) - { - *dis = *src; - dis ++; - src ++; - } - //return 0; -} -*/ - - -// -10........+10 - -U32 L2_fun_number_show(int i,char str[4]) -{ - U8 c; - int cint; - - if(i >= 0) - { - cint = i; - str[0] =' '; - - } - else - { - cint = 0 - i; - str[0] ='-'; - - - } - c = Lc_WEI(cint,1); - if(0 == c) - { - str[1] =' '; - } - else - { - str[1] = 0x30+ c; - - } - str[2] = 0x30+ Lc_WEI(cint,0); - return 0; -} - -//L1_lkt_write(s_room_val.ui_t3,s_room_val.ui_t3,s_task_lkt.din); -//U_uluiuc - -void Lc_2ui2buf(vU32 ui_t2,vU32 ui_t3,volatile BYTE out[]) -{ -#if 0 - volatile U_uluiuc t; - //s_temp[] - t.uiv[0] = ui_t2; - t.uiv[1] = ui_t3; - - - Lc_Byte_cp(t.dv,out,8); - - out[3] = D_ul2uc_0( ui_t2); - ui_t2 >>= 8; - out[2] = D_ul2uc_0( ui_t2); - ui_t2 >>= 8; - out[1] = D_ul2uc_0( ui_t2); - ui_t2 >>= 8; - out[0] = D_ul2uc_0( ui_t2); - - - out[7] = D_ul2uc_0( ui_t3); - ui_t2 >>= 8; - out[6] = D_ul2uc_0( ui_t3); - ui_t2 >>= 8; - out[5] = D_ul2uc_0( ui_t3); - ui_t2 >>= 8; - out[4] = D_ul2uc_0( ui_t3); - - - #else - out[0] = D_ul2uc_0( ui_t2); - ui_t2 >>= 8; - out[1] = D_ul2uc_0( ui_t2); - ui_t2 >>= 8; - out[2] = D_ul2uc_0( ui_t2); - ui_t2 >>= 8; - out[3] = D_ul2uc_0( ui_t2); - -/* - out[4] = D_ul2uc_0( ui_t3); - ui_t2 >>= 8; - out[5] = D_ul2uc_0( ui_t3); - ui_t2 >>= 8; - out[6] = D_ul2uc_0( ui_t3); - ui_t2 >>= 8; - out[7] = D_ul2uc_0( ui_t3); -*/ -#endif - -} - -void L1_buf22ui(volatile BYTE in[],vU32 *ui_t2,vU32 *ui_t3) -{ - #if 0 - volatile U_uluiuc t; - Lc_Byte_cp(in,t.dv,8); - *ui_t2 = t.uiv[0]; - *ui_t3 = t.uiv[1]; - *ui_t2 = 0; - *ui_t2|= (U32)in[3]; - *ui_t2|= (U32)(in[2]<<8); - *ui_t2|= (U32)(in[1]<<16); - *ui_t2|= (U32)(in[0]<<24); - - *ui_t3 = 0; - *ui_t3|= (U32)in[7]; - *ui_t3|= (U32)(in[6]<<8); - *ui_t3|= (U32)(in[5]<<16); - *ui_t3|= (U32)(in[4]<<24); - - #else - - - *ui_t2 = 0; - *ui_t2|= (U32)in[0]; - *ui_t2|= (U32)(in[1]<<8); - *ui_t2|= (U32)(in[2]<<16); - *ui_t2|= (U32)(in[3]<<24); - /* - *ui_t3 = 0; - *ui_t3|= (INT32U)in[4]; - *ui_t3|= (INT32U)(in[5]<<8); - *ui_t3|= (INT32U)(in[6]<<16); - *ui_t3|= (INT32U)(in[7]<<24); - */ - #endif -} - -U32 Lc_abs(vU32 a,vU32 b,vU32 *diff) -{ - if(a >= b) - { - *diff = a-b; - return 1; - }else - { - *diff = b-a; - return 0; - } -} - - - - - - -#endif //#if 0 //5436345673456 - - - -//12,34 -void Lc_int2str_2_2(U32 ui_in,char *d) -{ - U8 m = 0;//,i; - - if (ui_in >= ul2fun2[4])// 1000 123456 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - if (ui_in >= ul2fun2[3])// 1000 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = '0'; - m ++; - } - - *(d+m) = '.'; - m ++; - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = '0'; - m ++; - } - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - - m ++; - *(d+m) = 0; - -} - -/// 0-999 -void Lc_int2str_3(U32 ui_in,char *d) -{ - U8 m = 0;//,i; - if (ui_in >= ul2fun2[3]) - { - ui_in = 999; - } - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = ' '; - } - m ++; - - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = ' '; - } - m ++; - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - m ++; - *(d+m) = 0; -} -/// 0-99 -void Lc_int2str_2(U32 ui_in,char *d) -{ - U8 m = 0;//,i; - if (ui_in >= ul2fun2[2]) - { - ui_in = 99; - } - - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = ' '; - } - m ++; - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - m ++; - *(d+m) = 0; -} -void Lc_uc2str_2(U8 ui_in,char *d) -{ - U8 m = 0;//,i; - if (ui_in >= ul2fun2[2]) - { - ui_in = 99; - } - - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = ' '; - } - m ++; - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - m ++; - *(d+m) = 0; -} - -// 123.4 - -void Lc_int2str_3_1(U32 ui_in,char *d) -{ - U8 m = 0;//,i; - if (ui_in >= ul2fun2[4])// 1000 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - - if (ui_in >= ul2fun2[3])// 1000 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = '0'; - m ++; - } - *(d+m) = '.'; - m ++; - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - m ++; - *(d+m) = 0; - -} - - -//-123 -void Lc_sint2str_3(int i_in,char *d) -{ - U8 m = 0;//,i; - U32 ui_in; - if(i_in < 0) - { - ui_in = (U32)(0-i_in); - *(d+m) = '-'; - }else - { - ui_in = (U32)(i_in); - *(d+m) = ' '; - } - m ++; - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = ' '; - } - m ++; - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = ' '; - } - m ++; - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - m ++; - *(d+m) = 0; -} - -//-32.1 -void Lc_sint2str_2_1(int i_in,char *d) -{ - U8 m = 0;//,i; - U32 ui_in; - if(i_in < 0) - { - ui_in = (U32)(0-i_in); - *(d+m) = '-'; - }else - { - ui_in = (U32)(i_in); - *(d+m) = ' '; - } - m ++; - - if (ui_in >= ul2fun2[3])// 1000 12345 - { - ui_in = 999; - } - - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = ' '; - } - m ++; - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - } - else - { - *(d+m) = '0'; - } - m ++; - *(d+m) = '.'; - m ++; - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - m ++; - *(d+m) = 0; -} - -// 12345 - -void Lc_int2str_5(U32 ui_in,char *d) -{ - U8 m = 1;//,i; - *(d+0) = ' '; - if (ui_in >= ul2fun2[4])// 10,000 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(4));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - - if (ui_in >= ul2fun2[3])// 1,000 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(3));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[2])// 100 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(2));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - if (ui_in >= ul2fun2[1])// 10 12345 - { - *(d+m) = 0x30 + Lc_WEI(ui_in,(1));// (unsigned char)((ui_in/ul2fun2[len-i])%10); - m ++; - } - else - { - *(d+m) = ' '; - m ++; - } - - *(d+m) = 0x30 + Lc_WEI(ui_in,0); - -} - -/****************************************************************************** -** End Of File -******************************************************************************/ - diff --git a/source/clib/c_lib.h.bak b/source/clib/c_lib.h.bak deleted file mode 100644 index 099bf0f..0000000 --- a/source/clib/c_lib.h.bak +++ /dev/null @@ -1,121 +0,0 @@ -/***************************************************************************** - * uart.h: Header file for NXP LPC17xx Family Microprocessors - * - * Copyright (c) 2023 CCSENS - * All rights reserved. - * - * History - * 2009.05.27 ver 1.00 Prelimnary version, first Release - * -******************************************************************************/ -#ifndef _c_lib_H_ -#define _c_lib_H_ - - -#include -#include -#include "c_type51.h" -// -#include "c_delay.h" -#include "c_crc.h" -//#include "../debug/debug_drv.h" -//extern char guc_send[128]; -extern unsigned char code cguHex2Char[16][2]; -typedef struct -{ - vU16 up_point; - vU16 down_point; - - -}TS_up_down_p_; - -extern U8 Lc_Hex2Char(U8 CharStr); -extern U8 Lc_strStartsWith(U8 *s1,U8 *s2); - -//extern void Lc_int2str(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d); -// input: 123456d -// output: '1' '2' '3'.... -//Ӧĵ Ϊ 0123456789. ΪոרΪʾֵʹ -//extern void Lc_int2number(U32 ui_in,UN_TYPE len,UN_TYPE point,char *d); -//extern U32 L2_fun_number_show(int i,char str[4]); -#if 10 - -void Lc_sint2str_2_1(int i_in,char *d); -void Lc_int2str_2(U32 ui_in,char *d); -void Lc_uc2str_2(U8 ui_in,char *d); - -extern void Lc_int2str_2_2(U32 ui_in,char *d); -extern void Lc_int2str_3(U32 ui_in,char *d); - -extern void Lc_int2str_3(U32 ui_in,char *d); -extern void Lc_int2str_4(U32 ui_in,char *d); - -extern void Lc_sint2str_3(int i_in,char *d); -#define Lc_WEI(WEIx,WEIn) (U8)((WEIx/ul2fun2[WEIn])%10); -#define Lc_eee(WEIn) ul2fun2[WEIn] - - -#endif -extern int Lc_strlen(const char *str); -extern void Lc_despiking_shift3_U16(vU16 *m); -extern int libc_strlen(char *str); - -extern char *Lc_int2a(vS32 value, char *string, UN_TYPE radix); - -extern void Lc_int2D(vS16 value, char *string,char bits); -extern int hexToDec(const char *source); -extern int getIndexOfSigns(char ch); -extern unsigned char hex_to_char(unsigned char hex); - -extern char *strstr(const char *str1, const char *str2); -extern unsigned char catch_protocol (const char d_src[],char d_protocol[]) ; -#define Lc_delay_1us() L0_delay_1us() - -extern U8* Lc_strcpy(U8* dst,const char* str); - -//////////////// - -extern void Lc_uc_hex(char ww); -extern void Lc_us_hex(U16 ww); -//extern void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...); -extern void Lc_print(char *dat4,...); -extern void Lc_print_NC(char *dat,...); -extern void Lc_print_buf(char *dat4,...); - -extern u8 Lc_ocr8(const u8 *d,u8 len); - -extern void L3_us_big(U16 *d); -extern void L3_ui_big(vU32 *d); -extern void Lc_buf_copy_uc(U8 *d,const U8 *s,U16 num); - -extern void Lc_buf_copy_us(U16 *d,const U16 *s,U16 num); - -///void L2_line_algo_media(U8 *buf,vU16 len); -extern vU8 Lc_U8_media3(vU8 a,vU8 b,vU8 c); -extern vS32 Lc_S32_media3(vS32 a,vS32 b,vS32 c); -extern vS32 Lc_S32_media(vS32 val[],S16 num); -extern void Lc_array_sort(S32 arr[],int n); - -/// 0x11 0x22 ---> 0x31 0x31 0x32 0x32 '1' '1' '2' '2' -extern void Lc_hex2ascii(U8 *buf,U16 len,U8 *ascii); -extern int isBigEndianOrder(void); -extern U32 ntohl(U32 dat); -extern U32 htonl(U32 dat); -extern U16 ntohs(U16 dat); -extern U16 htons(U16 dat); -extern U32 Lc_abs(vS32 a,vS32 b); -extern void Lc_encrypt_id(U8 *enc_dst, U8 *enc_src, U32 enc_key, U8 src_len); -extern void Lc_encrypt_id1(U8 *enc_dst, U8 *enc_src, U8 enc_key[], U8 src_len); -extern int Lc_strlen(char *str); -extern U32 Lc_vU32_avg(U32 *d, U8 n); -extern U32 Lc_vS32_media(U32 *d, U8 n); -extern int Lc_memset(U8 *buf,U8 c,U16 len); - -extern void Lc_for_int8(U8 i); -extern void Lc_for_int16(U16 i); - - -#endif /* end _c_lib_H_ */ -/***************************************************************************** -** End Of File -******************************************************************************/ diff --git a/source/clib/c_type51.h.bak b/source/clib/c_type51.h.bak deleted file mode 100644 index c5bcda2..0000000 --- a/source/clib/c_type51.h.bak +++ /dev/null @@ -1,359 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -/// COPYRIGHT NOTICE -/// Copyright (c) 2020, 传控科技 -/// All rights reserved. -/// -/// @file main.c -/// @brief main app -/// -///(本文件实现的功能的详述) -/// -/// @version 1.1 CCsens technology -/// @author CC -/// @date 20150102 -/// -/// -/// 修订说明:最初版本 -/// Modified by: cc -/// Modified date: 20200531 -/// Version: -/// Descriptions: add u8 -////////////////////////////////////////////////////////////////////////// - - -//#include - -#ifndef __TYPE51_H__ -#define __TYPE51_H__ - -/********************************************************************************************************* - realView编译器需要添加的头文件 -*********************************************************************************************************/ -#include -#include -#include -//#include - -typedef unsigned char U8; - -typedef volatile unsigned short U16; /* 无符号16位整型变量 */ - -typedef volatile signed long S32; -typedef volatile unsigned long U32; /* 无符号32位整型变量 */ -typedef unsigned int FLAG_P; // 标准类变量 -//typedef unsigned char INTU; // 标准类变量8BIT MCU -typedef unsigned int INTU; // 标准类变量32BIT MCU - -typedef U8 UN_TYPE; -typedef U8 vtype; -typedef U8 vType; - -/********************************************************************************************************* - 返回值定义 -*********************************************************************************************************/ -#define ZY_OK 0 /* 操作成功 */ -#define ZY_NOT_OK 1 /* 操作失败 */ -#define ZY_PARAMETER_ERR 2 /* 参数错误 */ -#define ZY_NO_FIND_FUNCTION 6 /* 没有发现指定函数 */ -#define ZY_NO_MEMORY 12 /* 内存不足 */ -#define ZY_TIME_OUT 13 /* 超时 */ -#define ZY_NO_FIND_OBJECT 16 /* 没有发现对象 */ - - -#define D_flag_lock 2 -#define D_flag_clear 0 -#define D_flag_CanUse 1 - - -typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; -typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; - - - - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#ifndef FALSE -#define FALSE (0) -#endif - -#ifndef D_stop -#define D_stop (1) -#endif - -#ifndef D_run -#define D_run (0) -#endif - -#ifndef D_ready -#define D_ready (1) -#endif - -#ifndef D_ready2 -#define D_ready2 (2) -#endif - - -#ifndef D_max -#define D_max (3) -#endif - - - -#ifndef D_diff -#define D_diff (4) -#endif - -#ifndef D_set -#define D_set (1) -#endif - - - -#ifndef D_clear -#define D_clear (0) -#endif -#define D_ON 1 -#define D_OFF 0 - -#define D_sleep_wakeup 3 -#define D_sleep 1 -#define D_wakeup 0 - -#ifndef TRUE -#define TRUE (1) -#endif - -/********************************************************************************************************* - 定义与编译器无关的数据类型 -*********************************************************************************************************/ - -typedef U8 u8; -typedef volatile U8 vU8; - -typedef U8 uint8_t; -typedef U8 uint8; -typedef char int8_t; - - -typedef U8 BOOLEAN; /* 布尔变量 */ -typedef U8 *PU8; -typedef U8 BYTE; -typedef signed char S8; -typedef volatile signed char vS8; -typedef signed char *PS8; - - -typedef S8 s8; - - -#define bit char -//#define code - -typedef U16 u16; -typedef volatile U16 vU16; /* 无符号16位整型变量 */ -typedef volatile signed short S16; -typedef volatile signed short s16; -typedef volatile S16 vS16; /* 有符号16位整型变量 */ - - - -typedef volatile U16 uint16_t; - - - - - -typedef volatile S32 vS32; - -typedef U32 INT32U; // 无符号32位整型变量 - -typedef S32 INT32S; // 有符号32位整型变量 - - - -typedef volatile U32 vU32; /* 有符号32位整型变量 */ - -typedef float FP32; /* 单精度浮点数(32位长度) */ -typedef double FP64; /* 双精度浮点数(64位长度) */ - - -typedef U32 uint32_t; - -typedef U32 uint32; - - - -//typedef unsigned char BOOLEAN; // 布尔变量 -typedef unsigned char INT8U; // 无符号8位整型变量 -typedef signed char INT8S; // 有符号8位整型变量 -typedef unsigned short INT16U; // 无符号16位整型变量 -typedef signed short INT16S; // 有符号16位整型变量 -//typedef float FP32; // 单精度浮点数(32位长度) -//typedef double FP64; // 双精度浮点数(64位长度) - - - -///>>>>>>cpu类型特有>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>大端小端 - - -typedef union -{ - vU32 ui; - vU16 s[2]; - vU8 d[4]; -}tu_ui4uc; - -typedef union -{ - vU16 word; - struct - { - vU8 h; - vU8 l; - }BYTE2; -}U_U16; - -typedef union -{ - vU32 dWord; - ///High 0123 Low - struct - { - vU8 byte0; - vU8 byte1; - vU8 byte2; - vU8 byte3; - }BYTE4; - - vU16 us[2]; -}U_U32; -typedef union -{ - vU16 us; - vU8 uc[2]; - struct - { - vU8 H; - vU8 L; - }BYTE2; -}U_F16; -/********** -k.us = 0x1234 -uc - [0]=0x12 - [1]=0x34 -byte2 - H=0x12 - L=0x34 - -**********/ - - - -typedef union -{ - float fl; - vU8 uc[4]; - -}U_F32; - - -///<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<大端小端 - - -typedef struct -{ - u16 get; //想要达到的值 - u16 max; //​最大值 - u16 min; //最小值 -/// u16 diff; //get和最值max,min的差值 在有些输入的时候有用 不想 -}TS_u16get_;//电磁阀动作 - - -typedef struct -{ - vU8 *buffer; - vU8 wpt; - vU8 rpt; - vU8 cnt; -}byte_len_fifo_struct; - -typedef struct -{ - vU16 *buffer; - vU16 wpt; - vU16 rpt; - vU16 cnt; -}word_len_fifo_struct; - -typedef struct -{ - vU16 x; - vU16 y; -}point_struct; - - -typedef struct -{ - vU16 x; - vU16 y; - vU16 width; - vU16 height; -}rect_struct; - - -#define HIGHT 1 -#define LOW 0 -#if 0 -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef MAX -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif -#endif -#ifndef ABS -#define ABS(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) -#endif - - -#define F_FINSIH 1 -#define F_WORKING 0 -#define F_WAITINGKEY 2 - - -#define DF_var_up(v,step,max,init) (v) += (step);if((v) > (max)) (v) = (init); -//if step > 1 bug warning!! -#define DF_var_down(v,step,min,init) \ -if((v) < ((min) + (step))) \ -{ \ - (v) = (init); \ -}else \ -{ \ - (v) -= (step); \ -} - -#define D_us2uc_H(x) (U8)(0x00ff&((x)>>8)) -#define D_us2uc_L(x) (U8)(0x00ff&(x)) - - -#define D_ul2uc_0(xx) (U8)(0x000000ff&(xx)) -#define D_uc_high(ww) ((ww)>>4) -#define D_uc_low(ww) ((ww)&0x0f) - -#define D_2uc_u16(H,L) (((u16)H)<<8 | (u16)L) - -#define L0_type_byte(x) ((U8 *) &(x)) - - -//#define _nop_ __NOP -// #define _nop_ - - -extern void L3_us_big(U16 *d); -extern void L3_ui_big(vU32 *d); -#endif /* __TYPE_H__ */ diff --git a/source/debug/debug_drv.c b/source/debug/debug_drv.c index 235a913..b285916 100644 --- a/source/debug/debug_drv.c +++ b/source/debug/debug_drv.c @@ -36,7 +36,8 @@ if(ts_s2b_debug.idle) #include "msp_eeprom.h" -TS_P_debug *pd=NULL; +TS_P_debug *pd = NULL; +TS_P_rs485 *pd485 = NULL; u8 L3_tpc_D2uart(u8 cmd,u8 num) { @@ -65,9 +66,10 @@ u8 L3_tpc_D2uart(u8 cmd,u8 num) } ////通过debug串口 透传协议 +#if 0 u8 L3_tpc_hex(void) { - u8 cmd=0,num=0; + u8 cmd=0, num=0; cmd = D_uc_high(ts_Urec[D_UART1].sp[0]);////为485 调整 第一个 num = D_uc_low(ts_Urec[D_UART1].sp[0]); printf(" 1->cmd=%X num=%X len = %d ",(int)cmd,(int)num, (int)ts_Urec[D_UART1].num); @@ -97,6 +99,30 @@ u8 L3_tpc_hex(void) printfs("\r\n cmd error!!"); return 0; } +#else +u8 L3_tpc_hex(void) +{ + u8 filter = 0, slaveId = 0, cmd = 0; + filter = ts_Urec[D_UART1].sp[0]; + slaveId = ts_Urec[D_UART1].sp[1]; + cmd = ts_Urec[D_UART1].sp[2]; + //printf(" 1->filter=%X slaveId=%X cmd=%X len = %d ",(int)filter,(int)slaveId, (int)cmd, (int)ts_Urec[D_UART1].num); + + ////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为AA + ///AA 02 10 00 02 A3 B4 6C + if(0xAA == filter) + { + //L0_uartN_Arrayhex_withoutbuf(D_UART1,&ts_Urec[D_UART1].sp[0], ts_Urec[D_UART1].num); + if(0x02 == slaveId) + { + // if(ocr) + return 1; + } + } + printfs("\r\n cmd error!!"); + return 0; +} +#endif ////启动透传指令 开关打开 可以模拟当前串口发送 @@ -114,9 +140,9 @@ vtype L2_debug_ONcomand(void) ts_Urec[D_UART1].ok = 0;////解析协议 //// printf1("\r\nD_UART1 ok %d ",(int) ts_Urec[D_UART1].num); - D_LED1_REV(); + // D_LED1_REV(); - pd = (TS_P_debug *)ts_Urecbuf.r1; + pd485 = (TS_P_rs485 *)ts_Urecbuf.r1; /// L0_uartN_Arrayhex_withoutbuf(D_UART1,ts_Urecbuf.r1, ts_Urec[D_UART1].num); /// 串口1的协议分两类 1类是 Fx开头的针对外设x的标准debug协议;例如FD开头是系统debug Fc是iic调试设备 diff --git a/source/debug/debug_drv.h b/source/debug/debug_drv.h index 1bec8ad..7f331ec 100644 --- a/source/debug/debug_drv.h +++ b/source/debug/debug_drv.h @@ -38,12 +38,13 @@ //#include "tpc_debug.h" extern TS_P_debug *pd; +extern TS_P_rs485 *pd485; #define D_cmd_filter_debug 0xfd #define D_cmd_filter_gc032A 0xfc -#define D_cmd_filter_weight 0xFE +#define D_cmd_filter_weight 0xAA #define D_cmd_filter_iicx 0xf1 @@ -189,7 +190,7 @@ Lc_print(L0_uart_uc,__VA_ARGS__); int main() { int x = 3; - // һЩ... + // һЩ����... LOG("x = %d", x); // 2-1-5.cpp: Line 12: x = 3 } #endif diff --git a/source/debug/debug_drv.h.bak b/source/debug/debug_drv.h.bak deleted file mode 100644 index 0a37557..0000000 --- a/source/debug/debug_drv.h.bak +++ /dev/null @@ -1,203 +0,0 @@ -/***************************************************************************** - * DEBUG_DRV.h: Header file for DEBUY DRIVER FILES - * - * - * Copyright(C) 2013, cc - * All rights reserved. - * - * History - * 2013.05.24 ver 1.00 Prelimnary version, first Release - * 2020.02.22 ver 2.00 step 1 led点灯 - step 2.1 uart debug send - step 2.2 uart debug rev with led - step 2.3 debug protocol test - step 3 - step 4 timer test --> get tick - step 5 TTSS task test - step 6 - - -******************************************************************************/ - - -#ifndef __DEBUG_DRV_H -#define __DEBUG_DRV_H - -#include "c_type51.h" -#include "c_lib.h" -#include "msp_uartN.h" - -#include "msp_uart1.h" -//#include "msp_uart2.h"/// -///#include "msp_uart3.h" -///#include "msp_uart4.h"/// - -#include "stdio.h" -//#include "msp_uart4.h" -#include "tpc_x.h" -//#include "tpc_debug.h" - -extern TS_P_debug *pd; - - -#define D_cmd_filter_debug 0xfd -#define D_cmd_filter_gc032A 0xfc - -#define D_cmd_filter_weight 0xFE - - -#define D_cmd_filter_iicx 0xf1 - - -///根据实际电路进行调整 -#if 0 -#define L1_uartD_senduc(x) L1_uart4_senduc((x) -#define L1_uartD_sendArray(x,len) L1_uart4_sendArray((x),(len)) -#define L1_uartD_sendStr(x) L1_uart4_sendStr((x)) -#define L1_uartD_waitFree() L1_uart4_waitFree() -#define D_ts_uartX_rev (&TP_Uart_RE_) - -#define Uart_Send_Msg(X); L1_uartD_sendStr(X); - -#else -#define L1_uartD_0d0a() L0_uartN_0d0a(D_UART1) -#define L1_uartD_uc(x) L0_uartN_uc(D_UART1,(x)) -#define L1_uartD_us(x) L0_uartN_us(D_UART1,(x)) -#define L1_uartD_uchex(x) L0_uartN_uchex(D_UART1,(x)) -#define L1_uartD_ushex(x) L0_uartN_ushex(D_UART1,(x)) -#define L1_uartD_ulhex(x) L0_uartN_ulhex(D_UART1,(x)) -#define L1_uartD_Array(x,len) L0_uartN_Array(D_UART1,(x),(len)) -#define L1_uartD_ArrayLong(x,start,end) L0_uartN_Arraylong(D_UART1,x,start,end) -////#define L1_uartD_Arrayhex(x,len) L0_uartN_uchexArray(D_UART1,(x),(len)) - - -#define L1_uartD_Arrayhex(x,len) L0_uartN_Arrayhex_withoutbuf(D_UART1,(x),(len)) -////#define L1_uartD_ushexArray(x,len) L0_uartN_ushexArray(D_UART1,(x),(len)) - - -#define L1_uartD_Str(x) L0_uartN_str(D_UART1,(x)) -#define L1_uartD_waitFree() L0_waitFree_uartN(D_UART1) -#define D_ts_uartX_rev (&ts_s2b1_road) - -#define Uart__Msg(X); L1_uartD_Str(X); -#define uartSendByte(X) L0_uartN_ushex(D_UART1,(X)) -#define Uart__Hex(x,u) L0_uartN_ushex(D_UART1,(x)) - - -#endif - -///#define xxxlog(format, ...) printf("[%s:%d->%s] ",format, __FILE__, __LINE__, __func__, ##__VA_ARGS__) - -//////#define printfs_debug - -#ifdef printfs_debug -#define printfs(str) -#define printf1(str,i1) -#define printf2(str,i1,i2) -#define printf3(str,i1,i2,i3) -#define printf4(str,i1,i2,i3,i4) -#else - -#define printfs(str) L1_uartD_waitFree() ;printf(str) -#define printf1(str,i1) L1_uartD_waitFree() ;printf(str,i1) -#define printf2(str,i1,i2) L1_uartD_waitFree() ;printf(str,i1,i2) -#define printf3(str,i1,i2,i3) L1_uartD_waitFree() ;printf(str,i1,i2,i3) -#define printf4(str,i1,i2,i3,i4) L1_uartD_waitFree() ;printf(str,i1,i2,i3,i4) -#define printf5(str,i1,i2,i3,i4,i5) L1_uartD_waitFree() ;printf(str,i1,i2,i3,i4,i5) - -/* - -#define printfs(str) L1_uartD_Str(str);///L1_uartD_waitFree() ;printf(str) -#define printf1(str,i1) L1_uartD_Str(str);L1_uartD_ushex(i1);///L1_uartD_waitFree() ;printf(str,i1) -#define printf2(str,i1,i2) printf1(str,i1);L1_uartD_ushex(i2);///L1_uartD_waitFree() ;printf(str,i1,i2) -#define printf3(str,i1,i2,i3) printf2(str,i1,i2);L1_uartD_ushex(i3);///L1_uartD_Str(str);L1_uartD_ushex(i1);///L1_uartD_waitFree() ;printf(str,i1,i2,i3) -#define printf4(str,i1,i2,i3,i4) printf3(str,i1,i2,i3);L1_uartD_ushex(i4);///L1_uartD_Str(str);L1_uartD_ushex(i1);///L1_uartD_waitFree() ;printf(str,i1,i2,i3,i4) -#define printf5(str,i1,i2,i3,i4,i5) printf4(str,i1,i2,i3,i4);L1_uartD_ushex(i5);///L1_uartD_Str(str);L0_uartN_ushex(i1);/// L1_uartD_waitFree() ;printf(str,i1,i2,i3,i4,i5) -*/ - - -#endif -///L0_waitFree_uartN - -extern void L3_debug_drv_init(void); -extern void L3_test_ONdebug(u8 filter); -extern vtype L2_debug_ONcomand(void); - - -extern void L3_iicx_debug(u8 filter); - -#if 0 -if(1 == ts_uart4_rev.revok) -{ts_uart4_rev.revok= 0; - td = (TS_P_debug *)ts_uart4_rev.buf; - L1_uart4_sendArray(ts_uart4_rev.buf, 5); - if(D_sb_filter == td->filter) - { - if(0x04 == td->R1)///设置四个传感器的清零 - { //// fd 04 33 44 55 - -void L3_debug_drv_init(void); -#define L3_debug_time() L0pf_send_uc = L0_uart0_uc; ///Lc_print("\r\n%s,-%sL:%d,",__DATE__,__TIME__,__LINE__); -extern void L3_debug_cycle(void); - - -#define UART_debug_reg ((LPC_UART1_TypeDef *) LPC_UART1_BASE ) -//#define UART_debug ((LPC_UART1_TypeDef *) LPC_UART1_BASE ) -//#define UART_debug ((LPC_UART_TypeDef *) LPC_UART_BASE ) -//#define UART_debug ((LPC_UART_TypeDef *) LPC_UART_BASE ) -#define UART_debug 1 - -#define L0_debugS_uc(x) //L0_Usend_uc(UART_debug,x) -#define L0_debugS_uc_hex(x) //L0_Usend_uc_hex(UART_debug,x) -#define L0_debug_uc_show(x,y); //L0_USART_print(UART_debug,x,y); -#define L0_debug_us_show(x,y); //L0_USART_print(UART_debug,x,y); -#define L0_debug_ul_show(x,y); //L0_USART_print(UART_debug,x,y); - - -//#define L2_debug_info(x) //L0_USART_print(UART_debug,x); -#define L2_debug_Au4B(x) // L0_Usend_Au4B(UART_debug,x) -#define L0_debug_Au4B_show(x,y); //L0_USART_print(UART_debug,x,y); -#define L0_debug_Aus_show(x,y); //L0_USART_print(UART_debug,x,y); -#define L0_debug_A4B_show(x,y); //L0_USART_print(UART_debug,x,y); - - -//#define debug22(format...) Lc_print("%s (%d): ",__FILE__,__LINE__); - -//#define LOG(format, args...) Lc_print(format, ##args) -//#define RTA_printf(...) Lc_print(__VA_ARGS__) - -//#define L2_debug_info Lc_print - -//#define L3_debug_time() Lc_print(L0_uart0_uc,"\r\n%s,-%sL:%d,",__DATE__,__TIME__,__LINE__); - - - - -#define L2_debug_info(...) \ -Lc_print(L0_uart_uc,__VA_ARGS__); - -//do { -//Lc_print("%s (%d): ", __FILE__, __LINE__); -//Lc_print(format, __VA_ARGS__); -//} while (0) - - -#define CHECK1(x, ...) if (!(x)) { printf(__VA_ARGS__); } - -#define LOG(...) {\ - Lc_print(L0_uart_uc,"%s: Line %d:\t", __FILE__, __LINE__);\ - Lc_print(L0_uart_uc, __VA_ARGS__);\ - Lc_print(L0_uart_uc,"\n");\ -} - -int main() { - int x = 3; - // һЩ... - LOG("x = %d", x); // 2-1-5.cpp: Line 12: x = 3 -} -#endif -#endif /* end __DEBUG_DRV_H */ - -/***************************************************************************** -** End Of File -******************************************************************************/ diff --git a/source/debug/debug_drvdd.c b/source/debug/debug_drvdd.c deleted file mode 100644 index a06acb6..0000000 --- a/source/debug/debug_drvdd.c +++ /dev/null @@ -1,378 +0,0 @@ -/***************************************************************************** - * debug_drv.c: debug app - * - * Copyright(C) 2013, cc - * All rights reserved. - * - * History - * 2013.05.24 ver 1.00 Prelimnary version, first Release - * - - -if(ts_s2b_debug.idle) -{ - ts_s2b_debug.idle = 0; - printf("\r\n O"); - if(ts_s2b_debug.len > 0) - { -//// L1_uartD_sendArrayhex((U8 *)&ts_s2b_debug.t, 5); - /// xxxx///提取协议 - /// if(debgu) ts_s2b_debug.ok =1; - - printf("\r\n len = %d",(int)ts_s2b_debug.len); - ts_s2b_debug.len = 0; - } -} - - -******************************************************************************/ - -#include "debug_drv.h" -///#include "msp_iicM1.h" -#include "c_type51.h" -///#include "msp_uart2.h" - -#include "tpc_road.h" -TS_P_debug *pd=NULL; - -////启动透传指令 开关打开 可以模拟当前串口发送 -vtype L2_debug_comand(void) -{ - u8 cmd=0,num=0; - if(1 == ts_Urec[D_UART1].debugok) - { ts_Urec[D_UART1].debugok = 0;////解析协议 - /// printf("\r\nw ts_Urec[D_UART1].max = %d num = %d",(int)ts_Urec[D_UART1].rmax,(int)ts_Urec[D_UART1].num); - printf("\r\ndebugok",(int)(int)ts_Urec[D_UART1].debugok); - - } - if(1 == ts_Urec[D_UART1].ok) - { ts_Urec[D_UART1].ok = 0;////解析协议 - L1_uartD_sendArrayhex(ts_Urecbuf.r1, ts_Urec[D_UART1].num);L1_uartD_0d0a(); -///---------串口1的协议分两类 1类是 Fx开头的针对外设x的标准debug协议;例如FD开头是系统debug Fc是iic调试设备 -////一类是Dx开头的对串口x透传协议 ////D2。。。。 透传给串口2的数据 - cmd = D_uc_high(ts_Urecbuf.r1[0]); - num = D_uc_low(ts_Urecbuf.r1[0]); - printf(" 0->%X %X ",(int)cmd,(int)num ); - if(cmd == 0x0D) - {////D2。。。。 透传给串口2的数据 - L1_uartD_sendArrayhex(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - - if(2 == num) - { printf(" 2-> "); - L1_uart2_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - }else if(3 == num) - { printf(" 3-> "); - L1_uart3_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - - }else if(4 == num) - { printf(" 4-> "); - L1_uart4_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - - }else - { - } - return 1; - - } - ////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为Fx - if(0x0F == cmd) - { - ///TS_P_debug - pd = (TS_P_debug*)ts_Urecbuf.r1; - L1_uartD_sendArrayhex((U8 *)pd, 5);////(U8 *)&pd,错误的表达方式 pd就是地址 - return 1; - } - printf("\r\n ok "); - } - - if(1 == ts_Urec[D_UART2].ok) - { ts_Urec[D_UART2].ok = 0;////收到一帧数据 - - //pd = (TS_P_debug*)ts_Urecbuf.r2;//// - //L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num); - L1_uartD_sendArrayhex(ts_Urecbuf.r2, ts_Urec[D_UART2].num); - } - if(1 == ts_Urec[D_UART3].ok) - { ts_Urec[D_UART3].ok = 0;////解析协议 - - //pd = (TS_P_debug*)ts_Urecbuf.r2;//// - //L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num); - L1_uartD_sendArrayhex(ts_Urecbuf.r3, ts_Urec[D_UART3].num); - } - if(1 == ts_Urec[D_UART4].ok) - { ts_Urec[D_UART4].ok = 0;////解析协议 - - //pd = (TS_P_debug*)ts_Urecbuf.r2;//// - //L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num); - L1_uartD_sendArrayhex(ts_Urecbuf.r4, ts_Urec[D_UART4].num); - } - - return 0; -} -////启动透传指令 开关打开 可以模拟当前串口发送 -vtype L2_debug_comand333(void) -{ - if(1 == ts_Urec[D_UART1].debugok) - { ts_Urec[D_UART1].debugok = 0;////解析协议 - /// printf("\r\nw ts_Urec[D_UART1].max = %d num = %d",(int)ts_Urec[D_UART1].rmax,(int)ts_Urec[D_UART1].num); - printf("\r\ndebugok",(int)(int)ts_Urec[D_UART1].debugok); - - } - if(1 == ts_Urec[D_UART1].ok) - { ts_Urec[D_UART1].ok = 0;////解析协议 - L1_uartD_sendArrayhex(ts_Urecbuf.r1, ts_Urec[D_UART1].num);L1_uartD_0d0a(); -///---------串口1的协议分两类 1类是 Fx开头的针对外设x的标准debug协议;例如FD开头是系统debug Fc是iic调试设备 -////一类是Dx开头的对串口x透传协议 ////D2。。。。 透传给串口2的数据 - if((ts_Urecbuf.r1[0]&0xF0) == 0xD0) - {////D2。。。。 透传给串口2的数据 - printf("\r\n Dn=%x :",(int)(ts_Urecbuf.r1[0]&0x0F)); - L1_uartD_sendArrayhex(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - - if(ts_Urecbuf.r1[0]&0x0f == 0x02) - { printf(" 2-> "); - L1_uart2_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - }else if(ts_Urecbuf.r1[0]&0x0f == 0x03) - { printf(" 3-> "); - L1_uart3_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - - }else if(ts_Urecbuf.r1[0]&0x0f == 0x04) - { printf(" 4-> "); - L1_uart4_sendArray(&ts_Urecbuf.r1[1], ts_Urec[D_UART1].num-1); - - }else - {printf(" 4->%x %x ",(int)(ts_Urecbuf.r1[0]&0xF0), (int)(ts_Urecbuf.r1[0]&0x0f) ); - } - return 1; - - } - ////debug协议使用串口1 故而再次简单解析 要求第一个字符必须为Fx - if(ts_Urecbuf.r1[0]&0xf0 == 0xf0) - { - ///TS_P_debug - pd = (TS_P_debug*)ts_Urecbuf.r1; - L1_uartD_sendArrayhex((U8 *)pd, 5);////(U8 *)&pd,错误的表达方式 pd就是地址 - return 1; - } - printf("\r\n ok "); - } - - if(1 == ts_Urec[D_UART2].ok) - { ts_Urec[D_UART2].ok = 0;////收到一帧数据 - - //pd = (TS_P_debug*)ts_Urecbuf.r2;//// - //L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num); - L1_uartD_sendArrayhex(ts_Urecbuf.r2, ts_Urec[D_UART2].num); - } - if(1 == ts_Urec[D_UART3].ok) - { ts_Urec[D_UART3].ok = 0;////解析协议 - - //pd = (TS_P_debug*)ts_Urecbuf.r2;//// - //L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num); - L1_uartD_sendArrayhex(ts_Urecbuf.r3, ts_Urec[D_UART3].num); - } - if(1 == ts_Urec[D_UART4].ok) - { ts_Urec[D_UART4].ok = 0;////解析协议 - - //pd = (TS_P_debug*)ts_Urecbuf.r2;//// - //L1_uartD_sendArrayhex((char *)pd, ts_Urec[D_UART2].num); - L1_uartD_sendArrayhex(ts_Urecbuf.r4, ts_Urec[D_UART4].num); - } - - return 0; -} - -void L3_test_debug(u8 filter) -{ - if(filter == pd->filter) - {///filter num d1 d2 d3 ....dn - //// FD 08 11 22 33 44 55 66 77 88 - printf("\r\n FD ok"); - - switch (pd->ocr) - { - case 0x11: - - printf("11"); - //// D_lora_wakeup(); L0_uart2_sendArray(test, 13); - printf(" lora send "); -/// L1_uartD_sendArrayhex(test, 13); - //1/ 2 3 4 5 6 7 8 9 10 11 12 13 - break; - case 0x12: - printf("12"); - /// D_lora_wakeup(); L0_uart2_sendArray(test2, 7); - printf(" lora send2 "); - /// L1_uartD_sendArrayhex(test2, 7); - //1 2 3 4 5 6 7 8 9 10 11 12 13 - break; - default: - printf(" pp error\r\n "); - - break; - }; - - printf("333"); - } -} - -///#define D_keil_sim -#ifdef D_keil_sim -void UartInit(void) //9600bps@11.0592MHz -{ - SCON = 0x50; //8位数?可变波特? - AUXR |= 0x01; //串口1选择定时?为波特率发生? - AUXR |= 0x04; //定时?时钟为Fosc,?T - T2L = 0xE0; //设定定时初 ? - T2H = 0xFE; //设定定时初? - AUXR |= 0x10; //启动定时? -} - -void L3_debug_drv_init(void) -{ - - Ts_debug.uxrev = D_ts_uartX_rev; - - Ts_debug.td = (TS_P_debug *)Ts_debug.uxrev->buf; - Ts_debug.ok = &Ts_debug.uxrev->debugok; - UartInit(); - -} - - -char putchar(char ch) -{ - SBUF = ch; - while(TI == 0); - TI = 0; - return ch; -} - -#else - - -void L3_debug_drv_init(void) -{ - D_s2b_road1_init(); -} - -char putchar(char ch) -{ - /* Place your implementation of fputc here */ - /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */ - /// HAL_UART_Transmit_IT(&huart4, (uint8_t *)&ch, 1); - L1_uartD_senduc(ch); - return ch; - ///SBUF= ch; - /// while(t) -/// while(!TI); -// TI = 0; -/// return (SBUF = ch); -} -#endif ///#ifdef D_keil_sim - -#if 0 - -void L3_debug_drv_init(void) -{ - L0pf_send_uc = L0_uart0_uc; - Lc_print("\r\n debug shell init:\t"); -/// io õı׼д - - Lc_print("Mode:"); - #ifdef D_debug_time - Lc_print(" debug"); - #else - //D_debug_time_using - Lc_print(" normal"); - #endif -} - - -#ifdef D_debug_sim - -fff -void L3_debug_cycle(void) -{ - INTERRUPT_UART(); - TIMER0_IRQHandler(); - - - -} - -#else - -#endif -void L3_test_debug(u8 filter) -{ - if(filter == Ts_debug.td->filter) - {///filter num d1 d2 d3 ....dn - //// FD 08 11 22 33 44 55 66 77 88 - L1_uartD_sendArrayhex(Ts_debug.td,Ts_debug.td->R1); - } -} - -void L3_iicx_debug(u8 filter) -{ - - if(filter == Ts_debug.td->filter) - { - if(0x10 == Ts_debug.td->ocr)///read reg1 num 读取reg1地址中的num个数? - { - - //NUM: 0 1 2 3 4 - // Fx R1 R2 R3 ocr - // sla reg1 num - /// f1 32 15 06 10 - - - //NUM: 0 1 2 3 4 - // Fx R1 R2 R3 ocr - // sla reg1 num - /// f1 32 0x28 06 10 - /// f1 32 0x28 06 10 - /// 28 - /// 0010 1000 28 - /// 1010 1000 a8 - L2_IICM1_ReadReg(Ts_debug.td->R1,Ts_debug.td->R2,Ts_debug.d,Ts_debug.td->R3); - ///printf("\r\n 0x%2x 0x%2x\r\n",(int)Ts_debug.d[0],(int)Ts_debug.d[1]); - L1_uartD_sendArrayhex(Ts_debug.d,Ts_debug.td->R3); -/// printf("\r\n 0x%2x\r\n",(int)Ts_debug.td->ocr); - } - else if(0x11 == Ts_debug.td->ocr) - { - L2_IICM1_ReadReg(Ts_debug.td->R1,Ts_debug.td->R2,Ts_debug.d,Ts_debug.td->R3); - //printf("\r\n 0x%2x 0x%2x\r\n",(int)Ts_debug.d[0],(int)Ts_debug.d[1]); - //L1_uartD_sendArrayhex(Ts_debug.d,Ts_debug.td->R3); - - - printf("\r\n 0x%2x 0x%2x\r\n",(int)Ts_debug.d[0],(int)Ts_debug.d[1]); - - - - - } - else if(0x12 == Ts_debug.td->ocr) - { - } - else - { - - } - } -} - - - - -#else - - - -#endif - - - -/****************************************************************************** -** End Of File -******************************************************************************/ diff --git a/source/debug/testiic.uvla b/source/debug/testiic.uvla deleted file mode 100644 index 95fb5b0..0000000 Binary files a/source/debug/testiic.uvla and /dev/null differ diff --git a/source/tpc/tpc_x.h b/source/tpc/tpc_x.h index b29afa4..f97af20 100644 --- a/source/tpc/tpc_x.h +++ b/source/tpc/tpc_x.h @@ -41,6 +41,18 @@ typedef struct vU8 ocr; }TS_P_debug; +#define TS_RS485_BUF_MAX_LEN 16 + +typedef struct +{//8byte + vU8 filter; + vU8 slaveId; + vU8 cmd; + vU8 num[2]; + vU8 buf[TS_RS485_BUF_MAX_LEN]; + vU8 ocr; +}TS_P_rs485; + ////#define D_HETU_FX_buf_max 5 //定长协议 长度为5