zhunk пре 11 месеци
родитељ
комит
f34b66aec9

+ 4 - 128
Application_cbd_apm32f1/applications/beep.c

@@ -1,3 +1,4 @@
+#include <app_pwm.h>
 /*
  * Copyright (c) 2006-2020, RT-Thread Development Team
  *
@@ -8,7 +9,6 @@
  * 2020-05-23     Administrator       the first version
  */
 #include <rtdevice.h>  //使用 RT-Thread 的设备需要包含此头文件
-#include <beep.h>
 #include <control.h>
 #include "hmi.h"
 
@@ -39,56 +39,6 @@ static rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
 
 rt_device_t hw_dev = RT_NULL;   /* 定时器设备句柄 */
 
-static int hwtimer_sample(int argc, char *argv[])
-{
-    rt_err_t ret = RT_EOK;
-    rt_hwtimerval_t timeout_s;      /* 定时器超时值 */
-    rt_device_t hw_dev = RT_NULL;   /* 定时器设备句柄 */
-    rt_hwtimer_mode_t mode;         /* 定时器模式 */
-    rt_uint32_t freq = 10000;               /* 计数频率 */
-
-    /* 查找定时器设备 */
-    hw_dev = rt_device_find(HWTIMER_DEV_NAME);
-    if (hw_dev == RT_NULL)
-    {
-        rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
-        return RT_ERROR;
-    }
-
-    /* 以读写方式打开设备 */
-    ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
-    if (ret != RT_EOK)
-    {
-        rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
-        return ret;
-    }
-
-    /* 设置超时回调函数 */
-    rt_device_set_rx_indicate(hw_dev, timeout_cb);
-
-    /* 设置计数频率(若未设置该项,默认为1Mhz 或 支持的最小计数频率) */
-    rt_device_control(hw_dev, HWTIMER_CTRL_FREQ_SET, &freq);
-    /* 设置模式为周期性定时器(若未设置,默认是HWTIMER_MODE_ONESHOT)*/
-    mode = HWTIMER_MODE_PERIOD; //HWTIMER_MODE_ONESHOT;
-    ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
-    if (ret != RT_EOK)
-    {
-        rt_kprintf("set mode failed! ret is :%d\n", ret);
-        return ret;
-    }
-
-    /* 设置定时器超时值为5s并启动定时器 */
-    timeout_s.sec = 10;      /* 秒 */
-    timeout_s.usec = 0;     /* 微秒 */
-    if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
-    {
-        rt_kprintf("set timeout value failed\n");
-        return RT_ERROR;
-    }
-    //beep_init();
-    hwtimer2_pwm3_output(0,20000,1,1);
-    return ret;
-}
 
 
 /*初始化蜂鸣器*/
@@ -165,39 +115,6 @@ static int init_tim2(void)
     return 0;
 }
 
-int hwtimer2_pwm3_output(rt_uint32_t time,rt_uint32_t freq,uint8_t EN,uint8_t DIR)
-{
-    init_pwm3();
-    rt_pin_mode(Motor_EN, PIN_MODE_OUTPUT);
-    rt_pin_mode(Motor_DIR, PIN_MODE_OUTPUT);
-    rt_pin_write(Motor_EN, EN);
-    rt_pin_write(Motor_DIR, DIR);
-    rt_pwm_set(pwm_device, BEEP_PWM_CH, freq, freq/2);//channel,period,pulse
-    if(init_tim2()==0)
-        rt_pwm_enable(pwm_device, BEEP_PWM_CH); //使能蜂鸣器对应的 PWM 通道
-    return 0;
-}
-
-static void stop_motor_86(void)
-{
-    rt_kprintf("stop_motor_86!\n");
-    rt_pwm_disable(pwm_device, BEEP_PWM_CH);
-}
-
-void pin_motor_86_bind(void)
-{
-    rt_pin_mode(MOTOR_86, PIN_MODE_INPUT);
-    /* 绑定中断,下降沿模式,回调函数名为 */
-    rt_pin_attach_irq(MOTOR_86, PIN_IRQ_MODE_FALLING, stop_motor_86, RT_NULL);
-    /* 使能中断 */
-    rt_pin_irq_enable(MOTOR_86, PIN_IRQ_ENABLE);
-}
-
-void pin_motor_86_unbind(void)
-{
-    rt_pin_detach_irq(MOTOR_86);
-}
-
 
 /*打开蜂鸣器*/
 int pwm_on(uint8_t pwn_ch,rt_uint32_t pwm_freq)
@@ -270,53 +187,16 @@ void Beep_Tip(uint16_t volnum)
     rt_thread_mdelay(volnum);
     rt_pin_write(Beep, 0);
 }
