基本完成规则框架

基本完成数据打包(指定文件)
TCPclient 连接失败暂未定位
This commit is contained in:
murmur 2023-06-06 15:45:13 +08:00
parent de294e2c59
commit 88d2f1d0fc
14 changed files with 592 additions and 228 deletions

View File

@ -18,20 +18,23 @@
#include <ttmsg/ttmsg.h> #include <ttmsg/ttmsg.h>
#include <cfg.h> #include <cfg.h>
#include <usrcfg.h> #include <usrcfg.h>
struct rt_event sw_check;//软件条件 #include <ttTR.h>
struct rt_event hw_check;//硬件条件 static struct rt_event sw_check;//软件条件
static struct rt_event hw_check;//硬件条件
//#define FILE_IS_OK 1 //#define FILE_IS_OK 1
//#define TIMER_IS_OUT 1<<1 //#define TIMER_IS_OUT 1<<1
//#define TT_IS_OK 1<<2 //#define TT_IS_OK 1<<2
#define ALL_READY 1
static int maxTTWaitTime = 4; static int maxTTWaitTime = 4;
static int maxTTRetryCnt = 3; static int maxTTRetryCnt = 3;
static initEvent(void) static void initEvent(void)
{ {
/* 事 件 控 制 块 */ /* 事 件 控 制 块 */
rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_FIFO); rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_PRIO);
result = rt_event_init(&hw_check, "HWcheck", RT_IPC_FLAG_PRIO);
if (result != RT_EOK) if (result != RT_EOK)
{ {
LOG_E("init event failed.\n"); LOG_E("init event failed.\n");
@ -39,6 +42,15 @@ static initEvent(void)
} }
INIT_COMPONENT_EXPORT(initEvent); INIT_COMPONENT_EXPORT(initEvent);
void upSWflag(void)
{
rt_event_send(&sw_check, FILE_IS_OK);
}
void upTTflag(void)
{
rt_event_send(&sw_check, TT_IS_OK);
}
/** /**
* *
*/ */
@ -47,19 +59,20 @@ static void updatecfg()
maxTTWaitTime = get_cfg("maxTTWaitTime"); maxTTWaitTime = get_cfg("maxTTWaitTime");
maxTTRetryCnt = get_cfg("maxTTRetryCnt"); maxTTRetryCnt = get_cfg("maxTTRetryCnt");
} }
extern struct rt_event update_cfg; //extern struct rt_event update_cfg;
void t3(void) //void t3(void)
{ //{
int32_t e; // int32_t e;
int rst = rt_event_recv(&update_cfg, CFGCHANGEED, RT_EVENT_FLAG_OR , RT_WAITING_FOREVER, &e); // int rst = rt_event_recv(&update_cfg, CFGCHANGEED, RT_EVENT_FLAG_OR , RT_WAITING_FOREVER, &e);
if (rst == RT_EOK) { // if (rst == RT_EOK) {
// update_cfg(); //// update_cfg();
LOG_I("ggxb"); // LOG_I("ggxb");
} // }
} //}
//INIT_COMPONENT_EXPORT(t3); //INIT_COMPONENT_EXPORT(t3);
extern void ttinfoInit(void);
extern void startTTinfo(void);
/** /**
* TT状态1TT连续5个周期为激活状态且信号强度不低于5 * TT状态1TT连续5个周期为激活状态且信号强度不低于5
*/ */
@ -67,19 +80,24 @@ void checkTT()
{ {
static rt_thread_t thread = RT_NULL; static rt_thread_t thread = RT_NULL;
//上电 //上电
pwTT_thread_entry("1"); // pwTT_thread_entry("1");
//延时30s等待系统启动、可以GET信息避免不必要的错误 //延时30s等待系统启动、可以GET信息避免不必要的错误
rt_thread_mdelay(1000*30); // rt_thread_mdelay(1000*3);
char c[3][10]={"getTT","","3"} ; // char c[3][10]={"getTT","10","1"} ;
getTT(3,c); //// getTT(3,c);
// getTT(1, RT_NULL);
// getTTinfo_thread_entry() // getTTinfo_thread_entry()
#ifdef NEW_THREAD //#define NEW_THREAD
static CFG cfg; static CFG cfg;
memset(&cfg, 0, sizeof(CFG)); memset(&cfg, 0, sizeof(CFG));
//
cfg.s = 3; cfg.s = 1;
cfg.cnt = maxTTWaitTime/cfg.s-2;//避免通信异常 cfg.cnt = 10;//maxTTWaitTime/cfg.s-2;//避免通信异常
extern void getTTinfo_thread_entry(void* parameter);
#define NEW_THREAD
#ifdef NEW_THREAD
/* 创建 serial 线程 */ /* 创建 serial 线程 */
thread = rt_thread_create("getTT", getTTinfo_thread_entry, (void *) &cfg, 1024 * 3, 25, 10); thread = rt_thread_create("getTT", getTTinfo_thread_entry, (void *) &cfg, 1024 * 3, 25, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
@ -93,43 +111,247 @@ void checkTT()
return; return;
} }
#endif #endif
// ttinfoInit();
// startTTinfo();
// rt_thread_create("getS", startTTinfo, RT_NULL, 1024 * 3, 25, 10);
} }
void try()
static void getFileData_thread_entry(void)
{
//等待事件
extern struct rt_event hw_check;//硬件条件
while(1)
{
if (rt_event_recv(&hw_check, ALL_READY, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
RT_WAITING_FOREVER, RT_NULL) == RT_EOK)
{
//get file to be send
char *f="2023_05_22_11_27_12_245.txt";
// char *f="1023_05_19_15_29_59_254.txt";
// pack file
static rt_uint8_t d[10][200] = { };
static rt_uint8_t s[10] = { };
rt_uint8_t len = 0;
#define __PCK
#ifdef __PCK
// LOG_D("%p--%p",d,s);
// LOG_I("pack %s ...",f);
static MSG cfg;
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
len = pack_File(f, 0, d, s);
rt_kprintf("len is %d\n", len);
if (len)
{
for (size_t var = 0; var < len; var++) {
// LOG_HEX("d",27,d[var],s[var]);
// sendMsg(d[var], s[var]);
}
sendMsgs(d, s, len);
LOG_I("Done.");
}
#else
rt_uint8_t *buffer = RT_NULL;
static MSG cfg;
// static rt_uint8_t len=0;
{
//
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
rt_uint8_t rst = packInit(&cfg, f, 0);
if (rst != RT_EOK)
{
return 0;
}
int fd_in = -1; //, fd_out = -1;
static size_t file_size = 0;
// rt_uint8_t *buffer = RT_NULL;
static size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX
// rt_uint8_t len = 0;
fd_in = open(f, O_RDONLY, 0);
if (fd_in < 0)
{
LOG_E("open the input file : %s error!\n", f);
close(fd_in);
return len;
}
file_size = lseek(fd_in, 0, SEEK_END);
LOG_I("file size is %d bytes.", file_size);
lseek(fd_in, 0, SEEK_SET);
// static rt_uint8_t *buffer = RT_NULL;
buffer = rt_malloc(file_size);
if (buffer == RT_NULL)
{
LOG_E("No memory for read %s.", f);
return 0;
}
read(fd_in, buffer, file_size);
// LOG_HEX()
close(fd_in);
// 粗略调整每包大小
if (file_size > (size_t)FRAME_DATA_LEN_MAX)
{
while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83%
{
flen += 1;
}
if (file_size % flen < flen / 1.2)
{ // 到达限制仍不符合要求
flen = 150;
while (file_size % flen < flen / 2.5 && flen < FRAME_DATA_LEN_MAX) // 调整阈值为40%
{
flen += 1;
}
}
}
else
{
flen = file_size;
}
LOG_I("flen is %d",flen);
// s[0] = packMsg(&cfg, buffer, flen, d[0]);
len = packMsgs(&cfg, buffer, file_size, flen, d, s);
if (fd_in >= 0)
{
close(fd_in);
}
if (buffer != RT_NULL)
{
LOG_D("try to free buf.");
rt_free(buffer);
LOG_D("free buf done.");
}
}
#endif
}
}
}
//MSH_CMD_EXPORT(getFileData_thread_entry,tet);
static void gg(void)
{
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("PSmsg", getFileData_thread_entry, RT_NULL, 1024 * 12, 27, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
LOG_E("thread 'PSmsg' create failure.");
return;
}
}
static void try()
{ {
static rt_err_t rst = RT_ERROR; static rt_err_t rst = RT_ERROR;
updatecfg(); updatecfg();
static rt_uint8_t d[10][200] = { };
static rt_uint8_t s[10] = { };
while(1) while(1)
{ {
int e; // int e;
LOG_I("等待软件就绪");
rst = rt_event_recv(&sw_check, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, rst = rt_event_recv(&sw_check, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
RT_WAITING_FOREVER, &e); RT_WAITING_FOREVER, RT_NULL);
if (rst == RT_EOK)//软件条件满足 if (rst == RT_EOK)//软件条件满足
{ {
//检查硬件条件 //检查硬件条件
LOG_I("软件就绪开始等待TT");
// continue;
checkTT(); checkTT();
//打包数据 //打包数据
} }
for (size_t var = 0; var < maxTTRetryCnt; ++var)//轮询尝试 for (size_t var = 0; var < maxTTRetryCnt; var++)//轮询尝试
{ {
rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(maxTTWaitTime * 1000), LOG_I("第%d次尝试。",var+1);
&e); //rt_tick_from_millisecond(maxTTWaitTime * 1000)
rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 30*1000,
RT_NULL);
if (rst == RT_EOK)//硬件条件满足 if (rst == RT_EOK)//硬件条件满足
{ {
LOG_I("TT准备OK");
rt_event_send(&hw_check, ALL_READY);
break; break;
} }
elseif(rst == RT_ETIMEOUT);//超时则重试 else if(rst == RT_ETIMEOUT);//超时则重试
{ {
pwTT_thread_entry("0"); LOG_W("第%d次尝试中TT准备失败。",var+1);
// pwTT_thread_entry("0");
rt_thread_mdelay(1000); rt_thread_mdelay(1000);
checkTT(); checkTT();
// continue; // continue;
} }
} }
//continue;
//发送数据 //发送数据
//可能有多个待发文件,每个文件打包后为一个二维数组
// 如果先打包后发送,需要三维数组,和大内存占用
// 故改为“打包-发送”轮询操作
//gg();
#ifdef _NO
char *f="1023_05_19_15_29_59_254.txt";
// pack file
// static rt_uint8_t d[10][200] = { };
// static rt_uint8_t s[10] = { };
rt_uint8_t len = 0;
// LOG_D("%p--%p",d,s);
// LOG_I("pack %s ...",f);
len = pack_File(f, 0, d, s);
rt_kprintf("len is %d\n", len);
if (len)
{
for (size_t var = 0; var < len; ++var) {
// LOG_HEX("d",27,d[var],s[var]);
}
LOG_I("Done.");
}
#endif
LOG_I("----------------------------");
//initEvent();
// rt_thread_mdelay(100);
} }
} }
MSH_CMD_EXPORT(gg,file);
void smsg()
{
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("checkSta", try, RT_NULL, 1024 * 5, 24, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
LOG_E("thread 'checkSta' create failure.");
return;
}
}
INIT_COMPONENT_EXPORT(smsg);
MSH_CMD_EXPORT(smsg,smsg);

