添加sram后不稳定,暂存后回退版本
This commit is contained in:
parent
62408256d1
commit
6f94d7b52a
@ -310,7 +310,7 @@ int isInWindowZone()
|
||||
//
|
||||
//}
|
||||
|
||||
//MSH_CMD_EXPORT(stopAlarm,stop);
|
||||
//MSH_CMD_EXPORT(startAlarm,start);
|
||||
//MSH_CMD_EXPORT(isInWindow,isInWindow);
|
||||
MSH_CMD_EXPORT(stopAlarm,stop);
|
||||
MSH_CMD_EXPORT(startAlarm,start);
|
||||
MSH_CMD_EXPORT(isInWindowZone,isInWindow);
|
||||
//MSH_CMD_EXPORT(getCurrentTime,getCurrentTime);
|
||||
|
@ -463,11 +463,11 @@ void initTT_thread_entry()
|
||||
else if (!isTCPok()) //判断TCP连接是否正常,异常自动重连
|
||||
{
|
||||
// LOG_W("TT server is not ready,--%d",isTCPok());
|
||||
// tcpInit();
|
||||
if (tcpInit() != RT_EOK) {
|
||||
cmd_free();
|
||||
//此处
|
||||
}
|
||||
tcpInit();
|
||||
// if (tcpInit() != RT_EOK) {
|
||||
// cmd_free();
|
||||
// //此处
|
||||
// }
|
||||
// rt_thread_mdelay(1000);
|
||||
if (isTCPok())
|
||||
{
|
||||
@ -476,6 +476,7 @@ void initTT_thread_entry()
|
||||
recTT();
|
||||
repGetTT();
|
||||
reportLoc();
|
||||
LOG_D("threads are ready.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
extern SYS_CFG scfg;
|
||||
extern int cryptSingleMsg(uint8_t *din, size_t len, uint8_t *dout);
|
||||
extern int pointInPolygon(int polyCorners,float polyX[], float polyY[],float x,float y);
|
||||
void selfTest(void);
|
||||
/**
|
||||
* 将收发数据以ASCII字符形式存入log
|
||||
* @param din 待存储数据
|
||||
@ -25,7 +26,7 @@ extern int pointInPolygon(int polyCorners,float polyX[], float polyY[],float x,f
|
||||
* @return 1-发送的数据,0-接收的数据,其它为发送失败的数据
|
||||
*/
|
||||
int trDataTolog(uint8_t *din, size_t len, uint8_t isTx)
|
||||
{
|
||||
{return;
|
||||
char fn[60] = "\n";
|
||||
initDataLogPath(fn);
|
||||
|
||||
@ -82,6 +83,7 @@ void setCommMode(int isTT)
|
||||
//write to cfg file
|
||||
set_cfg("commMode", isTT);
|
||||
LOG_D("set commMode to %s",isTT?"TT":"BD");
|
||||
selfTest();
|
||||
}
|
||||
|
||||
int getCommMode()
|
||||
@ -211,7 +213,7 @@ void upSend_thread_entry(void* parameter)
|
||||
RT_WEAK int upSend(uint8_t *din, size_t len)
|
||||
{
|
||||
LOG_D("try to upsend to TT.");
|
||||
|
||||
//return;
|
||||
// if (one_msg_send_done == RT_NULL) {
|
||||
// one_msg_send_done = rt_sem_create("senddone", 1, RT_IPC_FLAG_PRIO);
|
||||
// }
|
||||
@ -246,7 +248,7 @@ RT_WEAK int upSend(uint8_t *din, size_t len)
|
||||
/**
|
||||
* 系统自检,自动发送自检结果
|
||||
*/
|
||||
void selfTest()
|
||||
void selfTest(void)
|
||||
{
|
||||
LOG_I("FUNC = selftest");
|
||||
rt_uint8_t rst[200]={0x5A, 0xA5, ADDR_ANJI, ADDR_TT, _CMD_SELF_TEST>>8, _CMD_SELF_TEST & 0xff};
|
||||
@ -256,24 +258,25 @@ void selfTest()
|
||||
rst[p++]=0x00;
|
||||
rst[p++]=0x09;
|
||||
|
||||
rst[p++] = sysSta;
|
||||
rst[p++] = getXh();//xh,jh
|
||||
rst[p++] = isTTjh();
|
||||
rst[p++] = commSpeed;
|
||||
rst[p++] = getPowerLevel();
|
||||
rst[p++] = sysSta; //系统状态
|
||||
rst[p++] = getXh();//xh,jh //信号值
|
||||
rst[p++] = isTTjh(); //激活
|
||||
rst[p++] = commSpeed; //速率
|
||||
// rst[p++] = scfg.commMode;
|
||||
rst[p++] = getPowerLevel(); //电量
|
||||
|
||||
//flash 剩餘空間
|
||||
//flash 剩餘空間 //FLASH剩余空间
|
||||
uint16_t cap = getFreeSpace("/");
|
||||
rst[p++] = (uint8_t)(cap >> 8);
|
||||
rst[p++] = (uint8_t)(cap & 0xff);
|
||||
|
||||
//SD卡剩餘空間
|
||||
cap = getFreeSpace("/sd");
|
||||
cap = getFreeSpace("/sd"); //SD卡剩余空间
|
||||
rst[p++] = (uint8_t)(cap >> 8);
|
||||
rst[p++] = (uint8_t)(cap & 0xff);
|
||||
|
||||
//添加配置文件信息
|
||||
uint8_t size = sizeof(scfg);
|
||||
uint8_t size = sizeof(scfg); //配置文件信息
|
||||
memcpy(rst + p,&scfg, size);
|
||||
p+=size;
|
||||
|
||||
@ -385,6 +388,7 @@ void openWindow(int t)
|
||||
rt_timer_start(timer1);
|
||||
LOG_D("手动开窗完成,%d分钟后自动关窗。",t);
|
||||
}
|
||||
selfTest();
|
||||
|
||||
}
|
||||
/**
|
||||
@ -634,7 +638,7 @@ int isInFence(uint8_t *loc);
|
||||
*/
|
||||
static void reportLoc_thread_entry(void *parameter)
|
||||
{
|
||||
#define CHECK_INTERVAL 15000
|
||||
#define CHECK_INTERVAL 6000
|
||||
size_t i = 0;
|
||||
while (isTCPok())
|
||||
{
|
||||
@ -1057,8 +1061,15 @@ void chkACK(uint8_t *msg, size_t size)
|
||||
* @param din
|
||||
* @param len
|
||||
*/
|
||||
void parseTTData(uint8_t *din, size_t len)
|
||||
void parseTTData_thread_entry(void *parameter)
|
||||
{
|
||||
|
||||
SMSG* msg = RT_NULL;
|
||||
msg = (SMSG*) parameter;
|
||||
uint8_t din[500];
|
||||
memcpy(din,msg->data,msg->len);
|
||||
size_t len = (size_t)msg->len;
|
||||
|
||||
/**
|
||||
* +---------------------+-----------+-----------+-----------+-----------+---------+---------------------+------------+
|
||||
* | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|
||||
@ -1116,7 +1127,28 @@ void parseTTData(uint8_t *din, size_t len)
|
||||
}
|
||||
|
||||
}
|
||||
void parseTTData(uint8_t *din, size_t len)
|
||||
{
|
||||
static SMSG msg;
|
||||
memset(&msg, 0, sizeof(SMSG));
|
||||
memcpy(msg.data,din,len);
|
||||
msg.len=len;
|
||||
|
||||
/* 创建 serial 线程 */
|
||||
rt_thread_t thread = rt_thread_create("parseTT", parseTTData_thread_entry, (void *) &msg, 1024 * 5, 27-1, 10);
|
||||
/* 创建成功则启动线程 */
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(thread);
|
||||
return RT_EOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("thread 'parseTT' create failure.");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* get file size in byte
|
||||
* @param file file name whith fullpath
|
||||
@ -1215,6 +1247,109 @@ void d_cacheData()
|
||||
cacheDataToFile(demo, len);
|
||||
}
|
||||
|
||||
#ifdef TR_USE_THREAD
|
||||
void parseRS232_thread_entry(void *parameter)
|
||||
{
|
||||
|
||||
SMSG* msg = RT_NULL;
|
||||
msg = (SMSG*) parameter;
|
||||
uint8_t din[500];
|
||||
memcpy(din,msg->data,msg->len);
|
||||
size_t len = (size_t)msg->len;
|
||||
|
||||
//有HEX有ASCII,统一按HEX解析
|
||||
//部分数据以10字节(20字符)的0数据开始,如深度查询,心跳包等
|
||||
//处理思路是先不管前导0,对应指令手动加前导数据
|
||||
// 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)) {
|
||||
//ascii
|
||||
LOG_I("type = ASCII");
|
||||
trDataTolog(din, len, 0);
|
||||
|
||||
|
||||
uint8_t index[10];
|
||||
uint8_t tmpHead[]={0x35, 0x41, 0x41, 0x35};
|
||||
size_t n=isInByte(din, len, tmpHead, sizeof(tmpHead), index);
|
||||
// LOG_D("n=%d",n);
|
||||
if (!n) {
|
||||
LOG_W("RS232中无匹配帧");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
//按帧头分割
|
||||
uint8_t ndin[400];
|
||||
int cnt=(i+1<n)?index[i+1]-index[i]:len-index[i];
|
||||
memcpy(ndin,din+index[i],cnt);
|
||||
ndin[cnt]='\0';
|
||||
uint8_t tmp[200];
|
||||
size_t ncnt = str2Byte(ndin, 2, 16, tmp);
|
||||
LOG_HEX("frame",16,tmp,ncnt);
|
||||
if (chk3SDataValid(tmp, ncnt) != RT_EOK) {
|
||||
return;
|
||||
}
|
||||
parse3SData(tmp,ncnt);
|
||||
}
|
||||
}
|
||||
else//如果不是ASCII则统一按HEX计// if (memcmp(din,hexHead,sizeof(hexHead)) == 0)
|
||||
{
|
||||
//bin
|
||||
LOG_I("type = BIN");
|
||||
char tmp[200]="";
|
||||
trDataTolog(bytes2str(din, len, 16, " ", tmp), strlen(tmp), 0);
|
||||
|
||||
|
||||
uint8_t index[10];
|
||||
size_t n=isInByte(din, len, hexHead, sizeof(hexHead), index);
|
||||
if (!n) {
|
||||
LOG_W("RS232中无匹配帧");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < n; i++)
|
||||
{
|
||||
//按帧头分割
|
||||
uint8_t ndin[200];
|
||||
int cnt=(i+1<n)?index[i+1]-index[i]:len-index[i];
|
||||
memcpy(ndin,din+index[i],cnt);
|
||||
LOG_HEX("frame",16,ndin,cnt);
|
||||
if (chk3SDataValid(ndin, cnt) != RT_EOK) {
|
||||
return;
|
||||
}
|
||||
parse3SData(ndin,cnt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void parseRS232(uint8_t *din, size_t len)
|
||||
{
|
||||
static SMSG msg;
|
||||
memset(&msg, 0, sizeof(SMSG));
|
||||
memcpy(msg.data, din, len);
|
||||
msg.len = len;
|
||||
|
||||
/* 创建 serial 线程 */
|
||||
rt_thread_t thread = rt_thread_create("parse232", parseRS232_thread_entry, (void *) &msg, 1024 * 5, 27 - 1, 10);
|
||||
/* 创建成功则启动线程 */
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(thread);
|
||||
return RT_EOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("thread 'parse232' create failure.");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
void parseRS232(uint8_t *din, size_t len)
|
||||
{
|
||||
@ -1289,10 +1424,7 @@ void parseRS232(uint8_t *din, size_t len)
|
||||
|
||||
}
|
||||
|
||||
|
||||
//#include <rtthread.h>
|
||||
//#include <rthw.h>
|
||||
|
||||
#endif
|
||||
#include <netdev_ipaddr.h>
|
||||
#include <netdev.h>
|
||||
/**
|
||||
|
@ -201,6 +201,7 @@ static void rulecheck(void)
|
||||
}
|
||||
if (okCnt >= scfg.minTTPeriCnt) {
|
||||
//TT具备发送条件
|
||||
LOG_I("----");
|
||||
TTIsReady();
|
||||
LOG_I("符合规则,TT具备发送状态。");
|
||||
okCnt = scfg.minTTPeriCnt -1;
|
||||
@ -455,7 +456,7 @@ void repGetTT_thread_entry(void* parameter)
|
||||
appendInfo(rstInfo, RST_LEN, buffer, len);
|
||||
}
|
||||
rulecheck();
|
||||
rt_thread_mdelay(10 * 1000);//间隔3s更新一次数据
|
||||
rt_thread_mdelay(3 * 1000);//间隔3s更新一次数据
|
||||
}
|
||||
memset(rstInfo,0x3f,RST_LEN);//初始化
|
||||
}
|
||||
@ -469,7 +470,7 @@ void repGetTT(void)
|
||||
{}
|
||||
memset(rstInfo,0x3f,RST_LEN);//初始化
|
||||
/* 创建 serial 线程 */
|
||||
rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 5, 27, 10);
|
||||
rt_thread_t thread = rt_thread_create("repGetTT", repGetTT_thread_entry, RT_NULL, 1024 * 10, 27+2, 10);
|
||||
/* 创建成功则启动线程 */
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
|
@ -21,13 +21,13 @@
|
||||
#include <usrcfg.h>
|
||||
#include <ttTR.h>
|
||||
|
||||
#define BUFSZ 200
|
||||
#define BUFSZ 2000
|
||||
#define RETRYCNT 10
|
||||
#define URL TTIP
|
||||
#define PORT 8005
|
||||
|
||||
static int sock=0;
|
||||
static int flag=0;
|
||||
volatile int flag=0;
|
||||
void tcpClose(void)
|
||||
{
|
||||
/* 关闭这个连接 */
|
||||
|
@ -483,3 +483,11 @@ void recTT(void)
|
||||
}
|
||||
}
|
||||
MSH_CMD_EXPORT(recTT,TTrx demo.)
|
||||
|
||||
/**
|
||||
* 更新目标地址
|
||||
*/
|
||||
void updateTargetAddr(uint8_t *din, uint8_t *addr)
|
||||
{
|
||||
memcpy(din+13,addr,4);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ static void serial_thread_entry(void *parameter)
|
||||
// struct rx_msg msg;
|
||||
rt_err_t result;
|
||||
rt_uint32_t rx_length=0;//单次收到的数据长度
|
||||
static char rx_buffer[RT_SERIAL_RB_BUFSZ/4 + 1];
|
||||
static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1];
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -309,7 +309,7 @@
|
||||
#define SYSWATCH_EXCEPT_CONFIRM_TMO 15
|
||||
#define SYSWATCH_EXCEPT_RESUME_DLY 15
|
||||
#define SYSWATCH_THREAD_PRIO 0
|
||||
#define SYSWATCH_THREAD_STK_SIZE 1024
|
||||
#define SYSWATCH_THREAD_STK_SIZE 1024*2
|
||||
#define SYSWATCH_THREAD_NAME "syswatch"
|
||||
#define SYSWATCH_WDT_NAME "wdt"
|
||||
#define SYSWATCH_WDT_TIMEOUT 5
|
||||
|
Loading…
Reference in New Issue
Block a user