-void Motor_Juandai(uint8_t on_off)
-{
-    pwm8_init();
-
-    rt_pwm_set(pwm_tim8, PC7_TIM3_CH, 200000, 100000);//channel,period,pulse
-
-    //
-    if(on_off==ON){
-        rt_pwm_enable(pwm_tim8, PC7_TIM3_CH);
-    }
-    else {
-        rt_pwm_disable(pwm_tim8, PC7_TIM3_CH);
-    }
-}
-void Motor_Qingsao_R_PWM(uint8_t on_off)
-{
-    pwm8_init();
-    rt_pwm_set(pwm_tim8, PC7_TIM3_CH, 200000, 150000);//channel,period,pulse
-    if(on_off==ON){
-        rt_pwm_enable(pwm_tim8, PC7_TIM3_CH);
-    }
-    else {
-        rt_pwm_disable(pwm_tim8, PC7_TIM3_CH);
-    }
-}
-void Motor_Qingsao_L_PWM(uint8_t on_off)
-{
-    pwm8_init();
-    rt_pwm_set(pwm_tim8, PC8_TIM3_CH, 200000, 150000);//channel,period,pulse
-    if(on_off==ON)
-    {
-        rt_pwm_enable(pwm_tim8, PC8_TIM3_CH);
-    }
-    else {
-        rt_pwm_disable(pwm_tim8, PC8_TIM3_CH);
-    }
-}
 
 void Motor_shake(uint8_t status_shake,uint16_t shake_sec)
 {
     rt_uint16_t turn_cnt = 0;
     beep_init();
     rt_pwm_set(pwm_device, PB1_TIM3_CH, 200000, 100000);//channel,period,pulse
-    rt_pin_mode(LIMIT_90, PIN_MODE_INPUT);
+    rt_pin_mode(LIMIT_FB, PIN_MODE_INPUT);
     rt_pwm_enable(pwm_device, PB1_TIM3_CH);
 
-    while(rt_pin_read(LIMIT_90)==0){
+    while(rt_pin_read(LIMIT_FB)==0){
         rt_thread_delay(100);
         turn_cnt++;
         if(turn_cnt==shake_sec){
@@ -327,7 +207,7 @@ void Motor_shake(uint8_t status_shake,uint16_t shake_sec)
     }
     if(turn_cnt==shake_sec) return;
     turn_cnt = 0;
-    while(rt_pin_read(LIMIT_90)==1){
+    while(rt_pin_read(LIMIT_FB)==1){
         turn_cnt++;
         rt_thread_delay(50);
         if(turn_cnt==shake_sec){
@@ -341,10 +221,6 @@ void Motor_shake(uint8_t status_shake,uint16_t shake_sec)
 }
 
 
-/* 导出到 msh 命令列表中 */
-MSH_CMD_EXPORT(hwtimer_sample, hwtimer sample);
-
-
 
 
 

+ 4 - 11
Application_cbd_apm32f1/applications/beep.h

@@ -7,13 +7,15 @@
  * Date           Author       Notes
  * 2020-05-23     Administrator       the first version
  */
-#ifndef APPLICATIONS_INC_BEEP_H_
-#define APPLICATIONS_INC_BEEP_H_
+#ifndef APPLICATIONS_INC_APP_PWM_H_
+#define APPLICATIONS_INC_APP_PWM_H_
 
 #include <rtthread.h>
 #define BEEP_PWM_DEVICE "pwm3"
 #define RAIN_PWM_DEVICE "pwm8"
 #define BEEP_PWM_CH 1
+#define PB1_TIM3_CH 4   //pwm3
+
 int beep_init(void);                            //蜂鸣器初始化
 int beep_on(void);                              //蜂鸣器开
 int beep_off(void);                             //蜂鸣器关
@@ -21,16 +23,7 @@ int pwm_off(uint8_t pwn_ch,rt_uint32_t pwm_freq);
 int pwm_on(uint8_t pwn_ch,rt_uint32_t pwm_freq);
 void beep_set(uint32_t freq, uint32_t volume);    //蜂鸣器设定
 void Beep_Tip(uint16_t volnum);
-/*****************************4.0******************************/
-void Motor_Qingsao_L_PWM(uint8_t on_off);
-void Motor_Qingsao_R_PWM(uint8_t on_off);
-/**************************吸虫塔****************************/
-void Motor_Juandai(uint8_t on_off);
 void Motor_shake(uint8_t status_shake,uint16_t shake_sec);
-/***********************************************************/
-void pin_motor_86_bind(void);
-void pin_motor_86_unbind(void);
-int hwtimer2_pwm3_output(rt_uint32_t time,rt_uint32_t freq,uint8_t EN,uint8_t DIR);
 
 
 #endif                                          /* APPLICATIONS_INC_BEEP_H_ */

Разлика између датотеке није приказан због своје велике величине
+ 114 - 1244
Application_cbd_apm32f1/applications/control.c


+ 26 - 146
Application_cbd_apm32f1/applications/control.h

@@ -15,17 +15,12 @@
 #include <rtdevice.h>
 //定制相关//////////////////////////////////////////////////////
 
-
-
-#define LAMP_EN          0             //李新3灯管:0关闭,1打开
-#define PCB_V1           1             //1-旧PCB,0-新PCB(模块化)
-
 #define SENSOR_EN        1             //温湿度:0关闭,1打开
 
 
 ////////////////////////////////////////////////////////////////
 
-#define VERSION  "2.5.9"
+#define VERSION  "3.0.0"
 
 
 extern rt_event_t event_485_play;
@@ -50,12 +45,7 @@ typedef struct  _packed
     uint8_t develop_flag;         //是否进入培养模式
     uint8_t cool_fan_status;      //散热风机状态 0-停止 1-打开
     uint8_t fsl_sw;               //凡士林开关:0-关,1-开
-    uint8_t collecting_sh1;       //采集开启1
-    uint8_t collecting_eh1;       //采集关闭1
-    uint8_t collecting_sh2;       //采集开启2
-    uint8_t collecting_eh2;       //采集关闭2
-    uint8_t collecting_sh3;       //采集开启3
-    uint8_t collecting_eh3;       //采集关闭3
+
     /*测报灯*/
     uint8_t heat_sw;         //加热开关
     uint8_t photo_ws;        //拍照
@@ -169,158 +159,48 @@ typedef struct  _packed
 #define Beep    GET_PIN(B, 4)
 #define OPEN 0x02
 #define CLOSE 0x03
-/************************************************/
+/****************************性诱3.0********************************/
 //光控
 #define LIGHT_PIN GET_PIN(C,0)
 //雨控
 #define RAIN_PIN GET_PIN(C,1)
-//加热
-#define  Heat_Pin GET_PIN(B,12)
-//采集/上仓门
-#define  Collect_fan_R GET_PIN(C, 5)
-#if PCB_V1 == 0
-#define  Collect_fan_L GET_PIN(B, 6)
-#else
-#define  Collect_fan_L GET_PIN(C, 4)
-#endif
-//下仓门
-#define  C_DOWN_R GET_PIN(B,0)
-#define  C_DOWN_L GET_PIN(B,1)
-//镇流器
-#define  LAMP_SW GET_PIN(C,9)
-//震动电机
-#define SHAKE_SW GET_PIN(B,2)
-//补光
-#define LED_SW GET_PIN(A,15)
-//清扫
-#define CLEAR_R GET_PIN(C,7)
-#define CLEAR_L GET_PIN(C,8)
-//相机供电
-#define PHOTO GET_PIN(A,12)
-//路由器供电
-#define ROUTER GET_PIN(A,8)
-//RTU/DTU供电
-#define RTU_DTU GET_PIN(B,13)
-//海康相机拍照
-#define HK_TAKE GET_PIN(A,11)
-#define HK_IO GET_PIN(B,14)     //备用触发拍照
-//清扫限位
-#define CLEAR_R_LIMIT GET_PIN(C,13)
-#define CLEAR_L_LIMIT GET_PIN(B,9)
-
-/*****************************4.0定制多光源*********************************/
-#define LAMP_1_SW GET_PIN(B,10)
-#define LAMP_2_SW GET_PIN(B,11)
-/***************************高空测报灯*************************/
-
-//上仓门电机限位
-#define CTR_UPC_LIMIT GET_PIN(B,9)
-//下仓门电机限位
-#define CTR_DWO_LIMIT GET_PIN(B,5)
-#define CTR_DWC_LIMIT GET_PIN(B,8)
-//雨控电机限位,控制排水和落虫
-
-#define CTR_RO_LIMIT GET_PIN(B,15)
-#define CTR_RC_LIMIT GET_PIN(C,6)
-/******************************吸虫塔*********************************/
-#define HK_5000W_P GET_PIN(B,12)
-#define ROUTER_P   GET_PIN(B,10)
-#define LED_P      GET_PIN(B,11)
 
-#define PC7_TIM3_CH 2   //pwm8
-#define PC8_TIM3_CH 3   //pwm8
-
-#define PB1_TIM3_CH 4   //pwm3
-
-#define MOTOR1_CTR_PIN GET_PIN(C,9)        //吸虫电机IO
-#define MOTOR2_CTR_PIN GET_PIN(B,2)        //吸附电机IO
-
-#define MOTOR_CR_PIN GET_PIN(C,7)
-#define MOTOR_CL_PIN GET_PIN(C,8)
-
-#define MOTOR_C_LIMIT GET_PIN(C,13)       //卷带限位
-
-void ctr_JD_Clear(uint8_t shake_sw);
-uint8_t ctr_Motor_xichong(uint8_t status_ws);
-uint8_t ctr_Motor_xifu(uint8_t status_ws);
-uint8_t ctr_Camera_Power(uint8_t status_ws);
-/*****************************5.0测报灯******************************/
-#define GUANG_SHAN GET_PIN(C,13)       //光栅
-#define MOTOR_86   GET_PIN(B,9)        //85电机限位
-void ctr_Motor_Driver_Power(uint8_t status_ws);
-/****************************性诱3.0********************************/
-#define SIGNAL_GaoYa GET_PIN(B,5)
-#define SIGNAL_GuangShan GET_PIN(B,8)
-/*****************************孢子仪**********************************/
-//制冷
-#define Cold_Pin GET_PIN(B,11)
-//采集
-#define Collect_Fan GET_PIN(B,10)
-//转盘
-#define  TURN_ZP_R GET_PIN(B,0)
-#define  TURN_ZP_L GET_PIN(B,1)
-//转盘限位
-#define LIMIT_0 GET_PIN(C,13)
-#define LIMIT_90 GET_PIN(B,9)
-//散热
-#define  Cool_Fan_R GET_PIN(C, 5)
-#define  Cool_Fan_L GET_PIN(C, 4)
-//步进电机限位
-#define LIMIT_UP GET_PIN(B,8)
-#define LIMIT_DOWN GET_PIN(B,5)
-//步进电机驱动
-#define Motor_EN    GET_PIN(B,14)
-#define Motor_DIR   GET_PIN(B,15)
-void ctr_turn(uint8_t v,uint8_t sta);
-uint8_t ctr_Cold(uint8_t status_cold);
-uint8_t ctr_Cool_Fan(uint8_t status_cool);          //散热风机
-uint8_t ctr_Collect_Fan(uint8_t status_collect);    //采集风机
-void ctr_Motor_Driver(uint8_t EN,uint8_t DIR,rt_uint32_t pwm,rt_uint32_t time_out); //步进电机
-void ctr_Petroleum_jelly(rt_uint32_t delay);        //凡士林
-/*****************************定制4.0-2000W***************************************/
-#define FAN_P   GET_PIN(B,10)
-#define FAN_I   GET_PIN(B,11)
-uint8_t ctr_Fan_IN(uint8_t status_ws);
-uint8_t ctr_Fan_PUT(uint8_t status_ws);
-/*******************************定制展厅机器人************************************/
-#define LIMIT_OPEN GET_PIN(B,8)
-#define LIMIT_CLOSE GET_PIN(B,5)
-#define Motor_Power GET_PIN(B,10)                       //电机驱动供电
-#define Motor_Direction_Button GET_PIN(B,9)             //IO输入,检测按键状态,用于控制方向
-#define Motor_Direction_Ctr GET_PIN(B,15)               //IO输出,控制电机运动方向
-#define EMS_Dir GET_PIN(B,14)
-void ctr_Motor_Robot(uint8_t status_ws);
-/***************************************************************/
+//屏幕供电5V
+#define  POWER_5V GET_PIN(C,9)
+//补光5V
+#define LED_5V GET_PIN(A,15)
+//高压12V
+#define GAOYA_12V GET_PIN(B,11)
+//路由器12V
+#define FourFaith_12V GET_PIN(A,8)
+//RTU12V
+#define RTU_12V GET_PIN(A,8)
+
+#define DC_M1 GET_PIN(C,8)
+#define DC_M2 GET_PIN(C,7)
+
+#define SIGNAL_GuangShan GET_PIN(B,5)
+//#define SIGNAL_GuangShan GET_PIN(B,8)
+#define LIMIT_FB GET_PIN(B,9)
 /***************************************************************/
-uint8_t ctr_Heat(uint8_t status_heat);          //加热
-uint8_t ctr_cangmen_up(uint8_t status_up);      //上仓门
-uint8_t ctr_cangmen_down(uint8_t status_down);  //下仓门
-uint8_t ctr_lamp(uint8_t status_lamp,uint8_t lamp_num);            //镇流器
-uint8_t ctr_shake(uint8_t status_shake,uint16_t shake_sec);        //震动
-uint8_t ctr_clear(uint16_t status_clear);       //清扫
-void ctr_TG_Clear(uint16_t clear_timeout);      //清扫2
+
+void ctr_hmi_5v(uint8_t sw);                        //5V电源[串口屏幕]
 uint8_t ctr_led(uint8_t status_led);            //补光灯
-void calorstat(uint16_t heat_time);             //恒温
 void ctr_router(uint8_t status_router);         //路由器
 void turnzp(void);                              //转仓
 void Hk_Take_io(void);                          //触发拍照
 void HK_TakePhoto(void);                        //拍照
-void ctr_photo(uint8_t status_photo);
-void ctr_RTU_DTU(uint8_t status_rtu);
-void HardWare_Init(uint8_t boot);               //初始化
-void HardWare_Check(uint8_t boot);              //自检
+void ctr_RTU_12V(uint8_t sw);
 void ResetInit(void);                           //上电复位
-void SunTest(void);                             //光控测试
+void ctr_clear(void);
 /*****************************************************/
 
-/***********************孢子仪****************************/
-
 /***************************************************/
 //线程
-int Control_clear(void);
 int Workstatus_check(void);
 int Work_Loop_Task(void);
-int Control_heat(void);
+int Check_Self(void);
+int Check_gaoya(void);
 int thread_485_play(void);
 
 int thread_delete_workloop(void);

+ 71 - 229
Application_cbd_apm32f1/applications/dtu_uart2.c

@@ -1,3 +1,4 @@
+#include <app_pwm.h>
 /*
  * Copyright (c) 2006-2020, RT-Thread Development Team
  *
@@ -21,9 +22,9 @@
 #include <easyflash.h>
 #include "sound.h"
 #include <ymodem.h>
-#include "beep.h"
 #include <selfcheck.h>
 #include <user_mb_app.h>
+#include <lwjson.h>
 
 #define DBG_ENABLE
 #define DBG_COLOR
@@ -47,12 +48,14 @@ struct rx_msg
     rt_device_t dev;
     rt_size_t size;
 };
-/* 消息队列句柄 */
-static struct rt_messagequeue  rx_mq_dtu;
+
+
+static struct rt_semaphore rx_sem;    /* 用于接收消息的信号量 */
+
 rt_thread_t dtu_recv_data = RT_NULL;
 rt_thread_t dtu_send_data = RT_NULL;
 
-
+static lwjson_stream_parser_t lwparser;
 rt_device_t dtuserial;   /*串口设备句柄*/
 struct  serial_configure dtuconfig = RT_SERIAL_CONFIG_DEFAULT;  /*初始化配置参数*/
 
@@ -78,7 +81,7 @@ static int DTU_uart2_init(void)
     rt_device_control(dtuserial, RT_DEVICE_CTRL_CONFIG, &dtuconfig);
     /* step4:打开串口设备。以DMA接收及轮询发送模式打开串口设备 */
     #ifdef RT_USING_SERIAL_V2
-    rt_err_t uart_res = rt_device_open(dtuserial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
+    rt_err_t uart_res = rt_device_open(dtuserial, RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING); // 串口设备使用模式为 (发送阻塞 接收非阻塞) 模式
     #else
     rt_err_t uart_res = rt_device_open(dtuserial, RT_DEVICE_FLAG_DMA_RX);  //RT_DEVICE_FLAG_DMA_RX
     #endif
@@ -108,144 +111,65 @@ void DTU_Write(char *fmt, ...)
         str_length = 1024 - 1;
     rt_device_write(dtuserial, 0, dtu_str, str_length);
     LOG_I("DTU_Write:%s",dtu_str);
-//    if(strstr(dtu_str,"volume")!=RT_NULL)
-//    {
-//        rt_device_write(dtuserial,0,dtu_conf,4);
-//    }
-//    else if (strstr(dtu_str,"reset")!=RT_NULL) {
-//        const char dtu_conf[4] = {7,0x00,0x00,0x00};
-//        rt_device_write(dtuserial,0,dtu_conf,4);
-//    }
+
 }
 /* 接收数据回调函数 */
 static rt_err_t dtu_input(rt_device_t dev, rt_size_t size)
 {
-    struct rx_msg msg;
-    rt_err_t result;
-    msg.dev = dev;
-    msg.size = size;
-    result = rt_mq_send(&rx_mq_dtu,&msg, sizeof(struct rx_msg));
-    if ( result == -RT_EFULL)
-    {
-        /* 消息队列满 */
-        LOG_E("rx_mq_dtu message queue full!\n");
-        rt_mq_control(&rx_mq_dtu, RT_IPC_CMD_RESET, RT_NULL); // 清空队列
-    }
-    return result;
+    /* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
+    rt_sem_release(&rx_sem);
+    return RT_EOK;
 }
 
 
-/* 入口函数-指令接收*/
 static void dtu_thread_entry_recv(void *parameter)
 {
-    struct rx_msg msg;
-    rt_memset(&msg, 0, sizeof(msg));
-    rt_err_t result;
-    rt_uint32_t rx_length;
-    static int rx_err = 0;
-    static char str_check[2]={'{','}'};
-    static char rx_buffer[512];
-    static char rx_buffer_tmp[512];
-    static char rx_buffer_tmp2[512];
-    while(1)
-    {
-        //
-        // 从消息队列中获取被回调函数放入消息队列中的内容
-        result = rt_mq_recv(&rx_mq_dtu, &msg, sizeof(struct rx_msg), 100);
-        #if 0
-        if (result != RT_EOK){
-            rx_err ++;
-            if(rx_err==15){
-                json_ctx.index = 0;
-            }
-//            if(rx_err==54000)//90分钟未接收到数据
-//            {
-//                ctr_RTU_DTU(OFF);
-//            }
-//            if (rx_err>54100&&device_status.bat_status==0)
-//            {
-//                LOG_W("通信中断,RTU重新上电");
-//                rx_err = 0;
-//                ctr_RTU_DTU(ON);
-//                ctr_photo(ON);
-//            }
-            continue;
-        }
-        // 动态分配接收缓冲区
-        char *rx_buffer = rt_malloc(msg.size + 1);
-        if (!rx_buffer) {
-            LOG_E("Memory allocation failed");
-            continue;
+    static char accum_buf[MAX_DTU_SIZE];  // 累积缓冲区(根据实际数据量调整)
+    static size_t accum_len = 0;        // 累积缓冲区当前长度
+    char ch;
+    while (1) {
+        /* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */
+        while (rt_device_read(dtuserial, -1, &ch, 1) != 1)
+        {
+            /* 阻塞等待接收信号量,等到信号量后再次读取数据 */
+            rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
         }
-        // 安全读取数据
-        int rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
-        if (rx_length <= 0) {
-            rt_free(rx_buffer);
+        accum_buf[accum_len++]=ch;
+        if (accum_len >= sizeof(accum_buf)) {
+            // 防止超范围
+            accum_len = 0;
+            lwjson_stream_reset(&lwparser);
             continue;
         }
-        rx_err = 0;
-        rx_buffer[rx_length] = '\0';
-        // 处理数据(新增调试接口)
-        LOG_I("Raw Data:%s-%d",rx_buffer, rx_length);
-        if(strstr(rx_buffer,"{")==RT_NULL||strstr(rx_buffer,"}")==RT_NULL)
-        {
-            HMI_WRITE("sysSet.va0.txt=\"%s\"",rx_buffer);
-        }else{
-            process_uart_data(rx_buffer, rx_length);
-        }
-
-        rt_free(rx_buffer);
-        #endif
-        #if 1
-        if(result == RT_EOK)
+        lwjsonr_t ret;
+        ret = lwjson_stream_parse(&lwparser, ch); // 把串口数据逐字节的喂给解析器去解析
+        switch(ret)
         {
-
-            rx_err = 0;
-            rx_length =(sizeof(rx_buffer) - 1) > msg.size ?
-                    msg.size : sizeof(rx_buffer) - 1;
-            rx_length = rt_device_read(msg.dev, 0, &rx_buffer[0], rx_length);
-            rx_buffer[rx_length] = '\0';
-            LOG_D("recv data:%s",rx_buffer);
-//            if(strstr(rx_buffer,"{")==RT_NULL||strstr(rx_buffer,"}")==RT_NULL)
-//            {
-//               HMI_WRITE("sysSet.va0.txt=\"%s\"",rx_buffer);
-//            }
-
-            //过滤异常数据
-            char str_check_head[2];
-            char str_check_end[2];
-            rt_sprintf(str_check_head, "%c",rx_buffer[0]);
-            rt_sprintf(str_check_end, "%c",rx_buffer[rx_length-1]);
-            if(str_check_end[0]==str_check[1]&&str_check_head[0]==str_check[0])
-            {
-                  parseDtu(rx_buffer);
-                  rt_memset(rx_buffer,0,sizeof(rx_buffer));
-                  rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
-                  rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
-            }
-            else {
-                   if(rx_buffer[rx_length-1]!='}')
-                   {
-                       rt_sprintf(rx_buffer_tmp, "%s",rx_buffer);
-                   }
-                   else {
-                       rt_sprintf(rx_buffer_tmp2,"%s",rx_buffer);
-                       rt_sprintf(rx_buffer, "%s%s",rx_buffer_tmp,rx_buffer_tmp2);
-                       parseDtu(rx_buffer);
-                       rt_memset(rx_buffer,0,sizeof(rx_buffer));
-                       rt_memset(rx_buffer_tmp,0,sizeof(rx_buffer_tmp));
-                       rt_memset(rx_buffer_tmp2,0,sizeof(rx_buffer_tmp2));
-                   }
-
-                 }
-            #endif
-         }
-//         else {
-//
-//
+            case lwjsonERRJSON:             // 1, 无效的字符
+              case lwjsonSTREAMWAITFIRSTCHAR: // 2, 等待首字符
+                LOG_W("invalid JSON byte:%s[%x]",ch,ch);
+                break;
+              case lwjsonSTREAMINPROG:        // 3, 正在解析中
+                break;
+              case lwjsonSTREAMDONE:          // 4, 解析已完成
+                 parseDtu(accum_buf);
+                 accum_len = 0;
+                 memset(accum_buf,0,sizeof(accum_buf));
+                 //rt_thread_kill(dtu_send_data, SIGUSR2);
+                 lwjson_stream_reset(&lwparser);
+                 break;
+              case lwjsonERRMEM:             // 5, 嵌套的太深("LWJSON_CFG_STREAM_STACK_SIZE")
+                 LOG_E("parser stack overflow (ERRMEM), resetting parser!");
+                 lwjson_stream_reset(&lwparser);
+                 break;
+              default: // 流式解析时, 其它的返回值, 都不应该出现
+                  LOG_E("internal error, lwjson_stream_parse() returned: %d, data receive thread will exit!!!",ret);
+                  break;
+          }
     }
 }
 
+
 // 解析时间戳并返回一个tm结构体
 struct tm* parseTimestamp(const char *timestamp) {
     if (strlen(timestamp) != 14) {
@@ -368,17 +292,11 @@ static void dtu_thread_entry_send(void *parameter)
 /* 创建线程 */
 int dtu_data_play(void)
 {
-    rt_err_t rm_dtu_result;
+    lwjson_stream_init(&lwparser, NULL);
+
     DTU_uart2_init();
-    //初始化消息队列
-    rm_dtu_result = rt_mq_init(&rx_mq_dtu, "dtu", &data_arry.msg_pool[0], 128 - sizeof(void*), sizeof(data_arry.msg_pool), RT_IPC_FLAG_FIFO);
-    if(rm_dtu_result==RT_EOK)
-    {
-        rt_kprintf("消息队列创建成功!!");
-    }
-    else {
-        rt_kprintf("消息队列创建失败!!");
-    }
+    /* 初始化信号量 */
+    rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
     /* 设置接收回调函数 */
     rt_device_set_rx_indicate(dtuserial, dtu_input);
     /*创建线程-指令发送*/
@@ -1021,7 +939,7 @@ int parseDtu(char *json_string)
                   DTU_Write("%s",json_temp);
                   free(json_temp);
               }
-              if(device_status.work_status==0) ctr_lamp(OFF, 1);  //关闭高压
+             // if(device_status.work_status==0) ctr_lamp(OFF, 1);  //关闭高压
               //收到拍照结果,
 
           }
@@ -1034,9 +952,9 @@ int parseDtu(char *json_string)
               char *json_temp = makeJson_selfCheck_(0);
               DTU_Write("%s",json_temp);
               free(json_temp);
-              ctr_lamp(OFF,1);
+              //ctr_lamp(OFF,1);
               rt_thread_delay(1000);
-              ctr_lamp(ON, 1);  //开启高压
+              //ctr_lamp(ON, 1);  //开启高压
               device_status.selfcheck_ws = 1;
           }
           //item_data = cJSON_GetObjectItem(root,"data");
@@ -1075,9 +993,9 @@ int parseDtu(char *json_string)
                   if(strstr(type->valuestring,"rtu_off_on")!=RT_NULL)
                   {
                       LOG_W("DTU 12V Power down");
-                      ctr_RTU_DTU(OFF);
+                      ctr_RTU_12V(OFF);
                       rt_thread_delay(5000);
-                      ctr_RTU_DTU(ON);
+                      ctr_RTU_12V(ON);
                   }
                   else if(strstr(type->valuestring,"takephoto")!=RT_NULL)
                   {
@@ -1088,7 +1006,7 @@ int parseDtu(char *json_string)
                       rt_free(photo);
                       rt_thread_delay(2000);
                   }
-
+                  //{"ext": {"type": "led_on"}, "cmd": "ctrl"}
                   else if (strstr(type->valuestring,"led_on")!=RT_NULL)
                   {
                       ctr_led(ON);
@@ -1098,6 +1016,16 @@ int parseDtu(char *json_string)
                   {
                       ctr_led(OFF);
                   }
+                  //{"ext": {"type": "hmi_on"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"hmi_on")!=RT_NULL)
+                  {
+                      ctr_hmi_5v(ON);
+                  }
+                  //{"ext": {"type": "hmi_off"}, "cmd": "ctrl"}
+                  else if (strstr(type->valuestring,"hmi_off")!=RT_NULL)
+                  {
+                      ctr_hmi_5v(OFF);
+                  }
                   //{"ext": {"type": "sleep_mode"}, "cmd": "ctrl"}
                   else if(strstr(type->valuestring,"sleep_mode")!=RT_NULL)
                   {
@@ -1141,7 +1069,6 @@ int parseDtu(char *json_string)
                   DTU_Write("%s",restart);
                   rt_free(restart);
                   rt_thread_delay(2000);
-
              }
               else if (strstr(item_cmd->valuestring,"update")!=RT_NULL)
               {
@@ -1641,92 +1568,7 @@ int parseDtu(char *json_string)
                               }
                           }
 #endif
-                          if(collt!=NULL)
-                          {
-                              if(collt->type==cJSON_Number)
-                              {
-                                  if(collt->valueint>=1&&collt->valueint<=60)
-                                  {
-                                      device_status.clt_time = collt->valueint;
-                                      ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));      //收集时间
-                                      LOG_I("收集时间collt:%d",collt->valueint);
-                                  }
-                                  else {
-                                      LOG_E("收集时间collt设置失败参数错误!!!");
-                                  }
-                              }
-                              else if (collt->type==cJSON_String) {
-                                  if(atoi(collt->valuestring)>=1&&atoi(collt->valuestring)<=60)
-                                  {
-                                      device_status.clt_time = atoi(collt->valuestring);
-                                      ef_set_env_blob("stime", &device_status.clt_time, sizeof(device_status.clt_time));      //收集时间
-                                      LOG_I("收集时间collt:%d",atoi(collt->valuestring));
-                                  }
-                                  else {
-                                      LOG_E("收集时间collt设置失败参数错误!!!");
-                                  }
-                              }
-                              else if (collt->type==cJSON_Array) {
-                                 int icnt = 0;
-                                 for(icnt=0;icnt < cJSON_GetArraySize(collt);icnt++)
-                                 {
-                                     cJSON *pSub = cJSON_GetArrayItem(collt, icnt);
-                                     if(NULL==pSub) break;
-                                     char ivalue[10];
-                                     rt_sprintf(ivalue,"%s",pSub->valuestring);
-                                     if(icnt==0)
-                                     {
-                                         if(ivalue[1]=='-')
-                                         {
-                                             device_status.collecting_sh1 = atoi(&ivalue[0]);
-                                             if(strlen(ivalue)==3)
-                                                 device_status.collecting_eh1 = atoi(&ivalue[2]);
-                                             if(strlen(ivalue)==4)
-                                                 device_status.collecting_eh1 = atoi(&ivalue[3])<<8|atoi(&ivalue[2]);
-                                             ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));
-                                             ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));
-                                         }
-                                         if(ivalue[2]=='-')
-                                         {
-                                             device_status.collecting_sh1 = atoi(&ivalue[1])<<8|atoi(&ivalue[0]);
-                                             if(strlen(ivalue)==3)
-                                                 device_status.collecting_eh1 = atoi(&ivalue[3]);
-                                             if(strlen(ivalue)==5)
-                                                 device_status.collecting_eh1 = atoi(&ivalue[4])<<8|atoi(&ivalue[3]);
-                                             ef_set_env_blob("collecting_sh1", &device_status.collecting_sh1, sizeof(device_status.collecting_sh1));
-                                             ef_set_env_blob("collecting_eh1", &device_status.collecting_eh1, sizeof(device_status.collecting_eh1));
-                                         }
-                                         LOG_I("开始结束时间1:%d-%d",device_status.collecting_sh1,device_status.collecting_eh1);
-                                     }
-                                     else if (icnt==1)
-                                     {
-                                         if((ivalue[1]=='-'))
-                                         {
-                                             device_status.collecting_sh2 = atoi(&ivalue[0]);
-                                             if(strlen(ivalue)==3)
-                                                 device_status.collecting_eh2 = atoi(&ivalue[2]);
-                                             if(strlen(ivalue)==4)
-                                                 device_status.collecting_eh2 = atoi(&ivalue[3])<<8|atoi(&ivalue[2]);
-                                             ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));
-                                             ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));
-                                         }
-                                         if((ivalue[2]=='-'))
-                                         {
-                                             device_status.collecting_sh2 = atoi(&ivalue[1])<<8|atoi(&ivalue[0]);
-                                             if(strlen(ivalue)==3)
-                                                 device_status.collecting_eh2 = atoi(&ivalue[2]);
-                                             if(strlen(ivalue)==5)
-                                                 device_status.collecting_eh2 = atoi(&ivalue[4])<<8|atoi(&ivalue[3]);
-                                             ef_set_env_blob("collecting_sh2", &device_status.collecting_sh2, sizeof(device_status.collecting_sh2));
-                                             ef_set_env_blob("collecting_eh2", &device_status.collecting_eh2, sizeof(device_status.collecting_eh2));
-                                         }
-                                         LOG_I("开始结束时间2:%d-%d",device_status.collecting_sh2,device_status.collecting_eh2);
-                                     }
-                                     LOG_I("下发设置收集:%d-%s",icnt,ivalue);
-                                 }
-                              }
 
