/*—————————————————————————— * 文 件 名:Cmd.c * 日 期:2013-12-30 * 文件说明:控制台主文件 *——————————————————————————*/ #include "Cmd.h" #include #include "include.h" #include "debug_printf.h" #include "Rtc.h" #include "addr.h" #include "uart.h" #include "storage.h" #include "apl.h" #include "PHY.h" #include "rtc_ext.h" #include "update.h" #include "gprs.h" u8 buf[10]; extern u8 tedtbuf[150]; extern u16 resettime;//系统复位次数 extern u8 g_DebugRxBuffer[]; extern struct st_uart_port COM_MBUS_MASTER_port; //extern struct st_uart_port COM_MBUS_SLAVE_port; extern struct st_uart_port COM_PLC_port; extern struct st_uart_port COM_485_port; extern void gprs_device_poweroff(); extern u8 gprs_power_offon(); extern void mbus_master_tx_begin(); extern void ClearMeterInfo_realdl( void ); void e5e50000_tx(void); void e5e50001_tx(void); void irda_tx(void); void auto_sync_list_meters(void); void read_ext_rtc(void); void set_ext_rtc(void); void read_mtype(void); void ctrl_12v_pow(void); void PrintfMonitorWaterMeterDataFrame( void ); void ClearXYDataFrameStore(void); void ClearMeterInfo( void ); void startsjreadmeter( void ); void COM_4852_TXProcess(u8 *buf, u8 length); void RS4852SendTestProcess( void ); void controlkey(void); void LEDTest( void ); void PowerTest( void ); void FlashTest( void ); void PLCTest( void ); void RS4851Test( void ); void RS4852Test( void ); void MBUSTest( void ); void RFPortTest( void ); void self_test_eeprom( void ); void test_led(void); void set_data_save_time(void); void get_data_save_time(void); void TestMode_PLCTest( void ); void TestMode_485Test( void ); void TestMode_MBUSTest( void ); void Set_DataSave_TimeProcess(u8 time); void set_mbus_charge_power_time( void ); void get_mbus_charge_power_time( void ); void serveripattr(void); void printenv(void); void gprspwoff(); void gprs_pw_offon(); extern void dl_start(); extern void rp_start(); extern void ctl_start(u8 flag); extern void amt_process_cmd(); extern void debug_reportdata(); extern void datacount_printf(); extern void data_printf(); void upgrade_flash(void); void upgrade(void); void ctl_start_all(); extern void dl_485_start(u8 type,u8 *addr, u8 addrlen); extern void hb_setdl_time(); void read_water_addr(); void read_water_data(); void datatest(); void rp_start_cmd(); void lsdata(); sCmd CmdList[] = { {"controlkey",controlkey,"开关阀控[FF,开 00,关]"}, {"PLCRFTest",TestMode_PLCTest,""}, {"RS485Test",TestMode_485Test,""}, {"EEPROMTest",self_test_eeprom,""}, {"FlashTest",FlashTest,""}, {"LEDTest",test_led,""}, {"PowerTest",PowerTest,""}, {"ver", ReadVersion,""}, {"reboot",SysReset,""}, {"port",scan_ports,""}, {"closepr",close_printf,""}, {"openpr",open_printf,""}, {"sintime",SetTime,"设置内部时钟"}, {"rintime",GetTime,"读取内部时钟"}, {"transparent", transparent_Proc,""}, {"rs4852send", RS4852SendTestProcess,""}, {"datatest",datatest,"数据测试"}, {"sexttime",set_ext_rtc,"设置外部时钟"}, {"rexttime",read_ext_rtc,"读取外部时钟"}, {"serveripattr",serveripattr,""}, {"printenv",printenv,""}, {"gprspwoff",gprspwoff,"关机"}, {"gprspwoffon",gprs_pw_offon,"先关机再开机"}, {"writeaddr",set_local_addr,""}, {"readaddr",read_local_addr,""}, {"dl",read_water_addr,"抄表"}, {"readmeterdata",read_water_data,"读水表数据"}, {"rpstart",rp_start_cmd,"上报数据"}, {"lsdata",lsdata,"显示数据"}, {"upgrade",upgrade,"升级"}, {"ls", ListCmd,""} }; u8 CmdListLen = sizeof(CmdList) / sizeof(sCmd); void lsdata() { datacount_printf(); data_printf(); } void datatest() { debug_reportdata(); } void gprspwoff() { gprs_device_poweroff(); } void gprs_pw_offon() { gprs_power_offon(); } void rp_start_cmd() { hb_setdl_time(); rp_start(); } void read_water_addr() { printf("\r\n"); dl_485_start(1,NULL,0); } void read_water_data() { u8 str[30] = {0}; u8 buf[30]; u8 addr[6]; u8 len = 0; GetStrPara((u8*)str,1); len = strlen(str); change_string_to_arry16((char*)str); len = len/2; for(u8 i = 0;i 0) { Cmd_Exe(); printf("C>"); } else { printf("\r\ncommand length error!\r\n"); } } u8 find_cmd_length(u8 * buf) { for (u8 i = 0; i < 255; i++) { if ((buf[i] == ' ') || (buf[i] == '\r') || (buf[i] == '\n')) { return i; } } return 0; } /*—————————————————————————— * 函 数 名:Cmd_Exe * 输入参数:None * 输出参数:None * 返 回 值:None * 功能说明:控制台执行 *——————————————————————————*/ void Cmd_Exe(void) { //u32 time_t = 0; u8 commandLength = 0; u8 commandByte = 0; const u8 *command; bool match = TRUE; u8 input_cmd_len; // go through each command for (u8 i = 0; i < CmdListLen; i++) { // get the command command = CmdList[i].cmd; // get the length of the cmd commandLength = 0; commandByte = CmdList[i].cmd[0]; while (commandByte != 0) { commandLength++; commandByte = CmdList[i].cmd[commandLength]; } match = TRUE; // check for differences in the command and what was entered input_cmd_len = find_cmd_length(g_DebugRxBuffer); if (input_cmd_len != commandLength) { match = FALSE; continue; } for (u8 j = 0; j < commandLength; j++) { if (command[j] != g_DebugRxBuffer[j]) { match = FALSE; break; } } // commands with 0 length are invalid if (commandLength < 1) { match = FALSE; } // if command matches command entered call the callback if (match) { //time_t = GetSysTime(); //LIST(printf("\r\n");); (CmdList[i].action)(); //LIST(printf("it has taken %d ms\r\n", GetSysTime() - time_t);); //DISP(printf("CMD: 耗时%dms\r\n",GetSysTime() - time_t);); break; } } if (!match) { if((g_DebugRxBuffer[0] != '\r') && (g_DebugRxBuffer[0] != '\n')) { //LIST(printf("\r\ncommand not recognized\r\n");); LIST(printf("CMD: 不支持命令\r\n");); } else { LIST(printf("\r\n");); } } } /*—————————————————————————— * 函 数 名:CharToU8 * 输入参数:None * 输出参数:None * 返 回 值:None * 功能说明:ASII码字符数据转换成u8型 *——————————————————————————*/ u8 CharToU8(u8 data) { if ('0' <= data && data <= '9') { return data - '0'; } else if ('a' <= data && data <= 'f') { return data - 'a' + 10; } else if ('A' <= data && data <= 'F') { return data - 'A' + 10; } else { return 0; } } /*—————————————————————————— * 函 数 名:GetU8Para * 输入参数:None * 输出参数:None * 返 回 值:None * 功能说明:控制台获取数据 *——————————————————————————*/ void GetU8Para(u8 *para,u8 index) { u8 i = 0; for(u16 j=0;j 5) { break; } } length = finger-header; if((*header) == '-') { startPos = 1; } for(i=length;i>startPos;i--) { finger--; placeVal = (*finger) - 48; value = value + (digitMod * placeVal); digitMod = digitMod * 10; } if(startPos == 1) { value = 65536 - value; } length=0; break; } } } *para = value; return; } /*—————————————————————————— * 函 数 名:GetStrPara * 输入参数:None * 输出参数:None * 返 回 值:None * 功能说明:控制台获取数据 *——————————————————————————*/ u8 GetStrPara(u8* buffer, u8 index) { u8 i = 0; u8 len = 0; u8* buf = buffer; u16 j = 0; u16 length = get_debugBuf_len(); for(j=0; j 99) { year = 10; } if (month == 0 || month > 12) { month = 1; } if (day == 0 || day > 31) { day = 1; } if (hour >= 24) { hour = 0; } if (minute >= 60) { minute = 0; } if (second >= 60) { second = 0; } Time_Set(year, month, day, hour, minute, second); printf("设置内部RTC时间成功\r\n"); } /*—————————————————————————— * 函 数 名:GetTime * 输入参数:None * 输出参数:None * 返 回 值:None * 功能说明:获取系统时钟 *——————————————————————————*/ void GetTime(void) { printf("内部时钟>>"); Time_Get(); } /*—————————————————————————— * 函 数 名:ListCmd * 输入参数:None * 输出参数:None * 返 回 值:None * 功能说明:打印控制台命令 *——————————————————————————*/ void ListCmd(void) { u8 i; for (i=0; i'9') return -1; data += str[i]-'0'; } return data; } int str2val(char *str,void *val,ENUM_DATA_TYPE data_type) { unsigned char i,j,base,data,len; unsigned long value=0,multiple; len = strlen(str); if((len >2 ) && (str[0] == '0') && (str[1] == 'x')) //HEX { base = 16; str +=2; len -=2; if(len > 8) //HEX (0~FFFFFFFF) { return -3 ; } } else { base = 10; if((len > 10) || ((len == 10) && (str[0] > '4'))) //DEC 0~4294967295 { return -4; } } for(i=0;i= '0') && (str[i] <= '9')) { data = str[i] - '0'; } else if((base == 16) && (str[i] >= 'a') && (str[i] <= 'f')) { data = str[i] - 'a' + 10; } else { break; } if(data != 0) { multiple = 1; for(j=0;j<(len -1-i);j++) { multiple = multiple * base; } value += data * multiple; } } if(data_type == TYPE_BYTE) { if(value > 0xff) { return -6; } else { *((unsigned char *)val) = (unsigned char)value; return 0; } } else if(data_type == TYPE_WORD) { if(value > 0xffff) { return -7; } else { *((unsigned short *)val) = (unsigned short)value; return 0; } } else if(data_type == TYPE_DWORD) { *((unsigned long*)val) = value; return 0; } else { return -8; } } extern u8 * addr_get(); void printenv(void) { printf("\r\n"); printf("Dtu Full Version "); u8 * addr = addr_get(); printf("address : %02x%02x%02x%02x%02x%02x\r\n",addr[5],addr[4],addr[3],addr[2],addr[1],addr[0]); printf("Master Server IP Address :"); printf("%d.",comm_04F3_param.primary.ip1); printf("%d.",comm_04F3_param.primary.ip2); printf("%d.",comm_04F3_param.primary.ip3); printf("%d\r\n",comm_04F3_param.primary.ip4); printf("Master Server Port : %d \r\n",comm_04F3_param.primary.port); printf("Slave Server IP Address : "); printf("%d.",comm_04F3_param.reserve.ip1); printf("%d.",comm_04F3_param.reserve.ip2); printf("%d.",comm_04F3_param.reserve.ip3); printf("%d\r\n",comm_04F3_param.reserve.ip4); printf("Master Server Port : %d \r\n",comm_04F3_param.reserve.port); printf("APN : %s \r\n",comm_04F3_param.APN); printf("user : %s \r\n",comm_04F3_param.user); printf("password : %s \r\n",comm_04F3_param.password); printf("sector 64 sector_write_count\r\n"); } void upgrade(void) { upgrade_flash(); } void serveripattr(void) { // u8 flashtemp[8]; char str1[50]; unsigned short port1,port2; unsigned char ip1[4]; unsigned char ip2[4]; char *str; int i,j,err=0; int ip; char ch='.'; memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,1); if ( (str1[0] == 'm'))// && (str[1] == 'x') && (str[14] == 0)) { memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,2); str = str1; for(j=0; j<4; j++) { if(j==3) ch = 0; i = 0; if(str[++i]!=ch) if(str[++i]!=ch) if(str[++i]!=ch) err = 1; str[i] = 0; ip = strtodec(str, i); if((ip > 255) || err) { //CLI_SEND_MSG("error in ip1\r\n"); return ; } ip1[j] = ip; str += i+1; } memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,3); str = str1; if(str2val(str,&port1,TYPE_WORD)!= 0) { //CLI_SEND_MSG("port1 error!\r\n"); return; } memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,4); if(str1[0] == 'b') { memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,5); str = str1; err = 0; ch = '.'; for(j=0; j<4; j++) { if(j==3) ch = 0; i = 0; if(str[++i]!=ch) if(str[++i]!=ch) if(str[++i]!=ch) err = 1; str[i] = 0; ip2[j] = strtodec(str, i); if((ip2[j] >= 255) || err) { //CLI_SEND_MSG("error in ip2\r\n"); return; } str += i+1; } memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,6); str = str1; if(str2val(str,&port2,TYPE_WORD)!= 0) { // CLI_SEND_MSG("port2 error!\r\n"); return; } } } comm_04F3_param.primary.ip1 = ip1[0]; comm_04F3_param.primary.ip2 = ip1[1]; comm_04F3_param.primary.ip3 = ip1[2]; comm_04F3_param.primary.ip4 = ip1[3]; comm_04F3_param.primary.port = port1; comm_04F3_param.reserve.ip1 = ip2[0]; comm_04F3_param.reserve.ip2 = ip2[1]; comm_04F3_param.reserve.ip3 = ip2[2]; comm_04F3_param.reserve.ip4 = ip2[3]; comm_04F3_param.reserve.port = port2; memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,7); strcpy(comm_04F3_param.APN,str1); memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,8); strcpy(comm_04F3_param.user,str1); memset(str1,0,sizeof(str1)); GetStrPara((u8*)str1,9); strcpy(comm_04F3_param.password,str1); printf("ip1 is %d %d %d %d\r\n",ip1[0],ip1[1],ip1[2],ip1[3]); printf("ip2 is %d %d %d %d\r\n",ip2[0],ip2[1],ip2[2],ip2[3]); printf("port1 is %d \r\n",port1); printf("port2 is %d \r\n",port2); ipport_write(); ipport_init(); #if 0 if (find_string16_len(str) != 12) { printf("addr len err\r\n"); return; } change_string_to_arry16(str); set_addr((u8*)str); if (read_addr(flashtemp)) { printf("local addr 0x"); for (u8 i = 0; i < 6; i++) { printf("%02X", flashtemp[5 - i]); } printf("\r\n"); } else { printf("write addr err\r\n"); } } else { printf("input haven't start at 0x\r\n"); } #endif } void read_local_addr(void) { u8 flashtemp[8]; read_addr(flashtemp); printf("local addr 0x"); for (u8 i = 0; i < 6; i++) { printf("%.2x", flashtemp[5 -i]); } printf("\r\n"); } void controlkeyaddr(u8 *str1,u8 val) { u8 str[30] = {0}; u8 buf[30]; u8 addr[6]; //GetStrPara((u8*)str,1); //change_string_to_arry16((char*)str); str[0] = 0x10; memmove(&str[1],str1,7); str[8] = val; read_addr(addr); buf[0] = 0x68; memcpy(buf + 1, addr, 6); buf[7] = 0x68; buf[8] = 0x19; buf[9] = 0x0E; // buf[10] = 0x00; // buf[11] = 0xFF; // buf[12] = 0x01; // buf[13] = 0x00; buf[10] = 0x03; buf[11] = 0x0E; buf[12] = 0x00; buf[13] = 0x04; buf[14] = str[8]; buf[15] = str[8]; memcpy(buf + 16, str, 8); for (u8 i = 0; i < buf[9]; i++) { buf[i+ 10] += 0x33; } buf[buf[9]+ 10] = GetSum(buf, buf[9]+ 10); buf[buf[9]+11] = 0x16; simulate_mbus_plc_rx(buf, buf[9]+12); } void controlkey(void) { u8 str[30] = {0}; u8 buf[30]; u8 addr[6]; GetStrPara((u8*)str,1); change_string_to_arry16((char*)str); read_addr(addr); buf[0] = 0x68; memcpy(buf + 1, addr, 6); buf[7] = 0x68; buf[8] = 0x19; buf[9] = 0x0E; // buf[10] = 0x00; // buf[11] = 0xFF; // buf[12] = 0x01; // buf[13] = 0x00; buf[10] = 0x03; buf[11] = 0x0E; buf[12] = 0x00; buf[13] = 0x04; buf[14] = str[8]; buf[15] = str[8]; memcpy(buf + 16, str, 8); for (u8 i = 0; i < buf[9]; i++) { buf[i+ 10] += 0x33; } buf[buf[9]+ 10] = GetSum(buf, buf[9]+ 10); buf[buf[9]+11] = 0x16; simulate_mbus_plc_rx(buf, buf[9]+12); } void add_list_node(void) { } void add_in_flash(void) { } void ctl_start_all(void) { // u8 pow; // GetU8Para(&pow,1); // if(pow < 2) // { // ctl_start(pow); // } } /***************************************************************************** * Function : delete_space_key * Description : none * Input : u8 *buf * Output : None * Return : * Others : * Record * 1.Date : 20170413 * Author : barry * Modification: Created function *****************************************************************************/ void delete_space_key(u8 *buf) { u16 length = strlen((char*)buf); for (u16 i = 0; i < length; i++) { if (buf[i] == 0x20) { MemCpy(&buf[i], &buf[i + 1], length - (i + 1)); } } } /***************************************************************************** * Function : mbus_direct_tx * Description : none * Input : void * Output : None * Return : * Others : * Record * 1.Date : 20170413 * Author : barry * Modification: Created function *****************************************************************************/ void mbus_direct_tx(void) { static u8 buf[100] = {0}; u16 length; // u8 direct_cmd[] = "mdirect"; MemCpy(buf,g_DebugRxBuffer + sizeof("mdirect"), get_debugBuf_len() - sizeof("mdirect")); delete_space_key(buf); length = change_string_to_arry16((char*)buf); MBUS_mater_Tx(buf, length); } /***************************************************************************** * Function : change_stop_bits * Description : none * Input : u16 uart_stopbit * Output : None * Return : * Others : * Record * 1.Date : 20170414 * Author : barry * Modification: Created function *****************************************************************************/ float change_stop_bits(u16 uart_stopbit) { float bit; switch (uart_stopbit) { case USART_StopBits_1: bit = 1; break; case USART_StopBits_0_5: bit = 0.5; break; case USART_StopBits_2: bit = 2; break; case USART_StopBits_1_5: bit = 1.5; break; default: bit = 0; break; } return bit; } /***************************************************************************** * Function : change_parity * Description : none * Input : u16 parity * Output : None * Return : * Others : * Record * 1.Date : 20170417 * Author : barry * Modification: Created function *****************************************************************************/ char change_parity(u16 parity) { char checkBit; switch (parity) { case USART_Parity_No: checkBit = 'n'; break; case USART_Parity_Even: checkBit = 'e'; break; case USART_Parity_Odd: checkBit = 'o'; break; default: checkBit = 0; break; } return checkBit; } /***************************************************************************** * Function : printf_uart_port * Description : none * Input : st_uart_int port_init * Output : None * Return : * Others : * Record * 1.Date : 20170414 * Author : barry * Modification: Created function *****************************************************************************/ void printf_uart_port(st_uart_int port_init) { float stopBits; char checkBit; char * master = "MBUS master"; char * radio = "radio------"; char * plc = "PLC--------"; char * RS485 = "485--------"; char * debug = "debug------"; char *ptr; stopBits = change_stop_bits(port_init.uart_param.USART_StopBits); checkBit = change_parity(port_init.uart_param.USART_Parity); if (port_init.com == COM_MBUS_MASTER_NO) { ptr = master; } else if (port_init.com == COM_RADIO_NO) { ptr = radio; } else if (port_init.com == COM_PLC_NO) { ptr = plc; } else if (port_init.com == COM_485_NO) { ptr = RS485; } else if (port_init.com == COM_DEBUG_NO) { ptr = debug; } else { ptr = NULL; } printf("%s: %d, %d, %c, %.1f\r\n", ptr, \ port_init.uart_param.USART_BaudRate, \ (port_init.uart_param.USART_WordLength == 0)?8:9,\ checkBit, stopBits); } /***************************************************************************** * Function : scan_ports * Description : none * Input : void * Output : None * Return : * Others : * Record * 1.Date : 20170413 * Author : barry * Modification: Created function *****************************************************************************/ void scan_ports(void) { printf_uart_port(COM_MBUS_MASTER_port.init); //printf_uart_port(COM_MBUS_SLAVE_port.init); printf_uart_port(COM_PLC_port.init); printf_uart_port(COM_485_port.init); } /***************************************************************************** * Function : read_curent_protocl * Description : none * Input : void * Output : None * Return : * Others : * Record * 1.Date : 20170417 * Author : barry * Modification: Created function *****************************************************************************/ void read_curent_protocl(void) { } /***************************************************************************** * Function : set_mbus_port * Description : none * Input : void * Output : None * Return : * Others : * Record * 1.Date : 20170413 * Author : barry * Modification: Created function *****************************************************************************/ void set_mbus_port(void) { u8 buf[10] = {0}; u8 check; u16 check_bit = USART_Parity_Even; u32 baud; GetStrPara(buf, 1); GetU8Para(&check,2); baud = strtol((char*)buf,NULL,10); if (check == 0) { check_bit = USART_Parity_No; } else if (check == 1) { check_bit = USART_Parity_Odd; } else if (check == 2) { check_bit = USART_Parity_Even; } else { printf("input check bit err\r\n"); return; } set_mbus_master_params(baud, check_bit); } void write_maintain(void) { } void read_maintain(void) { } void set_data_save_time( void ) { } void get_data_save_time( void ) { } void set_mbus_charge_power_time( void ) { } void get_mbus_charge_power_time( void ) { } void lora_cmd_tx(void ) { u8 length; GetU8Para(&length,1); mac_data_req(tedtbuf, length); } void release_debug(void) { } /***************************************************************************** * Function : set_gMeterConfig * Description : none * Input : void * Output : None * Return : * Others : * Record * 1.Date : 20170424 * Author : barry * Modification: Created function *****************************************************************************/ void set_gMeterConfig(void) { } /***************************************************************************** * Function : e5e50000_tx * Description : none * e5e50000 0 0x0b ...//auto even * e5e50000 0 0x03 ...//auto none * e5e50000 0 0x4b ...//2400 even * e5e50000 0 0x43 ...//2400 none * e5e50000 0 0x2b ...//1200 even * e5e50000 0 0x23 ...//1200 none * e5e50000 0 0x4b 49030325220000 6810490303252200000103901f00c116 * Input : void * Output : None * Return : * Others : * Record * 1.Date : 20170524 * Author : barry * Modification: Created function *****************************************************************************/ void e5e50000_tx(void) { u8 port; u8 config; u8 id[20]; u8 str[100]; u8 buf[100]; u8 length; ST_E5E50000_packet *e5e50000_ptr = (ST_E5E50000_packet *)buf; GetU8Para(&port,1); GetU8Para(&config,2); GetStrPara((u8*)id,3); GetStrPara((u8*)str,4); change_string_to_arry16((char*)id); length = change_string_to_arry16((char*)str); e5e50000_ptr->start68 = 0x68; read_addr(e5e50000_ptr->id); e5e50000_ptr->end68 = 0x68; e5e50000_ptr->ctrl = 0x11; e5e50000_ptr->len = 14 + length; e5e50000_ptr->DI[0] = 0x33; e5e50000_ptr->DI[1] = 0x33; e5e50000_ptr->DI[2] = 0x18; e5e50000_ptr->DI[3] = 0x18; e5e50000_ptr->port = port; e5e50000_ptr->meter_config = config; MemCpy(&e5e50000_ptr->meter_type, id, 8); MemCpy(buf + sizeof(ST_E5E50000_packet), str, length); buf[sizeof(ST_E5E50000_packet) + length] = GetSum(buf, buf[9] +10); buf[sizeof(ST_E5E50000_packet) + length + 1] = 0x16; simulate_mbus_plc_rx(buf, buf[9] +12); } void e5e50001_tx(void) { ST_E5E50001_packet e5e50001_packet; u8 str[30] = {0}; u8 addr[6]; GetStrPara((u8*)str,1); change_string_to_arry16((char*)str); read_addr(addr); e5e50001_packet.start68 = 0x68; memcpy(e5e50001_packet.id, addr, 6); e5e50001_packet.end68 = 0x68; e5e50001_packet.ctrl = 0x11; e5e50001_packet.len = 14 + sizeof(ST_J188_read); e5e50001_packet.DI[0] = 0x34; e5e50001_packet.DI[1] = 0x33; e5e50001_packet.DI[2] = 0x18; e5e50001_packet.DI[3] = 0x18; e5e50001_packet.port = 0x00; e5e50001_packet.port_config = 0x0b; memcpy(&e5e50001_packet.meter_type, str , 8); e5e50001_packet.packet188.head.start68 = 0x68; memcpy(&e5e50001_packet.packet188.head.type, str, 8); e5e50001_packet.packet188.head.ctrl = 0x01; e5e50001_packet.packet188.head.len = 0x03; e5e50001_packet.packet188.head.DI[0] = 0x90; e5e50001_packet.packet188.head.DI[1] = 0x1f; e5e50001_packet.packet188.SER = 0x05; e5e50001_packet.packet188.cs = GetSum(&e5e50001_packet.packet188.head.start68, sizeof(ST_J188_read) -2); e5e50001_packet.packet188.end = 0x16; e5e50001_packet.cs = GetSum(&e5e50001_packet.start68, sizeof(ST_E5E50001_packet)-2 ); e5e50001_packet.end16 = 0x16; simulate_mbus_plc_rx((u8*)&e5e50001_packet, sizeof(ST_E5E50001_packet)); } //void irda_tx(void) //{ // u8 irda_buf[] = {0x68, 0x09, 0x13, 0x88, 0x06, 0x00, 0x00, 0x68, 0x11, 0x04, 0x33, 0x33, 0x34, 0x33, 0x5C, 0x16}; // IRDA_TX(irda_buf, sizeof(irda_buf)); //} //输入是BCD码,星期天是0,星期1-星期6 对应1<<1——1<<6 void set_ext_rtc(void) { st_rtc_ext rtc_dat; GetU8Para(&rtc_dat.year, 1); GetU8Para(&rtc_dat.month, 2); GetU8Para(&rtc_dat.day, 3); GetU8Para(&rtc_dat.hour, 4); GetU8Para(&rtc_dat.min, 5); GetU8Para(&rtc_dat.sec, 6); GetU8Para(&rtc_dat.week, 7); rtc_dat.year = (rtc_dat.year / 10) * 16 + rtc_dat.year % 10; rtc_dat.month = (rtc_dat.month / 10) * 16 + rtc_dat.month % 10; rtc_dat.day = (rtc_dat.day / 10) * 16 + rtc_dat.day % 10; rtc_dat.hour = (rtc_dat.hour / 10) * 16 + rtc_dat.hour % 10; rtc_dat.min = (rtc_dat.min / 10) * 16 + rtc_dat.min % 10; rtc_dat.sec = (rtc_dat.sec / 10) * 16 + rtc_dat.sec % 10; rtc_dat.week = 1<< rtc_dat.week; set_rtc_time( rtc_dat ); printf("设置外部时钟成功\r\n"); read_ext_rtc(); } //输出也是BCD码 void read_ext_rtc(void) { u8 week; st_rtc_ext rtc_dat = {0x00}; read_rtc_time(&rtc_dat); week = (u8)(log(rtc_dat.week) / log(2)); printf("当前外部时钟>>"); printf("%.2x-%.2x-%.2x %.2x:%.2x:%.2x week-%.2x\r\n", rtc_dat.year, rtc_dat.month, rtc_dat.day, \ rtc_dat.hour, rtc_dat.min, rtc_dat.sec, week); } typedef struct { u8 mtype; u8 *string; }st_mtype; st_mtype mtypelist[] = { {MBUS_901F_2400_E, "标准188 901F"}, {MBUS_1F90_2400_E, "标准188 1F90"}, {MBUS_HHCQ_2400_N, "重庆智能"}, {MBUS_YZSJ_1200_E, "湖南双佳"}, {MBUS_HZJD_1200_E, "杭州竞达"}, {RS485_NJSM_1200_N, "南京水门485"}, {RS485_CS485_2400_E, "长沙485"}, {RS485_XYDX_2400_8N2, "兴源鼎新485"}, {MUT_RS232_CD_115200_N, "常德RS232"}, }; void read_mtype(void) { printf("\r\n"); for(u8 i = 0; i < sizeof(mtypelist)/sizeof(st_mtype); i++) { printf("%d %s\r\n", mtypelist[i].mtype, mtypelist[i].string); } } void ctrl_12v_pow(void) { u8 open; GetU8Para(&open,1); if (open) { open_RS485_switch(); printf("open 12V\r\n"); } else { close_RS485_switch(); printf("close 12V\r\n"); } } void PowerTest( void ) { open_RS485_switch(); vTaskDelay(50/portTICK_RATE_MS); if(RS485_in_state() == 0x00) { printf("OK\r\n"); } else { printf("ERROR\r\n"); } } void RS4852SendTestProcess( void ) { u8 Testbuff[] = {0x68 ,0x49 ,0x48 ,0x08 ,0x16 ,0x00 ,0x00 ,0x68 ,0x11 ,0x04 ,0x33 ,0x33 ,0x34 ,0x33 ,0x61 ,0x16}; COM_4852_TXProcess(Testbuff, sizeof(Testbuff)); } ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// #if 0 //void sbus_ack(void) //{ // static u8 mbusCmd[] = { 0x68, 0x10, 0x14, 0x64, 0x02, 0x38, 0x00, 0x00, 0x00, 0x81, 0x03, 0x90, 0x1f,0x00, 0x5d, 0x16}; // // open_mbus_switch(); // // hal_UartDMATx(com_MBUS_slave_DMA_cfg, mbusCmd, sizeof(mbusCmd)); // // printf("%d MBUS slave TX:",clock_time()); // printf_buf(mbusCmd, sizeof(mbusCmd)); //} // // // // //void read_update_datas(void) //{ // /* // st_update_params st_update; // // if ( read_update_flash(&st_update) ) // { // printf("totalBytes: %d\r\n",st_update.totalBytes); // printf("total_packets: %d\r\n",st_update.total_packets); // printf("version: %d\r\n",st_update.version); // printf("current_packets: %d\r\n",st_update.current_packets); // printf("received_packets: %d\r\n",st_update.received_packets); // printf("status: %d\r\n",st_update.status); // } // else // { // printf("update crc err\r\n"); // } // */ //} // // // // //void read_local_addr(void) //{ // u8 flashtemp[8]; // // read_addr(flashtemp); // // printf("local addr 0x"); // for (u8 i = 0; i < 6; i++) // { // printf("%.2X", flashtemp[5 -i]); // } // printf("\r\n"); //} // //void read_id(void) //{ // u8 id[12] = {0}; // // read_unique_id( id); // // printf("unique id: "); // // for (u8 i = 0; i < 12; i++) // { // printf("%.2X", id[i]); // } // printf("\r\n"); //} // // //void write_RTC_reg(void) //{ // //} // // // ///* //void add_slave_node_info(void) //{ // u8 meter_id[22]; // // ST_slave_doc node; // // GetStrPara(meter_id, 1); // // change_string_to_arry16((char*)meter_id); // // MemCpy(node.meter_addr, meter_id + 1, 7); // node.meter_type = meter_id[0]; // // add_slave_node(node); //} // // //void read_slave_node_info(void) //{ // u8 meter_id[20]; // ST_slave_doc node; // GetStrPara(meter_id, 1); // // change_string_to_arry16((char*)meter_id); // // if (find_slave_node_from_id(meter_id, &node)) // { // printf("valid = %.2x \r\n", node.valid_node); // printf("meter type = 0x%.2x\r\n",node.meter_type); // // printf("meter_addr :"); // for (u8 i = 0; i< 7; i++) // { // printf(" %.2x", node.meter_addr[i]); // } // } // else // { // printf("slave node not exist\r\n"); // } //} // // //void delete_slave_node_info(void) //{ // u8 meter_id[20]; // // GetStrPara(meter_id, 1); // change_string_to_arry16((char*)meter_id); // // delete_salve_node_from_id(meter_id); //} //*/ // // //void IRDA_debug_tx(void) //{ // u8 irda_buf[] = {0x68, 0x09, 0x13, 0x88, 0x06, 0x00, 0x00, 0x68, 0x11, 0x04, 0x33, 0x33, 0x34, 0x33, 0x5C, 0x16}; // IRDA_TX(irda_buf, sizeof(irda_buf)); //} // // // // // // // // // // // // //void start_self_test(void) //{ // process_start(&TEST_self_process, NULL); //} // // ////输入是BCD码,星期天是0,星期1-星期6 对应1<<1——1<<6 //void set_ext_rtc(void) //{ // st_rtc_ext rtc_dat; // // GetU8Para(&rtc_dat.year, 1); // GetU8Para(&rtc_dat.month, 2); // GetU8Para(&rtc_dat.day, 3); // GetU8Para(&rtc_dat.hour, 4); // GetU8Para(&rtc_dat.min, 5); // GetU8Para(&rtc_dat.sec, 6); // GetU8Para(&rtc_dat.week, 7); // // rtc_dat.year = (rtc_dat.year / 10) * 16 + rtc_dat.year % 10; // rtc_dat.month = (rtc_dat.month / 10) * 16 + rtc_dat.month % 10; // rtc_dat.day = (rtc_dat.day / 10) * 16 + rtc_dat.day % 10; // rtc_dat.hour = (rtc_dat.hour / 10) * 16 + rtc_dat.hour % 10; // rtc_dat.min = (rtc_dat.min / 10) * 16 + rtc_dat.min % 10; // rtc_dat.sec = (rtc_dat.sec / 10) * 16 + rtc_dat.sec % 10; // // rtc_dat.week = 1<< rtc_dat.week; // // set_rtc_time( rtc_dat ); // // printf("OK\r\n"); //} // ////输出也是BCD码 //void read_ext_rtc(void) //{ // u8 week; // // st_rtc_ext rtc_dat; // // read_rtc_time(&rtc_dat); // // week = (u8)(log(rtc_dat.week) / log(2)); // // printf("%.2x-%.2x-%.2x %.2x:%.2x:%.2x week-%.2x\r\n", rtc_dat.year, rtc_dat.month, rtc_dat.day, \ // rtc_dat.hour, rtc_dat.min, rtc_dat.sec, week); //} // // //void read_reg_all(void) //{ // u8 startReg = 0; // u8 endReg = 0; // u8 tempValue; // // GetU8Para(&startReg, 1); // GetU8Para(&endReg, 2); // // for (u8 i = startReg; i<= endReg; i++) // { // if ((i % 10 == 0) && (i > 0)) // { // printf("\r\n"); // } // SX1276Read(i, &tempValue); // printf("%x ", tempValue); // } // printf("\r\n"); //} // //void send_packet(void) //{ // u8 length; // GetU8Para(&length, 1); // #ifndef USE_LORA_MODE // SX1276Fsk_Send_Packet(tedtbuf, length); //#else // SX1276LoRa_Send_Packet(tedtbuf, length); // #endif //} // // // // //void simul_plc_rx(void) //{ // u8 str[30] = {0}; // u8 buf[30]; // u8 addr[6]; // GetStrPara((u8*)str,1); // change_string_to_arry16((char*)str); // // read_addr(addr); // // if (!read_current_HUSF()) // { // buf[0] = 0x68; // memcpy(buf + 1, addr, 6); // buf[7] = 0x68; // // buf[8] = 0x11; // buf[9] = 0x0c; // // buf[10] = 0x00; // buf[11] = 0xFF; // buf[12] = 0x01; // buf[13] = 0x00; // // memcpy(buf + 14, str, 8); // // for (u8 i = 0; i < buf[9]; i++) // { // buf[i+ 10] += 0x33; // } // // buf[buf[9]+ 10] = GetSum(buf, buf[9]+ 10); // buf[buf[9]+11] = 0x16; // simulate_mbus_plc_rx(buf, buf[9]+12); // } // else // { // buf[0] = 0x68; // memcpy(buf + 1, str + 1, 6); // buf[7] = 0x68; // // buf[8] = 0x11; // buf[9] = 0x06; // // buf[10] = 0x1F; // buf[11] = 0x90; // buf[12] = str[7]; // buf[13] = 0x10; // buf[14] = 0x00; // buf[15] = 0x03; // // for (u8 i = 0; i < buf[9]; i++) // { // buf[i+ 10] += 0x33; // } // // buf[buf[9]+ 10] = GetSum(buf, buf[9]+ 10); // buf[buf[9]+11] = 0x16; // simulate_mbus_plc_rx(buf, buf[9]+12); // } //} // // //void simul_plc_frozen(void) //{ // u8 str[30] = {0}; // u8 buf[30]; // u8 addr[6]; // GetStrPara((u8*)str,1); // change_string_to_arry16((char*)str); // // read_addr(addr); // // buf[0] = 0x68; // memcpy(buf + 1, addr, 6); // buf[7] = 0x68; // // buf[8] = 0x11; // buf[9] = 0x0c; // // buf[10] = 0x01; // buf[11] = 0x01; // buf[12] = 0x06; // buf[13] = 0x05; // // memcpy(buf + 14, str, 8); // // for (u8 i = 0; i < buf[9]; i++) // { // buf[i+ 10] += 0x33; // } // // buf[buf[9]+ 10] = GetSum(buf, buf[9]+ 10); // buf[buf[9]+11] = 0x16; // simulate_mbus_plc_rx(buf, buf[9]+12); //} // // //void simul_slave_rx(void) //{ // // u8 str[30] = {0}; // u8 addr[7]; // GetStrPara((u8*)str,1); // change_string_to_arry16((char*)str); // // memcpy(addr, str + 1, 7); // // simulate_mbus_slave_rx(addr, 7); //} // //void read_meter(void) //{ // u8 buf[] = {0x68, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x68, 0x11, 0x04, 0x33, 0x33, 0x34, 0x33, 0xAE, 0x16 }; // // simulate_mbus_plc_rx(buf, buf[9]+12); //} // // // //void set_gMeterConfig(void) //{ // u8 temp_confirmed; // u8 temp_config; // // bool saved_confirmed_val; // // GetU8Para(&temp_confirmed, 1); // GetU8Para(&temp_config, 2); // // saved_confirmed_val = (bool)temp_confirmed; // // if (set_meter_config_info((bool)temp_confirmed, temp_config)) // { // if (read_meter_config(&temp_confirmed, &temp_config)) // { // printf("confirmed = %d, g_meterConfig = %d\r\n", (u8)temp_confirmed, temp_config); // // if (saved_confirmed_val) // { // process_post(&PLC_find_type_process, PROCESS_EVENT_EXIT, NULL); // } // else // { // process_post(&PLC_Moudel_process, PROCESS_EVENT_EXIT, NULL); // } // // } // else // { // printf("read from flash err\r\n"); // } // } // else // { // printf("set meter config err\r\n"); // } //} // // // // //void read_gMeterConfig(void) //{ // u8 temp_confirmed; // u8 temp_config; // // if (read_meter_config(&temp_confirmed, &temp_config)) // { // printf("confirmed = %d, g_meterConfig = %d\r\n", (u8)temp_confirmed, temp_config); // } // else // { // printf("read from flash err\r\n"); // } //} // //void del_meter_data(void) //{ // u8 str[30] = {0}; // GetStrPara((u8*)str,1); // change_string_to_arry16((char*)str); // delete_meter_data(str); // printf("delete finish\r\n"); //} // //void manual_add_meter_data(void) //{ // u8 str[20] = {0}; //addr // u8 p_data[12] = {0}; //addr // u8 success = 0; // // struct st_meter_temp_value tempNode; // // GetStrPara((u8*)str,1); // GetU8Para(&success,2); // GetStrPara((u8*)p_data,3); // change_string_to_arry16((char*)str); // change_string_to_arry16((char*)p_data); // // MemCpy(tempNode.id, str, 7); // MemCpy(tempNode.data + 1, p_data, 4); // tempNode.data[0] = 0x2C; // // tempNode.valid = 1; // tempNode.status = (success == 0)? READ_METER_FAILED : READ_METER_OK; // tempNode.failed_count = 0; // // tempNode.exp_time = clock_time() + 3600000*2; // // if (add_meter_in_list(tempNode)) // { // printf("add node ok\r\n"); // } // else // { // printf("add node failed\r\n"); // } //} // //void write_maintain(void) //{ // u8 tir; // u16 getval; // GetU8Para(&tir,1); // // if (tir > 48) // { // printf("can not exceed 48 hour\r\n"); // } // else // { // set_maintain_time((u16)tir); // // if (read_maintain_time(&getval)) // { // printf("maintian time = %d\r\n", getval); // } // else // { // printf("write maintain time err\r\n"); // } // } //} // // //void read_maintain(void) //{ // u16 val; // // if (read_maintain_time(&val)) // { // printf("maintian time = %d\r\n", val); // } // else // { // printf("read eeprom err\r\n"); // } // //} // //void set_version_of_HBSF(void) //{ // bool ver_HBSF; // // GetU8Para((u8*)&ver_HBSF,1); // // set_HBSF_version(ver_HBSF); // // if (get_HBSF_version()) // { // printf("set HBSF true\r\n"); // } // else // { // printf("set HBSF false\r\n"); // } //} // // //void read_version_of_HBSF(void) //{ // if (get_HBSF_version()) // { // printf(" HBSF true\r\n"); // } // else // { // printf(" HBSF false\r\n"); // } //} #endif