1914 lines
40 KiB
C
1914 lines
40 KiB
C
/*——————————————————————————
|
||
* 文 件 名:Cmd.c
|
||
* 日 期:2013-12-30
|
||
* 文件说明:控制台主文件
|
||
*——————————————————————————*/
|
||
#include "Cmd.h"
|
||
#include <math.h>
|
||
#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"
|
||
|
||
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;
|
||
|
||
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 ReadSystemMeterAddrList( void );
|
||
|
||
|
||
sCmd CmdList[] =
|
||
{
|
||
{"writeaddr",set_local_addr,""},
|
||
{"readaddr",read_local_addr,""},
|
||
{"simulplc",simul_plc_rx,""},
|
||
{"addlist",add_list_node,""},
|
||
{"addflash",add_in_flash,""},
|
||
{"scanlist",scan_list,""},
|
||
{"setmpow",set_mbus_power,""},
|
||
{"getmpow", read_mbus_power,""},
|
||
{"simultx",simul_read_meter,""},
|
||
{"ver", ReadVersion,""},
|
||
{"reboot",SysReset,""},
|
||
{"mdirect",mbus_direct_tx,""},
|
||
{"port",scan_ports,""},
|
||
{"setmport",set_mbus_port,""},
|
||
{"setmaintain", write_maintain,""},
|
||
{"readmaintain", read_maintain,""},
|
||
{"readmconfig",read_curent_protocl,""},
|
||
{"closepr",close_printf,""},
|
||
{"openpr",open_printf,""},
|
||
|
||
|
||
{"setmconfig",set_gMeterConfig,""},
|
||
{"readxywaf",PrintfMonitorWaterMeterDataFrame,""},
|
||
{"clearxywaf",ClearXYDataFrameStore,""},
|
||
{"transparent", transparent_Proc,""},
|
||
|
||
{"ReadWMAddr",ReadSystemMeterAddrList,"Read Water Meter ADDR And Data List"},
|
||
{"clearminfo",ClearMeterInfo,"Clear Water Meter ADDR And Data List"},
|
||
|
||
{"settime",set_ext_rtc,""},
|
||
{"readtime",read_ext_rtc,""},
|
||
|
||
{"irda",irda_tx,""},
|
||
{"auto",auto_sync_list_meters,""},
|
||
{"setrtc",set_ext_rtc,""},
|
||
{"readrtc",read_ext_rtc,""},
|
||
{"mtype", read_mtype,""},
|
||
{"ctr12v",ctrl_12v_pow,""},
|
||
{"ls", ListCmd,""}
|
||
};
|
||
|
||
u8 CmdListLen = sizeof(CmdList) / sizeof(sCmd);
|
||
|
||
|
||
/*——————————————————————————
|
||
* 函 数 名:Cmd_Proc
|
||
* 输入参数:None
|
||
* 输出参数:None
|
||
* 返 回 值:None
|
||
* 功能说明:控制台任务调度
|
||
*——————————————————————————*/
|
||
void Cmd_Proc(void)
|
||
{
|
||
if (get_debugBuf_len() > 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<get_debugBuf_len() ;j++)
|
||
{
|
||
if(g_DebugRxBuffer[j] == ' ')
|
||
{
|
||
i++;
|
||
if(i == index)
|
||
{
|
||
if ((g_DebugRxBuffer[j + 2] == ' ') \
|
||
|| (g_DebugRxBuffer[j + 2] == '\r') \
|
||
|| (g_DebugRxBuffer[j + 2] == '\n'))
|
||
{
|
||
(*para) = CharToU8(g_DebugRxBuffer[j+1]);
|
||
}
|
||
else if ((g_DebugRxBuffer[j + 3] == ' ') \
|
||
|| (g_DebugRxBuffer[j + 3] == '\r') \
|
||
|| (g_DebugRxBuffer[j + 3] == '\n'))
|
||
{
|
||
u8 temp1,temp2;
|
||
temp1 = CharToU8(g_DebugRxBuffer[j + 1]);
|
||
temp1 *= 10;
|
||
temp2 = CharToU8(g_DebugRxBuffer[j + 2]);
|
||
temp2 += temp1;
|
||
*para = temp2;
|
||
}
|
||
else
|
||
{
|
||
u8 temp1, temp2, temp3;
|
||
temp1 = CharToU8(g_DebugRxBuffer[j + 1]);
|
||
temp1 *= 100;
|
||
temp2 = CharToU8(g_DebugRxBuffer[j + 2]);
|
||
temp2 *= 10;
|
||
temp3 = CharToU8(g_DebugRxBuffer[j + 3]);
|
||
temp3 += temp1 + temp2;
|
||
(*para) = temp3;
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
*para = 0;
|
||
|
||
return;
|
||
}
|
||
/*——————————————————————————
|
||
* 函 数 名:GetU16Para
|
||
* 输入参数:None
|
||
* 输出参数:None
|
||
* 返 回 值:None
|
||
* 功能说明:控制台获取数据
|
||
*——————————————————————————*/
|
||
void GetU16Para(u16 *para,u8 index)
|
||
{
|
||
u8 i = 0;
|
||
u8 length;
|
||
u8 placeVal;
|
||
u8 startPos = 0;
|
||
u16 j = 0;
|
||
u16 value = 0;
|
||
u16 digitMod = 1;
|
||
|
||
for(j=0;j<get_debugBuf_len() ;j++)
|
||
{
|
||
if(g_DebugRxBuffer[j] == ' ')
|
||
{
|
||
i++;
|
||
|
||
if(i == index)
|
||
{
|
||
u8 *finger = &g_DebugRxBuffer[j+1];
|
||
u8 *header = &g_DebugRxBuffer[j+1];
|
||
|
||
while((*finger) != ' ')
|
||
{
|
||
finger++;
|
||
|
||
if((*finger) == '\r' || (*finger) == '\n')
|
||
{
|
||
break;
|
||
}
|
||
|
||
if((finger-header) > 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<length; j++)
|
||
{
|
||
if(g_DebugRxBuffer[j] == ' ')
|
||
{
|
||
i++;
|
||
|
||
if(i == index)
|
||
{
|
||
while(g_DebugRxBuffer[j+1] != ' ' & (g_DebugRxBuffer[j+1] != '\r') & (g_DebugRxBuffer[j+1] != '\n'))
|
||
{
|
||
*buf = g_DebugRxBuffer[j+1];
|
||
buf++;
|
||
j++;
|
||
len++;
|
||
}
|
||
|
||
return len;
|
||
}
|
||
}
|
||
}
|
||
|
||
return len;
|
||
}
|
||
/*——————————————————————————
|
||
* 函 数 名:SetTime
|
||
* 输入参数:None
|
||
* 输出参数:None
|
||
* 返 回 值:None
|
||
* 功能说明:设置系统时钟
|
||
*——————————————————————————*/
|
||
void SetTime(void)
|
||
{
|
||
u8 year = 10;
|
||
u8 month = 1;
|
||
u8 day = 1;
|
||
u8 hour = 0;
|
||
u8 minute = 0;
|
||
u8 second = 0;
|
||
|
||
GetU8Para(&year, 1);
|
||
GetU8Para(&month, 2);
|
||
GetU8Para(&day, 3);
|
||
GetU8Para(&hour, 4);
|
||
GetU8Para(&minute, 5);
|
||
GetU8Para(&second, 6);
|
||
|
||
if (year == 0 || year > 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);
|
||
}
|
||
|
||
|
||
|
||
/*——————————————————————————
|
||
* 函 数 名:GetTime
|
||
* 输入参数:None
|
||
* 输出参数:None
|
||
* 返 回 值:None
|
||
* 功能说明:获取系统时钟
|
||
*——————————————————————————*/
|
||
void GetTime(void)
|
||
{
|
||
Time_Get();
|
||
}
|
||
|
||
/*——————————————————————————
|
||
* 函 数 名:ListCmd
|
||
* 输入参数:None
|
||
* 输出参数:None
|
||
* 返 回 值:None
|
||
* 功能说明:打印控制台命令
|
||
*——————————————————————————*/
|
||
void ListCmd(void)
|
||
{
|
||
u8 i;
|
||
|
||
for (i=0; i<CmdListLen; i++)
|
||
{
|
||
printf("CMD: %s\t\t%s\r\n",CmdList[i].cmd,CmdList[i].info);
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
|
||
u16 find_string16_len(char * str)
|
||
{
|
||
u16 len = strlen(str);
|
||
|
||
u8 * ptr = (u8*)str;
|
||
|
||
if ((str[0] == '0') && (str[1] == 'x'))
|
||
{
|
||
len -= 2;
|
||
ptr += 2;
|
||
}
|
||
|
||
for (u16 i = 0; i < len; i++)
|
||
{
|
||
if ('0' <= ptr[i] && ptr[i] <= '9')
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if ('a' <= ptr[i] && ptr[i] <= 'f')
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if ('A' <= ptr[i] && ptr[i] <= 'F')
|
||
{
|
||
continue;
|
||
}
|
||
|
||
len = i;
|
||
break;
|
||
}
|
||
|
||
return len;
|
||
}
|
||
|
||
|
||
|
||
u16 change_string_to_arry16(char * input)
|
||
{
|
||
u16 len;
|
||
|
||
u8 temp[3] = {0,0,0};
|
||
u16 count;
|
||
|
||
len = find_string16_len(input);
|
||
|
||
count = (len%2 == 0)?(len/2 ):(len/2 + 1);
|
||
|
||
if ((input[0] == '0') && (input[1] == 'x'))
|
||
{
|
||
MemCpy(input, input + 2, len);
|
||
}
|
||
|
||
for (u16 i = 0; i < count; i++)
|
||
{
|
||
if ( (i == 0) && (len%2 == 1))
|
||
{
|
||
temp[0] = 0;
|
||
temp[1] = input[i];
|
||
}
|
||
else
|
||
{
|
||
temp[0] = input[i*2];
|
||
temp[1] = input[i*2 + 1];
|
||
}
|
||
input[i] = strtol((char*)temp,NULL,16);
|
||
}
|
||
|
||
return count;
|
||
}
|
||
|
||
void set_local_addr(void)
|
||
{
|
||
u8 flashtemp[8];
|
||
char str[20];
|
||
|
||
GetStrPara((u8*)str,1);
|
||
|
||
if ( (str[0] == '0') && (str[1] == 'x') && (str[14] == 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("%X", flashtemp[5 - i]);
|
||
}
|
||
printf("\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("write addr err\r\n");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("input haven't start at 0x\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 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);
|
||
|
||
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;
|
||
// buf[10] = 0x03;
|
||
// buf[11] = 0x0E;
|
||
// buf[12] = 0x00;
|
||
// buf[13] = 0x04;
|
||
|
||
// buf[14] = 0x00;
|
||
// buf[15] = 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);
|
||
|
||
}
|
||
|
||
void add_list_node(void)
|
||
{
|
||
u8 id[20];
|
||
GetStrPara(id,1);
|
||
change_string_to_arry16((char*)id);
|
||
add_empty_meter_in_list(id);
|
||
scan_list();
|
||
}
|
||
|
||
void add_in_flash(void)
|
||
{
|
||
u8 id[20];
|
||
GetStrPara(id,1);
|
||
change_string_to_arry16((char*)id);
|
||
struct st_meter_temp_value *ptr = find_meter_from_id(id);
|
||
|
||
if (ptr)
|
||
{
|
||
//add_list_meter_in_flash(ptr);
|
||
}
|
||
else
|
||
{
|
||
printf("node is not in list\r\n");
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : set_mbus_power
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170412
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void set_mbus_power(void)
|
||
{
|
||
u8 pow;
|
||
GetU8Para(&pow,1);
|
||
set_power_level((bool)pow);
|
||
read_mbus_power();
|
||
}
|
||
/*****************************************************************************
|
||
* Function : read_mbus_power
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170412
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void read_mbus_power(void)
|
||
{
|
||
if (!read_power_level())
|
||
{
|
||
printf("MBUS power high\r\n");
|
||
}
|
||
else
|
||
{
|
||
printf("MBUS power low\r\n");
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* Function : simul_read_meter
|
||
* Description : none
|
||
* Input : void
|
||
* Output : None
|
||
* Return :
|
||
* Others :
|
||
* Record
|
||
* 1.Date : 20170413
|
||
* Author : barry
|
||
* Modification: Created function
|
||
|
||
*****************************************************************************/
|
||
void simul_read_meter(void)
|
||
{
|
||
u8 protl;
|
||
u8 id[20] = {0};
|
||
static u8 sendBuf[100];
|
||
u16 send_length;
|
||
|
||
GetU8Para(&protl,1);
|
||
GetStrPara(id, 2);
|
||
change_string_to_arry16((char*)id);
|
||
get_read_meter_packet(protl, id[0], id+1, sendBuf, &send_length);
|
||
|
||
if (protl <= MBUS_METER_START)
|
||
{
|
||
printf("协议错误\r\n");
|
||
}
|
||
else if (protl < MBUS_METER_MAX)
|
||
{
|
||
printf_buf(sendBuf, send_length);
|
||
MBUS_mater_Tx(sendBuf, send_length);
|
||
}
|
||
else if ( (protl == MBUS_METER_MAX) || (protl == RS485_METER_START))
|
||
{
|
||
printf("协议错误\r\n");
|
||
}
|
||
else if (protl < RS485_METER_MAX)
|
||
{
|
||
printf_buf(sendBuf, send_length);
|
||
RS4852_SendDataPacket(sendBuf, send_length);
|
||
}
|
||
else if ((protl == RS485_METER_MAX) || (protl == MUT_METER_START))
|
||
{
|
||
printf("协议错误\r\n");
|
||
}
|
||
else if (protl < MUT_METER_MAX)
|
||
{
|
||
//printf_buf(sendBuf, send_length);
|
||
//mac_data_req(sendBuf, send_length);
|
||
}
|
||
else
|
||
{
|
||
printf("协议错误\r\n");
|
||
return;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* 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(direct_cmd), get_debugBuf_len() - sizeof(direct_cmd));
|
||
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)
|
||
{
|
||
printf("当前协议:");
|
||
|
||
switch (get_protocl_inRAM())
|
||
{
|
||
case PROTCL_AUTO:
|
||
printf("自动\r\n");
|
||
break;
|
||
|
||
case MBUS_901F_2400_E:
|
||
printf("标准188_901F\r\n");
|
||
break;
|
||
|
||
case MBUS_1F90_2400_E:
|
||
printf("标准188_1F90\r\n");
|
||
break;
|
||
|
||
case MBUS_HHCQ_2400_N:
|
||
printf("重庆智能\r\n");
|
||
break;
|
||
|
||
case MBUS_YZSJ_1200_E:
|
||
printf("双佳\r\n");
|
||
break;
|
||
|
||
case MBUS_HZJD_1200_E:
|
||
printf("竞达\r\n");
|
||
break;
|
||
|
||
case RS485_NJSM_1200_N:
|
||
printf("水门485\r\n");
|
||
break;
|
||
|
||
case RS485_CS485_2400_E:
|
||
printf("长沙485\r\n");
|
||
break;
|
||
|
||
case MUT_SPI_LORA:
|
||
printf("SPI_LORA\r\n");
|
||
break;
|
||
|
||
default:
|
||
printf("err\r\n");
|
||
break;
|
||
|
||
}
|
||
}
|
||
|
||
/*****************************************************************************
|
||
* 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)
|
||
{
|
||
u8 tir;
|
||
u16 getval;
|
||
GetU8Para(&tir,1);
|
||
|
||
if (tir > 48)
|
||
{
|
||
printf("can not exceed 48 hour\r\n");
|
||
}
|
||
else
|
||
{
|
||
set_maintain_time((u16)tir);
|
||
|
||
getval = read_maintain_time();
|
||
|
||
printf("maintian time = %d\r\n", getval);
|
||
}
|
||
}
|
||
|
||
|
||
void read_maintain(void)
|
||
{
|
||
u16 getval;
|
||
|
||
getval = read_maintain_time();
|
||
|
||
printf("maintian time = %d\r\n", getval);
|
||
}
|
||
|
||
|
||
|
||
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)
|
||
{
|
||
u8 protl;
|
||
GetU8Para(&protl,1);
|
||
set_curent_protocl(protl);
|
||
read_curent_protocl();
|
||
}
|
||
|
||
|
||
|
||
/*****************************************************************************
|
||
* 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 );
|
||
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("%.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"},
|
||
};
|
||
|
||
|
||
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");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////
|
||
|
||
#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
|