View File

@ -25,7 +25,7 @@ void iniEvent(void)
{ {
/* 事 件 控 制 块 */ /* 事 件 控 制 块 */
rt_err_t result = rt_event_init(&update_cfg, "update_cfg", RT_IPC_FLAG_FIFO); rt_err_t result = rt_event_init(&update_cfg, "cfg", RT_IPC_FLAG_FIFO);
if (result != RT_EOK) if (result != RT_EOK)
{ {
LOG_E("init event failed.\n"); LOG_E("init event failed.\n");
@ -33,7 +33,7 @@ void iniEvent(void)
} }
} }
/* 导出到自动初始化 */ /* 导出到自动初始化 */
INIT_COMPONENT_EXPORT(iniEvent); //INIT_COMPONENT_EXPORT(iniEvent);
/** /**
* config项 * config项
@ -54,7 +54,7 @@ int set_cfg(const char *k, const char*v)
//以下消息队列通知各线程更新参数 //以下消息队列通知各线程更新参数
// CFG_MSG msg; // CFG_MSG msg;
rt_err_t result; // rt_err_t result;
rt_event_send(&update_cfg, CFGCHANGEED|COMPRESSTYPE); rt_event_send(&update_cfg, CFGCHANGEED|COMPRESSTYPE);

View File

@ -9,12 +9,13 @@
*/ */
#include <rtthread.h> #include <rtthread.h>
/* 串口接收消息结构*/
typedef struct
{ //typedef struct
char key[10]; //{
char value[10]; // char key[10];
} CFG_MSG; // char value[10];
//} CFG_MSG;
#define CFGCHANGEED 1 #define CFGCHANGEED 1
#define SENDINTERVAL 1<<1 #define SENDINTERVAL 1<<1