-                          }
                           if(datt!=NULL)
                           {
                               if(datt->type==cJSON_Number)

+ 47 - 165
Application_cbd_apm32f1/applications/hmi.c

@@ -1,3 +1,4 @@
+#include <app_pwm.h>
 /*
  * Copyright (c) 2006-2020, RT-Thread Development Team
  *
@@ -18,7 +19,6 @@
 #include  "stdarg.h"
 #include  "string.h"
 #include "sht30_collect.h"
-#include "beep.h"
 #include "easyflash.h"
 #include "sound.h"
 #include "ymodem.h"
@@ -408,18 +408,6 @@ static void HMI_Decode(void)
         LOG_I("关闭补光!!!");
         ctr_led(OFF);
     }
-    //关闭加热
-    else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
-        device_status.heat_status = 0;
-        ctr_Heat(OFF);
-        LOG_I("Close Heat!");
-    }
-    //打开加热
-    else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
-        device_status.heat_status = 1;
-        ctr_Heat(ON);
-        LOG_I("Open Heat!");
-    }
 
     //清扫
     else if (strstr(rx_buffer,"clear")!=NULL) {
@@ -443,11 +431,8 @@ static void HMI_Decode(void)
     {
         device_status.test_flag=1;
         rt_kprintf("Open Lamp!\n");
-        ctr_lamp(ON,1);
-        #if LAMP_EN == 1
-        ctr_lamp(ON,2);
-        ctr_lamp(ON,3);
-        #endif
+        //ctr_lamp(ON,1);
+
         DTU_Write("{\"cmd\":\"workstart\"}");
         USHORT dkdg[] = {0xb4f2,0xbfaa,0xb5c6,0xb9dc};
         _485_play(dkdg,4);
@@ -458,27 +443,13 @@ static void HMI_Decode(void)
     {
         device_status.test_flag=0;
         rt_kprintf("Close Lamp1!\n");
-        ctr_lamp(OFF,1);
-        #if LAMP_EN == 1
-        ctr_lamp(OFF,2);
-        ctr_lamp(OFF,3);
-        #endif
+        //ctr_lamp(OFF,1);
+
         DTU_Write("{\"cmd\":\"workdone\"}");
         USHORT gbdg[] = {0xb9d8,0xb1d5,0xb5c6,0xb9dc};
         _485_play(gbdg,4);
     }
-    //关闭加热
-    else if(strstr(rx_buffer,"putTest.switchHeat=0")!=NULL) {
-        device_status.heat_status = 0;
-        ctr_Heat(OFF);
-        rt_kprintf("Close Heat!\n");
-    }
-    //打开加热
-    else if(strstr(rx_buffer,"putTest.switchHeat=1")!=NULL) {
-        device_status.heat_status = 1;
-        ctr_Heat(ON);
-        rt_kprintf("Open Heat!\n");
-    }
+
 
     //设置设备时间
     else if (strstr(rx_buffer,"stamp=")!=NULL)
@@ -887,35 +858,7 @@ static void Ctr_Mortor_entry(void* parameter)
         #endif
 
         //拍照
-        if(device_status.photo_ws==1)
-        {
-            photo_led_sec--;
-            ctr_led(ON);
-            //打开补光灯
-            if(photo_led_sec==890)
-            {
-                gettimeofday(&tv, NULL);
-                device_status.photo_stamp = tv.tv_sec;
-                DTU_Write("takephoto.mp3");
-                //延时
-                rt_thread_delay(1000);
-                LOG_I("测试拍照!");
-                Hk_Take_io();
-                char *takephotojson = makeJson_takephoto();
-                DTU_Write("%s",takephotojson);
-                rt_free(takephotojson);
-            }
-
-            if(photo_led_sec==500)    //4800W相机
-            {
-                ctr_led(OFF);
-                photo_led_sec = 900;
-                device_status.photo_ws = 0;
-                HMI_WRITE("sysTest.switchPhoto.val=0");
-                HMI_WRITE("sysTest.switchFill.val=0");
-            }
-
-        }else if(device_status.photo_ws ==2){
+        if(device_status.photo_ws ==2){
             ctr_led(ON);
             photo_led_sec--;
             if(photo_led_sec==890){
@@ -1007,39 +950,24 @@ void Check_ParamConfig(void)
         /*设备类型,7孢子仪,3测报灯,默认设置测报灯*/
         device_status.dtype = 8;
         device_status.version_type = 8; //4.0
-        device_status.clt_time = 10;    //收集时间
-        device_status.heattime = 10;    //加热时间
-        device_status.heatvalue=100;//加热温度
         device_status.thsp = 300;       //默认熄屏时间5分钟
         device_status.sunBar = 9;       //光控定时时长
-        device_status.startBar = 9;    //定时开始时间
-        device_status.stopBar  = 17;     //定时结束时间
+        device_status.startBar = 9;     //定时开始时间
+        device_status.stopBar  = 17;    //定时结束时间
         device_status.tph = 70;         //高温保护阈值
         device_status.tpl = 5;          //低温保护阈值
-        device_status.shake_ws = 1;     //震动开关,默认开
-        device_status.shake_sec = 1;    //震动时间,s
         device_status.vol = 7;          //音量
         device_status.timeSwitch = 1;   //工作模式:时控
-        device_status.passWord = 8888;    //屏幕密码
-        device_status.dattim = 20;      //数据上传间隔
+        device_status.passWord = 8888;  //屏幕密码
+        device_status.dattim = 60;      //数据上传间隔
         device_status.ds = 1;           //设备状态
         device_status.update_flag = 0;
         device_status.sleep_mode = 0;
-        /*孢子仪*/
-        /*孢子仪*/
-        device_status.collecting_sh1 = 9;
-        device_status.collecting_eh1 = 10;
-        device_status.collecting_sh2 = 14;
-        device_status.collecting_eh2 = 16;
-        device_status.cold_sw = 0;
-        device_status.heat_sw =0;
-        device_status.cul_time = 60;
         device_status.run_sta = 0;
         device_status.InsectSpecies = 0;
         device_status.Power_Type = 0;
         sprintf(device_status.deviceId,"0");
         sprintf(device_status.driver, "%s",VERSION);
-
         rt_sprintf(device_status.tempture, "-15");
         rt_sprintf(device_status.humidity, "31");
         rt_sprintf(device_status.mqttcfg1, "8.136.98.49");
@@ -1050,27 +978,13 @@ void Check_ParamConfig(void)
         ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
         ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
         ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
-        ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
-        ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
         ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
         ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
-        ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws));   //震动开关
-        ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));   //震动时间
         ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
         ef_set_env_blob("passWord", &device_status.passWord,sizeof(device_status.passWord));
         ef_set_env_blob("dattim",&device_status.dattim,sizeof(device_status.dattim));        //上传时间
         ef_set_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type));        //版本类型
-        ef_set_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture));        //温度
-        ef_set_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity));        //湿度
         ef_set_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1));        //上传平台
-
-        ef_set_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time));     //采集时间
-        ef_set_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw));        //制冷开关
-        ef_set_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw));        //加热开关
-        ef_set_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1));        //风机开关
-        ef_set_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1));        //采集时间
-        ef_set_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2));        //采集时间
-        ef_set_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2));        //采集时间
         ef_set_env_blob("run_sta", &device_status.run_sta, sizeof(device_status.run_sta));      //
         ef_set_env_blob("InsectSpecies", &device_status.InsectSpecies, sizeof(device_status.InsectSpecies));  //昆虫种类
         ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));     //供电类型
@@ -1079,7 +993,6 @@ void Check_ParamConfig(void)
         LOG_I("SOFTWARE VERSION:%s",device_status.driver);
         LOG_I("Default paramconf is:");
         LOG_I("clt_time:%d",device_status.iSave);
-        LOG_I("cul_time:%d",device_status.cul_time);
         LOG_I("startBar:%d",device_status.startBar);
         LOG_I("stopBar:%d",device_status.stopBar);
         LOG_I("timeSwitch:%d",device_status.timeSwitch);
@@ -1100,10 +1013,6 @@ void Check_ParamConfig(void)
         ef_get_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar), NULL);                    //结束时间
         ef_get_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch), NULL);           //模式
         ef_get_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar), NULL);                       //光控时间
-        ef_get_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime), NULL);                    //加热时间
-        ef_get_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue), NULL);                  //加热温度
-        ef_get_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws), NULL);                 //震动开关
-        ef_get_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec), NULL);              //震动时间
         ef_get_env_blob("tph", &device_status.tph, sizeof(device_status.tph), NULL);                                //高温保护
         ef_get_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl), NULL);                                //低温保护
         ef_get_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim), NULL);                       //数据上传间隔
@@ -1116,24 +1025,13 @@ void Check_ParamConfig(void)
         ef_get_env_blob("ds",&device_status.ds,sizeof(device_status.ds),NULL);                                      //开关机状态
         ef_get_env_blob("env_t",&device_status.tempture,sizeof(device_status.tempture),NULL);                       //环境温度
         ef_get_env_blob("env_h",&device_status.humidity,sizeof(device_status.humidity),NULL);                       //环境湿度
-        ef_get_env_blob("json_w_clock",&device_status.json_w_clock,sizeof(device_status.json_w_clock),NULL);        //时间
-        ef_get_env_blob("json_w_reset",&device_status.json_w_reset,sizeof(device_status.json_w_reset),NULL);        //重置
-        ef_get_env_blob("json_w_platform",&device_status.json_w_platform,sizeof(device_status.json_w_platform),NULL);//平台
         ef_get_env_blob("version_type",&device_status.version_type,sizeof(device_status.version_type),NULL);        //版本类型
         ef_get_env_blob("driver_bl",&device_status.driver_bl,sizeof(device_status.driver_bl),NULL);                 //BL版本号 进BL的时候存储到FLASH
         ef_get_env_blob("platform",&device_status.mqttcfg1,sizeof(device_status.mqttcfg1),NULL);                    //平台地址
-        /*孢子仪*/
-        ef_get_env_blob("cul_time",&device_status.cul_time,sizeof(device_status.cul_time),NULL);                    //培养时间
-        ef_get_env_blob("cold_sw",&device_status.cold_sw,sizeof(device_status.cold_sw),NULL);                       //制冷开关
-        ef_get_env_blob("heat_sw",&device_status.heat_sw,sizeof(device_status.heat_sw),NULL);                       //加热开关
-        ef_get_env_blob("collecting_sh1",&device_status.collecting_sh1,sizeof(device_status.collecting_sh1),NULL);  //采集开始1
-        ef_get_env_blob("collecting_eh1",&device_status.collecting_eh1,sizeof(device_status.collecting_eh1),NULL);  //采集结束1
-        ef_get_env_blob("collecting_sh2",&device_status.collecting_sh2,sizeof(device_status.collecting_sh2),NULL);  //采集开始2
-        ef_get_env_blob("collecting_eh2",&device_status.collecting_eh2,sizeof(device_status.collecting_eh2),NULL);  //采集结束2
         ef_get_env_blob("run_sta",&device_status.run_sta,sizeof(device_status.run_sta),NULL);                       //运行状态
         ef_get_env_blob("InsectSpecies",&device_status.InsectSpecies,sizeof(device_status.InsectSpecies),NULL);     //昆虫种类
-        ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL);     //昆虫种类
-        ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL);     //昆虫种类
+        ef_get_env_blob("Power_Type",&device_status.Power_Type,sizeof(device_status.Power_Type),NULL);              //昆虫种类
+        ef_get_env_blob("deviceId",&device_status.deviceId,sizeof(device_status.deviceId),NULL);                    //昆虫种类
         ef_get_env_blob("sleep_mode",&device_status.sleep_mode,sizeof(device_status.sleep_mode),NULL);              //休眠开关
         device_status.light_over_tim = device_status.sunBar * 3600;                                                 //光控计数
         device_status.work_done = 0;
@@ -1142,11 +1040,9 @@ void Check_ParamConfig(void)
         {
             device_status.dattim = 10;
         }
-
         device_status.dtype = 8;
         device_status.version_type = 8;
         rt_sprintf(device_status.driver, "%s",VERSION);
-
         if(device_status.Power_Type>1) device_status.Power_Type = 0;
 
         LOG_I("SOFTWARE VERSION:%s-imei:%s--iccid:%s",device_status.driver,device_status.imei,device_status.iccid);
@@ -1155,7 +1051,6 @@ void Check_ParamConfig(void)
         LOG_I("定时开始时间:%d",device_status.startBar);
         LOG_I("定时结束时间:%d",device_status.stopBar);
         LOG_I("timeSwitch:%d",device_status.timeSwitch);
-        LOG_I("光控定时时长:%d",device_status.sunBar);
         LOG_I("诱虫时间:%d",device_status.cul_time);
         LOG_I("加热温度:%d",device_status.heatvalue);
         LOG_I("震动开关:%d",device_status.shake_ws);
@@ -1185,11 +1080,10 @@ void Check_ParamConfig(void)
         rt_sprintf(device_status.net,"1");
         rt_sprintf(device_status.csq,"0");
         rt_sprintf(device_status.sim,"1");
-        ctr_RTU_DTU(ON);
-        ctr_router(ON);
+        ctr_RTU_12V(ON);    //RTU供电
+        ctr_router(ON);     //路由器供电
         Hmi_Fresh();
-        Control_clear();
-        Control_heat();
+        Check_Self();
         dtu_data_play();
         sht30_collect();
 
@@ -1235,14 +1129,14 @@ void Check_ParamConfig(void)
         dtu_send_data_start();
         Workstatus_check();
         Work_Loop_Task();
