添加流程文件

添加主逻辑函数
待完善ttgetinfo 文件
This commit is contained in:
murmur 2023-06-01 17:10:00 +08:00
parent 8cb31be86b
commit 9b76e1fbe8
13 changed files with 574 additions and 54 deletions

98
applications/_main.c Normal file
View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-01 murmur the first version
*/
#include <rtthread.h>
#define LOG_TAG "main_scha"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
#include <board.h>
#include <ttmsg/ttmsg.h>
#include <cfg.h>
struct rt_event sw_check;//软件条件
struct rt_event hw_check;//硬件条件
#define FILE_IS_OK 1
#define TIMER_IS_OUT 1<<1
#define TT_IS_OK 1<<2
static maxWaitTime = 4;
static maxRetryCnt = 3;
static init()
{
/* 事 件 控 制 块 */
rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_FIFO);
if (result != RT_EOK)
{
LOG_E("init event failed.\n");
}
}
/**
*
*/
static void updatecfg()
{
maxWaitTime = get_cfg("maxWaitTime");
maxRetryCnt = get_cfg("maxRetryCnt");
}
/**
* TT状态1TT连续5个周期为激活状态且信号强度不低于5
*/
void checkTT()
{
//上电
pwTT_thread_entry("1");
// rt_thread_create(name, entry, parameter, stack_size, priority, tick)
getTT();
// getTTinfo_thread_entry()
}
void try()
{
static rt_err_t rst = RT_ERROR;
updatecfg();
while(1)
{
int e;
rst = rt_event_recv(&sw_check, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
RT_WAITING_FOREVER, &e);
if (rst == RT_EOK)
{
//上电
pwTT_thread_entry("1");
}
for (size_t var = 0; var < maxRetryCnt; ++var)
{
rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(maxWaitTime * 1000),
&e);
if (rst == RT_ETIMEOUT)
{
pwTT_thread_entry("0");
rt_thread_mdelay(1000);
pwTT_thread_entry("1");
}
else if (rst == RT_EOK)
{
break;
}
else
{
LOG_E("Unknown error.");
}
}
}
}

View File