View File

@ -161,7 +161,7 @@ _exit:
return ret; return ret;
} }
#ifdef USE_D
static int compress_file(int fd_in, int *fout) static int compress_file(int fd_in, int *fout)
{ {
@ -301,7 +301,7 @@ _exit:
return ret; return ret;
} }
#endif
void comp_file_test(int argc, char **argv) void comp_file_test(int argc, char **argv)
{ {

View File

@ -13,50 +13,50 @@
#include <ulog.h> #include <ulog.h>
#include <cJSON.h> #include <cJSON.h>
#include <dfs_file.h> #include <dfs_file.h>
#include <cfg.h> #include <usrcfg.h>
void getcfg(void) //void getcfg(void)
{ //{
// extern struct rt_messagequeue update_cfg; //// extern struct rt_messagequeue update_cfg;
extern struct rt_event update_cfg; // extern struct rt_event update_cfg;
CFG_MSG msg; // CFG_MSG msg;
pwTT_thread_entry("1"); // pwTT_thread_entry("1");
while (1) // while (1)
{ // {
//
//
// rt_memset(&msg, 0, sizeof(msg)); //// rt_memset(&msg, 0, sizeof(msg));
// /* 从消息队列中读取消息*/ //// /* 从消息队列中读取消息*/
// rt_err_t result = rt_mq_recv(&update_cfg, &msg, sizeof(msg), RT_WAITING_NO); //// rt_err_t result = rt_mq_recv(&update_cfg, &msg, sizeof(msg), RT_WAITING_NO);
//// if (result == RT_EOK)
//// {
//// LOG_I("updatecfg:%10s -->%s", msg.key, msg.value);
//// }
// rt_uint32_t e;
// rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|COMPRESSTYPE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e);
// if (result == RT_EOK) // if (result == RT_EOK)
// { // {
// LOG_I("updatecfg:%10s -->%s", msg.key, msg.value); // LOG_I("updatecfg");
// } // }
rt_uint32_t e; // rt_thread_delay(100);
rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|COMPRESSTYPE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e); // }
if (result == RT_EOK) //}
{ //void mpcfg()
LOG_I("updatecfg"); //{
} ///* 创建线程 */
rt_thread_delay(100); // rt_thread_t thread = rt_thread_create("getcfg", getcfg, RT_NULL, 1024 * 2, 20, 10);
} // /* 创建成功则启动线程 */
} // if (thread != RT_NULL)
void mpcfg() // {
{ // rt_thread_startup(thread);
/* 创建线程 */ // // rt_kprintf("done");
rt_thread_t thread = rt_thread_create("getcfg", getcfg, RT_NULL, 1024 * 2, 20, 10); // }
/* 创建成功则启动线程 */ // else
if (thread != RT_NULL) // {
{ // LOG_E("thread 'pmsg' create failure.");
rt_thread_startup(thread); // return RT_ERROR;
// rt_kprintf("done"); // }
} //}
else
{
LOG_E("thread 'pmsg' create failure.");
return RT_ERROR;
}
}
/* 导出到自动初始化 */ /* 导出到自动初始化 */
//INIT_COMPONENT_EXPORT(mpcfg); //INIT_COMPONENT_EXPORT(mpcfg);
MSH_CMD_EXPORT(mpcfg, 线); //MSH_CMD_EXPORT(mpcfg, 线程消息接收测试);

View File

@ -12,7 +12,7 @@
//#define HTTP_GET_URL "http://www.rt-thread.com/service/rt-thread.txt" //#define HTTP_GET_URL "http://www.rt-thread.com/service/rt-thread.txt"
#ifndef TT_IP #ifndef TT_IP
#define TT_IP "http://192.168.0.232:4005" #define TT_IP "http://10.10.10.72:4005"
#endif #endif
#define TT_SIM TT_IP "/action/webGetSIMState"//SIM #define TT_SIM TT_IP "/action/webGetSIMState"//SIM
#define TT_XH TT_IP "/action/webGetTDSignal"//信号值 #define TT_XH TT_IP "/action/webGetTDSignal"//信号值
@ -29,28 +29,37 @@
//#include <string.h> //#include <string.h>
char *infoH[] = { TT_SIM, TT_XH, TT_RW, TT_JH, TT_DW}; char *infoH[] = { TT_SIM, TT_XH, TT_RW, TT_JH, TT_DW};
typedef struct //typedef struct
{ //{
rt_uint8_t cnt; // rt_uint8_t cnt;
rt_uint8_t s; // rt_uint8_t s;
} CFG; //} CFG;
typedef struct typedef struct
{ {
char sim[MAX_LEN]; // SIM char sim[MAX_LEN]; // SIM
rt_uint8_t xh; // 信号值 char xh[MAX_LEN]; // SIM
rt_uint8_t rw; // 入网 char rw[MAX_LEN]; // SIM
rt_uint8_t jh; // 激活 char jh[MAX_LEN]; // SIM
char *jd; // 经度 char jd[MAX_LEN]; // SIM
char *wd; // 纬度 char wd[MAX_LEN]; // SIM
char *ele; // 高度 char ele[MAX_LEN]; // SIM
} TT; // rt_uint8_t sim; // SIM
// rt_uint8_t xh; // 信号值
// rt_uint8_t rw; // 入网
// rt_uint8_t jh; // 激活
// char *jd; // 经度
// char *wd; // 纬度
// char *ele; // 高度
}TT;
static TT tmp; TT tmp={.sim="0",.xh="0",.jh="0",.jd=":0.000000",.wd=":0.000000",.ele=":0.000000"};
static TT *TTinfo=&tmp; //memset(&tmp,0x00,sizeof(TT));
TT *TTinfo=&tmp;
static rt_tick_t bootstamp=0; static rt_tick_t bootstamp=0;
//rt_memset(&tmp,0,sizeof(TT)); //rt_memset(TTinfo,0,sizeof(TT));
//TT *TTinfo=RT_NULL;
//TTinfo = rt_malloc(sizeof(TT)); //TTinfo = rt_malloc(sizeof(TT));
/** /**
* @description: TT结构体转换为数组 * @description: TT结构体转换为数组
@ -95,7 +104,8 @@ static int minTTPeriCnt=5;
static int minTTsinal=5; static int minTTsinal=5;
static int minActiveTime=0; static int minActiveTime=0;
static int maxActiveTime=0; static int maxActiveTime=0;
extern struct rt_event sw_check;//软件条件 //extern struct rt_event sw_check;//软件条件
extern void upTTflag(void);
static void updatecfg() static void updatecfg()
{ {
minTTsinal = get_cfg("minTTsinal"); minTTsinal = get_cfg("minTTsinal");
@ -110,12 +120,15 @@ void initcfg()
bootstamp = rt_tick_get_millisecond(); bootstamp = rt_tick_get_millisecond();
} }
void updateSta() /**
*
*/
static void updateSta()
{ {
uint16_t v = (rt_tick_get_millisecond()-bootstamp)/1000;//转换为秒 uint16_t v = (rt_tick_get_millisecond()-bootstamp)/1000;//转换为秒
LOG_D("耗时%dS.",v); LOG_I("耗时%dS.",v);
if ((minActiveTime ==0) | (minActiveTime > v)) { if ((minActiveTime ==0) | (minActiveTime > v)) {
minTTsinal = v; minActiveTime = v;
set_val("minActiveTime", v); set_val("minActiveTime", v);
} }
if (v>maxActiveTime) { if (v>maxActiveTime) {
@ -127,27 +140,40 @@ void updateSta()
/** /**
* TT状态 * TT状态
*/ */
void rulecheck(void) static void rulecheck(void)
{ {
//默认为 TT连续5个周期为激活状态且信号强度不低于5。 //默认为 TT连续5个周期为激活状态且信号强度不低于5。
//满足加1不满足清零 //满足加1不满足清零
static int okCnt=0; static rt_uint16_t okCnt=0;
if (!okCnt) {
LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal); LOG_I("当前规则为:连续%d个采集周期TT信号质量不低于%d",minTTPeriCnt,minTTsinal);
if (atoi(TTinfo->jh) & !(atoi(TTinfo->xh) < minTTsinal) ) {// }
if (atoi(TTinfo->sim) & !(atoi(TTinfo->xh) < minTTsinal) ) {//
okCnt += 1; okCnt += 1;
LOG_D("第%d次符合规则。",okCnt); LOG_D("第%d次符合规则。",okCnt);
} }
else { else {
okCnt = 0; okCnt = 0;
LOG_D("不符合。"); LOG_W("不符合。");
return; return;
} }
if (okCnt > minTTPeriCnt -1) { if (okCnt >= minTTPeriCnt) {
//TT具备发送条件 //TT具备发送条件
rt_event_send(&sw_check, TT_IS_OK); // rt_event_send(&sw_check, TT_IS_OK);
upTTflag();
LOG_D("符合规则TT具备发送状态。"); LOG_D("符合规则TT具备发送状态。");
updateSta(); // updateSta();
okCnt = minTTPeriCnt -1;
} }
// if (okCnt > minTTPeriCnt) {
// //TT具备发送条件
//// rt_event_send(&sw_check, TT_IS_OK);
// upTTflag();
// okCnt = 2;
// LOG_I("符合规则TT具备发送状态。");
//// updateSta();
// }
} }
@ -168,9 +194,9 @@ static void tt_parse(rt_uint8_t *data)
item = cJSON_GetObjectItem(object, "tdsignal"); item = cJSON_GetObjectItem(object, "tdsignal");
if (item) if (item)
{ {
TTinfo->xh = atoi(item->valuestring); // TTinfo->xh = atoi(item->valuestring);
// tmp.xh = item->valuestring; // tmp.xh = item->valuestring;
// strcpy(TTinfo->xh,item->valuestring); strcpy(TTinfo->xh,item->valuestring);
// rt_kprintf("\nxh:%s ", item->valuestring); // rt_kprintf("\nxh:%s ", item->valuestring);
// rt_kprintf("\nxh:%s ", TTinfo->xh); // rt_kprintf("\nxh:%s ", TTinfo->xh);
cJSON_Delete(root); cJSON_Delete(root);
@ -180,8 +206,9 @@ static void tt_parse(rt_uint8_t *data)
item = cJSON_GetObjectItem(object, "tdnetregstate"); item = cJSON_GetObjectItem(object, "tdnetregstate");
if (item) if (item)
{ {
TTinfo->rw = atoi(item->valuestring); // TTinfo->rw = atoi(item->valuestring);
// rt_kprintf("\nrw:%s ", TTinfo.rw); // rt_kprintf("\nrw:%s ", TTinfo.rw);
strcpy(TTinfo->rw,item->valuestring);
cJSON_Delete(root); cJSON_Delete(root);
return RT_EOK; return RT_EOK;
} }
@ -189,8 +216,9 @@ static void tt_parse(rt_uint8_t *data)
item = cJSON_GetObjectItem(object, "tdpsstate"); item = cJSON_GetObjectItem(object, "tdpsstate");
if (item) if (item)
{ {
TTinfo->jh = atoi(item->valuestring); // TTinfo->jh = atoi(item->valuestring);
// rt_kprintf("\njh:%s ", TTinfo.jh); // rt_kprintf("\njh:%s ", TTinfo.jh);
strcpy(TTinfo->jh,item->valuestring);
cJSON_Delete(root); cJSON_Delete(root);
return RT_EOK; return RT_EOK;
} }
@ -198,13 +226,16 @@ static void tt_parse(rt_uint8_t *data)
item = cJSON_GetObjectItem(object, "latitude"); item = cJSON_GetObjectItem(object, "latitude");
if (item) if (item)
{ {
TTinfo->wd = item->valuestring; // TTinfo->wd = item->valuestring;
strcpy(TTinfo->wd,item->valuestring);
item = cJSON_GetObjectItem(object, "longitude"); item = cJSON_GetObjectItem(object, "longitude");
TTinfo->jd = item->valuestring; // TTinfo->jd = item->valuestring;
strcpy(TTinfo->jd,item->valuestring);
item = cJSON_GetObjectItem(object, "elevation"); item = cJSON_GetObjectItem(object, "elevation");
TTinfo->ele = item->valuestring; // TTinfo->ele = item->valuestring;
strcpy(TTinfo->ele,item->valuestring);
// rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, // rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw,
// TTinfo->jh, TTinfo->jd, TTinfo->wd,TTinfo->ele); // TTinfo->jh, TTinfo->jd, TTinfo->wd,TTinfo->ele);
@ -283,7 +314,7 @@ void getTTinfo_thread_entry(void* parameter)
rt_thread_mdelay(100); rt_thread_mdelay(100);
} }
rulecheck(); rulecheck();
rt_kprintf("%5s%5d%5d%5d%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, TTinfo->jh, TTinfo->jd, rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, TTinfo->jh, TTinfo->jd,
TTinfo->wd, TTinfo->ele); TTinfo->wd, TTinfo->ele);
if (i != cfg->cnt - 1) //最后一次采集不延时 if (i != cfg->cnt - 1) //最后一次采集不延时
{ {
@ -331,6 +362,11 @@ void getTT(int argc, char **argv)
return RT_ERROR; return RT_ERROR;
} }
// struct rt_thread infoTT_thread;
// ALIGN(RT_ALIGN_SIZE)
// static char thread2_stack[1024*3];
// rt_thread_init(&infoTT_thread, "getTT", getTTinfo_thread_entry, (void *) &cfg, &thread2_stack[0], sizeof(thread2_stack), 25, 10);
// rt_thread_startup(&infoTT_thread);
} }
/* 导出到自动初始化 */ /* 导出到自动初始化 */

View File

@ -15,18 +15,19 @@
#include <ulog.h> #include <ulog.h>
#include <board.h> #include <board.h>
#include <ttmsg/ttmsg.h> #include <ttmsg/ttmsg.h>
#include <cfg.h> //#include <cfg.h>
///
static rt_uint8_t d[35][200] = { };
static rt_uint8_t s[35] = { }; //static rt_uint8_t d[35][200] = { };
//static rt_uint8_t s[35] = { };
void pfdemo(void) void pfdemo(void)
{ {
// #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n"); // #define cmb_println(...) rt_kprintf(__VA_ARGS__);rt_kprintf("\r\n");
// char *f = "1023_05_19_15_29_59_254.txt"; // char *f = "1023_05_19_15_29_59_254.txt";
// char *f = "2023_05_19_15_29_59_255.txt"; // char *f = "2023_05_19_15_29_59_255.txt";
char *f = "2023_05_22_11_27_12_245.txt"; char *f = "2023_05_22_11_27_12_245.txt";
// rt_uint8_t d[10][200] = { }; static rt_uint8_t d[10][200] = { };
// rt_uint8_t s[10] = { }; static rt_uint8_t s[10] = { };
rt_uint8_t len = 0; rt_uint8_t len = 0;
LOG_D("%p--%p",d,s); LOG_D("%p--%p",d,s);
LOG_I("pack %s ...",f); LOG_I("pack %s ...",f);
@ -55,13 +56,13 @@ int main(void)
// #define LED_HEART GET_PIN(E,3) // #define LED_HEART GET_PIN(E,3)
/* 设置PIN脚模式为输出 */ /* 设置PIN脚模式为输出 */
rt_pin_mode(LED_HEART, PIN_MODE_OUTPUT); rt_pin_mode(LED_HEART, PIN_MODE_OUTPUT);
// rt_pin_mode(LED_HEART_DEBUG, PIN_MODE_OUTPUT); rt_pin_mode(LED_HEART_DEBUG, PIN_MODE_OUTPUT);
rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT); rt_pin_mode(ETH_RESET_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(TT_EN, PIN_MODE_OUTPUT); rt_pin_mode(TT_EN, PIN_MODE_OUTPUT);
// rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH // rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH
rt_pin_write(TT_EN, PIN_HIGH);//关闭TT
// rt_err_t ret = RT_EOK; // rt_err_t ret = RT_EOK;
/* 设 置 日 期 */ /* 设 置 日 期 */
// ret = set_date(2018, 12, 3); // ret = set_date(2018, 12, 3);
@ -84,14 +85,14 @@ int main(void)
{ {
/* 拉低PIN脚 */ /* 拉低PIN脚 */
rt_pin_write(LED_HEART, PIN_LOW); rt_pin_write(LED_HEART, PIN_LOW);
// rt_pin_write(LED_HEART_DEBUG, PIN_LOW); rt_pin_write(LED_HEART_DEBUG, PIN_HIGH);
/* 延时1ms省电 */ /* 延时1ms省电 */
rt_thread_mdelay(10); //去掉延时共用print替换 rt_thread_mdelay(10); //去掉延时共用print替换
// rt_kprintf("Heartbeat.\n"); // rt_kprintf("Heartbeat.\n");
/* 拉高PIN脚 */ /* 拉高PIN脚 */
rt_pin_write(LED_HEART, PIN_HIGH); rt_pin_write(LED_HEART, PIN_HIGH);
// rt_pin_write(LED_HEART_DEBUG, PIN_HIGH); rt_pin_write(LED_HEART_DEBUG, PIN_LOW);
rt_thread_mdelay(1000); rt_thread_mdelay(1000);

View File

@ -33,7 +33,7 @@
#define BUFSZ 1024 #define BUFSZ 1024
static const char send_data[] = "This is TCP Client from RT-Thread."; /* 发送用到的数据 */ static const char send_data[] = {0x88,0xAA,0xBB,0x88,0x00,0x01,0x00,0x00,0x70,0x21,0x00,0x03,0x49,0x41,0x43,0x4B};//"This is TCP Client from RT-Thread."; /* 发送用到的数据 */
void tcpclient(int argc, char **argv) void tcpclient(int argc, char **argv)
{ {
int ret; int ret;
@ -47,7 +47,7 @@ void tcpclient(int argc, char **argv)
if (argc < 3) if (argc < 3)
{ {
rt_kprintf("Usage: tcpclient URL PORT\n"); rt_kprintf("Usage: tcpclient URL PORT\n");
rt_kprintf("Like: tcpclient 192.168.12.44 5000\n"); rt_kprintf("Like: tcpclient 10.10.10.72 8005\n");
return ; return ;
} }
@ -136,6 +136,12 @@ void tcpclient(int argc, char **argv)
{ {
/* 在控制终端显示收到的数据 */ /* 在控制终端显示收到的数据 */
rt_kprintf("\nReceived data = %s ", recv_data); rt_kprintf("\nReceived data = %s ", recv_data);
closesocket(sock);
// rt_kprintf("\n got a 'q' or 'Q',close the socket.\r\n");
/* 释放接收缓冲 */
rt_free(recv_data);
break;
} }
/* 发送数据到sock连接 */ /* 发送数据到sock连接 */

73
applications/tools.c Normal file
View File

@ -0,0 +1,73 @@
#include <rtthread.h>
#define LOG_TAG "tool"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
//#include <cJSON.h>
#include <dfs_file.h>
#include <usrcfg.h>
/**
* HEX显示文件内容
*/
void hex()
{
}
/**
*
*/
void updatecfg(void)
{
//因为不知原因,采用事件集独立更新配置出错
//独立响应单个参数更新事件,程序上更复杂也没特别必要
//现采用事件通知、统一全部重新加载
}
void sDemo()
{
// extern struct rt_event sw_check;//软件条件
// rt_event_send(&sw_check, FILE_IS_OK);
void upSWflag(void);
upSWflag();
}
MSH_CMD_EXPORT(sDemo,swTest);
static struct rt_thread infoTT_thread;
void ttinfoInit()
{
static CFG cfg;
memset(&cfg, 0, sizeof(CFG));
cfg.s = 1;
cfg.cnt = 10; //避免通信异常
extern void getTTinfo_thread_entry(void* parameter);
// extern void getTTinfo_thread_entry(void* parameter);
// struct rt_thread infoTT_thread;
ALIGN(RT_ALIGN_SIZE)
static char thread2_stack[1024 * 3];
rt_thread_init(&infoTT_thread, "getTT", getTTinfo_thread_entry, (void *) &cfg, &thread2_stack[0],
sizeof(thread2_stack), 25, 10);
// rt_thread_startup(&infoTT_thread);
}
void startTTinfo(void)
{
if (&infoTT_thread == RT_NULL) {
//to Init
}
if ((infoTT_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT) {
}
rt_thread_startup(&infoTT_thread);
}
//MSH_CMD_EXPORT(ttinfoInit,init ttinfo);
//INIT_COMPONENT_EXPORT(ttinfoInit);

View File

@ -15,12 +15,12 @@
#include <string.h> #include <string.h>
#define LOG_TAG "ttTR" #define LOG_TAG "ttTR"
#define LOG_LVL LOG_LVL_INFO #define LOG_LVL LOG_LVL_DBG
#include <ulog.h> #include <ulog.h>
#define BUFSZ 1024 #define BUFSZ 1024
#define RETRYCNT 10 #define RETRYCNT 10
#define URL "http://192.168.0.232" #define URL "http://10.10.10.72"
#define PORT 8005 #define PORT 8005
int sock=0; int sock=0;

View File

@ -290,8 +290,8 @@ LOG_HEX("buf",16,buf,100);
*/ */
rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[200], rt_uint8_t *arrLen) rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[200], rt_uint8_t *arrLen)
{ {
static MSG cfg; extern MSG cfg;
rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间 // rt_memset(&cfg, 0, sizeof(MSG)); // 分配空间
rt_uint8_t rst = packInit(&cfg, fin, flag); rt_uint8_t rst = packInit(&cfg, fin, flag);
if (rst != RT_EOK) if (rst != RT_EOK)
{ {
@ -301,9 +301,10 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[
int fd_in = -1; //, fd_out = -1; int fd_in = -1; //, fd_out = -1;
static size_t file_size = 0; static size_t file_size = 0;
// rt_uint8_t *buffer = RT_NULL; rt_uint8_t len=0;
size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX // rt_uint8_t *buffer = RT_NULL;
rt_uint8_t len = 0; static size_t flen = 150; // 每包数据初始长度,最大不超过 FRAME_DATA_LEN_MAX
// rt_uint8_t len = 0;
fd_in = open(fin, O_RDONLY, 0); fd_in = open(fin, O_RDONLY, 0);
if (fd_in < 0) if (fd_in < 0)
@ -314,19 +315,22 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[
} }
file_size = lseek(fd_in, 0, SEEK_END); file_size = lseek(fd_in, 0, SEEK_END);
LOG_I("file size is %d bytes.",file_size); LOG_I("file size is %d bytes.", file_size);
lseek(fd_in, 0, SEEK_SET); lseek(fd_in, 0, SEEK_SET);
rt_uint8_t *buffer=RT_NULL ; rt_uint8_t *buffer = RT_NULL;
buffer = rt_malloc(file_size); buffer = rt_malloc(file_size);
if (buffer == RT_NULL) { if (buffer == RT_NULL)
LOG_E("No memory for read %s.",fin); {
LOG_E("No memory for read %s.", fin);
return 0; return 0;
} }
read(fd_in, buffer, file_size); read(fd_in, buffer, file_size);
// LOG_HEX()
close(fd_in); close(fd_in);
// 粗略调整每包大小 // 粗略调整每包大小
if (file_size > FRAME_DATA_LEN_MAX) { if (file_size > (size_t)FRAME_DATA_LEN_MAX)
{
while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83% while (file_size % flen < flen / 1.2 && flen < FRAME_DATA_LEN_MAX) // 阈值约83%
{ {
flen += 1; flen += 1;
@ -340,26 +344,24 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[
} }
} }
} }
else { else
{
flen = file_size; flen = file_size;
} }
LOG_I("len of data per pack is %d Bytes.",flen); LOG_I("flen is %d",flen);
LOG_I("cnt of packages is %d",(file_size / flen) + (file_size % flen > 0 ? 1 : 0)); // s[0] = packMsg(&cfg, buffer, flen, d[0]);
len = packMsgs(&cfg, buffer, file_size, flen, dout, arrLen); len = packMsgs(&cfg, buffer, file_size, flen, dout, arrLen);
if (fd_in >= 0) if (fd_in >= 0)
{ {
close(fd_in); close(fd_in);
} }
if (buffer!=RT_NULL) if (buffer != RT_NULL)
{ {
LOG_D("try to free buf."); LOG_D("try to free buf.");
rt_free(buffer); rt_free(buffer);
LOG_D("free buf done."); LOG_D("free buf done.");
} }
// LOG_D("%p--%p",dout,arrLen);
return len; return len;
@ -509,20 +511,24 @@ MSH_CMD_EXPORT(pmsg, 打包文件。);
void pwTT_thread_entry(void *parameter) void pwTT_thread_entry(void *parameter)
{ {
// LOG_I("--%s--",parameter); // LOG_I("--%s--",parameter);
if (parameter == NULL) if (strcmp(parameter,"NULL")==0)
{ {
// LOG_I("null");
int f = rt_pin_read(TT_EN); int f = rt_pin_read(TT_EN);
rt_pin_write(TT_EN, !f); rt_pin_write(TT_EN, !f);
} }
else else
{ {
rt_bool_t flag = (rt_bool_t) parameter; rt_bool_t flag = (rt_bool_t) atoi(parameter);
// LOG_I("flag is %d",flag);
rt_pin_write(TT_EN, flag); rt_pin_write(TT_EN, flag);
} }
if (rt_pin_read(TT_EN)) if (rt_pin_read(TT_EN))
{ {
//#ifdef NO_RELAY
LOG_I("set TT %s", "ON"); LOG_I("set TT %s", "ON");
//#endif
add_val("swCnt");//更新统计值 add_val("swCnt");//更新统计值
} }
else else
@ -534,14 +540,17 @@ void pwTT_thread_entry(void *parameter)
static int swTT(int argc, char **argv) static int swTT(int argc, char **argv)
{ {
int f = NULL;//不带参数时argv[1]为NULL static char s[5]="NULL";
if (argc == 2) if (argc >= 2)
{ {
f = atoi(argv[1]); rt_strcpy(s,argv[1]);
}
else {
rt_strcpy(s,"NULL");
} }
/* 创建线程 */ /* 创建线程 */
rt_thread_t thread = rt_thread_create("sw_TT", pwTT_thread_entry, (void *) f, 1024 * 2, 25, 10); rt_thread_t thread = rt_thread_create("sw_TT", pwTT_thread_entry, (void *) s, 1024 * 2, 25, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (thread != RT_NULL) if (thread != RT_NULL)
{ {

View File

@ -17,13 +17,17 @@
#include <rtthread.h> #include <rtthread.h>
#include <dfs_file.h> #include <dfs_file.h>
#include <cfg.h> #include <usrcfg.h>
#define LOG_TAG "uart" #define LOG_TAG "uart"
#define LOG_LVL LOG_LVL_DBG #define LOG_LVL LOG_LVL_DBG
#include <ulog.h> #include <ulog.h>
#ifdef WORK_BOARD
#define SAMPLE_UART_NAME "uart1" /* 串口设备名称 */
#else
#define SAMPLE_UART_NAME "uart3" /* 串口设备名称 */ #define SAMPLE_UART_NAME "uart3" /* 串口设备名称 */
#endif
#define MAX_SIZE_TO_SAVE 1024*2 #define MAX_SIZE_TO_SAVE 1024*2
/* 串口接收消息结构*/ /* 串口接收消息结构*/
struct rx_msg struct rx_msg
@ -61,22 +65,19 @@ static void serial_thread_entry(void *parameter)
rt_err_t result; rt_err_t result;
rt_uint32_t rx_length; rt_uint32_t rx_length;
static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1]; static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1];
// extern struct rt_messagequeue update_cfg;
extern struct rt_event update_cfg;
// CFG_MSG cfg;
while (1) while (1)
{ {
// rt_memset(&cfg, 0, sizeof(cfg)); // rt_memset(&cfg, 0, sizeof(cfg));
rt_memset(&msg, 0, sizeof(msg)); rt_memset(&msg, 0, sizeof(msg));
/* 从消息队列中读取消息*/ /* 从消息队列中读取消息*/
rt_uint32_t e; // rt_uint32_t e;
rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|MAXSIZEPERFILE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e); // rt_err_t result = rt_event_recv(&update_cfg, CFGCHANGEED|MAXSIZEPERFILE, RT_EVENT_FLAG_OR|RT_EVENT_FLAG_CLEAR, RT_WAITING_NO, &e);
if (result == RT_EOK) // if (result == RT_EOK)
{ // {
LOG_I("updatecfg"); // LOG_I("updatecfg");
} // }
result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), RT_WAITING_NO); result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), RT_WAITING_FOREVER);
if (result == RT_EOK) if (result == RT_EOK)
{ {
/* 从串口读取数据*/ /* 从串口读取数据*/

View File

@ -10,10 +10,25 @@
#ifndef APPLICATIONS_USRCFG_H_ #ifndef APPLICATIONS_USRCFG_H_
#define APPLICATIONS_USRCFG_H_ #define APPLICATIONS_USRCFG_H_
#include "cfg.h"
#define WORK_BOARD #define WORK_BOARD
#define FILE_IS_OK 1 #define FILE_IS_OK 1
#define TIMER_IS_OUT 1<<1 #define TIMER_IS_OUT 1<<1
#define TT_IS_OK 1<<2 #define TT_IS_OK 1<<2
typedef struct
{
rt_uint8_t cnt;
rt_uint8_t s;
} CFG;
//struct rt_event sw_check;//软件条件
#endif /* APPLICATIONS_USRCFG_H_ */ #endif /* APPLICATIONS_USRCFG_H_ */

View File

@ -49,7 +49,7 @@
#define RT_USING_DEVICE #define RT_USING_DEVICE
#define RT_USING_CONSOLE #define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 256 #define RT_CONSOLEBUF_SIZE 256
#define RT_CONSOLE_DEVICE_NAME "uart1" #define RT_CONSOLE_DEVICE_NAME "uart3"
/* end of Kernel Device Object */ /* end of Kernel Device Object */
#define RT_VER_NUM 0x40101 #define RT_VER_NUM 0x40101
/* end of RT-Thread Kernel */ /* end of RT-Thread Kernel */
@ -68,8 +68,8 @@
#define RT_USING_FINSH #define RT_USING_FINSH
#define FINSH_USING_MSH #define FINSH_USING_MSH
#define FINSH_THREAD_NAME "tshell" #define FINSH_THREAD_NAME "tshell"
#define FINSH_THREAD_PRIORITY 20 #define FINSH_THREAD_PRIORITY 30
#define FINSH_THREAD_STACK_SIZE 4096 #define FINSH_THREAD_STACK_SIZE 4096*2
#define FINSH_USING_HISTORY #define FINSH_USING_HISTORY
#define FINSH_HISTORY_LINES 5 #define FINSH_HISTORY_LINES 5
#define FINSH_USING_SYMTAB #define FINSH_USING_SYMTAB
@ -155,8 +155,8 @@
/* Static IPv4 Address */ /* Static IPv4 Address */
#define RT_LWIP_IPADDR "192.168.0.30" #define RT_LWIP_IPADDR "10.10.10.10"
#define RT_LWIP_GWADDR "192.168.0.1" #define RT_LWIP_GWADDR "10.10.10.1"
#define RT_LWIP_MSKADDR "255.255.255.0" #define RT_LWIP_MSKADDR "255.255.255.0"
/* end of Static IPv4 Address */ /* end of Static IPv4 Address */
#define RT_LWIP_UDP #define RT_LWIP_UDP
@ -269,12 +269,12 @@
/* tools packages */ /* tools packages */
#define PKG_USING_CMBACKTRACE //#define PKG_USING_CMBACKTRACE
#define PKG_CMBACKTRACE_PLATFORM_M4 //#define PKG_CMBACKTRACE_PLATFORM_M4
#define PKG_CMBACKTRACE_DUMP_STACK //#define PKG_CMBACKTRACE_DUMP_STACK
#define PKG_CMBACKTRACE_PRINT_CHINESE_UTF8 //#define PKG_CMBACKTRACE_PRINT_CHINESE_UTF8
#define PKG_USING_CMBACKTRACE_V10401 //#define PKG_USING_CMBACKTRACE_V10401
#define PKG_CMBACKTRACE_VER_NUM 0x10401 //#define PKG_CMBACKTRACE_VER_NUM 0x10401
/* end of tools packages */ /* end of tools packages */
/* system packages */ /* system packages */