-
+        Check_gaoya();
     }
 }
 
 void ResetParamDefault(void)
 {
     ctr_router(ON);
-    ctr_RTU_DTU(ON);
+    ctr_RTU_12V(ON);
     device_status.dtype = 8;
     device_status.version_type = 8;
     ef_set_env_blob("dtype", &device_status.dtype, sizeof(device_status.dtype));
@@ -1253,44 +1147,36 @@ void ResetParamDefault(void)
     device_status.thsp = 300;
     device_status.passWord = 8888;
     device_status.dattim = 30;
-    device_status.collecting_sh1 = 9;
-    device_status.collecting_eh1 = 10;
-    device_status.collecting_sh2 = 14;
-    device_status.collecting_eh2 = 16;
     device_status.Power_Type = 0;
     ef_set_env_blob("Power_Type", &device_status.Power_Type, sizeof(device_status.Power_Type));
-    if(device_status.dtype==8)
-    {
-        device_status.cul_time = 60;    //收集时间
-        ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
-        device_status.dattim = 30;      //数据上传间隔
-        ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); //数据上传间隔
-
-        device_status.startBar = 9;    //定时开始时间
-        device_status.stopBar = 18;      //定时结束时间
-
-        device_status.heattime = 10;    //加热时间
-        device_status.shake_ws = 1;     //针对开关
-        device_status.shake_sec = 1;    //震动时间1-100ms
-        device_status.sunBar = 8;
-        device_status.tph = 70;         //高温保护阈值
-        device_status.tpl = -5;          //低温保护阈值
-        device_status.timeSwitch = 1;   //定时模式:时控
-        device_status.heatvalue=100;    //加热温度
-        device_status.sleep_mode = 0;
-        ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));
-        ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
-        ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
-        ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
-        ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
-        ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
-        ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
-        ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
-        ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
-        ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
-        ef_set_env_blob("shake_ws", &device_status.shake_ws, sizeof(device_status.shake_ws));       //震动开关
-        ef_set_env_blob("shake_sec", &device_status.shake_sec, sizeof(device_status.shake_sec));    //震动时间
-    }
+
+    device_status.cul_time = 60;    //收集时间
+    ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
+    device_status.dattim = 30;      //数据上传间隔
+    ef_set_env_blob("dattim", &device_status.dattim, sizeof(device_status.dattim)); //数据上传间隔
+
+    device_status.startBar = 9;    //定时开始时间
+    device_status.stopBar = 18;      //定时结束时间
+
+    device_status.heattime = 10;    //加热时间
+
+    device_status.sunBar = 8;
+    device_status.tph = 70;         //高温保护阈值
+    device_status.tpl = -5;          //低温保护阈值
+    device_status.timeSwitch = 1;   //定时模式:时控
+    device_status.heatvalue=100;    //加热温度
+    device_status.sleep_mode = 0;
+    ef_set_env_blob("sleep_mode", &device_status.sleep_mode, sizeof(device_status.sleep_mode));
+    ef_set_env_blob("cul_time", &device_status.cul_time, sizeof(device_status.cul_time));
+    ef_set_env_blob("startBar", &device_status.startBar, sizeof(device_status.startBar));
+    ef_set_env_blob("stopBar", &device_status.stopBar, sizeof(device_status.stopBar));
+    ef_set_env_blob("timeSwitch", &device_status.timeSwitch, sizeof(device_status.timeSwitch));
+    ef_set_env_blob("sunBar", &device_status.sunBar, sizeof(device_status.sunBar));
+    ef_set_env_blob("jtime", &device_status.heattime, sizeof(device_status.heattime));
+    ef_set_env_blob("jheat", &device_status.heatvalue, sizeof(device_status.heatvalue));
+    ef_set_env_blob("tph", &device_status.tph, sizeof(device_status.tph));
+    ef_set_env_blob("tpl", &device_status.tpl, sizeof(device_status.tpl));
+
 
     ef_set_env_blob("ds", &device_status.ds, sizeof(device_status.ds));
     ef_set_env_blob("thsp", &device_status.thsp, sizeof(device_status.thsp));
