添加了标定部分程序

This commit is contained in:
小马_666 2024-12-01 15:31:07 +08:00
parent b2c5011701
commit ee85ee6813
10 changed files with 367 additions and 299 deletions

View File

@ -197,5 +197,5 @@
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="refreshScope"/>
</cproject> </cproject>

View File

@ -2,7 +2,7 @@
* @Author: mbw * @Author: mbw
* @Date: 2024-10-23 17:14:16 * @Date: 2024-10-23 17:14:16
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2024-12-01 13:04:55 * @LastEditTime: 2024-12-01 14:44:58
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c * @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c
* @Descrt_thread_ * @Descrt_thread_
* *
@ -41,6 +41,7 @@ TsSysControl SysControl;
struct rt_timer work_cnt_timer; struct rt_timer work_cnt_timer;
void Send_Laser_Alarm_Event(AlarmEvent event_type); void Send_Laser_Alarm_Event(AlarmEvent event_type);
TeCalibrationStatus g_Calibration_status = kNotCalibrated;
static void Set_Event(AlarmEvent event_type) static void Set_Event(AlarmEvent event_type)
{ {
if (event_type < kMaxEventcnt) if (event_type < kMaxEventcnt)
@ -139,16 +140,54 @@ void Work_Cnt_Timer_Callback(void *parameter)
int main(void) int main(void)
{ {
// 定义超时时间,单位为毫秒 // 定义超时时间,单位为毫秒
#define TIMEOUT_MS 10000 #define TIMEOUT_MS 3 * 60 * 1000
#define WORK_TIMER_CNT (1000 * 60 * 60 * 24) #define WORK_TIMER_CNT (1000 * 60 * 60 * 24)
rt_err_t result = RT_EINVAL; rt_err_t result = RT_EINVAL;
rt_uint32_t received_event; rt_uint32_t received_event;
rt_kprintf("JT-DT-YD4N02A Software version: %02X", (uint8_t)Flash_Get_SysCfg(kSwVerId)); rt_kprintf("JT-DT-YD4N02A Software version: %02X\r\n", (uint8_t)Flash_Get_SysCfg(kSwVerId));
// 读取历史记录总数 // 读取历史记录总数
Flash_GetTotalRecord(&TotalRecords); Flash_GetTotalRecord(&TotalRecords);
g_Calibration_status = Flash_Get_Calibration_State();
if (g_Calibration_status == kNotCalibrated)//没标定
{
LED_STOP(r);
LED_STOP(y);
LED_CTRL(g, "1000,500", -1);
LED_START(g);
uint16_t ticks = 0, gas_calibration_voltage;
while (1)
{
gas_calibration_voltage = Get_Gas_VoltageInt1000x();
LOG_D("ticks[%d] gas_calibration_voltage = %d", ticks++, gas_calibration_voltage);
if (g_Calibration_status == kNotCalibrated)//没标定
{
if (ticks > TIMEOUT_MS)
{
if(gas_calibration_voltage > (MQ_VOLTAGE_ALARM_DEFAULT - 500)
&& gas_calibration_voltage < (MQ_VOLTAGE_ALARM_DEFAULT + 500))
{
uint8_t calibration_buf[2] = {0};
calibration_buf[0] = gas_calibration_voltage << 8;// 低字节
calibration_buf[1] = gas_calibration_voltage >> 8;//高字节
LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]);
Flash_Sys_Cfg(kAlarmLValueId, calibration_buf, 2);
// 标定完成打开绿灯常亮,蜂鸣器叫一下
BEEP_CALIBRATION_OK;
LED_STOP(g);
LED_ON(g);
Flash_Set_Calibration_State(kSysGasCalibStatus);
g_Calibration_status = kSysGasCalibStatus;
}
}
}
rt_thread_mdelay(1000);
}
}
else
{
SYS_EventInit(); SYS_EventInit();
work_duration = Flash_Get_WorkDuration(); work_duration = Flash_Get_WorkDuration();
rt_timer_init(&work_cnt_timer, rt_timer_init(&work_cnt_timer,
@ -232,7 +271,6 @@ int main(void)
LED_STOP(y); LED_STOP(y);
LOG_D("预热完成"); LOG_D("预热完成");
Send_Laser_Alarm_Event(kNormalDetectionEvents); Send_Laser_Alarm_Event(kNormalDetectionEvents);
} }
else if (received_event & Get_Sys_Event_Flag(kNormalDetectionEvents)) // 正常检测 else if (received_event & Get_Sys_Event_Flag(kNormalDetectionEvents)) // 正常检测
{ {
@ -399,6 +437,7 @@ int main(void)
} }
} }
} }
}
#ifdef TEST_ENABLE #ifdef TEST_ENABLE
static void SYS_Set_RtcProductTime(int argc, char **argv) static void SYS_Set_RtcProductTime(int argc, char **argv)