@ -69,26 +69,30 @@ int set_cfg(const char *k, const char*v)
int get_cfg(const char *k)
{
char buf[16];
int rst = ini_gets("config",k,"000000",buf,16,LJW_CFG_FILE_NAME);
if(strcmp(buf, "000000") == 0) {
// 采用默认值
// char buf[MAX_KEY_LEN];
// int rst = ini_gets("config",k,"000000",buf,MAX_KEY_LEN,LJW_CFG_FILE_NAME);
// if(strcmp(buf, "000000") == 0) {
// // 采用默认值
int rst = ini_getl("config", k, -1, LJW_CFG_FILE_NAME);
if (rst == -1) {
LOG_W("no such KEY:%s",k);
return -RT_ERROR;
}
else {
LOG_I("%s = %s",k,buf);
// LOG_I("%s = %s",k,buf);
LOG_I("%s = %d",k,rst);
}
return rst;
}
void get_cfg_all(void)
{
char buf[16];
char kstr[16];
char buf[MAX_KEY_LEN];
char kstr[MAX_KEY_LEN];
LOG_I("%23s","---CONFIG---");
for (size_t k = 0; ini_getkey("config", k, kstr, 16, LJW_CFG_FILE_NAME) > 0; k++) {
int rst = ini_gets("config",kstr,"000000",buf,16,LJW_CFG_FILE_NAME);
for (size_t k = 0; ini_getkey("config", k, kstr, MAX_KEY_LEN, LJW_CFG_FILE_NAME) > 0; k++) {
int rst = ini_gets("config",kstr,"000000",buf,MAX_KEY_LEN,LJW_CFG_FILE_NAME);
LOG_I("%16s = %s",kstr,buf);
}
@ -112,11 +116,11 @@ void cfg(int argc, char ** argv)
static void get_sta_all(void)
{
char buf[16];
char kstr[16];
char buf[MAX_KEY_LEN];
char kstr[MAX_KEY_LEN];
LOG_I("%23s","---STATS---");
for (size_t k = 0; ini_getkey("stats", k, kstr, 16, LJW_CFG_FILE_NAME) > 0; k++) {
int rst = ini_gets("stats",kstr,"000000",buf,16,LJW_CFG_FILE_NAME);
for (size_t k = 0; ini_getkey("stats", k, kstr, MAX_KEY_LEN, LJW_CFG_FILE_NAME) > 0; k++) {
int rst = ini_gets("stats",kstr,"000000",buf,MAX_KEY_LEN,LJW_CFG_FILE_NAME);
LOG_I("%16s = %s",kstr,buf);
}
}
@ -205,5 +209,68 @@ static void clear_sta(void)
MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, )
/**
*
* @param f
* @param v
* @return
*/
int setFileToSend(const char *f, int v)
{
int rst = ini_putl(SECTION_TO_SEND, f, v, LJW_CFG_FILE_NAME);
if (!rst) {
LOG_E("add file to send error.");
}
return rst;
}
/**
*
* @param kstr
* @param v 0
* @return
*/
int getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v)
{
// char buf[MAX_KEY_LEN];
// char kstr[MAX_KEY_LEN];
size_t len=0;
for (size_t k = 0; ini_getkey(SECTION_TO_SEND, k, kstr[len], MAX_KEY_LEN, LJW_CFG_FILE_NAME) > 0; k++) {
v[len] = ini_getl(SECTION_TO_SEND, kstr[len], -1, LJW_CFG_FILE_NAME);
len +=1;
}
return len;
}
/**
*
*/
int clearFileToSend(const char *k)
{
int rst = ini_puts(SECTION_TO_SEND, k, NULL, LJW_CFG_FILE_NAME);
if (!rst) {
LOG_E("clear file to send error.");
}
return rst;
}
void gf()
{
int v[MAX_KEY_LEN];
char kstr[10][MAX_KEY_LEN];
size_t cnt = getFilesToSend(kstr, v);
for (size_t var = 0; var < cnt; ++var) {
LOG_I("%s -- %d",kstr[var],v[var]);
}
}
void add(int argc, char **argv)
{
setFileToSend(argv[1],atoi(argv[2]));
gf();
clearFileToSend(argv[1]);
gf();
}
MSH_CMD_EXPORT(gf, )
MSH_CMD_EXPORT_ALIAS(add, cf,)
//set_if()
#endif

View File

@ -22,6 +22,16 @@ typedef struct
#define COMPRESSTYPE 1<<3
#define ENCRYTTYPE 1<<4
#define MAX_KEY_LEN 30
#define SECTION_TO_SEND "tosend"
int get_cfg(const char *k);
int set_cfg(const char *k, const char*v);
int add_val(const char *k);
int setFileToSend(const char *f, int v);
int getFilesToSend(char (*kstr)[MAX_KEY_LEN], int *v);
int clearFileToSend(const char *k);

View File

@ -1,3 +1,7 @@
#include <rtthread.h>
//#include <../packages/webclient-v2.2.0/inc/webclient.h>
#include <webclient.h>
@ -16,12 +20,13 @@
#define TT_JH TT_IP "/action/webGetPSState"//激活
#define TT_DW TT_IP "/action/webGetBDGPS"//定位
//http://192.168.0.232:4005/action/webGetSIMState webGetBDGPS
#define MAX_LEN 15
#include <cJSON.h>
#include <finsh.h>
#include <stdio.h>
#include <stdlib.h> //用于strtod函数
#include <string.h>
//#include <stdio.h>
//#include <stdlib.h> //用于strtod函数
//#include <string.h>
char *infoH[] = { TT_SIM, TT_XH, TT_RW, TT_JH, TT_DW};
typedef struct
@ -32,7 +37,7 @@ typedef struct
typedef struct
{
rt_uint8_t sim; // SIM
char sim[MAX_LEN]; // SIM
rt_uint8_t xh; // 信号值
rt_uint8_t rw; // 入网
rt_uint8_t jh; // 激活
@ -40,8 +45,12 @@ typedef struct
char *wd; // 纬度
char *ele; // 高度
} TT;
static TT tmp;
static TT *TTinfo=&tmp;
//rt_memset(&tmp,0,sizeof(TT));
//TTinfo = rt_malloc(sizeof(TT));
/**
* @description: TT结构体转换为数组
* @param {TT} *TTinfo TT结构体
@ -89,8 +98,6 @@ static void tt_parse(rt_uint8_t *data)
{
extern TT *TTinfo;
cJSON *root = RT_NULL, *object = RT_NULL, *item = RT_NULL;
// rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw,
// TTinfo->jh, TTinfo->jd, TTinfo->wd,TTinfo->ele);
root = cJSON_Parse((const char *) data);
if (!root)
@ -151,9 +158,9 @@ static void tt_parse(rt_uint8_t *data)
item = cJSON_GetObjectItem(object, "tdsimstate");
if (item)
{
TTinfo->sim = atoi(item->valuestring);
// TTinfo->sim = atoi(item->valuestring);
// tmp.sim = item->valuestring;
// strcpy(TTinfo.sim,item->valuestring)
strcpy(TTinfo->sim,item->valuestring);
// rt_kprintf("\nSIM:%s \n", TTinfo->sim);
cJSON_Delete(root);
return RT_EOK;
@ -166,7 +173,7 @@ static void tt_parse(rt_uint8_t *data)
/* HTTP client download data by GET request */
static int webclient_get_data(const char *url)
{
unsigned char *buffer = RT_NULL;
static unsigned char *buffer = RT_NULL;
size_t length = 0;
if (webclient_request(url, RT_NULL, RT_NULL, 0, (void **) &buffer, &length) < 0)
@ -198,29 +205,27 @@ void getTTinfo_thread_entry(void* parameter)
isize = sizeof(infoH) / sizeof(infoH[0]);
rt_kprintf("\n%10s%s\n", " ", "↓---------getTT START.--------↓");
rt_kprintf("%5s%5s%5s%5s%15s%15s%10s\n", "SIM", "xh", "rw", "jh", "N", "E", "ele");
for (i = 0; i < cfg->cnt; ++i)//按指定次数轮询
for (i = 0; i < cfg->cnt; ++i) //按指定次数轮询
{
for (var = 0; var < isize; var++)//轮询每个参数
for (var = 0; var < isize; var++) //轮询每个参数
{
char *url = RT_NULL;
static char *url = RT_NULL;
url = web_strdup(*(infoH + var));
if (url == RT_NULL)
{
LOG_E("no memory for create getTT url buffer.\n");
// return -RT_ENOMEM;
}
if(webclient_get_data(url) != RT_EOK)
{
break;
}
if (webclient_get_data(url) != RT_EOK)
{
break;
}
web_free(url);
rt_thread_mdelay(100);
}
// rt_kprintf("%5d++%5d --%5d\n",TTinfo->xh,tmp.xh,TTinfo->sim);
// rt_kprintf("%5d%5d%5d%5d%15s%15s%10s\n", TTinfo.sim, TTinfo.xh, TTinfo.rw, TTinfo.jh, TTinfo.jd, TTinfo.wd,TTinfo.ele);
rt_kprintf("%5d%5d%5d%5d%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw,
TTinfo->jh, TTinfo->jd, TTinfo->wd,TTinfo->ele);
if (i != cfg->cnt - 1)//最后一次采集不延时
rt_kprintf("%5s%5d%5d%5d%15s%15s%10s\n", TTinfo->sim, TTinfo->xh, TTinfo->rw, TTinfo->jh, TTinfo->jd,
TTinfo->wd, TTinfo->ele);
if (i != cfg->cnt - 1) //最后一次采集不延时
{
rt_thread_mdelay(cfg->s * 1000);
}

174
applications/idle.c Normal file
View File

@ -0,0 +1,174 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-01 murmur the first version
*/
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-08-24 yangjie the first version
*/
/*
*
*
* 线
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <rthw.h>
#define THREAD_PRIORITY 20
#define THREAD_STACK_SIZE 1024
#define THREAD_TIMESLICE 5
/* 指向线程控制块的指针 */
static rt_thread_t tid = RT_NULL;
/* 空闲函数钩子函数执行次数 */
volatile static int hook_times = 0;
int t=0;
extern rt_device_t wdg_dev; /* 看门狗设备句柄 */
/* 空闲任务钩子函数 */
static void idle_hook()
{
// if (0 == (hook_times % 10000))
//
// {
//
// rt_kprintf("enter idle hook %d times.\n", hook_times);
//
// }
rt_thread_mdelay(1000);
rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_GET_TIMEOUT, &t);
rt_kprintf("---%d\n", t);
// rt_enter_critical();
//
// hook_times++;
//
// rt_exit_critical();
}
/* 线程入口 */
static void thread_entry(void *parameter)
{
int i = 5;
// while (1)
//
// {
// rt_kprintf("enter thread1.\n");
//
// rt_enter_critical();
//
// hook_times = 0;
//
// rt_exit_critical();
/* 休眠500ms */
// rt_kprintf("thread1 delay 50 OS Tick.\n", hook_times);
//
// rt_thread_mdelay(500);
//
// }
// rt_kprintf("delete idle hook.\n");
/* 删除空闲钩子函数 */
// rt_thread_idle_delhook(idle_hook);
// rt_kprintf("thread1 finish.\n");
}
int idle_hook_sample(void)
{
/* 设置空闲线程钩子 */
rt_thread_idle_sethook(idle_hook);
/* 创建线程 */
tid = rt_thread_create("thread1",
thread_entry, RT_NULL,
THREAD_STACK_SIZE,
THREAD_PRIORITY, THREAD_TIMESLICE);
if (tid != RT_NULL)
rt_thread_startup(tid);
return 0;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(idle_hook_sample, idle hook sample);

View File

@ -21,12 +21,12 @@
#define IWDG_DEVICE_NAME "wdt" /* 看门狗设备名称 */
static rt_device_t wdg_dev; /* 看门狗设备句柄 */
rt_device_t wdg_dev; /* 看门狗设备句柄 */
static void idle_hook(void)
{
/* 在空闲线程的回调函数里喂狗 */
rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, NULL);
// rt_device_control(wdg_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, NULL);
// rt_thread_mdelay(500);
// rt_kprintf("feed the dog!\n ");
}
@ -74,7 +74,7 @@ static int iwdg_sample(int argc, char *argv[])
return -RT_ERROR;
}
/* 设置空闲线程回调函数 */
rt_thread_idle_sethook(idle_hook);
// rt_thread_idle_sethook(idle_hook);
return ret;
}

143
applications/timer.c Normal file
View File

@ -0,0 +1,143 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-01 murmur the first version
*/
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-08-24 yangjie the first version
*/
/*
*
*
*
*
*/
#include <rtthread.h>
/* 定时器的控制块 */
static rt_timer_t timer1;
static rt_timer_t timer2;
static int cnt = 0;
/* 定时器1超时函数 */
static void timeout1(void *parameter)
{
rt_kprintf("periodic timer is timeout %d\n", cnt);
/* 运行第10次停止周期定时器 */
if (cnt++ >= 9)
{
rt_timer_stop(timer1);
rt_kprintf("periodic timer was stopped! \n");
}
}
/* 定时器2超时函数 */
static void timeout2(void *parameter)
{
rt_kprintf("one shot timer is timeout\n");
}
int timer_sample(void)
{
/* 创建定时器1 周期定时器 */
timer1 = rt_timer_create("timer1", timeout1,
RT_NULL, 10,
RT_TIMER_FLAG_PERIODIC);
/* 启动定时器1 */
if (timer1 != RT_NULL)
rt_timer_start(timer1);
/* 创建定时器2 单次定时器 */
timer2 = rt_timer_create("timer2", timeout2,
RT_NULL, 30,
RT_TIMER_FLAG_ONE_SHOT);
/* 启动定时器2 */
if (timer2 != RT_NULL)
rt_timer_start(timer2);
return 0;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(timer_sample, timer sample);

View File

@ -502,7 +502,10 @@ static int pmsg(int argc, char **argv)
MSH_CMD_EXPORT(pmsg, );
/**
*
* @param parameter
*/
void pwTT_thread_entry(void *parameter)
{
// LOG_I("--%s--",parameter);

View File

@ -100,4 +100,6 @@ rt_uint8_t pack_File(const char *fin, rt_uint8_t flag, const rt_uint8_t (*dout)[
//rt_uint8_t packMsgs(MSG *cfg, rt_uint8_t *din, size_t len, rt_uint8_t w, rt_uint8_t (*dout)[500], rt_uint8_t *arrlen);
void pwTT_thread_entry(void *parameter);
#endif /* APPLICATIONS_TTMSG_TTMSG_H_ */

View File

@ -52,15 +52,17 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
}
return result;
}
struct rx_msg msg;
extern struct rt_event update_cfg;
//static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1];
static void serial_thread_entry(void *parameter)
{
struct rx_msg msg;
// struct rx_msg msg;
rt_err_t result;
rt_uint32_t rx_length;
static char rx_buffer[RT_SERIAL_RB_BUFSZ + 1];
// extern struct rt_messagequeue update_cfg;
extern struct rt_event update_cfg;
// extern struct rt_event update_cfg;
// CFG_MSG cfg;
while (1)
{
@ -74,12 +76,12 @@ static void serial_thread_entry(void *parameter)
// LOG_I("updatecfg:%10s -->%s", cfg.key, cfg.value);
// }
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);
if (result == RT_EOK)
{
LOG_I("updatecfg");
}
// 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);
// if (result == RT_EOK)
// {
// LOG_I("updatecfg");
// }
result = rt_mq_recv(&rx_mq, &msg, sizeof(msg), RT_WAITING_FOREVER);
if (result == RT_EOK)
{
@ -106,7 +108,11 @@ static void serial_thread_entry(void *parameter)
/* 打印数据 */
rt_kprintf("%s\n",rx_buffer);
}
else {
LOG_D("no data reced.");
}
rt_thread_mdelay(100);
}
}
@ -149,7 +155,7 @@ static int uart_dma_sample(int argc, char *argv[])
rt_device_write(serial, 0, str, (sizeof(str) - 1));
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024*1, 25+1, 10);
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024*10, 25+1, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{

9
applications/流程.md Normal file
View File

@ -0,0 +1,9 @@
# main
1等待事件flag为 待发数据大小累计超minSizeToSend的设置值
或 sendInterval设置值到达
2满足后上电
3等待事件flag为 TT连续5个周期为激活状态且信号强度不低于5
4读入待发文件
5发送
# ttcheck

View File

@ -77,14 +77,17 @@ fcfg为配置项长1字节为**数据类型**、**压缩方式**、**加
DATA_MODE=(1<<7),
```
# 发送:
天通设备进行通信,将打包后数据依次送出。
TT设备进行通信,将打包后数据依次送出。
## 发送逻辑
先依次检查发送条件满足条件后开始发送发送完毕后关闭TT设备
## 发送条件
### 软件条件
待发数据大小累计超minSizeToSend的设置值
sendInterval设置值到达
需求条件1待发数据大小累计超minSizeToSend的设置值
需求条件2sendInterval设置值到达
以上任意条件满足则进入硬件条件检查
### 硬件条件
TT连续5个周期为激活状态且信号强度不低于5
需求条件1TT连续5个周期为激活状态且信号强度不低于5。
软件条件满足后TT上电MaxWaitTime内不达标则断电重启并重试MaxRetryCnt如仍不成功则等待下次发送

View File

@ -15,7 +15,7 @@
#define RT_HOOK_USING_FUNC_PTR
#define RT_USING_IDLE_HOOK
#define RT_IDLE_HOOK_LIST_SIZE 4
#define IDLE_THREAD_STACK_SIZE 256*2
#define IDLE_THREAD_STACK_SIZE 256*4
#define RT_USING_TIMER_SOFT
#define RT_TIMER_THREAD_PRIO 4
#define RT_TIMER_THREAD_STACK_SIZE 512