增加RTC设置和ACK

This commit is contained in:
CSSC-WORK\murmur 2023-09-07 15:24:38 +08:00
parent 725f387f3e
commit 4f4ef32d1b
4 changed files with 83 additions and 6 deletions

View File

@ -30,7 +30,7 @@
static rt_timer_t timer485=RT_NULL;
static rt_sem_t sendcmd=RT_NULL;
static rt_mutex_t sendcmd=RT_NULL;
#ifndef MIN_FRAME_LEN
#define MIN_FRAME_LEN 10
#endif
@ -97,7 +97,7 @@ static BATT_INFO batt;
static void timer485_cb()
{
rt_sem_release(sendcmd);
rt_mutex_release(sendcmd);
}
static int b2v(uint8_t *din)
{
@ -200,7 +200,7 @@ static void serial485_thread_entry(void *parameter)
parseBattInfo(rx_buffer, rx_length);
}
rt_thread_mdelay(9*60*1000);
rt_thread_mdelay(1*60*1000);
}
@ -269,7 +269,7 @@ static int uart485_dma_sample(int argc, char *argv[])
}
sendcmd = rt_mutex_create("reqBatt", RT_IPC_FLAG_FIFO);
timer485 = rt_timer_create("batt", timer485_cb, RT_NULL, rt_tick_from_millisecond(10*1000), RT_TIMER_FLAG_PERIODIC);
timer485 = rt_timer_create("batt", timer485_cb, RT_NULL, rt_tick_from_millisecond(6*10*1000), RT_TIMER_FLAG_PERIODIC);
/* 启动定时器1 */
if (timer485 != RT_NULL)
@ -284,6 +284,6 @@ static int uart485_dma_sample(int argc, char *argv[])
/* 导出到 msh 命令列表中 */
//MSH_CMD_EXPORT(uart485_dma_sample,uart485_dma_sample);
INIT_APP_EXPORT(uart485_dma_sample);
INIT_COMPONENT_EXPORT(uart485_dma_sample);
MSH_CMD_EXPORT(dumpBattInfo,);

View File

@ -707,7 +707,7 @@ void deInitTT_thread_entry()
}
pwTT_thread_entry("0");
startAlarm();//alarm 引起崩溃
startAlarm();
clearWindowMode();
setManualWindow(-1);
LOG_W("shunt down TT DONE");

View File

@ -21,6 +21,7 @@ extern int pointInPolygon(int polyCorners,float polyX[], float polyY[],float x,f
extern rt_sem_t okToreport;
extern void resetTM(void);
unsigned long getFileSize(char *file);
void updateSysRTC(uint8_t *din, size_t len);
#define CFG_ACK
/**
* ack信号
@ -1020,6 +1021,9 @@ void ttRunCMD_thread_entry(uint8_t *din, size_t len)
case _INFO_BATT:
parseBattInfo(din+8, din[7]);
break;
case _CMD_SET_RTC:
updateSysRTC(din+8, din[7]);
break;
default:
LOG_W("0x%04X=未支持的指令。",cmd);
break;
@ -1686,6 +1690,77 @@ void reportINFO(void)
}
//INIT_APP_EXPORT(reportINFO);
/**
* 3S的RTC时间
*/
void set3SRTC(void)
{
uint8_t cmd[16]={0x5A, 0xA5, ADDR_3S, ADDR_ANJI, _CMD_SET_RTC >> 8, _CMD_SET_RTC & 0xFF, 0x00, 0x06 };
uint8_t tm[10];
time2Byte(tm);
memcpy(cmd+8,tm,6);
cmd[14]=bccCRC(cmd+2, 14);
cmd[15]=0xED;
LOG_HEX("sRTC",16,cmd,sizeof(cmd));
formatAndSendTo3S(cmd, sizeof(cmd));
}
/**
* RTC时间
* @param din
* @param len
*/
void updateSysRTC(uint8_t *din, size_t len)
{
LOG_I("FUNC = sest RTC");
struct tm tm_new = { 0 };
time_t old = (time_t)0;
time_t now = (time_t)0;
int err = get_timestamp(&old);
if (err != RT_EOK)
{
LOG_E("Get current timestamp failed. %d", err);
return;
}
din[0] += 2000 - 1900;
din[1] -= 1;
// memcpy(tm_new, din, sizeof(tm_new));
tm_new.tm_year = din[0];
tm_new.tm_mon = din[1];
tm_new.tm_mday = din[2];
tm_new.tm_hour = din[3];
tm_new.tm_min = din[4];
tm_new.tm_sec = din[5];
/* converts the local time into the calendar time. */
now = mktime(&tm_new);
err = set_timestamp(now);
if (err != RT_EOK)
{
LOG_E("set date failed. %d", err);
return;
}
get_timestamp(&now); /* get new timestamp */
rt_kprintf("old: %.*s", 25, ctime(&old));
rt_kprintf("now: %.*s", 25, ctime(&now));
//ACK
uint8_t rst[16]={0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _INFO_RTC_ANSWER >> 8, _INFO_RTC_ANSWER & 0xFF, 0x00, 0x06 };
uint8_t tm[10];
time2Byte(tm);
memcpy(rst+8,tm,6);
rst[14]=bccCRC(rst+2, 14);
rst[15]=0xED;
LOG_HEX("sRTC",16,rst,sizeof(rst));
if (isTTjh()) {
upSend(rst, sizeof(rst));
}
}
#define FUNC_DEMO
#ifdef FUNC_DEMO //测试时导出命令到控制台

View File

@ -74,6 +74,8 @@ enum
//3S
#define _CMD_DEPTH_REQUEST 0x0601
#define _CMD_RTC_REQUEST 0x410F
#define _CMD_SET_RTC 0x4006
#define _INFO_RTC_ANSWER 0x4016
//需补充信息
#define _INFO_DEPTH_ANSWER 0x0608 //深度回复