View File

@ -13,6 +13,7 @@
#include "ctype.h" #include "ctype.h"
#include "rtthread.h" #include "rtthread.h"
#include "stdlib.h" #include "stdlib.h"
#include "bsp_flash.h"
volatile rt_uint16_t work_duration = 1; // 工作时长 volatile rt_uint16_t work_duration = 1; // 工作时长
volatile rt_uint8_t device_life_check = 0; volatile rt_uint8_t device_life_check = 0;

View File

@ -2,8 +2,8 @@
* @Author: mbw * @Author: mbw
* @Date: 2024-10-09 08:42:14 * @Date: 2024-10-09 08:42:14
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2024-11-12 14:19:50 * @LastEditTime: 2024-12-01 14:18:19
* @FilePath: \JT-DT-YD4N02A_RTT_MRS\applications\user_sys.h * @FilePath: \ble_bjq_ch303rct6_ml307\applications\user_sys.h
* @Description: * @Description:
* @ * @
* @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
@ -12,7 +12,6 @@
#define __USER_SYS_H__ #define __USER_SYS_H__
#include "rtdef.h" #include "rtdef.h"
#include "bsp_flash.h"
#define SYS_PREHEAT_TIME_S (10U) #define SYS_PREHEAT_TIME_S (10U)
@ -37,13 +36,20 @@ typedef enum
kMaxEventcnt, kMaxEventcnt,
} AlarmEvent; } AlarmEvent;
// 定义系统状态枚举类型
typedef enum
{
kNotCalibrated = 0, // 未标定
kSysGasCalibStatus, // 已经标定
}TeCalibrationStatus;
// 定义开关状态枚举类型 // 定义开关状态枚举类型
typedef enum typedef enum
{ {
kStatusOff = 0, // 关闭状态 kStatusOff = 0, // 关闭状态
kStatusOn // 打开状态 kStatusOn // 打开状态
} TeStatus; } TeStatus;
// 定义系统标志位结构体 // 定义系统标志位结构体
typedef struct typedef struct
{ {
@ -51,31 +57,6 @@ typedef struct
TeStatus relay_status; // 继电器状态 TeStatus relay_status; // 继电器状态
} TsDeviceStatus; } TsDeviceStatus;
// 定义系统状态枚举类型
typedef enum
{
kSysToBeCalibStatus = 0, // 系统待校准状态
kSysGasCalibStatus, // 气体校准状态
KSysTestStatus, // 测试状态
kSysSelfCheckingStatus, // 自检状态
kSysPowerUpStatus, // 上电状态
kSysPowerDownStatus, // 下电状态
kSysStartupPreheatingStatus, // 启动预热状态
kSysRuningStatus, // 运行中状态
kSysAlarmStatus, // 报警状态
kSysMuteStatus, // 消音状态
kSysFaultStatus, // 故障状态
kSysSensorEndOfLifeStatus, // 传感器寿命结束状态
kSysRestoreFactoryStatus, // 恢复出厂设置状态
}TeSysStatus;
// 定义系统控制结构体 // 定义系统控制结构体
typedef struct typedef struct
{ {
@ -85,19 +66,24 @@ typedef struct
extern volatile rt_uint16_t work_duration;//工作天数 extern volatile rt_uint16_t work_duration;//工作天数
extern volatile rt_uint8_t device_state_flag; extern volatile rt_uint8_t device_state_flag;
extern TeCalibrationStatus g_Calibration_status;
extern struct rt_event alarm_event; extern struct rt_event alarm_event;
extern TsSysControl SysControl; extern TsSysControl SysControl;
void Send_Laser_Alarm_Event(AlarmEvent event); void Send_Laser_Alarm_Event(AlarmEvent event);
unsigned short crc1021(const char *data, unsigned int length); unsigned short crc1021(const char *data, unsigned int length);
void HexStrToBytes(const char *hexString, unsigned char *byteArray, size_t byteCount); void HexStrToBytes(const char *hexString, unsigned char *byteArray, size_t byteCount);
void String2Hex(char *hex_arry, char *str); void String2Hex(char *hex_arry, char *str);
unsigned int VerToHex(const char *version); unsigned int VerToHex(const char *version);
int Extract_Value(const char *str, const char *key); int Extract_Value(const char *str, const char *key);
int _Self_Check_Mode(void); int _Self_Check_Mode(void);
int Convert_To_Hex(const struct flash_sever_info *sever_info, uint8_t *hex_array);
#endif //!__USER_SYS_H__ #endif //!__USER_SYS_H__

View File

@ -29,6 +29,13 @@ extern agile_led_t *beep;
} while (0U) } while (0U)
/************************预设的一些鸣叫模式**************/ /************************预设的一些鸣叫模式**************/
#define BEEP_CALIBRATION_OK \
do \
{ \
BEEP_CTRL("1000,100", 1); \
BEEP_START; \
} while (0U)
#define BEEP_PREAT_OK \ #define BEEP_PREAT_OK \
do \ do \
{ \ { \

View File

@ -14,6 +14,8 @@
#include "board.h" #include "board.h"
#include "rtdef.h" #include "rtdef.h"
#include "bsp_hr.h" #include "bsp_hr.h"
#include "user_sys.h"
#define FLASH_PAGE_SIZE (256U) #define FLASH_PAGE_SIZE (256U)
#define FLASH_PAGE_HR_RECORD_NUM (25U) #define FLASH_PAGE_HR_RECORD_NUM (25U)
@ -122,7 +124,9 @@
#define FLASH_SERVER_ADDR_ADDR (FLASH_WORK_TIME_ADDR + FLASH_WORK_TIME_LEN) #define FLASH_SERVER_ADDR_ADDR (FLASH_WORK_TIME_ADDR + FLASH_WORK_TIME_LEN)
#define FLASH_SERVER_LEN (6) //FF.FF.FF.FF:FFFF #define FLASH_SERVER_LEN (6) //FF.FF.FF.FF:FFFF
/*标定状态*/
#define FLASH_CALIBRATION_STATUS_ADDR (FLASH_SERVER_ADDR_ADDR + FLASH_SERVER_LEN)
#define FLASH_CALIBRATION_STATUS_LEN (1)
@ -236,8 +240,8 @@ typedef struct __attribute__((packed))
{ {
rt_uint8_t hw_ver; // 硬件版本号 rt_uint8_t hw_ver; // 硬件版本号
rt_uint8_t sw_ver; // 软件版本号 rt_uint8_t sw_ver; // 软件版本号
rt_uint8_t alarm_l_value; // 报警低阈值 rt_uint16_t alarm_l_value; // 报警低阈值
rt_uint8_t alarm_h_value; // 报警高阈值 rt_uint16_t alarm_h_value; // 报警高阈值
rt_uint8_t temp_alarm_threshold;//温度报警阈值 rt_uint8_t temp_alarm_threshold;//温度报警阈值
rt_uint16_t nb_upload_cycle; // NB上传周期 rt_uint16_t nb_upload_cycle; // NB上传周期
rt_uint8_t nb_retry; // 重试次数 rt_uint8_t nb_retry; // 重试次数
@ -253,7 +257,9 @@ struct flash_sever_info
char server_url[64]; char server_url[64];
char server_port[8]; char server_port[8];
}; };
extern struct flash_sever_info sever_info; extern struct flash_sever_info sever_info;
void Flash_Write_Record(TeRecord record); void Flash_Write_Record(TeRecord record);
int Get_Nb_Imei(char *buf, rt_size_t len); int Get_Nb_Imei(char *buf, rt_size_t len);
int Get_Nb_Imsi(char *buf, rt_size_t len); int Get_Nb_Imsi(char *buf, rt_size_t len);
@ -295,8 +301,23 @@ int Flash_Set_Sever_Data(rt_uint8_t *data);
rt_uint16_t Flash_Get_WorkDuration(void); rt_uint16_t Flash_Get_WorkDuration(void);
int Flash_Set_WorkDuration(rt_uint16_t value); int Flash_Set_WorkDuration(rt_uint16_t value);
TeCalibrationStatus Flash_Get_Calibration_State(void);
int Flash_Set_Calibration_State(TeCalibrationStatus status);
#endif //!@__BSP_FLASH_H__ #endif //!@__BSP_FLASH_H__

View File

@ -1,12 +1,10 @@
#include "bsp_flash.h" #include "bsp_flash.h"
#include "lwutil.h" #include "lwutil.h"
#include "bsp_rtc.h" #include "bsp_rtc.h"
// #include "bsp_wdg.h"
#include "bsp_hr.h" #include "bsp_hr.h"
#include "at_device_mb26.h" #include "at_device_mb26.h"
#include <rtthread.h> #include <rtthread.h>
#include <rthw.h> #include <rthw.h>
#include "user_sys.h"
#define LOG_TAG "bsp_flash" #define LOG_TAG "bsp_flash"
#define LOG_LVL LOG_LVL_DBG #define LOG_LVL LOG_LVL_DBG
@ -14,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
extern int Convert_To_Hex(const struct flash_sever_info *sever_info, uint8_t *hex_array);
#define GETATTR(info, id) ((id) == kHwVerId ? (&(info)->hw_ver) \ #define GETATTR(info, id) ((id) == kHwVerId ? (&(info)->hw_ver) \
: (id) == kSwVerId ? (&(info)->sw_ver) \ : (id) == kSwVerId ? (&(info)->sw_ver) \
: (id) == kAlarmLValueId ? (&(info)->alarm_l_value) \ : (id) == kAlarmLValueId ? (&(info)->alarm_l_value) \
@ -85,10 +84,11 @@ rt_uint8_t sys_sw_ver = 0x11;
rt_uint8_t sys_nb_retry = 0x03; // 重试次数3次 rt_uint8_t sys_nb_retry = 0x03; // 重试次数3次
rt_uint16_t sys_nb_upload_cycle = 0x7800; // 120分钟一次 ,低位在前,高为在后,为了和服务器下发时保持一致,有利于读取 rt_uint16_t sys_nb_upload_cycle = 0x7800; // 120分钟一次 ,低位在前,高为在后,为了和服务器下发时保持一致,有利于读取
rt_uint16_t sys_alarm_h_value = 0x0032; // 50 rt_uint16_t sys_alarm_h_value = 0x0032; // 50
rt_uint16_t sys_alarm_l_value = 0x000A; // 10 rt_uint16_t sys_alarm_l_value = 0x09C4; // 10
rt_uint8_t sys_temp_alarm_threshold = 0x32; rt_uint8_t sys_temp_alarm_threshold = 0x32;
rt_uint8_t sys_emagnetic_switch = 0x04; // 具备阀门功能 rt_uint8_t sys_emagnetic_switch = 0x04; // 具备阀门功能
rt_uint8_t sys_relay_switch = 0x04; // 具备继电器功能 rt_uint8_t sys_relay_switch = 0x04; // 具备继电器功能
struct flash_sever_info sever_info = struct flash_sever_info sever_info =
{ {
.server_url = "47.94.169.135", .server_url = "47.94.169.135",
@ -322,6 +322,26 @@ int Flash_Set_Sever_Data(rt_uint8_t *data)
return Flash_Write_ConfigInfo(page_buf); return Flash_Write_ConfigInfo(page_buf);
} }
TeCalibrationStatus Flash_Get_Calibration_State(void)
{
return *(rt_uint8_t *)FLASH_CALIBRATION_STATUS_ADDR;
}
int Flash_Set_Calibration_State(TeCalibrationStatus status)
{
rt_uint8_t page_buf[FLASH_PAGE_SIZE] = {0};
rt_uint8_t in_page_offset = (FLASH_CALIBRATION_STATUS_ADDR - FLASH_CONFIG_INFO_START_ADDR);
Flash_ErasePage_ReadConfigInfo(page_buf);
//*将传入的数据写到flash地址中
page_buf[in_page_offset] = status;
return Flash_Write_ConfigInfo(page_buf);
}
/** /**
* @description: Flash Erase Page * @description: Flash Erase Page
* @param {TeRecord} record * @param {TeRecord} record
@ -730,8 +750,19 @@ rt_uint8_t Flash_Sys_Cfg(TeFlashCfgInfoId id, rt_uint8_t *buf, rt_size_t len)
size_t Flash_Get_SysCfg(TeFlashCfgInfoId id) size_t Flash_Get_SysCfg(TeFlashCfgInfoId id)
{ {
size_t value = 0; size_t value = 0;
rt_memcpy(&value, (void *)hr_sys_cfg_info_addr[id], hr_sys_cfg_info_len[id]); if (hr_sys_cfg_info_len[id] == 1)
{
return *(rt_uint8_t *)hr_sys_cfg_info_addr[id];
}
else if (hr_sys_cfg_info_len[id] == 2)
{
rt_uint8_t buf[2] = {0};
rt_memcpy(&buf, (rt_uint8_t *)hr_sys_cfg_info_addr[id], hr_sys_cfg_info_len[id]);
value = buf[0] | (buf[1] << 8);
LOG_D("buf[0]= %u, buf[1]: %u", buf[0], buf[1]);
}
LOG_D("value: %u", value); LOG_D("value: %u", value);
return value; return value;
} }
@ -844,6 +875,7 @@ int BSP_Flash_Init(void)
{ {
LOG_D("Flash_Set_Sever_Data error!"); LOG_D("Flash_Set_Sever_Data error!");
} }
Flash_Set_Calibration_State(kNotCalibrated);//未标定状态
Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci, Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci,
(sizeof(sys_config_info) - 50)); (sizeof(sys_config_info) - 50));

View File

@ -8,26 +8,6 @@
* *
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
*/ */
/*
* @Author: mbw
* @Date: 2024-10-09 08:42:14
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2024-11-29 14:38:14
* @FilePath: \JT-DT-YD4N02A_RTT_MRS\bsp\src\bsp_mb26.c
* @Description:
*
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
*/
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-12-13 qiyongzhong first version
*/
#include <at_device_mb26.h> #include <at_device_mb26.h>
#include "drv_gpio.h" #include "drv_gpio.h"
#include "bsp_mb26.h" #include "bsp_mb26.h"

View File

@ -172,6 +172,7 @@ static void Sensor_detection_thread_entry(void *param)
int BSP_MQ_Init(void) int BSP_MQ_Init(void)
{ {
Sensor_device.alarm_value = Flash_Get_SysCfg(kAlarmLValueId); Sensor_device.alarm_value = Flash_Get_SysCfg(kAlarmLValueId);
LOG_D("报警阈值为:%d", Sensor_device.alarm_value);
rt_thread_init(&Sensor_Thread, //可以用定时器做,没必要线程 rt_thread_init(&Sensor_Thread, //可以用定时器做,没必要线程
"sensor_thread", "sensor_thread",
Sensor_detection_thread_entry, Sensor_detection_thread_entry,

View File

@ -54,6 +54,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>
#endif /* RT_USING_LIBC */ #endif /* RT_USING_LIBC */
#ifdef __cplusplus #ifdef __cplusplus