@@ -1303,7 +1189,7 @@ void ResetParamDefault(void)
 void ResetParamDefault_DC(void)
 {
     ctr_router(ON);
-    ctr_RTU_DTU(ON);
+    ctr_RTU_12V(ON);
     device_status.dtype = 8;
     device_status.version_type = 8;
     ef_set_env_blob("dtype", &device_status.dtype, sizeof(device_status.dtype));
@@ -1322,11 +1208,7 @@ void ResetParamDefault_DC(void)
     device_status.heattime = 10;    //加热时间
     device_status.shake_ws = 1;     //针对开关
     device_status.shake_sec = 1;    //震动时间1-100ms
-    #if LAMP_EN == 1
-    device_status.sunBar = 3;       //光控定时时长
-    #else
     device_status.sunBar = 4;
-    #endif
     device_status.Power_Type = 1;
     device_status.tph = 70;         //高温保护阈值
     device_status.tpl = -5;          //低温保护阈值

+ 773 - 0
Application_cbd_apm32f1/applications/lwjson.c

@@ -0,0 +1,773 @@
+/**
+ * \file            lwjson.c
+ * \brief           Lightweight JSON format parser
+ */
+
+/*
+ * Copyright (c) 2024 Tilen MAJERLE
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * This file is part of LwJSON - Lightweight JSON format parser.
+ *
+ * Author:          Tilen MAJERLE <tilen@majerle.eu>
+ * Version:         v1.8.1
+ */
+#include <string.h>
+#include "lwjson.h"
+
+/**
+ * \brief           Internal string object
+ */
+typedef struct {
+    const char* start; /*!< Original pointer to beginning of JSON object */
+    size_t len;        /*!< Total length of input json string */
+    const char* p;     /*!< Current char pointer */
+} lwjson_int_str_t;
+
+/**
+ * \brief           Allocate new token for JSON block
+ * \param[in]       lwobj: LwJSON instance
+ * \return          Pointer to new token
+ */
+static lwjson_token_t*
+prv_alloc_token(lwjson_t* lwobj) {
+    if (lwobj->next_free_token_pos < lwobj->tokens_len) {
+        LWJSON_MEMSET(&lwobj->tokens[lwobj->next_free_token_pos], 0x00, sizeof(*lwobj->tokens));
+        return &lwobj->tokens[lwobj->next_free_token_pos++];
+    }
+    return NULL;
+}
+
+/**
+ * \brief           Skip all characters that are considered *blank* as per RFC4627
+ * \param[in,out]   pobj: Pointer to text that is modified on success
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+static lwjsonr_t
+prv_skip_blank(lwjson_int_str_t* pobj) {
+    while (pobj->p != NULL && (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p != '\0') {
+        if (*pobj->p == ' ' || *pobj->p == '\t' || *pobj->p == '\r' || *pobj->p == '\n' || *pobj->p == '\f') {
+            ++pobj->p;
+#if LWJSON_CFG_COMMENTS
+            /* Check for comments and remove them */
+        } else if (*pobj->p == '/') {
+            ++pobj->p;
+            if (pobj->p != NULL && (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p == '*') {
+                ++pobj->p;
+                while (pobj->p != NULL && (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p != '\0') {
+                    if (*pobj->p == '*') {
+                        ++pobj->p;
+                        if ((size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p == '/') {
+                            ++pobj->p;
+                            break;
+                        }
+                    }
+                    ++pobj->p;
+                }
+            }
+#endif /* LWJSON_CFG_COMMENTS */
+        } else {
+            break;
+        }
+    }
+    if (pobj->p != NULL && (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p != '\0') {
+        return lwjsonOK;
+    }
+    return lwjsonERRJSON;
+}
+
+/**
+ * \brief           Parse JSON string that must start end end with double quotes `"` character
+ * It just parses length of characters and does not perform any decode operation
+ * \param[in,out]   pobj: Pointer to text that is modified on success
+ * \param[out]      pout: Pointer to pointer to string that is set where string starts
+ * \param[out]      poutlen: Length of string in units of characters is stored here
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+static lwjsonr_t
+prv_parse_string(lwjson_int_str_t* pobj, const char** pout, size_t* poutlen) {
+    lwjsonr_t res;
+    size_t len = 0;
+
+    res = prv_skip_blank(pobj);
+    if (res != lwjsonOK) {
+        return res;
+    }
+    if ((size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p++ != '"') {
+        return lwjsonERRJSON;
+    }
+    *pout = pobj->p;
+    /* Parse string but take care of escape characters */
+    for (;; ++pobj->p, ++len) {
+        if (pobj->p == NULL || (size_t)(pobj->p - pobj->start) >= pobj->len || *pobj->p == '\0') {
+            return lwjsonERRJSON;
+        }
+        /* Check special characters */
+        if (*pobj->p == '\\') {
+            ++pobj->p;
+            ++len;
+
+            if ((size_t)(pobj->p - pobj->start) >= pobj->len) {
+                return lwjsonERRJSON;
+            }
+
+            switch (*pobj->p) {
+                case '"':  /* fallthrough */
+                case '\\': /* fallthrough */
+                case '/':  /* fallthrough */
+                case 'b':  /* fallthrough */
+                case 'f':  /* fallthrough */
+                case 'n':  /* fallthrough */
+                case 'r':  /* fallthrough */
+                case 't': break;
+                case 'u':
+                    ++pobj->p;
+                    for (size_t i = 0; i < 4; ++i, ++len) {
+                        if (!(((size_t)(pobj->p - pobj->start) < pobj->len)
+                              && ((*pobj->p >= '0' && *pobj->p <= '9') || (*pobj->p >= 'a' && *pobj->p <= 'f')
+                                  || (*pobj->p >= 'A' && *pobj->p <= 'F')))) {
+                            return lwjsonERRJSON;
+                        }
+                        if (i < 3) {
+                            ++pobj->p;
+                        }
+                    }
+                    break;
+                default: return lwjsonERRJSON;
+            }
+        } else if (*pobj->p == '"') {
+            ++pobj->p;
+            break;
+        }
+    }
+    *poutlen = len;
+    return res;
+}
+
+/**
+ * \brief           Parse property name that must comply with JSON string format as in RFC4627
+ * Property string must be followed by colon character ":"
+ * \param[in,out]   pobj: Pointer to text that is modified on success
+ * \param[out]      t: Token instance to write property name to
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+static lwjsonr_t
+prv_parse_property_name(lwjson_int_str_t* pobj, lwjson_token_t* t) {
+    lwjsonr_t res;
+
+    /* Parse property string first */
+    res = prv_parse_string(pobj, &t->token_name, &t->token_name_len);
+    if (res != lwjsonOK) {
+        return res;
+    }
+    /* Skip any spaces */
+    res = prv_skip_blank(pobj);
+    if (res != lwjsonOK) {
+        return res;
+    }
+    /* Must continue with colon */
+    if ((size_t)(pobj->p - pobj->start) >= pobj->len || *pobj->p++ != ':') {
+        return lwjsonERRJSON;
+    }
+    /* Skip any spaces */
+    res = prv_skip_blank(pobj);
+    if (res != lwjsonOK) {
+        return res;
+    }
+    return lwjsonOK;
+}
+
+/**
+ * \brief           Calculate new value for exponent 10^exponent.
+ * \param[in]       exp: Exponent.
+ * \param[in]       is_minus: Indicates whether the exponent is negative.
+ * \return          Value of 10^exponent.
+ */
+static lwjson_real_t
+prv_power10(lwjson_int_t exp, uint8_t is_minus) {
+    lwjson_real_t result = (lwjson_real_t)1;
+    lwjson_real_t base = (lwjson_real_t)10;
+
+    for (; exp > 0; base *= base, exp >>= 1) {
+        if ((exp & 1) == 1) {
+            result *= base;
+        }
+    }
+
+    return is_minus ? ((lwjson_real_t)1 / result) : result;
+}
+
+/**
+ * \brief           Parse number as described in RFC4627
+ * \param[in,out]   pobj: Pointer to text that is modified on success
+ * \param[out]      tout: Pointer to output number format
+ * \param[out]      fout: Pointer to output real-type variable. Used if type is REAL.
+ * \param[out]      iout: Pointer to output int-type variable. Used if type is INT.
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+static lwjsonr_t
+prv_parse_number(lwjson_int_str_t* pobj, lwjson_type_t* tout, lwjson_real_t* fout, lwjson_int_t* iout) {
+    lwjsonr_t res;
+    uint8_t is_minus;
+    lwjson_real_t real_num = 0;
+    lwjson_int_t int_num = 0;
+    lwjson_type_t type = LWJSON_TYPE_NUM_INT;
+
+    res = prv_skip_blank(pobj);
+    if (res != lwjsonOK) {
+        return res;
+    }
+    if ((size_t)(pobj->p - pobj->start) >= pobj->len || *pobj->p == '\0') {
+        return lwjsonERRJSON;
+    }
+    is_minus = *pobj->p == '-' ? (++pobj->p, 1) : 0;
+    if ((size_t)(pobj->p - pobj->start) >= pobj->len /* End of json input */
+        || *pobj->p == '\0'                          /* Invalid string */
+        || *pobj->p < '0' || *pobj->p > '9'          /* Character outside number range */
+        || (*pobj->p == '0' && (size_t)(pobj->p + 1 - pobj->start) < pobj->len
+            && (pobj->p[1] >= '0' && pobj->p[1] <= '9'))) { /* Number starts with 0 but not followed by dot */
+        return lwjsonERRJSON;
+    }
+
+    /* Parse number */
+    for (int_num = 0; (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p >= '0' && *pobj->p <= '9'; ++pobj->p) {
+        int_num = int_num * (lwjson_int_t)10 + (*pobj->p - '0');
+    }
+
+    real_num = (lwjson_real_t)int_num;
+
+    if (pobj->p != NULL && (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p == '.') { /* Number has exponent */
+        lwjson_real_t exp;
+        lwjson_int_t dec_num;
+
+        real_num = (lwjson_real_t)int_num;
+
+        type = LWJSON_TYPE_NUM_REAL; /* Format is real */
+        ++pobj->p;                   /* Ignore comma character */
+        if ((size_t)(pobj->p - pobj->start) >= pobj->len || *pobj->p < '0'
+            || *pobj->p > '9') { /* Must be followed by number characters */
+            return lwjsonERRJSON;
+        }
+
+        /* Get number after decimal point */
+        for (exp = (lwjson_real_t)1, dec_num = 0;
+             (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p >= '0' && *pobj->p <= '9';
+             ++pobj->p, exp *= (lwjson_real_t)10) {
+            dec_num = dec_num * (lwjson_int_t)10 + (lwjson_int_t)(*pobj->p - '0');
+        }
+
+        /* Add decimal part to number */
+        real_num += (lwjson_real_t)dec_num / exp;
+    }
+    if (pobj->p != NULL && (size_t)(pobj->p - pobj->start) < pobj->len
+        && (*pobj->p == 'e' || *pobj->p == 'E')) { /* Engineering mode */
+        uint8_t is_minus_exp;
+        lwjson_int_t exp_cnt;
+
+        type = LWJSON_TYPE_NUM_REAL; /* Format is real */
+        ++pobj->p;                   /* Ignore enginnering sing part */
+        if ((size_t)(pobj->p - pobj->start) >= pobj->len) {
+            return lwjsonERRJSON;
+        }
+        is_minus_exp = *pobj->p == '-' ? (++pobj->p, 1) : 0;                  /* Check if negative */
+        if ((size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p == '+') { /* Optional '+' is possible too */
+            ++pobj->p;
+        }
+        if ((size_t)(pobj->p - pobj->start) >= pobj->len || *pobj->p < '0'
+            || *pobj->p > '9') { /* Must be followed by number characters */
+            return lwjsonERRJSON;
+        }
+
+        /* Parse exponent number */
+        for (exp_cnt = 0; (size_t)(pobj->p - pobj->start) < pobj->len && *pobj->p >= '0' && *pobj->p <= '9';
+             ++pobj->p) {
+            exp_cnt = exp_cnt * (lwjson_int_t)10 + (lwjson_int_t)(*pobj->p - '0');
+        }
+
+        /* Calculate new value for exponent 10^exponent */
+        real_num *= prv_power10(exp_cnt, is_minus_exp);
+    }
+
+    /* Write output values */
+    if (tout != NULL) {
+        *tout = type;
+    }
+    if (type == LWJSON_TYPE_NUM_INT) {
+        *iout = is_minus ? -int_num : int_num;
+    } else {
+        *fout = is_minus ? -real_num : real_num;
+    }
+    return lwjsonOK;
+}
+
+/**
+ * \brief           Create path segment from input path for search operation
+ * \param[in,out]   ppath: Pointer to pointer to input path. Pointer is modified
+ * \param[out]      opath: Pointer to pointer to write path segment
+ * \param[out]      olen: Pointer to variable to write length of segment
+ * \param[out]      is_last: Pointer to write if this is last segment
+ * \return          `1` on success, `0` otherwise
+ */
+static uint8_t
+prv_create_path_segment(const char** ppath, const char** opath, size_t* olen, uint8_t* is_last) {
+    const char* segment = *ppath;
+
+    *is_last = 0;
+    *opath = NULL;
+    *olen = 0;
+
+    /* Check input path */
+    if (segment == NULL || *segment == '\0') {
+        *is_last = 1;
+        return 0;
+    }
+
+    /*
+     * Path must be one of:
+     * - literal text
+     * - "#" followed by dot "."
+     */
+    if (*segment == '#') {
+        *opath = segment;
+        for (*olen = 0;; ++segment, ++(*olen)) {
+            if (*segment == '.') {
+                ++segment;
+                break;
+            } else if (*segment == '\0') {
+                if (*olen == 1) {
+                    return 0;
+                } else {
+                    break;
+                }
+            }
+        }
+        *ppath = segment;
+    } else {
+        *opath = segment;
+        for (*olen = 0; *segment != '\0' && *segment != '.'; ++(*olen), ++segment) {}
+        *ppath = segment + 1;
+    }
+    if (*segment == '\0') {
+        *is_last = 1;
+    }
+    return 1;
+}
+
+/**
+ * \brief           Input recursive function for find operation
+ * \param[in]       parent: Parent token of type \ref LWJSON_TYPE_ARRAY or LWJSON_TYPE_OBJECT
+ * \param[in]       path: Path to search for starting this token further
+ * \return          Found token on success, `NULL` otherwise
+ */
+static const lwjson_token_t*
+prv_find(const lwjson_token_t* parent, const char* path) {
+    const char* segment;
+    size_t segment_len;
+    uint8_t is_last, res;
+
+    /* Get path segments */
+    res = prv_create_path_segment(&path, &segment, &segment_len, &is_last);
+    if (res != 0) {
+        /* Check if detected an array request */
+        if (*segment == '#') {
+            /* Parent must be array */
+            if (parent->type != LWJSON_TYPE_ARRAY) {
+                return NULL;
+            }
+
+            /* Check if index requested */
+            if (segment_len > 1) {
+                const lwjson_token_t* tkn;
+                size_t index = 0;
+
+                /* Parse number */
+                for (size_t i = 1; i < segment_len; ++i) {
+                    if (segment[i] < '0' || segment[i] > '9') {
+                        return NULL;
+                    } else {
+                        index = index * 10 + (segment[i] - '0');
+                    }
+                }
+
+                /* Start from beginning */
+                for (tkn = parent->u.first_child; tkn != NULL && index > 0; tkn = tkn->next, --index) {}
+                if (tkn != NULL) {
+                    if (is_last) {
+                        return tkn;
+                    } else {
+                        return prv_find(tkn, path);
+                    }
+                }
+                return NULL;
+            }
+
+            /* Scan all indexes and get first match */
+            for (const lwjson_token_t* tkn = parent->u.first_child; tkn != NULL; tkn = tkn->next) {
+                const lwjson_token_t* tmp = prv_find(tkn, path);
+                if (tmp != NULL) {
+                    return tmp;
+                }
+            }
+        } else {
+            if (parent->type != LWJSON_TYPE_OBJECT) {
+                return NULL;
+            }
+            for (const lwjson_token_t* tkn = parent->u.first_child; tkn != NULL; tkn = tkn->next) {
+                if (tkn->token_name_len == segment_len && !strncmp(tkn->token_name, segment, segment_len)) {
+                    const lwjson_token_t* tmp;
+                    if (is_last) {
+                        return tkn;
+                    }
+                    tmp = prv_find(tkn, path);
+                    if (tmp != NULL) {
+                        return tmp;
+                    }
+                }
+            }
+        }
+    }
+    return NULL;
+}
+
+/**
+ * \brief           Check for character after opening bracket of array or object
+ * \param[in,out]   pobj: JSON string
+ * \param[in]       t: Token to check for type
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+static inline lwjsonr_t
+prv_check_valid_char_after_open_bracket(lwjson_int_str_t* pobj, lwjson_token_t* t) {
+    lwjsonr_t res;
+
+    /* Check next character after object open */
+    res = prv_skip_blank(pobj);
+    if (res != lwjsonOK) {
+        return res;
+    }
+    if ((size_t)(pobj->p - pobj->start) >= pobj->len || *pobj->p == '\0'
+        || (t->type == LWJSON_TYPE_OBJECT && (*pobj->p != '"' && *pobj->p != '}'))
+        || (t->type == LWJSON_TYPE_ARRAY
+            && (*pobj->p != '"' && *pobj->p != ']' && *pobj->p != '[' && *pobj->p != '{' && *pobj->p != '-'
+                && (*pobj->p < '0' || *pobj->p > '9') && *pobj->p != 't' && *pobj->p != 'n' && *pobj->p != 'f'))) {
+        res = lwjsonERRJSON;
+    }
+    return res;
+}
+
+/**
+ * \brief           Setup LwJSON instance for parsing JSON strings
+ * \param[in,out]   lwobj: LwJSON instance
+ * \param[in]       tokens: Pointer to array of tokens used for parsing
+ * \param[in]       tokens_len: Number of tokens
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+lwjsonr_t
+lwjson_init(lwjson_t* lwobj, lwjson_token_t* tokens, size_t tokens_len) {
+    LWJSON_MEMSET(lwobj, 0x00, sizeof(*lwobj));
+    LWJSON_MEMSET(tokens, 0x00, sizeof(*tokens) * tokens_len);
+    lwobj->tokens = tokens;
+    lwobj->tokens_len = tokens_len;
+    lwobj->first_token.type = LWJSON_TYPE_OBJECT;
+    return lwjsonOK;
+}
+
+/**
+ * \brief           Parse JSON data with length parameter
+ * JSON format must be complete and must comply with RFC4627
+ * \param[in,out]   lwobj: LwJSON instance
+ * \param[in]       json_data: JSON string to parse
+ * \param[in]       jsonČlen: JSON data length
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+lwjsonr_t
+lwjson_parse_ex(lwjson_t* lwobj, const void* json_data, size_t json_len) {
+    lwjsonr_t res = lwjsonOK;
+    lwjson_token_t *t, *to;
+    lwjson_int_str_t pobj = {.start = json_data, .len = json_len, .p = json_data};
+
+    /* Check input parameters */
+    if (lwobj == NULL || json_data == NULL || json_len == 0) {
+        res = lwjsonERRPAR;
+        goto ret;
+    }
+
+    /* set first token */
+    to = &lwobj->first_token;
+
+    /* values from very beginning */
+    lwobj->flags.parsed = 0;
+    lwobj->next_free_token_pos = 0;
+    LWJSON_MEMSET(to, 0x00, sizeof(*to));
+
+    /* First parse */
+    res = prv_skip_blank(&pobj);
+    if (res != lwjsonOK) {
+        goto ret;
+    }
+    if ((size_t)(pobj.p - pobj.start) >= pobj.len) {
+        res = lwjsonERRJSON;
+        goto ret;
+    }
+    if (*pobj.p == '{') {
+        to->type = LWJSON_TYPE_OBJECT;
+    } else if (*pobj.p == '[') {
+        to->type = LWJSON_TYPE_ARRAY;
+    } else {
+        res = lwjsonERRJSON;
+        goto ret;
+    }
+    ++pobj.p;
+    res = prv_check_valid_char_after_open_bracket(&pobj, to);
+    if (res != lwjsonOK) {
+        goto ret;
+    }
+
+    /* Process all characters as indicated by input user */
+    while (pobj.p != NULL && (size_t)(pobj.p - pobj.start) < pobj.len && *pobj.p != '\0') {
+        /* Filter out blanks */
+        res = prv_skip_blank(&pobj);
+        if (res != lwjsonOK) {
+            goto ret;
+        }
+        if (*pobj.p == ',') {
+            ++pobj.p;
+            continue;
+        }
+
+        /* Check if end of object or array*/
+        if (*pobj.p == (to->type == LWJSON_TYPE_OBJECT ? '}' : ']')) {
+            lwjson_token_t* parent = to->next;
+            to->next = NULL;
+            ++pobj.p;
+
+            /* End of string if to == NULL (no parent), check if properly terminated */
+            to = parent;
+            if (to == NULL) {
+                prv_skip_blank(&pobj);
+                res = (pobj.p == NULL || (size_t)(pobj.p - pobj.start) >= pobj.len || *pobj.p == '\0') ? lwjsonOK
+                                                                                                       : lwjsonERR;
+                goto ret;
+            }
+            continue;
+        }
+
+        /* Allocate new token */
+        t = prv_alloc_token(lwobj);
+        if (t == NULL) {
+            res = lwjsonERRMEM;
+            goto ret;
+        }
+
+        /* If object type is not array, first thing is property that starts with quotes */
+        if (to->type != LWJSON_TYPE_ARRAY) {
+            if (*pobj.p != '"') {
+                res = lwjsonERRJSON;
+                goto ret;
+            }
+            res = prv_parse_property_name(&pobj, t);
+            if (res != lwjsonOK) {
+                goto ret;
+            }
+        }
+
+        /* Add element to linked list */
+        if (to->u.first_child == NULL) {
+            to->u.first_child = t;
+        } else {
+            lwjson_token_t* c;
+            for (c = to->u.first_child; c->next != NULL; c = c->next) {}
+            c->next = t;
+        }
+
+        /* Check next character to process */
+        switch (*pobj.p) {
+            case '{':
+            case '[':
+                t->type = *pobj.p == '{' ? LWJSON_TYPE_OBJECT : LWJSON_TYPE_ARRAY;
+                ++pobj.p;
+
+                res = prv_check_valid_char_after_open_bracket(&pobj, t);
+                if (res != lwjsonOK) {
+                    goto ret;
+                }
+                t->next = to; /* Temporary saved as parent object */
+                to = t;
+                break;
+            case '"':
+                res = prv_parse_string(&pobj, &t->u.str.token_value, &t->u.str.token_value_len);
+                if (res == lwjsonOK) {
+                    t->type = LWJSON_TYPE_STRING;
+                } else {
+                    goto ret;
+                }
+                break;
+            case 't':
+                /* RFC4627 is lower-case only */
+                if ((size_t)(pobj.p + 3 - pobj.start) < pobj.len && strncmp(pobj.p, "true", 4) == 0) {
+                    t->type = LWJSON_TYPE_TRUE;
+                    pobj.p += 4;
+                } else {
+                    res = lwjsonERRJSON;
+                    goto ret;
+                }
+                break;
+            case 'f':
+                /* RFC4627 is lower-case only */
+                if ((size_t)(pobj.p + 4 - pobj.start) < pobj.len && strncmp(pobj.p, "false", 5) == 0) {
+                    t->type = LWJSON_TYPE_FALSE;
+                    pobj.p += 5;
+                } else {
+                    res = lwjsonERRJSON;
+                    goto ret;
+                }
+                break;
+            case 'n':
+                /* RFC4627 is lower-case only */
+                if ((size_t)(pobj.p + 3 - pobj.start) < pobj.len && strncmp(pobj.p, "null", 4) == 0) {
+                    t->type = LWJSON_TYPE_NULL;
+                    pobj.p += 4;
+                } else {
+                    res = lwjsonERRJSON;
+                    goto ret;
+                }
+                break;
+            default:
+                if (*pobj.p == '-' || (*pobj.p >= '0' && *pobj.p <= '9')) {
+                    if (prv_parse_number(&pobj, &t->type, &t->u.num_real, &t->u.num_int) != lwjsonOK) {
+                        res = lwjsonERRJSON;
+                        goto ret;
+                    }
+                } else {
+                    res = lwjsonERRJSON;
+                    goto ret;
+                }
+                break;
+        }
+
+        /* Below code is used to check characters after valid tokens */
+        if (t->type == LWJSON_TYPE_ARRAY || t->type == LWJSON_TYPE_OBJECT) {
+            continue;
+        }
+
+        /*
+         * Check what are values after the token value
+         *
+         * As per RFC4627, every token value may have one or more
+         * blank characters, followed by one of below options:
+         *  - Comma separator for next token
+         *  - End of array indication
+         *  - End of object indication
+         */
+        res = prv_skip_blank(&pobj);
+        if (res != lwjsonOK) {
+            goto ret;
+        }
+        /* Check if valid string is availabe after */
+        if (pobj.p == NULL || (size_t)(pobj.p - pobj.start) >= pobj.len || *pobj.p == '\0'
+            || (*pobj.p != ',' && *pobj.p != ']' && *pobj.p != '}')) {
+            res = lwjsonERRJSON;
+            goto ret;
+        } else if (*pobj.p == ',') { /* Check to advance to next token immediately */
+            ++pobj.p;
+        }
+    }
+    if (to != &lwobj->first_token || (to != NULL && to->next != NULL)) {
+        res = lwjsonERRJSON;
+        to = NULL;
+    }
+    if (to != NULL) {
+        if (to->type != LWJSON_TYPE_ARRAY && to->type != LWJSON_TYPE_OBJECT) {
+            res = lwjsonERRJSON;
+        }
+        to->token_name = NULL;
+        to->token_name_len = 0;
+    }
+ret:
+    if (res == lwjsonOK) {
+        lwobj->flags.parsed = 1;
+    }
+    return res;
+}
+
+/**
+ * \brief           Parse input JSON format
+ * JSON format must be complete and must comply with RFC4627
+ * \param[in,out]   lwobj: LwJSON instance
+ * \param[in]       json_str: JSON string to parse
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+lwjsonr_t
+lwjson_parse(lwjson_t* lwobj, const char* json_str) {
+    return lwjson_parse_ex(lwobj, json_str, strlen(json_str));
+}
+
+/**
+ * \brief           Free token instances (specially used in case of dynamic memory allocation)
+ * \param[in,out]   lwobj: LwJSON instance
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+lwjsonr_t
+lwjson_free(lwjson_t* lwobj) {
+    LWJSON_MEMSET(lwobj->tokens, 0x00, sizeof(*lwobj->tokens) * lwobj->tokens_len);
+    lwobj->flags.parsed = 0;
+    return lwjsonOK;
+}
+
+/**
+ * \brief           Find first match in the given path for JSON entry
+ * JSON must be valid and parsed with \ref lwjson_parse function
+ * \param[in]       lwobj: JSON instance with parsed JSON string
+ * \param[in]       path: Path with dot-separated entries to search for the JSON key to return
+ * \return          Pointer to found token on success, `NULL` if token cannot be found
+ */
+const lwjson_token_t*
+lwjson_find(lwjson_t* lwobj, const char* path) {
+    if (lwobj == NULL || !lwobj->flags.parsed || path == NULL) {
+        return NULL;
+    }
+    return prv_find(lwjson_get_first_token(lwobj), path);
+}
+
+/**
+ * \brief           Find first match in the given path for JSON path
+ * JSON must be valid and parsed with \ref lwjson_parse function
+ *
+ * \param[in]       lwobj: JSON instance with parsed JSON string
+ * \param[in]       token: Root token to start search at.
+ *                      Token must be type \ref LWJSON_TYPE_OBJECT or \ref LWJSON_TYPE_ARRAY.
+ *                      Set to `NULL` to use root token of LwJSON object
+ * \param[in]       path: path with dot-separated entries to search for JSON key
+ * \return          Pointer to found token on success, `NULL` if token cannot be found
+ */
+const lwjson_token_t*
+lwjson_find_ex(lwjson_t* lwobj, const lwjson_token_t* token, const char* path) {
+    if (lwobj == NULL || !lwobj->flags.parsed || path == NULL) {
+        return NULL;
+    }
+    if (token == NULL) {
+        token = lwjson_get_first_token(lwobj);
+    }
+    if (token == NULL || (token->type != LWJSON_TYPE_ARRAY && token->type != LWJSON_TYPE_OBJECT)) {
+        return NULL;
+    }
+    return prv_find(token, path);
+}

+ 388 - 0
Application_cbd_apm32f1/applications/lwjson.h

@@ -0,0 +1,388 @@
+/**
+ * \file            lwjson.h
+ * \brief           LwJSON - Lightweight JSON format parser
+ */
+
+/*
+ * Copyright (c) 2024 Tilen MAJERLE
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * This file is part of LwJSON - Lightweight JSON format parser.
+ *
+ * Author:          Tilen MAJERLE <tilen@majerle.eu>
+ * Version:         v1.8.1
+ */
+#ifndef LWJSON_HDR_H
+#define LWJSON_HDR_H
+
+#include <stdint.h>
+#include <string.h>
+#include "lwjson_opt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * \defgroup        LWJSON Lightweight JSON format parser
+ * \brief           LwJSON - Lightweight JSON format parser
+ * \{
+ */
+
+/**
+ * \brief           Get size of statically allocated array
+ * \param[in]       x: Object to get array size of
+ * \return          Number of elements in array
+ */
+#define LWJSON_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+/**
+ * \brief           List of supported JSON types
+ */
+typedef enum {
+    LWJSON_TYPE_STRING,   /*!< String/Text format. Everything that has beginning and ending quote character */
+    LWJSON_TYPE_NUM_INT,  /*!< Number type for integer */
+    LWJSON_TYPE_NUM_REAL, /*!< Number type for real number */
+    LWJSON_TYPE_OBJECT,   /*!< Object data type */
+    LWJSON_TYPE_ARRAY,    /*!< Array data type */
+    LWJSON_TYPE_TRUE,     /*!< True boolean value */
+    LWJSON_TYPE_FALSE,    /*!< False boolean value */
+    LWJSON_TYPE_NULL,     /*!< Null value */
+} lwjson_type_t;
+
+#if defined(LWJSON_DEV)
+extern const char* const lwjson_type_strings[];
+#endif
+
+/**
+ * \brief           Real data type
+ */
+typedef LWJSON_CFG_REAL_TYPE lwjson_real_t;
+
+/**
+ * \brief           Integer data type
+ */
+typedef LWJSON_CFG_INT_TYPE lwjson_int_t;
+
+/**
+ * \brief           JSON token
+ */
+typedef struct lwjson_token {
+    struct lwjson_token* next; /*!< Next token on a list */
+    lwjson_type_t type;        /*!< Token type */
+    const char* token_name;    /*!< Token name (if exists) */
+    size_t token_name_len;     /*!< Length of token name (this is needed to support const input strings to parse) */
+
+    union {
+        struct {
+            const char* token_value; /*!< Pointer to the beginning of the string */
+            size_t
+                token_value_len; /*!< Length of token value (this is needed to support const input strings to parse) */
+        } str;                   /*!< String data */
+
+        lwjson_real_t num_real;           /*!< Real number format */
+        lwjson_int_t num_int;             /*!< Int number format */
+        struct lwjson_token* first_child; /*!< First children object for object or array type */
+    } u;                                  /*!< Union with different data types */
+} lwjson_token_t;
+
+/**
+ * \brief           JSON result enumeration
+ */
+typedef enum {
+    lwjsonOK = 0x00, /*!< Function returns successfully */
+    lwjsonERR,       /*!< Generic error message */
+    lwjsonERRJSON,   /*!< Error JSON format */
+    lwjsonERRMEM,    /*!< Memory error */
+    lwjsonERRPAR,    /*!< Parameter error */
+
+    lwjsonSTREAMWAITFIRSTCHAR, /*!< Streaming parser did not yet receive first valid character
+                                    indicating start of JSON sequence */
+    lwjsonSTREAMDONE,          /*!< Streaming parser is done,
+                                    closing character matched the stream opening one */
+    lwjsonSTREAMINPROG,        /*!< Stream parsing is still in progress */
+} lwjsonr_t;
+
+/**
+ * \brief           LwJSON instance
+ */
+typedef struct {
+    lwjson_token_t* tokens;     /*!< Pointer to array of tokens */
+    size_t tokens_len;          /*!< Size of all tokens */
+    size_t next_free_token_pos; /*!< Position of next free token instance */
+    lwjson_token_t first_token; /*!< First token on a list */
+
+    struct {
+        uint8_t parsed : 1; /*!< Flag indicating JSON parsing has finished successfully */
+    } flags;                /*!< List of flags */
+} lwjson_t;
+
+lwjsonr_t lwjson_init(lwjson_t* lwobj, lwjson_token_t* tokens, size_t tokens_len);
+lwjsonr_t lwjson_parse_ex(lwjson_t* lwobj, const void* json_data, size_t len);
+lwjsonr_t lwjson_parse(lwjson_t* lwobj, const char* json_str);
+const lwjson_token_t* lwjson_find(lwjson_t* lwobj, const char* path);
+const lwjson_token_t* lwjson_find_ex(lwjson_t* lwobj, const lwjson_token_t* token, const char* path);
+lwjsonr_t lwjson_free(lwjson_t* lwobj);
+
+void lwjson_print_token(const lwjson_token_t* token);
+void lwjson_print_json(const lwjson_t* lwobj);
+
+/**
+ * \brief           Object type for streaming parser
+ */
+typedef enum {
+    LWJSON_STREAM_TYPE_NONE,       /*!< No entry - not used */
+    LWJSON_STREAM_TYPE_OBJECT,     /*!< Object indication */
+    LWJSON_STREAM_TYPE_OBJECT_END, /*!< Object end indication */
+    LWJSON_STREAM_TYPE_ARRAY,      /*!< Array indication */
+    LWJSON_STREAM_TYPE_ARRAY_END,  /*!< Array end indication */
+    LWJSON_STREAM_TYPE_KEY,        /*!< Key string */
+    LWJSON_STREAM_TYPE_STRING,     /*!< Strin type */
+    LWJSON_STREAM_TYPE_TRUE,       /*!< True primitive */
+    LWJSON_STREAM_TYPE_FALSE,      /*!< False primitive */
+    LWJSON_STREAM_TYPE_NULL,       /*!< Null primitive */
+    LWJSON_STREAM_TYPE_NUMBER,     /*!< Generic number */
+} lwjson_stream_type_t;
+
+/**
+ * \brief           Stream parsing stack object
+ */
+typedef struct {
+    lwjson_stream_type_t type; /*!< Streaming type - current value */
+
+    union {
+        char name[LWJSON_CFG_STREAM_KEY_MAX_LEN
+                  + 1]; /*!< Last known key name, used only for \ref LWJSON_STREAM_TYPE_KEY type */
+        uint16_t index; /*!< Current index when type is an array */
+    } meta;             /*!< Meta information */
+} lwjson_stream_stack_t;
+
+typedef enum {
+    LWJSON_STREAM_STATE_WAITINGFIRSTCHAR = 0x00, /*!< State to wait for very first opening character */
+    LWJSON_STREAM_STATE_PARSING,        /*!< In parsing of the first char state - detecting next character state */
+    LWJSON_STREAM_STATE_PARSING_STRING, /*!< Parse string primitive */
+    LWJSON_STREAM_STATE_PARSING_PRIMITIVE, /*!< Parse any primitive that is non-string, either "true", "false", "null" or a number */
+    LWJSON_STREAM_STATE_EXPECTING_COMMA_OR_END, /*!< Expecting ',', '}' or ']' */
+    LWJSON_STREAM_STATE_EXPECTING_COLON,        /*!< Expecting ':' */
+} lwjson_stream_state_t;
+
+/* Forward declaration */
+struct lwjson_stream_parser;
+
+/**
+ * \brief           Callback function for various events
+ * 
+ */
+typedef void (*lwjson_stream_parser_callback_fn)(struct lwjson_stream_parser* jsp, lwjson_stream_type_t type);
+
+/**
+ * \brief           LwJSON streaming structure
+ */
+typedef struct lwjson_stream_parser {
+    lwjson_stream_stack_t
+        stack[LWJSON_CFG_STREAM_STACK_SIZE]; /*!< Stack used for parsing. TODO: Add conditional compilation flag */
+    size_t stack_pos;                        /*!< Current stack position */
+
+    lwjson_stream_state_t parse_state; /*!< Parser state */
+
+    lwjson_stream_parser_callback_fn evt_fn; /*!< Event function for user */
+
+    void* user_data; /*!< User data for callback function */
+
+    /* State */
+    union {
+        struct {
+            char buff[LWJSON_CFG_STREAM_STRING_MAX_LEN
+                      + 1];        /*!< Buffer to write temporary data. TODO: Size to be variable with define */
+            size_t buff_pos;       /*!< Buffer position for next write (length of bytes in buffer) */
+            size_t buff_total_pos; /*!< Total buffer position used up to now (in several data chunks) */
+            uint8_t is_last;       /*!< Status indicates if this is the last part of the string */
+        } str;                     /*!< String structure. It is only used for keys and string objects.
+                                        Use primitive part for all other options */
+
+        struct {
+            char buff[LWJSON_CFG_STREAM_PRIMITIVE_MAX_LEN + 1]; /*!< Temporary write buffer */
+            size_t buff_pos;                                    /*!< Buffer position for next write */
+        } prim; /*!< Primitive object. Used for all types, except key or string */
+
+        /* Todo: Add other types */
+    } data; /*!< Data union used to parse various */
+
+    char prev_c; /*!< History of characters */
+} lwjson_stream_parser_t;
+
+lwjsonr_t lwjson_stream_init(lwjson_stream_parser_t* jsp, lwjson_stream_parser_callback_fn evt_fn);
+lwjsonr_t lwjson_stream_set_user_data(lwjson_stream_parser_t* jsp, void* user_data);
+void* lwjson_stream_get_user_data(lwjson_stream_parser_t* jsp);
+lwjsonr_t lwjson_stream_reset(lwjson_stream_parser_t* jsp);
+lwjsonr_t lwjson_stream_parse(lwjson_stream_parser_t* jsp, char c);
+
+/**
+ * \brief           Get number of tokens used to parse JSON
+ * \param[in]       lwobj: Pointer to LwJSON instance
+ * \return          Number of tokens used to parse JSON
+ */
+#define lwjson_get_tokens_used(lwobj) (((lwobj) != NULL) ? ((lwobj)->next_free_token_pos + 1) : 0)
+
+/**
+ * \brief           Get very first token of LwJSON instance
+ * \param[in]       lwobj: Pointer to LwJSON instance
+ * \return          Pointer to first token
+ */
+#define lwjson_get_first_token(lwobj) (((lwobj) != NULL) ? (&(lwobj)->first_token) : NULL)
+
+/**
+ * \brief           Get token value for \ref LWJSON_TYPE_NUM_INT type
+ * \param[in]       token: token with integer type
+ * \return          Int number if type is integer, `0` otherwise
+ */
+#define lwjson_get_val_int(token)                                                                                      \
+    ((lwjson_int_t)(((token) != NULL && (token)->type == LWJSON_TYPE_NUM_INT) ? (token)->u.num_int : 0))
+
+/**
+ * \brief           Get token value for \ref LWJSON_TYPE_NUM_REAL type
+ * \param[in]       token: token with real type
+ * \return          Real numbeer if type is real, `0` otherwise
+ */
+#define lwjson_get_val_real(token)                                                                                     \
+    ((lwjson_real_t)(((token) != NULL && (token)->type == LWJSON_TYPE_NUM_REAL) ? (token)->u.num_real : 0))
+
+/**
+ * \brief           Get first child token for \ref LWJSON_TYPE_OBJECT or \ref LWJSON_TYPE_ARRAY types
+ * \param[in]       token: token with integer type
+ * \return          Pointer to first child or `NULL` if parent token is not object or array
+ */
+#define lwjson_get_first_child(token)                                                                                  \
+    (const void*)(((token) != NULL && ((token)->type == LWJSON_TYPE_OBJECT || (token)->type == LWJSON_TYPE_ARRAY))     \
+                      ? (token)->u.first_child                                                                         \
+                      : NULL)
+
+/**
+ * \brief           Get string value from JSON token
+ * \param[in]       token: Token with string type
+ * \param[out]      str_len: Pointer to variable holding length of string.
+ *                      Set to `NULL` if not used
+ * \return          Pointer to string or `NULL` if invalid token type
+ */
+static inline const char*
+lwjson_get_val_string(const lwjson_token_t* token, size_t* str_len) {
+    if (token != NULL && token->type == LWJSON_TYPE_STRING) {
+        if (str_len != NULL) {
+            *str_len = token->u.str.token_value_len;
+        }
+        return token->u.str.token_value;
+    }
+    return NULL;
+}
+
+/**
+ * \brief           Get length of string for \ref LWJSON_TYPE_STRING token type
+ * \param[in]       token: token with string type
+ * \return          Length of string in units of bytes
+ */
+#define lwjson_get_val_string_length(token)                                                                            \
+    ((size_t)(((token) != NULL && (token)->type == LWJSON_TYPE_STRING) ? (token)->u.str.token_value_len : 0))
+
+/**
+ * \brief           Compare string token with user input string for a case-sensitive match
+ * \param[in]       token: Token with string type
+ * \param[in]       str: NULL-terminated string to compare
+ * \return          `1` if equal, `0` otherwise
+ */
+static inline uint8_t
+lwjson_string_compare(const lwjson_token_t* token, const char* str) {
+    if (token != NULL && token->type == LWJSON_TYPE_STRING) {
+        return strncmp(token->u.str.token_value, str, token->u.str.token_value_len) == 0;
+    }
+    return 0;
+}
+
+/**
+ * \brief           Compare string token with user input string for a case-sensitive match
+ * \param[in]       token: Token with string type
+ * \param[in]       str: NULL-terminated string to compare
+ * \param[in]       len: Length of the string in bytes
+ * \return          `1` if equal, `0` otherwise
+ */
+static inline uint8_t
+lwjson_string_compare_n(const lwjson_token_t* token, const char* str, size_t len) {
+    if (token != NULL && token->type == LWJSON_TYPE_STRING && len <= token->u.str.token_value_len) {
+        return strncmp(token->u.str.token_value, str, len) == 0;
+    }
+    return 0;
+}
+
+/**
+ * \name            LWJSON_STREAM_SEQ
+ * \brief           Helper functions for stack analysis in a callback function
+ * \note            Useful exclusively for streaming functions
+ * \{
+ */
+
+/**
+ * \brief           Check the sequence of JSON stack, starting from start_number index
+ * \note            This applies only to one sequence element. Other macros, starting with
+ *                      `lwjson_stack_seq_X` (where X is the sequence length), provide
+ *                      more parameters for longer sequences.
+ * 
+ * \param[in]       jsp: LwJSON stream instance
+ * \param[in]       start_num: Start number in the stack. Typically starts with `0`, but user may choose another
+ *                      number, if intention is to check partial sequence only
+ * \param[in]       sp0: Stream stack type. Value of \ref lwjson_stream_type_t, but only last part of the enum.
+ *                      If user is interested in the \ref LWJSON_STREAM_TYPE_OBJECT,
+ *                      you should only write `OBJECT` as parameter.
+ *                      Idea behind is to make code smaller and easier to read, especially when
+ *                      using other sequence values with more parameters.
+ * \return          `0` if sequence doesn't match, non-zero otherwise
+ */
+#define lwjson_stack_seq_1(jsp, start_num, sp0) ((jsp)->stack[(start_num)].type == LWJSON_STREAM_TYPE_##sp0)
+#define lwjson_stack_seq_2(jsp, start_num, sp0, sp1)                                                                   \
+    (lwjson_stack_seq_1((jsp), (start_num) + 0, sp0) && lwjson_stack_seq_1((jsp), (start_num) + 1, sp1))
+#define lwjson_stack_seq_3(jsp, start_num, sp0, sp1, sp2)                                                              \
+    (lwjson_stack_seq_1((jsp), (start_num) + 0, sp0) && lwjson_stack_seq_2((jsp), (start_num) + 1, sp1, sp2))
+#define lwjson_stack_seq_4(jsp, start_num, sp0, sp1, sp2, sp3)                                                         \
+    (lwjson_stack_seq_1((jsp), (start_num) + 0, sp0) && lwjson_stack_seq_3((jsp), (start_num) + 1, sp1, sp2, sp3))
+#define lwjson_stack_seq_5(jsp, start_num, sp0, sp1, sp2, sp3, sp4)                                                    \
+    (lwjson_stack_seq_1((jsp), (start_num) + 0, sp0) && lwjson_stack_seq_4((jsp), (start_num) + 1, sp1, sp2, sp3, sp4))
+#define lwjson_stack_seq_6(jsp, start_num, sp0, sp1, sp2, sp3, sp4, sp5)                                               \
+    (lwjson_stack_seq_1((jsp), (start_num) + 0, sp0)                                                                   \
+     && lwjson_stack_seq_5((jsp), (start_num) + 1, sp1, sp2, sp3, sp4, sp5))
+#define lwjson_stack_seq_7(jsp, start_num, sp0, sp1, sp2, sp3, sp4, sp5, sp6)                                          \
+    (lwjson_stack_seq_1((jsp), (start_num) + 0, sp0)                                                                   \
+     && lwjson_stack_seq_6((jsp), (start_num) + 1, sp1, sp2, sp3, sp4, sp5, sp6))
+#define lwjson_stack_seq_8(jsp, start_num, sp0, sp1, sp2, sp3, sp4, sp5, sp6, sp7)                                     \
+    (lwjson_stack_seq_1((jsp), (start_num) + 0, sp0)                                                                   \
+     && lwjson_stack_seq_7((jsp), (start_num) + 1, sp1, sp2, sp3, sp4, sp5, sp6, sp7))
+
+/**
+ * \}
+ */
+
+/**
+ * \}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LWJSON_HDR_H */

+ 133 - 0
Application_cbd_apm32f1/applications/lwjson_debug.c

@@ -0,0 +1,133 @@
+/**
+ * \file            lwjson_debug.c
+ * \brief           Debug and print function for tokens
+ */
+
+/*
+ * Copyright (c) 2024 Tilen MAJERLE
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * This file is part of LwJSON - Lightweight JSON format parser.
+ *
+ * Author:          Tilen MAJERLE <tilen@majerle.eu>
+ * Version:         v1.8.1
+ */
+#include <stdio.h>
+#include <string.h>
+#include "lwjson.h"
+
+/**
+ * \brief           Token print instance
+ */
+typedef struct {
+    size_t indent; /*!< Indent level for token print */
+} lwjson_token_print_t;
+
+/**
+ * \brief           Print token value
+ * \param[in]       prt: Token print instance
+ * \param[in]       token: Token to print
+ */
+static void
+prv_print_token(lwjson_token_print_t* prt, const lwjson_token_t* token) {
+#define print_indent() printf("%.*s", (int)((prt->indent)), "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
+
+    if (token == NULL) {
+        return;
+    }
+
+    /* Check if token has a name */
+    print_indent();
+    if (token->token_name != NULL) {
+        printf("\"%.*s\":", (int)token->token_name_len, token->token_name);
+    }
+
+    /* Print different types */
+    switch (token->type) {
+        case LWJSON_TYPE_OBJECT:
+        case LWJSON_TYPE_ARRAY: {
+            printf("%c", token->type == LWJSON_TYPE_OBJECT ? '{' : '[');
+            if (token->u.first_child != NULL) {
+                printf("\n");
+                ++prt->indent;
+                for (const lwjson_token_t* t = lwjson_get_first_child(token); t != NULL; t = t->next) {
+                    prv_print_token(prt, t);
+                }
+                --prt->indent;
+                print_indent();
+            }
+            printf("%c", token->type == LWJSON_TYPE_OBJECT ? '}' : ']');
+            break;
+        }
+        case LWJSON_TYPE_STRING: {
+            printf("\"%.*s\"", (int)lwjson_get_val_string_length(token), lwjson_get_val_string(token, NULL));
+            break;
+        }
+        case LWJSON_TYPE_NUM_INT: {
+            printf("%lld", (long long)lwjson_get_val_int(token));
+            break;
+        }
+        case LWJSON_TYPE_NUM_REAL: {
+            printf("%f", (double)lwjson_get_val_real(token));
+            break;
+        }
+        case LWJSON_TYPE_TRUE: {
+            printf("true");
+            break;
+        }
+        case LWJSON_TYPE_FALSE: {
+            printf("false");
+            break;
+        }
+        case LWJSON_TYPE_NULL: {
+            printf("NULL");
+            break;
+        }
+        default: break;
+    }
+    if (token->next != NULL) {
+        printf(",");
+    }
+    printf("\n");
+}
+
+/**
+ * \brief           Prints and outputs token data to the stream output
+ * \note            This function is not re-entrant
+ * \param[in]       token: Token to print
+ */
+void
+lwjson_print_token(const lwjson_token_t* token) {
+    lwjson_token_print_t prt = {0};
+    prv_print_token(&prt, token);
+}
+
+/**
+ * \brief           Prints and outputs full parsed LwJSON instance
+ * \note            This function is not re-entrant
+ * \param[in]       lwobj: LwJSON instance to print
+ */
+void
+lwjson_print_json(const lwjson_t* lwobj) {
+    lwjson_token_print_t prt = {0};
+    prv_print_token(&prt, lwjson_get_first_token(lwobj));
+}

+ 153 - 0
Application_cbd_apm32f1/applications/lwjson_opt.h

@@ -0,0 +1,153 @@
+/**
+ * \file            lwjson_opt.h
+ * \brief           LwJSON options
+ */
+
+/*
+ * Copyright (c) 2024 Tilen MAJERLE
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * This file is part of LwJSON - Lightweight JSON format parser.
+ *
+ * Author:          Tilen MAJERLE <tilen@majerle.eu>
+ * Version:         v1.8.1
+ */
+#ifndef LWJSON_OPT_HDR_H
+#define LWJSON_OPT_HDR_H
+
+/* Uncomment to ignore user options (or set macro in compiler flags) */
+/* #define LWJSON_IGNORE_USER_OPTS */
+
+/* Include application options */
+#ifndef LWJSON_IGNORE_USER_OPTS
+#include "lwjson_opts.h"
+#endif /* LWJSON_IGNORE_USER_OPTS */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * \defgroup        LWJSON_OPT Configuration
+ * \brief           LwJSON options
+ * \{
+ */
+
+/**
+ * \brief           Real data type used to parse numbers with floating point number
+ * \note            Data type must be signed, normally `float` or `double`
+ *
+ * This is used for numbers in \ref LWJSON_TYPE_NUM_REAL token data type.
+ */
+#ifndef LWJSON_CFG_REAL_TYPE
+#define LWJSON_CFG_REAL_TYPE float
+#endif
+
+/**
+ * \brief           Integer type used to parse numbers
+ * \note            Data type must be signed integer
+ *
+ * This is used for numbers in \ref LWJSON_TYPE_NUM_INT token data type.
+ */
+#ifndef LWJSON_CFG_INT_TYPE
+#define LWJSON_CFG_INT_TYPE long long
+#endif
+
+/**
+ * \brief           Enables `1` or disables `0` support for inline comments
+ *
+ * Default set to `0` to be JSON compliant
+ */
+#ifndef LWJSON_CFG_COMMENTS
+#define LWJSON_CFG_COMMENTS 0
+#endif
+
+/**
+ * \brief           Memory set function
+ * 
+ * \note            Function footprint is the same as \ref memset
+ */
+#ifndef LWJSON_MEMSET
+#define LWJSON_MEMSET(dst, val, len) memset((dst), (val), (len))
+#endif
+
+/**
+ * \brief           Memory copy function
+ * 
+ * \note            Function footprint is the same as \ref memcpy
+ */
+#ifndef LWJSON_MEMCPY
+#define LWJSON_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
+#endif
+
+/**
+ * \defgroup        LWJSON_OPT_STREAM JSON stream
+ * \brief           JSON streaming confiuration
+ * \{
+ */
+
+/**
+ * \brief           Max length of token key (object key name) to be available for stack storage
+ * 
+ */
+#ifndef LWJSON_CFG_STREAM_KEY_MAX_LEN
+#define LWJSON_CFG_STREAM_KEY_MAX_LEN 32
+#endif
+
+/**
+ * \brief           Max stack size (depth) in units of \ref lwjson_stream_stack_t structure
+ * 
+ */
+#ifndef LWJSON_CFG_STREAM_STACK_SIZE
+#define LWJSON_CFG_STREAM_STACK_SIZE 16
+#endif
+
+/**
+ * \brief           Max size of string for single parsing in units of bytes
+ * 
+ */
+#ifndef LWJSON_CFG_STREAM_STRING_MAX_LEN
+#define LWJSON_CFG_STREAM_STRING_MAX_LEN 256
+#endif
+
+/**
+ * \brief           Max number of bytes used to parse primitive.
+ * 
+ * Primitives are all numbers and logical values (null, true, false)
+ */
+#ifndef LWJSON_CFG_STREAM_PRIMITIVE_MAX_LEN
+#define LWJSON_CFG_STREAM_PRIMITIVE_MAX_LEN 32
+#endif
+
+/**
+ * \}
+ */
+
+/**
+ * \}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LWJSON_OPT_HDR_H */

+ 44 - 0
Application_cbd_apm32f1/applications/lwjson_opts.h

@@ -0,0 +1,44 @@
+/**
+ * \file            lwjson_opts_template.h
+ * \brief           Template config file
+ */
+
+/*
+ * Copyright (c) 2024 Tilen MAJERLE
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * This file is part of LwJSON - Lightweight JSON format parser.
+ *
+ * Author:          Tilen MAJERLE <tilen@majerle.eu>
+ * Version:         v1.8.1
+ */
+#ifndef LWJSON_OPTS_HDR_H
+#define LWJSON_OPTS_HDR_H
+
+/* Rename this file to "lwjson_opts.h" for your application */
+
+/*
+ * Open "include/lwjson/lwjson_opt.h" and
+ * copy & replace here settings you want to change values
+ */
+
+#endif /* LWJSON_OPTS_HDR_H */

+ 501 - 0
Application_cbd_apm32f1/applications/lwjson_stream.c

@@ -0,0 +1,501 @@
+/**
+ * \file            lwjson_stream.c
+ * \brief           Lightweight JSON format parser
+ */
+
+/*
+ * Copyright (c) 2024 Tilen MAJERLE
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+ * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * This file is part of LwJSON - Lightweight JSON format parser.
+ *
+ * Author:          Tilen MAJERLE <tilen@majerle.eu>
+ * Version:         v1.8.1
+ */
+#include <string.h>
+#include "lwjson.h"
+
+#if defined(LWJSON_DEV)
+#include <stdio.h>
+#define DEBUG_STRING_PREFIX_SPACES                                                                                     \
+    "                                                                                                "
+#define LWJSON_DEBUG(jsp, ...)                                                                                         \
+    do {                                                                                                               \
+        if ((jsp) != NULL) {                                                                                           \
+            printf("%.*s", (int)(4 * (jsp)->stack_pos), DEBUG_STRING_PREFIX_SPACES);                                   \
+        }                                                                                                              \
+        printf(__VA_ARGS__);                                                                                           \
+    } while (0)
+
+/* Strings for debug */
+const char* const lwjson_type_strings[] = {
+    [LWJSON_STREAM_TYPE_NONE] = "none",
+    [LWJSON_STREAM_TYPE_OBJECT] = "object",
+    [LWJSON_STREAM_TYPE_OBJECT_END] = "object_end",
+    [LWJSON_STREAM_TYPE_ARRAY] = "array",
+    [LWJSON_STREAM_TYPE_ARRAY_END] = "array_end",
+    [LWJSON_STREAM_TYPE_KEY] = "key",
+    [LWJSON_STREAM_TYPE_STRING] = "string",
+    [LWJSON_STREAM_TYPE_TRUE] = "true",
+    [LWJSON_STREAM_TYPE_FALSE] = "false",
+    [LWJSON_STREAM_TYPE_NULL] = "null",
+    [LWJSON_STREAM_TYPE_NUMBER] = "number",
+};
+#else
+#define LWJSON_DEBUG(jsp, ...)
+#endif /* defined(LWJSON_DEV) */
+
+/**
+ * \brief           Sends an event to user for further processing
+ * 
+ */
+#define SEND_EVT(jsp, type)                                                                                            \
+    if ((jsp) != NULL && (jsp)->evt_fn != NULL) {                                                                      \
+        (jsp)->evt_fn((jsp), (type));                                                                                  \
+    }
+
+/**
+ * \brief           Check if character is a space character (with extended chars)
+ * \param[in]       c: Character to check
+ * \return          `1` if considered extended space, `0` otherwise
+ */
+#define prv_is_space_char_ext(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n' || (c) == '\f')
+
+/**
+ * \brief           Push "parent" state to the artificial stack
+ * \param           jsp: JSON stream parser instance
+ * \param           type: Stream type to be pushed on stack
+ * \return          `1` on success, `0` otherwise
+ */
+static uint8_t
+prv_stack_push(lwjson_stream_parser_t* jsp, lwjson_stream_type_t type) {
+    if (jsp->stack_pos < LWJSON_ARRAYSIZE(jsp->stack)) {
+        jsp->stack[jsp->stack_pos].type = type;
+        jsp->stack[jsp->stack_pos].meta.index = 0;
+        LWJSON_DEBUG(jsp, "Pushed to stack: %s\r\n", lwjson_type_strings[type]);
+        jsp->stack_pos++;
+        return 1;
+    }
+    return 0;
+}
+
+/**
+ * \brief           Pop value from stack (remove it) and return its value
+ * \param           jsp: JSON stream parser instance
+ * \return          Member of \ref lwjson_stream_type_t enumeration 
+ */
+static lwjson_stream_type_t
+prv_stack_pop(lwjson_stream_parser_t* jsp) {
+    if (jsp->stack_pos > 0) {
+        lwjson_stream_type_t type = jsp->stack[--jsp->stack_pos].type;
+
+        jsp->stack[jsp->stack_pos].type = LWJSON_STREAM_TYPE_NONE;
+        LWJSON_DEBUG(jsp, "Popped from stack: %s\r\n", lwjson_type_strings[type]);
+
+        /* Take care of array to indicate number of entries */
+        if (jsp->stack_pos > 0 && jsp->stack[jsp->stack_pos - 1].type == LWJSON_STREAM_TYPE_ARRAY) {
+            jsp->stack[jsp->stack_pos - 1].meta.index++;
+        }
+        return type;
+    }
+    return LWJSON_STREAM_TYPE_NONE;
+}
+
+/**
+ * \brief           Get top type value currently on the stack
+ * \param           jsp: JSON stream parser instance
+ * \return          Member of \ref lwjson_stream_type_t enumeration 
+ */
+static lwjson_stream_type_t
+prv_stack_get_top(lwjson_stream_parser_t* jsp) {
+    if (jsp->stack_pos > 0) {
+        return jsp->stack[jsp->stack_pos - 1].type;
+    }
+    return LWJSON_STREAM_TYPE_NONE;
+}
+
+/**
+ * \brief           Initialize LwJSON stream object before parsing takes place
+ * \param[in,out]   jsp: Stream JSON structure 
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+lwjsonr_t
+lwjson_stream_init(lwjson_stream_parser_t* jsp, lwjson_stream_parser_callback_fn evt_fn) {
+    LWJSON_MEMSET(jsp, 0x00, sizeof(*jsp));
+    jsp->parse_state = LWJSON_STREAM_STATE_WAITINGFIRSTCHAR;
+    jsp->evt_fn = evt_fn;
+    jsp->user_data = NULL;
+    return lwjsonOK;
+}
+
+/**
+ * \brief           Reset LwJSON stream structure
+ * 
+ * \param[in,out]   jsp: LwJSON stream parser
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+lwjsonr_t
+lwjson_stream_reset(lwjson_stream_parser_t* jsp) {
+    jsp->parse_state = LWJSON_STREAM_STATE_WAITINGFIRSTCHAR;
+    jsp->stack_pos = 0;
+    return lwjsonOK;
+}
+
+/**
+ * \brief           Set user_data in stream parser
+ * 
+ * \param[in,out]   jsp: LwJSON stream parser
+ * \param[in]       user_data: user data
+ * \return          \ref lwjsonOK on success, member of \ref lwjsonr_t otherwise
+ */
+lwjsonr_t
+lwjson_stream_set_user_data(lwjson_stream_parser_t* jsp, void* user_data) {
+    jsp->user_data = user_data;
+    return lwjsonOK;
+}
+
+/**
+ * \brief           Get user_data in stream parser
+ * 
+ * \param[in]       jsp: LwJSON stream parser
+ * \return          pointer to user data
+ */
+void*
+lwjson_stream_get_user_data(lwjson_stream_parser_t* jsp) {
+    return jsp->user_data;
+}
+
+/**
+ * \brief           Parse JSON string in streaming mode
+ * \param[in,out]   jsp: Stream JSON structure 
+ * \param[in]       chr: Character to parse
+ * \return          \ref lwjsonSTREAMWAITFIRSTCHAR when stream did not start parsing since no valid start character has been received
+ * \return          \ref lwjsonSTREAMINPROG if parsing is in progress and no hard error detected
+ * \return          \ref lwjsonSTREAMDONE when valid JSON was detected and stack level reached back `0` level
+ * \return          \ref One of enumeration otherwise
+ */
+lwjsonr_t
+lwjson_stream_parse(lwjson_stream_parser_t* jsp, char chr) {
+    /* Get first character first */
+    if (jsp->parse_state == LWJSON_STREAM_STATE_WAITINGFIRSTCHAR && chr != '{' && chr != '[') {
+        return prv_is_space_char_ext(chr) ? lwjsonSTREAMWAITFIRSTCHAR : lwjsonERRJSON;
+    }
+
+start_over:
+    /* Determine what to do from parsing state */
+    switch (jsp->parse_state) {
+
+        /*
+         * Waiting for very first valid characters,
+         * that is used to indicate start of JSON stream
+         */
+        case LWJSON_STREAM_STATE_WAITINGFIRSTCHAR:
+        case LWJSON_STREAM_STATE_EXPECTING_COMMA_OR_END:
+        case LWJSON_STREAM_STATE_PARSING: {
+            /* Ignore whitespace chars */
+            if (prv_is_space_char_ext(chr)) {
+                break;
+
+                /* Determine value separator */
+            } else if (chr == ',') {
+                if (jsp->parse_state == LWJSON_STREAM_STATE_EXPECTING_COMMA_OR_END) {
+                    jsp->parse_state = LWJSON_STREAM_STATE_PARSING;
+                } else {
+                    LWJSON_DEBUG(jsp, "ERROR - ',' can only follow value\r\n");
+                    return lwjsonERRJSON;
+                }
+
+                /* Determine end of object or an array */
+            } else if (chr == '}' || chr == ']') {
+                lwjson_stream_type_t type = prv_stack_get_top(jsp);
+
+                /* 
+                 * If it is a key last entry on closing area,
+                 * it is an error - an example: {"key":}
+                 */
+                if (type == LWJSON_STREAM_TYPE_KEY) {
+                    LWJSON_DEBUG(jsp, "ERROR - key should not be followed by ] without value for a key\r\n");
+                    return lwjsonERRJSON;
+                }
+
+                /*
+                 * Check if closing character matches stack value
+                 * Avoid cases like: {"key":"value"] or ["v1", "v2", "v3"}
+                 */
+                if ((chr == '}' && type != LWJSON_STREAM_TYPE_OBJECT)
+                    || (chr == ']' && type != LWJSON_STREAM_TYPE_ARRAY)) {
+                    LWJSON_DEBUG(jsp, "ERROR - closing character '%c' does not match stack element \"%s\"\r\n", chr,
+                                 lwjson_type_strings[type]);
+                    return lwjsonERRJSON;
+                }
+
+                /* Now remove the array or object from stack */
+                if (prv_stack_pop(jsp) == LWJSON_STREAM_TYPE_NONE) {
+                    return lwjsonERRJSON;
+                }
+
+                SEND_EVT(jsp, chr == '}' ? LWJSON_STREAM_TYPE_OBJECT_END : LWJSON_STREAM_TYPE_ARRAY_END);
+
+                /*
+                 * Check if above is a key type
+                 * and remove it too as we finished with processing of potential case.
+                 * 
+                 * {"key":{"abc":1}} - remove "key" part
+                 */
+                if (prv_stack_get_top(jsp) == LWJSON_STREAM_TYPE_KEY) {
+                    prv_stack_pop(jsp);
+                }
+
+                /* If that is the end of JSON */
+                if (jsp->stack_pos == 0) {
+                    lwjson_stream_reset(jsp);
+                    return lwjsonSTREAMDONE;
+                }
+
+                jsp->parse_state = LWJSON_STREAM_STATE_EXPECTING_COMMA_OR_END;
+
+                /* If comma or end was expected, then it is already error here */
+            } else if (jsp->parse_state == LWJSON_STREAM_STATE_EXPECTING_COMMA_OR_END) {
+                LWJSON_DEBUG(jsp, "ERROR - ',', '}' or ']' was expected\r\n");
+                return lwjsonERRJSON;
+
+                /* Determine start of string - can be key or regular string (in array or after key) */
+            } else if (chr == '"') {
+#if defined(LWJSON_DEV)
+                lwjson_stream_type_t type = prv_stack_get_top(jsp);
+                if (type == LWJSON_STREAM_TYPE_OBJECT) {
+                    LWJSON_DEBUG(jsp, "Start of string parsing - expected key name in an object\r\n");
+                } else if (type == LWJSON_STREAM_TYPE_KEY) {
+                    LWJSON_DEBUG(jsp,
+                                 "Start of string parsing - string value associated to previous key in an object\r\n");
+                } else if (type == LWJSON_STREAM_TYPE_ARRAY) {
+                    LWJSON_DEBUG(jsp, "Start of string parsing - string entry in an array\r\n");
+                }
+#endif /* defined(LWJSON_DEV) */
+                jsp->parse_state = LWJSON_STREAM_STATE_PARSING_STRING;
+                LWJSON_MEMSET(&jsp->data.str, 0x00, sizeof(jsp->data.str));
+
+            } else if (prv_stack_get_top(jsp) == LWJSON_STREAM_TYPE_OBJECT) {
+                /* Key must be before value */
+                LWJSON_DEBUG(jsp, "ERROR - key must be before value\r\n");
+                return lwjsonERRJSON;
+
+                /* Determine start of object or an array */
+            } else if (chr == '{' || chr == '[') {
+                /* Reset stack pointer if this character came from waiting for first character */
+                if (jsp->parse_state == LWJSON_STREAM_STATE_WAITINGFIRSTCHAR) {
+                    jsp->stack_pos = 0;
+                }
+                SEND_EVT(jsp, chr == '{' ? LWJSON_STREAM_TYPE_OBJECT : LWJSON_STREAM_TYPE_ARRAY);
+                if (!prv_stack_push(jsp, chr == '{' ? LWJSON_STREAM_TYPE_OBJECT : LWJSON_STREAM_TYPE_ARRAY)) {
+                    LWJSON_DEBUG(jsp, "Cannot push object/array to stack\r\n");
+                    return lwjsonERRMEM;
+                }
+                jsp->parse_state = LWJSON_STREAM_STATE_PARSING;
+
+                /* Check if this is start of number or "true", "false" or "null" */
+            } else if (chr == '-' || (chr >= '0' && chr <= '9') || chr == 't' || chr == 'f' || chr == 'n') {
+                if (prv_stack_get_top(jsp) == LWJSON_STREAM_TYPE_OBJECT) {
+                    LWJSON_DEBUG(jsp, "ERROR - key must be before value (primitive)\r\n");
+                    /* Key must be before value */
+                    return lwjsonERRJSON;
+                }
+
+                LWJSON_DEBUG(jsp, "Start of primitive parsing parsing - %s, First char: %c\r\n",
+                             (chr == '-' || (chr >= '0' && chr <= '9')) ? "number" : "true,false,null", chr);
+                jsp->parse_state = LWJSON_STREAM_STATE_PARSING_PRIMITIVE;
+                LWJSON_MEMSET(&jsp->data.prim, 0x00, sizeof(jsp->data.prim));
+                jsp->data.prim.buff[jsp->data.prim.buff_pos++] = chr;
+
+                /* Wrong char */
+            } else {
+                LWJSON_DEBUG(jsp, "ERROR - wrong char %c\r\n", chr);
+                return lwjsonERRJSON;
+            }
+            break;
+        }
+
+        /* Check for end of key character i.e. name separator ':' */
+        case LWJSON_STREAM_STATE_EXPECTING_COLON:
+            /* Ignore whitespace chars */
+            if (prv_is_space_char_ext(chr)) {
+                break;
+            } else if (chr == ':') {
+                jsp->parse_state = LWJSON_STREAM_STATE_PARSING;
+            } else {
+                LWJSON_DEBUG(jsp, "ERROR - expecting ':'\r\n");
+                return lwjsonERRJSON;
+            }
+            break;
+
+        /*
+         * Parse any type of string in a sequence
+         *
+         * It is used for key or string in an object or an array
+         */
+        case LWJSON_STREAM_STATE_PARSING_STRING: {
+            lwjson_stream_type_t type = prv_stack_get_top(jsp);
+
+            /* 
+             * Quote character may trigger end of string, 
+             * or if backslasled before - it is part of string
+             * 
+             * TODO: Handle backslash
+             */
+            if (chr == '"' && jsp->prev_c != '\\') {
+#if defined(LWJSON_DEV)
+                if (type == LWJSON_STREAM_TYPE_OBJECT) {
+                    LWJSON_DEBUG(jsp, "End of string parsing - object key name: \"%s\"\r\n", jsp->data.str.buff);
+                } else if (type == LWJSON_STREAM_TYPE_KEY) {
+                    LWJSON_DEBUG(
+                        jsp, "End of string parsing - string value associated to previous key in an object: \"%s\"\r\n",
+                        jsp->data.str.buff);
+                } else if (type == LWJSON_STREAM_TYPE_ARRAY) {
+                    LWJSON_DEBUG(jsp, "End of string parsing - an array string entry: \"%s\"\r\n", jsp->data.str.buff);
+                }
+#endif /* defined(LWJSON_DEV) */
+
+                /* Set is_last to 1 as this is the last part of this string token */
+                jsp->data.str.is_last = 1;
+
+                /*
+                 * When top of stack is object - string is treated as a key
+                 * When top of stack is a key - string is a value for a key - notify user and pop the value for key
+                 * When top of stack is an array - string is one type - notify user and don't do anything
+                 */
+                jsp->parse_state = LWJSON_STREAM_STATE_EXPECTING_COMMA_OR_END;
+                if (type == LWJSON_STREAM_TYPE_OBJECT) {
+                    SEND_EVT(jsp, LWJSON_STREAM_TYPE_KEY);
+                    if (prv_stack_push(jsp, LWJSON_STREAM_TYPE_KEY)) {
+                        size_t len = jsp->data.str.buff_pos;
+                        if (len > (sizeof(jsp->stack[0].meta.name) - 1)) {
+                            len = sizeof(jsp->stack[0].meta.name) - 1;
+                        }
+                        LWJSON_MEMCPY(jsp->stack[jsp->stack_pos - 1].meta.name, jsp->data.str.buff, len);
+                        jsp->stack[jsp->stack_pos - 1].meta.name[len] = '\0';
+                    } else {
+                        LWJSON_DEBUG(jsp, "Cannot push key to stack\r\n");
+                        return lwjsonERRMEM;
+                    }
+                    jsp->parse_state = LWJSON_STREAM_STATE_EXPECTING_COLON;
+                } else if (type == LWJSON_STREAM_TYPE_KEY) {
+                    SEND_EVT(jsp, LWJSON_STREAM_TYPE_STRING);
+                    prv_stack_pop(jsp);
+                    /* Next character to wait for is either space or comma or end of object */
+                } else if (type == LWJSON_STREAM_TYPE_ARRAY) {
+                    SEND_EVT(jsp, LWJSON_STREAM_TYPE_STRING);
+                    jsp->stack[jsp->stack_pos - 1].meta.index++;
+                }
+            } else {
+                /* TODO: Check other backslash elements */
+                jsp->data.str.buff[jsp->data.str.buff_pos++] = chr;
+                jsp->data.str.buff_total_pos++;
+
+                /* Handle buffer "overflow" */
+                if (jsp->data.str.buff_pos >= (LWJSON_CFG_STREAM_STRING_MAX_LEN - 1)) {
+                    jsp->data.str.buff[jsp->data.str.buff_pos] = '\0';
+
+                    /* 
+                     * - For array or key types - following one is always string
+                     * - For object type - character is key
+                     */
+                    SEND_EVT(jsp, (type == LWJSON_STREAM_TYPE_KEY || type == LWJSON_STREAM_TYPE_ARRAY)
+                                      ? LWJSON_STREAM_TYPE_STRING
+                                      : LWJSON_STREAM_TYPE_KEY);
+                    jsp->data.str.buff_pos = 0;
+                }
+            }
+            break;
+        }
+
+        /*
+         * Parse any type of primitive that is not a string.
+         *
+         * true, false, null or any number primitive
+         */
+        case LWJSON_STREAM_STATE_PARSING_PRIMITIVE: {
+            /* Any character except space, comma, or end of array/object are valid */
+            if (!prv_is_space_char_ext(chr) && chr != ',' && chr != ']' && chr != '}') {
+                if (jsp->data.prim.buff_pos < sizeof(jsp->data.prim.buff) - 1) {
+                    jsp->data.prim.buff[jsp->data.prim.buff_pos++] = chr;
+                } else {
+                    LWJSON_DEBUG(jsp, "Buffer overflow for primitive\r\n");
+                    return lwjsonERRJSON;
+                }
+            } else {
+                lwjson_stream_type_t type = prv_stack_get_top(jsp);
+
+#if defined(LWJSON_DEV)
+                if (type == LWJSON_STREAM_TYPE_KEY) {
+                    LWJSON_DEBUG(
+                        jsp,
+                        "End of primitive parsing - string value associated to previous key in an object: \"%s\"\r\n",
+                        jsp->data.prim.buff);
+                } else if (type == LWJSON_STREAM_TYPE_ARRAY) {
+                    LWJSON_DEBUG(jsp, "End of primitive parsing - an array string entry: \"%s\"\r\n",
+                                 jsp->data.prim.buff);
+                }
+#endif /* defined(LWJSON_DEV) */
+
+                /*
+                 * This is the end of primitive parsing
+                 *
+                 * It is assumed that buffer for primitive can handle at least
+                 * true, false, null or all number characters (that being real or int number)
+                 */
+                if (jsp->data.prim.buff_pos == 4 && strncmp(jsp->data.prim.buff, "true", 4) == 0) {
+                    LWJSON_DEBUG(jsp, "Primitive parsed as %s\r\n", "true");
+                    SEND_EVT(jsp, LWJSON_STREAM_TYPE_TRUE);
+                } else if (jsp->data.prim.buff_pos == 4 && strncmp(jsp->data.prim.buff, "null", 4) == 0) {
+                    LWJSON_DEBUG(jsp, "Primitive parsed as %s\r\n", "null");
+                    SEND_EVT(jsp, LWJSON_STREAM_TYPE_NULL);
+                } else if (jsp->data.prim.buff_pos == 5 && strncmp(jsp->data.prim.buff, "false", 5) == 0) {
+                    LWJSON_DEBUG(jsp, "Primitive parsed as %s\r\n", "false");
+                    SEND_EVT(jsp, LWJSON_STREAM_TYPE_FALSE);
+                } else if (jsp->data.prim.buff[0] == '-'
+                           || (jsp->data.prim.buff[0] >= '0' && jsp->data.prim.buff[0] <= '9')) {
+                    LWJSON_DEBUG(jsp, "Primitive parsed - number\r\n");
+                    SEND_EVT(jsp, LWJSON_STREAM_TYPE_NUMBER);
+                } else {
+                    LWJSON_DEBUG(jsp, "Invalid primitive type. Got: %s\r\n", jsp->data.prim.buff);
+                    return lwjsonERRJSON;
+                }
+                if (type == LWJSON_STREAM_TYPE_KEY) {
+                    prv_stack_pop(jsp);
+                } else if (type == LWJSON_STREAM_TYPE_ARRAY) {
+                    jsp->stack[jsp->stack_pos - 1].meta.index++;
+                }
+
+                /* 
+                 * Received character is not part of the primitive and must be processed again
+                 */
+                jsp->parse_state = LWJSON_STREAM_STATE_EXPECTING_COMMA_OR_END;
+                goto start_over;
+            }
+            break;
+        }
+
+        default: break;
+    }
+    jsp->prev_c = chr; /* Save current c as previous for next round */
+    return lwjsonSTREAMINPROG;
+}

+ 1 - 2
Application_cbd_apm32f1/applications/main.c

@@ -18,7 +18,7 @@
 #include <rtdbg.h>
 #include <ledblink.h>
 #include <control.h>
-#include "beep.h"
+#include <app_pwm.h>
 #include "hmi.h"
 
 Device_Status_typedef device_status;
@@ -33,7 +33,6 @@ int main(void)
     clock_information();
     Beep_Tip(100);
     Check_ParamConfig();
-    //打印内存占用
     memtrace(0, NULL);
     while(1)
     {

+ 6 - 23
Application_cbd_apm32f1/applications/sht30_collect.c

@@ -204,29 +204,14 @@ static void Power_ReadCheck(void *parameter)
     rt_thread_delay(1000);
     while(1)
     {
-        #if PCB_V1 == 0
         rt_uint16_t _24v_current_int = moving_average_filter_update(filter,Read_Real_Current());
-        if(_24v_current_int-2430>0)
+        if(_24v_current_int-2500>0)
         {
-            sprintf(device_status.power,"%.2f",(float)(_24v_current_int-2430)/0.4);
+            sprintf(device_status.power,"%.2f",(float)(_24v_current_int-2500)/0.4);
         }else {
             sprintf(device_status.power,"0.0");
         }
 
-        //消除误差
-        if(Read_Heat_Current()-2450<10)
-        {
-            sprintf(device_status.heat_power,"%.f",0.0);
-        }
-        else
-        {
-            //rt_uint16_t _heat_current_int = moving_average_filter_update(filter_hi,Read_Heat_Current());
-            sprintf(device_status.heat_power,"%.2f",(float)(Read_Heat_Current()-2450)/0.1);     //2481-2465
-        }
-        #else
-
-        sprintf(device_status.power,"%.2f",(float)(moving_average_filter_update(filter, (float)Read_Real_Current()/100*2.5))+20.0);
-        #endif
         //LOG_I("负载电流:%s,加热电流:%s",device_status.power,device_status.heat_power);
         if (Read_Real_Voltage()/100<11)
         {
@@ -256,9 +241,6 @@ static void Power_ReadCheck(void *parameter)
             {
                 device_status.C01 |= (1<<5);
                 device_status.rain_status = 1;
-                ctr_lamp(OFF,1);
-                ctr_lamp(OFF,2);
-                ctr_lamp(OFF,3);
                 rain_cnt = 0;
             }
             else {
@@ -279,8 +261,9 @@ static void Power_ReadCheck(void *parameter)
         rt_uint16_t in_voltage_int = moving_average_filter_update(filter_v,Read_Real_Voltage());
         sprintf(device_status.voltage,"%d.%02d",in_voltage_int/100,in_voltage_int%100);
         //LOG_D("voltage is:%sV",device_status.voltage);
-        sprintf(device_status.fuse_voltage, "%d.%02d",Read_Fuse_Voltage()/100,Read_Fuse_Voltage()%100);
-        rt_thread_mdelay(10);
+        //sprintf(device_status.fuse_voltage, "%d.%02d",Read_Fuse_Voltage()/100,Read_Fuse_Voltage()%100);
+        //LOG_D("高压检测:%d",Read_Fuse_Voltage());
+        rt_thread_mdelay(100);
     }
 }
 /*读取电流值*/
@@ -371,7 +354,7 @@ int Read_Fuse_Voltage(void)
     adc13_value = rt_adc_read(adc_dev, ADC_DEV_CHANNLE_5);
     /* 关闭通道 */
     rt_adc_disable(adc_dev, ADC_DEV_CHANNLE_5);
-    return  (adc13_value * REFER_VOLTAGE/CONVERT_BITS*12+8);
+    return  (adc13_value);
 }
 /*读取雨控*/
 int Read_Rain_Voltage(void)

+ 4 - 2
Application_cbd_apm32f1/packages/syswatch-latest/src/syswatch.c

@@ -413,7 +413,8 @@ static void syswatch_thread_entry(void *parameter)
                 if(alarm_new.tm_year>=2025)
                 {
                     ctr_router(OFF);
-                    ctr_RTU_DTU(OFF);
+                    ctr_RTU_12V(OFF);
+                    ctr_hmi_5v(OFF);         //屏幕供电
                 }
             }
 
@@ -424,7 +425,8 @@ static void syswatch_thread_entry(void *parameter)
             if((alarm_new.tm_min==0) && (alarm_new.tm_sec==0))
             {
                 ctr_router(ON);
-                ctr_RTU_DTU(ON);
+                ctr_RTU_12V(ON);
+                ctr_hmi_5v(ON);         //屏幕供电
             }
         }
 

+ 6 - 0
Application_cbd_apm32f1/readme.md

@@ -1,3 +1,9 @@
+# 2025-12-08 更新说明
+	版本:3.0.0
+1、基于2.5.9版本项目适配[YF_IO_BOARD V1.0 BYTSX 20251030]
+2、 引入lwjson
+3、屏幕电源可控
+
 # 2025-11-03 更新说明
 	版本:2.5.9
 	1. 修复屏幕设置北大荒ID的前缀类型为测报灯,修改为性诱;