添加了标定部分程序
This commit is contained in:
parent
b2c5011701
commit
ee85ee6813
|
@ -197,5 +197,5 @@
|
|||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
</cproject>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-10-23 17:14:16
|
||||
* @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
|
||||
* @Descrt_thread_
|
||||
*
|
||||
|
@ -21,7 +21,7 @@
|
|||
#include "bsp_flash.h"
|
||||
#include "bsp_hr.h"
|
||||
#include "bsp_mq.h"
|
||||
#include "bsp_button.h"
|
||||
#include "bsp_button.h"
|
||||
#include "bsp_mb26.h"
|
||||
#include "bsp_vin_detection.h"
|
||||
#include "user_sys.h"
|
||||
|
@ -41,6 +41,7 @@ TsSysControl SysControl;
|
|||
struct rt_timer work_cnt_timer;
|
||||
void Send_Laser_Alarm_Event(AlarmEvent event_type);
|
||||
|
||||
TeCalibrationStatus g_Calibration_status = kNotCalibrated;
|
||||
static void Set_Event(AlarmEvent event_type)
|
||||
{
|
||||
if (event_type < kMaxEventcnt)
|
||||
|
@ -139,16 +140,54 @@ void Work_Cnt_Timer_Callback(void *parameter)
|
|||
int main(void)
|
||||
{
|
||||
// 定义超时时间,单位为毫秒
|
||||
#define TIMEOUT_MS 10000
|
||||
#define TIMEOUT_MS 3 * 60 * 1000
|
||||
#define WORK_TIMER_CNT (1000 * 60 * 60 * 24)
|
||||
|
||||
rt_err_t result = RT_EINVAL;
|
||||
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);
|
||||
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();
|
||||
work_duration = Flash_Get_WorkDuration();
|
||||
rt_timer_init(&work_cnt_timer,
|
||||
|
@ -232,7 +271,6 @@ int main(void)
|
|||
LED_STOP(y);
|
||||
LOG_D("预热完成");
|
||||
Send_Laser_Alarm_Event(kNormalDetectionEvents);
|
||||
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag(kNormalDetectionEvents)) // 正常检测
|
||||
{
|
||||
|
@ -398,6 +436,7 @@ int main(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "ctype.h"
|
||||
#include "rtthread.h"
|
||||
#include "stdlib.h"
|
||||
#include "bsp_flash.h"
|
||||
|
||||
volatile rt_uint16_t work_duration = 1; // 工作时长
|
||||
volatile rt_uint8_t device_life_check = 0;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* @Author: mbw
|
||||
* @Date: 2024-10-09 08:42:14
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2024-11-12 14:19:50
|
||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS\applications\user_sys.h
|
||||
* @LastEditTime: 2024-12-01 14:18:19
|
||||
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\user_sys.h
|
||||
* @Description:
|
||||
* @
|
||||
* @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||
|
@ -12,7 +12,6 @@
|
|||
#define __USER_SYS_H__
|
||||
|
||||
#include "rtdef.h"
|
||||
#include "bsp_flash.h"
|
||||
|
||||
|
||||
#define SYS_PREHEAT_TIME_S (10U)
|
||||
|
@ -37,13 +36,20 @@ typedef enum
|
|||
kMaxEventcnt,
|
||||
} AlarmEvent;
|
||||
|
||||
// 定义系统状态枚举类型
|
||||
typedef enum
|
||||
{
|
||||
kNotCalibrated = 0, // 未标定
|
||||
kSysGasCalibStatus, // 已经标定
|
||||
|
||||
}TeCalibrationStatus;
|
||||
// 定义开关状态枚举类型
|
||||
typedef enum
|
||||
{
|
||||
kStatusOff = 0, // 关闭状态
|
||||
kStatusOn // 打开状态
|
||||
} TeStatus;
|
||||
|
||||
// 定义系统标志位结构体
|
||||
typedef struct
|
||||
{
|
||||
|
@ -51,31 +57,6 @@ typedef struct
|
|||
TeStatus relay_status; // 继电器状态
|
||||
} TsDeviceStatus;
|
||||
|
||||
|
||||
// 定义系统状态枚举类型
|
||||
typedef enum
|
||||
{
|
||||
kSysToBeCalibStatus = 0, // 系统待校准状态
|
||||
kSysGasCalibStatus, // 气体校准状态
|
||||
KSysTestStatus, // 测试状态
|
||||
|
||||
kSysSelfCheckingStatus, // 自检状态
|
||||
|
||||
kSysPowerUpStatus, // 上电状态
|
||||
kSysPowerDownStatus, // 下电状态
|
||||
|
||||
kSysStartupPreheatingStatus, // 启动预热状态
|
||||
kSysRuningStatus, // 运行中状态
|
||||
|
||||
kSysAlarmStatus, // 报警状态
|
||||
kSysMuteStatus, // 消音状态
|
||||
|
||||
kSysFaultStatus, // 故障状态
|
||||
kSysSensorEndOfLifeStatus, // 传感器寿命结束状态
|
||||
|
||||
kSysRestoreFactoryStatus, // 恢复出厂设置状态
|
||||
}TeSysStatus;
|
||||
|
||||
// 定义系统控制结构体
|
||||
typedef struct
|
||||
{
|
||||
|
@ -85,19 +66,24 @@ typedef struct
|
|||
|
||||
extern volatile rt_uint16_t work_duration;//工作天数
|
||||
extern volatile rt_uint8_t device_state_flag;
|
||||
|
||||
extern TeCalibrationStatus g_Calibration_status;
|
||||
extern struct rt_event alarm_event;
|
||||
extern TsSysControl SysControl;
|
||||
|
||||
|
||||
|
||||
void Send_Laser_Alarm_Event(AlarmEvent event);
|
||||
|
||||
|
||||
unsigned short crc1021(const char *data, unsigned int length);
|
||||
void HexStrToBytes(const char *hexString, unsigned char *byteArray, size_t byteCount);
|
||||
void String2Hex(char *hex_arry, char *str);
|
||||
unsigned int VerToHex(const char *version);
|
||||
int Extract_Value(const char *str, const char *key);
|
||||
int _Self_Check_Mode(void);
|
||||
int Convert_To_Hex(const struct flash_sever_info *sever_info, uint8_t *hex_array);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //!__USER_SYS_H__
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,13 @@ extern agile_led_t *beep;
|
|||
} while (0U)
|
||||
|
||||
/************************预设的一些鸣叫模式**************/
|
||||
#define BEEP_CALIBRATION_OK \
|
||||
do \
|
||||
{ \
|
||||
BEEP_CTRL("1000,100", 1); \
|
||||
BEEP_START; \
|
||||
} while (0U)
|
||||
|
||||
#define BEEP_PREAT_OK \
|
||||
do \
|
||||
{ \
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "board.h"
|
||||
#include "rtdef.h"
|
||||
#include "bsp_hr.h"
|
||||
#include "user_sys.h"
|
||||
|
||||
|
||||
#define FLASH_PAGE_SIZE (256U)
|
||||
#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_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 sw_ver; // 软件版本号
|
||||
rt_uint8_t alarm_l_value; // 报警低阈值
|
||||
rt_uint8_t alarm_h_value; // 报警高阈值
|
||||
rt_uint16_t alarm_l_value; // 报警低阈值
|
||||
rt_uint16_t alarm_h_value; // 报警高阈值
|
||||
rt_uint8_t temp_alarm_threshold;//温度报警阈值
|
||||
rt_uint16_t nb_upload_cycle; // NB上传周期
|
||||
rt_uint8_t nb_retry; // 重试次数
|
||||
|
@ -253,7 +257,9 @@ struct flash_sever_info
|
|||
char server_url[64];
|
||||
char server_port[8];
|
||||
};
|
||||
|
||||
extern struct flash_sever_info sever_info;
|
||||
|
||||
void Flash_Write_Record(TeRecord record);
|
||||
int Get_Nb_Imei(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);
|
||||
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__
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include "bsp_flash.h"
|
||||
#include "lwutil.h"
|
||||
#include "bsp_rtc.h"
|
||||
// #include "bsp_wdg.h"
|
||||
#include "bsp_hr.h"
|
||||
#include "at_device_mb26.h"
|
||||
#include "at_device_mb26.h"
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include "user_sys.h"
|
||||
|
||||
#define LOG_TAG "bsp_flash"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
|
@ -14,6 +12,7 @@
|
|||
|
||||
#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) \
|
||||
: (id) == kSwVerId ? (&(info)->sw_ver) \
|
||||
: (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_uint16_t sys_nb_upload_cycle = 0x7800; // 120分钟一次 ,低位在前,高为在后,为了和服务器下发时保持一致,有利于读取
|
||||
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_emagnetic_switch = 0x04; // 具备阀门功能
|
||||
rt_uint8_t sys_relay_switch = 0x04; // 具备继电器功能
|
||||
|
||||
struct flash_sever_info sever_info =
|
||||
{
|
||||
.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);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
* @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 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);
|
||||
return value;
|
||||
}
|
||||
|
@ -844,6 +875,7 @@ int BSP_Flash_Init(void)
|
|||
{
|
||||
LOG_D("Flash_Set_Sever_Data error!");
|
||||
}
|
||||
Flash_Set_Calibration_State(kNotCalibrated);//未标定状态
|
||||
|
||||
Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci,
|
||||
(sizeof(sys_config_info) - 50));
|
||||
|
|
|
@ -8,26 +8,6 @@
|
|||
*
|
||||
* 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 "drv_gpio.h"
|
||||
#include "bsp_mb26.h"
|
||||
|
|
|
@ -172,6 +172,7 @@ static void Sensor_detection_thread_entry(void *param)
|
|||
int BSP_MQ_Init(void)
|
||||
{
|
||||
Sensor_device.alarm_value = Flash_Get_SysCfg(kAlarmLValueId);
|
||||
LOG_D("报警阈值为:%d", Sensor_device.alarm_value);
|
||||
rt_thread_init(&Sensor_Thread, //可以用定时器做,没必要线程
|
||||
"sensor_thread",
|
||||
Sensor_detection_thread_entry,
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#endif /* RT_USING_LIBC */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Reference in New Issue