core.c 添加激活后发送当前缓存文件的功能--待测试

func.c 中 setCommWindow 添加取值核验
isManualWindow 逻辑更新
parseRS232 更新ASCII判断逻辑(数据有\r\n但是前期采集未体现)
更新岸基地址为ADDR_ANJI = 0x3E
增加tcpRecMQ堆栈
This commit is contained in:
CSSC-WORK\murmur 2023-09-05 18:53:01 +08:00
parent 4dba0a67bc
commit 710ffb8e62
9 changed files with 105 additions and 38 deletions

View File

@ -57,6 +57,7 @@ static rt_err_t uart485_input(rt_device_t dev, rt_size_t size)
cachecnt += size;
if (cachecnt < 63) {
// LOG_W("not enough data[%d byte(s)], cached and waiting...",size);//处理半包
LOG_D("%d byte(s)",size);
return -1;
}
msg.dev = dev;
@ -199,7 +200,7 @@ static void serial485_thread_entry(void *parameter)
parseBattInfo(rx_buffer, rx_length);
}
rt_thread_mdelay(30*1000);
rt_thread_mdelay(9*60*1000);
}

View File

@ -30,7 +30,7 @@ void initCfgMutex()
isCfgOk = rt_mutex_create("cfg", RT_IPC_FLAG_FIFO);
isTosendOk = rt_mutex_create("tosend", RT_IPC_FLAG_FIFO);
}
//INIT_APP_EXPORT(initCfg);
INIT_APP_EXPORT(initCfgMutex);
static void setLock()
{

View File

@ -215,7 +215,7 @@ void sysSemInit()
// rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_FIFO);//检查天通状态
// rt_sem_release(cfgUpdate); //上电更新值
initCfgMutex();
// initCfgMutex();
// void reportINFO();
reportINFO();
/* 创建 serial 线程 */
@ -256,10 +256,12 @@ void sysInit(void)
{
sysSemInit();
initCfg();
checkManualWindow();
if (isInWindowZone() || isManualWindow()) {//开机检查是否在开窗区间内是则给TT开机
initTT();
setWindowMode();
}
}
//INIT_COMPONENT_EXPORT(sysInit);
@ -328,6 +330,11 @@ void resetTM(void)
LOG_W("TIMEOUT stopped.[isWindowMode]");
return;
}
if (isManualWindow()) {
stopTM();
LOG_W("TIMEOUT stopped.[isManualMode]");
return;
}
rt_tick_t t= rt_tick_from_millisecond(scfg.timeout*60*1000);
rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_SET_TIME,(void*) &t);
@ -485,6 +492,19 @@ void d_upSendFile(int argc, char **argv)
*/
void getAndSendFile()
{
//优先发送未达指定大小的文件
char fnow[50];
getLstCacheFileName(fnow);
if (getFileSize(fnow)) {//有数据才发
updateCacheFileName();
LOG_I("send latest data first");
// rt_sem_release(okTosend);//初始赋值
upSendFile(fnow,0);
rt_thread_mdelay(10*1000);
}
static int index[MAX_KEY_LEN];
static char f[5][MAX_KEY_LEN];
int cnt = getFilesToSend(f, index);

View File

@ -153,7 +153,7 @@ return 0x63;
typedef struct
{
rt_uint8_t len;
rt_uint8_t data[];
rt_uint8_t data[200];
} SMSG;//single messgae
@ -185,7 +185,7 @@ void upSend_thread_entry(void* parameter)
//打包数据
uint8_t dout[200];
uint8_t dout[300];
static MSG cfg;
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
char fin[30];
@ -198,7 +198,9 @@ void upSend_thread_entry(void* parameter)
//crypt before pack
uint8_t tmp[200];
uint8_t len = cryptSingleMsg(msg->data, msg->len, tmp);
if (len>170) {
LOG_W("length of msg is too long.[%d->%d]",msg->len,len);
}
size_t rst = packMsg(&cfg, tmp, len, dout);//packMsgs
#else
size_t rst = packMsg(&cfg, tmpmsg->data, msg->len, dout);//packMsgs
@ -359,8 +361,13 @@ extern void updateAlarm(uint8_t *t, size_t len);
void setCommWindow(uint8_t *t, size_t len)
{
LOG_I("FUNC = setCommWindow");
size_t cnt = sizeof(scfg.openWindowTime);
if (len>cnt) {
LOG_W("only support %d windows",cnt/4);
len = cnt;
}
len= len/4*4;//窗口需要成对
// extern void updateAlarm(uint8_t *t, size_t len);
updateAlarm(t,len);
memcpy(scfg.openWindowTime,t,len);
rt_sem_release(cfgUpdate);
@ -382,6 +389,7 @@ void d_sw(void)
*/
void setManualWindow(int isManualWindow)
{
scfg.isMaWin = isManualWindow;
set_cfg("isMaWin", isManualWindow);
}
@ -393,13 +401,26 @@ void closeWindow(void);
*/
int isManualWindow(void)
{
int rst = get_cfg("isMaWin");
if (rst < 0) {//none
return 0;
int rst = scfg.isMaWin;
if (rst >= 0) {
rst = 1;
LOG_I("is in manual open mode.");
}
LOG_I("is in manual window.");
else {
rst = 0;
}
return rst;
}
void checkManualWindow(void)
{
int rst = get_cfg("isMaWin");
scfg.isMaWin = rst;
if (rst < 0) {//none
return;
}
if (rst == 0) {//manual open without auto close
return 1;
return;
}
//设置定时器,定时器到则关窗
/* 创建定时器,单次定时器 */
@ -413,7 +434,7 @@ int isManualWindow(void)
rt_timer_start(timer1);
LOG_D("手动开窗完成,%d分钟后自动关窗。",rst);
}
return 1;
return;
}
/**
@ -535,11 +556,7 @@ int reportDepth(uint8_t *din,size_t len)
rt_memcpy(dout+10, din, len);//5aa5从第11字节开始共len个字节
LOG_HEX("depth",16,dout,len+10);
//加密。因加密后数据长度会变化,故不能只加密位置数据。
nlen = cryptSingleMsg(din, len+10, dout);
LOG_HEX("crypt",16,dout,nlen);
// LOG_D("位置数据加密完成");
upSend(dout, nlen);
upSend(dout, len+10);
}
//天通指令类型0x70 0x01
/**
@ -579,7 +596,7 @@ void updateAllSysCfg(uint8_t *cfg, size_t len)
rst &= set_cfg("minTTsinal",scfg.minTTsinal);
rst &= set_cfg("timeout",scfg.timeout);
char tmpstr[20];
char tmpstr[sizeof(scfg.commMode)*4];
bytes2str(scfg.openWindowTime, 8, 10, ",", tmpstr);
rst &= set_cfgs("openWindowTime",tmpstr);
@ -677,10 +694,12 @@ static int packLocMsg(uint8_t *dout)
}
static void d_packLocMsg(void)
{
uint8_t tmp[200];
size_t len = packLocMsg(tmp);
// uint8_t tmp[200];
// size_t len = packLocMsg(tmp);
// len = cryptSingleMsg(tmp, len, tmp);
LOG_HEX("c",16,tmp,len);
uint8_t din[]={0x5A,0xA5,0x3E,0x32,0x06,0x08,0x00,0x0A,0x17,0x09,0x05,0x0F,0x24,0x0B,0xFF,0xFF,0xFF,0xFF,0x33,0xED};
reportDepth(din, sizeof(din));
// LOG_HEX("c",16,tmp,len);
// upSend(tmp, len);
}
/**
@ -1030,7 +1049,7 @@ RT_WEAK int formatAndSendTo3S(uint8_t * din, size_t len)
sendTo3S(str, strlen(str));//作为字符串发送
return 0;
}
//#define CHECK_3S_DATA
int chk3SDataValid(uint8_t *din, size_t count)
{
uint8_t head[]={0x5A,0xA5};
@ -1071,7 +1090,9 @@ void parse3SData(uint8_t *din, size_t count)
+--------+--------+------------+------------+---------+--------+------+------+-------+-----+-------+---------+------+
*/
if (chk3SDataValid(din, count) != RT_EOK) {
return;
#ifdef CHECK_3S_DATA
return;
#endif
}
//有效的数据才能复位超时
@ -1099,7 +1120,10 @@ void parse3SData(uint8_t *din, size_t count)
int cmd = (din[4] << 8) + din[5];
switch (cmd)
{
case _CMD_DEPTH_REQUEST:
// case _CMD_DEPTH_REQUEST:
// reportDepth(din, count);
// break;
case _INFO_DEPTH_ANSWER:
reportDepth(din, count);
break;
default:
@ -1339,6 +1363,22 @@ void d_getFileSize(int argc, char ** argv)
LOG_D("size = %d Byte.",size);
}
/**
*
* @param f
* @return
*/
int isFileExit(char *f)
{
int rst = 0;
int fd = open(f, O_RDONLY);
if (fd > 0)
{
rst = 1;
close(fd);
}
return rst;
}
extern SYS_CFG scfg;
static uint8_t iscdlock=0;
/**
@ -1513,14 +1553,14 @@ void parseRS232(uint8_t *din, size_t len)
//有HEX有ASCII统一按HEX解析
//部分数据以10字节20字符的0数据开始如深度查询心跳包等
//处理思路是先不管前导0对应指令手动加前导数据
// uint8_t asciiHead[]={0x41, 0x54, 0x2B, 0x53, 0x4E, 0x44,};//"AT+SND"
uint8_t asciiHead[]={0x41, 0x54, 0x2B, 0x53, 0x4E, 0x44,};//"AT+SND"
uint8_t hexHead[]={0x5a, 0xa5};//"5AA5"
//由于帧头有多种且ascii和hex混发无法处理粘包
// LOG_D("data is %s",isDataASCII(din, len)?"ASCII":"BIN");
//check
// if (memcmp(din,asciiHead,sizeof(asciiHead)) == 0) {
if (isDataASCII(din, len)) {
if (memcmp(din,asciiHead,sizeof(asciiHead)) == 0) {
// if (isDataASCII(din, len) || memcmp(din,asciiHead,sizeof(asciiHead)) == 0) {
//ascii
LOG_I("type = ASCII");
trDataTolog(din, len, 0);
@ -1531,7 +1571,7 @@ void parseRS232(uint8_t *din, size_t len)
size_t n=isInByte(din, len, tmpHead, sizeof(tmpHead), index);
// LOG_D("n=%d",n);
if (!n) {
LOG_W("RS232中无匹配帧");
LOG_W("RS232中无匹配帧[ASCII]");
return;
}
for (size_t i = 0; i < n; i++)
@ -1542,10 +1582,12 @@ void parseRS232(uint8_t *din, size_t len)
memcpy(ndin,din+index[i],cnt);
ndin[cnt]='\0';
uint8_t tmp[200];
size_t ncnt = str2Byte(ndin, 2, 16, tmp);
size_t ncnt = str2Byte(ndin, 2, 16, tmp)-1;//结尾有\r\n
LOG_HEX("frame",16,tmp,ncnt);
if (chk3SDataValid(tmp, ncnt) != RT_EOK) {
#ifdef CHECK_3S_DATA
return;
#endif
}
parse3SData(tmp,ncnt);
}
@ -1561,7 +1603,7 @@ void parseRS232(uint8_t *din, size_t len)
uint8_t index[10];
size_t n=isInByte(din, len, hexHead, sizeof(hexHead), index);
if (!n) {
LOG_W("RS232中无匹配帧");
LOG_W("RS232中无匹配帧[BIN]");
return;
}
for (size_t i = 0; i < n; i++)
@ -1572,7 +1614,9 @@ void parseRS232(uint8_t *din, size_t len)
memcpy(ndin,din+index[i],cnt);
LOG_HEX("frame",16,ndin,cnt);
if (chk3SDataValid(ndin, cnt) != RT_EOK) {
#ifdef CHECK_3S_DATA
return;
#endif
}
parse3SData(ndin,cnt);
}

View File

@ -74,10 +74,11 @@ enum
//3S
#define _CMD_DEPTH_REQUEST 0x0601
#define _CMD_RTC_REQUEST 0x410F
//需补充信息
#define _INFO_DEPTH_ANSWER 0x0608 //深度回复
//
#define ADDR_ANJI 0x42 //0x42?
#define ADDR_ANJI 0x3E //0x42?
#define ADDR_TT 0x41
#define ADDR_3S 0x32

View File

@ -86,7 +86,7 @@ void show_version(void)
char str[30];
uint8_t t[10];
size_t len=time2Byte(t);
rt_kprintf("SW Version: %s, build-%s\n","1.8d",bytes2str(t, 3, 10, "", str));
rt_kprintf("SW Version: %s, build-%s\n","1.9d",bytes2str(t, 3, 10, "", str));
}
MSH_CMD_EXPORT(show_version,);

View File

@ -202,7 +202,7 @@ void tcpRecMQ_thread_entry(void)
void tcpRecMQ(void)
{
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("tcpRecMQ", tcpRecMQ_thread_entry, RT_NULL, 1024*1, 25, 10);
rt_thread_t thread = rt_thread_create("tcpRecMQ", tcpRecMQ_thread_entry, RT_NULL, 1024*10, 25, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{

View File

@ -50,7 +50,7 @@ typedef struct
uint8_t minTTPeriCnt;
uint8_t minTTsinal;
uint8_t timeout;
uint8_t openWindowTime[20];
uint8_t openWindowTime[60];
uint16_t maxSizePerFile;
uint8_t commMode;
uint8_t selfDesSW;

View File

@ -67,7 +67,7 @@ INIT_COMPONENT_EXPORT(w25q128_mount);
void sdmnt_init(void)
{
rt_thread_mdelay(100);//这段延时必须加上系统上电过程中存在延时否则会出现先挂载后注册块设备sd0的情况
rt_thread_mdelay(300);//这段延时必须加上系统上电过程中存在延时否则会出现先挂载后注册块设备sd0的情况
// mkfs("elm","sd0");//挂在前需格式化
if(dfs_mount("sd0","/sd","elm",0,0)==0) //挂载文件系统参数块设备名称、挂载目录、文件系统类型、读写标志、私有数据0
{
@ -75,7 +75,8 @@ void sdmnt_init(void)
}
else
{
LOG_E("dfs mount failed\r\n");
LOG_E("dfs mount failed");
// mkfs("elm","sd0");
}
}
/* 导出到自动初始化 */