暂存一下
This commit is contained in:
parent
90617df89e
commit
958f90e78f
|
@ -170,6 +170,7 @@ void Preheat_Sensor(rt_uint32_t timeout_counter)
|
|||
Preheat_Sensor (timeout_counter);
|
||||
}
|
||||
}
|
||||
|
||||
void Work_Cnt_Timer_Callback (void *parameter)
|
||||
{
|
||||
work_duration++;
|
||||
|
@ -182,6 +183,7 @@ void Work_Cnt_Timer_Callback(void *parameter)
|
|||
Send_Laser_Alarm_Event (kSensorFailureEvent);
|
||||
}
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
#define WORK_TIMER_CNT (1000 * 60 * 60 * 24)
|
||||
|
@ -208,7 +210,32 @@ int main(void)
|
|||
WORK_TIMER_CNT,
|
||||
RT_TIMER_FLAG_PERIODIC);
|
||||
rt_timer_start (&work_cnt_timer);
|
||||
TuFlashProductTimeLimitFrame LimitTime;
|
||||
if (Flash_GetProductTimeLimit (&LimitTime, kExpirationTimeId) == READY)
|
||||
{
|
||||
// 计算出 到期时间对应的RTC秒数
|
||||
H308.expiration_seconds = DateTime2Seconds (LimitTime.Struct.year,
|
||||
LimitTime.Struct.month, LimitTime.Struct.day, LimitTime.Struct.hour,
|
||||
LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
LOG_D ("h308_expiration_time:%04d-%02d-%02d,%02d:%02d",
|
||||
LimitTime.Struct.year, LimitTime.Struct.month, LimitTime.Struct.day,
|
||||
LimitTime.Struct.hour, LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
}
|
||||
|
||||
if (Flash_GetNum_Records (kRecordSensoEndOfLife) == 1)
|
||||
{
|
||||
LOG_W ("寿命已到期");
|
||||
H308.end_of_life = 1;
|
||||
}
|
||||
// 寿命到期检测
|
||||
if (IS_H308_EndOfLife())
|
||||
{
|
||||
if (Flash_GetNum_Records (kRecordSensoEndOfLife) == 0)
|
||||
{
|
||||
Flash_Write_Record (kRecordSensoEndOfLife);
|
||||
}
|
||||
Send_Laser_Alarm_Event (kSensorFailureEvent);
|
||||
}
|
||||
// 检测上电/掉电复位标志
|
||||
if (RCC_GetFlagStatus (RCC_FLAG_PORRST) != RESET) // TODO:这块超级电容会造成掉电重启,并且标志是上电复位,只能通过其超级电容造成复位时事件创建失败进行判断,不治本
|
||||
{
|
||||
|
@ -474,12 +501,14 @@ static void SYS_Set_RtcProductTime(int argc, char **argv)
|
|||
LOG_E ("SYS_Set_RtcProductTime --use _cmd_ [2000 + y] [m] [d] [h] [m] [s]");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (SYS_Set_RtcProductTime, "SYS_Set_RtcProductTime");
|
||||
|
||||
static void SYS_SW_Version (void)
|
||||
{
|
||||
rt_kprintf ("JT-DT-YD4N02A Software version: V%02X\r\n", (uint8_t)Flash_Get_SysCfg (kSwVerId));
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (SYS_SW_Version, "软件版本");
|
||||
|
||||
#endif
|
||||
|
|
|
@ -253,7 +253,6 @@ rt_uint32_t IMEI_Delay(void)
|
|||
|
||||
int BSP_SYS_Init(void)
|
||||
{
|
||||
BSP_Flash_Init();
|
||||
BSP_RTC_Init();
|
||||
BSP_Rng_Init();
|
||||
BSP_WDG_Init();
|
||||
|
@ -262,10 +261,7 @@ int BSP_SYS_Init(void)
|
|||
BSP_BEEP_Init();
|
||||
BSP_EMV_Init();
|
||||
BSP_BUTTON_Init();
|
||||
BSP_H308_Init();
|
||||
BSP_HR_Init();
|
||||
nt26k_device_class_register();
|
||||
nt26k_device_register();
|
||||
BSP_Nt26k_Thread_Init();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,3 @@
|
|||
/***
|
||||
* @Author: mbw
|
||||
* @Date: 2024-10-09 08:42:14
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2024-12-30 16:30:57
|
||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\bsp\inc\at_device_nt26k.h
|
||||
* @Description:
|
||||
* @
|
||||
* @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-10-14 14:25:58
|
||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\bsp\inc\at_device_nt26k.h
|
||||
* @Description:
|
||||
* @
|
||||
* @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __AT_DEVICE_NT26K_H__
|
||||
#define __AT_DEVICE_NT26K_H__
|
||||
|
||||
|
@ -86,7 +65,6 @@ typedef struct __attribute__((packed))
|
|||
extern nt26k_sys_info nt26k;
|
||||
extern rt_uint8_t nt26k_init_complate_flag;
|
||||
extern struct rt_completion nt26k_init_complate;
|
||||
int nt26k_device_class_register(void);
|
||||
int at_send_data(struct at_device *device, const char *data, rt_size_t size);
|
||||
rt_err_t Nt26k_Reset(struct at_device *device);
|
||||
int Time_Calibration(struct at_device *device);
|
||||
|
|
|
@ -207,6 +207,5 @@ extern rt_sem_t nt26k_disconnect_sem;
|
|||
extern rt_uint8_t nt26k_conncet_tcp_flag;
|
||||
extern rt_uint8_t nt26k_disconnect_pdp_flag;
|
||||
extern rt_uint8_t power_on_send_flag;
|
||||
int nt26k_device_register(void);
|
||||
int BSP_Nt26k_Thread_Init(void);
|
||||
void Nt26k_Send_Event(Nt26kEvent event_type);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-09-04 13:33:49
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2025-01-13 09:46:29
|
||||
* @LastEditTime: 2025-01-15 09:27:15
|
||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\at_device_nt26k.c
|
||||
* @Description :
|
||||
*
|
||||
|
@ -760,7 +760,7 @@ static struct netdev *nt26k_netdev_add(const char *netdev_name)
|
|||
static void nt26k_init_thread_entry (void *parameter)
|
||||
{
|
||||
#define INIT_RETRY 5
|
||||
#define CPIN_RETRY 5
|
||||
#define CPIN_RETRY 10
|
||||
#define CSQ_RETRY 20
|
||||
#define CEREG_RETRY 50
|
||||
#define IPADDR_RETRY 10
|
||||
|
@ -787,8 +787,7 @@ static void nt26k_init_thread_entry(void *parameter)
|
|||
nt26k_power_off (device);
|
||||
rt_thread_mdelay (100);
|
||||
nt26k_power_on (device);
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
rt_thread_mdelay (100);
|
||||
/* wait nt26k startup finish, send AT every 500ms, if receive OK, SYNC success*/
|
||||
if (at_client_obj_wait_connect (client, NT26K_WAIT_CONNECT_TIME))
|
||||
{
|
||||
|
@ -811,12 +810,6 @@ static void nt26k_init_thread_entry(void *parameter)
|
|||
{
|
||||
LOG_D ("%s", at_resp_get_line (resp, i + 1));
|
||||
}
|
||||
// // AT+QSIMDET=0,1
|
||||
// if (at_obj_exec_cmd(device->client, resp, "AT+QSIMDET=0,1") != RT_EOK)
|
||||
// {
|
||||
// result = -RT_ERROR;
|
||||
// goto __exit;
|
||||
// }
|
||||
|
||||
/* disable sleep mode */
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+ECPMUCFG=1,0") != RT_EOK)
|
||||
|
@ -853,7 +846,25 @@ static void nt26k_init_thread_entry(void *parameter)
|
|||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
/* check SIM card */
|
||||
for (i = 0; i < CPIN_RETRY; i++)
|
||||
{
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+CPIN?") == RT_EOK)
|
||||
{
|
||||
if (at_resp_get_line_by_kw (resp, "+CPIN: READY") != RT_NULL)
|
||||
break;
|
||||
}
|
||||
rt_thread_mdelay (1000);
|
||||
}
|
||||
if (i == CPIN_RETRY)
|
||||
{
|
||||
LOG_E ("%s device SIM card detection failed.", device->name);
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
/* set network interface device hardware address(IMEI) */
|
||||
if ((*(rt_uint16_t *)FLASH_NB_IMEI_ADDR == 0xE339) || (*(rt_uint16_t *)FLASH_NB_IMEI_ADDR == 0x39E3)) // 未写入
|
||||
{
|
||||
#define NT26K_NETDEV_HWADDR_LEN 8
|
||||
#define NT26K_IMEI_LEN 15
|
||||
|
@ -875,45 +886,11 @@ static void nt26k_init_thread_entry(void *parameter)
|
|||
LOG_D ("%s device IMEI number: %s", device->name, imei);
|
||||
|
||||
rt_memcpy (nt26k.imei, imei, NT26K_IMEI_LEN);
|
||||
|
||||
}
|
||||
/* check SIM card */
|
||||
for (i = 0; i < CPIN_RETRY; i++)
|
||||
{
|
||||
if (at_obj_exec_cmd(device->client, resp, "AT+CPIN?") == RT_EOK)
|
||||
{
|
||||
if (at_resp_get_line_by_kw(resp, "+CPIN: READY") != RT_NULL)
|
||||
break;
|
||||
}
|
||||
rt_thread_mdelay(2000);
|
||||
}
|
||||
if (i == CPIN_RETRY)
|
||||
{
|
||||
LOG_E("%s device SIM card detection failed.", device->name);
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
/*网络注册 */
|
||||
for (i = 0; i < CSQ_RETRY; i++)
|
||||
{
|
||||
|
||||
if (at_obj_exec_cmd(device->client, resp, "AT+CREG=2") == RT_EOK)
|
||||
{
|
||||
if (at_resp_get_line_by_kw(resp, "OK") > 0)
|
||||
{
|
||||
LOG_D("%s device network registration success.", device->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
if (i == CSQ_RETRY)
|
||||
{
|
||||
LOG_D("%s device network registration failed.", device->name);
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
Flash_Sys_Cfg (kIotImeiId, nt26k.imei, NT26K_IMEI_LEN);
|
||||
}
|
||||
rt_thread_mdelay (1);
|
||||
/* set network interface device hardware iccid */
|
||||
if ((*(rt_uint16_t *)FLASH_NB_ICCID_ADDR == 0xE339) || (*(rt_uint16_t *)FLASH_NB_ICCID_ADDR == 0x39E3)) // 未写入
|
||||
{
|
||||
|
||||
#define NT26K_ICCID_LEN 20
|
||||
|
@ -936,10 +913,11 @@ static void nt26k_init_thread_entry(void *parameter)
|
|||
LOG_D ("%s device iccid number: %s", device->name, iccid);
|
||||
|
||||
rt_memcpy (nt26k.iccid, iccid, NT26K_ICCID_LEN);
|
||||
|
||||
Flash_Sys_Cfg (kIotIccidId, nt26k.iccid, NT26K_ICCID_LEN);
|
||||
}
|
||||
|
||||
rt_thread_mdelay (1);
|
||||
/* set network interface device hardware imsi */
|
||||
if ((*(rt_uint16_t *)FLASH_NB_IMSI_ADDR == 0xE339) || (*(rt_uint16_t *)FLASH_NB_IMSI_ADDR == 0x39E3)) // 未写入
|
||||
{
|
||||
|
||||
#define NT26K_IMSI_LEN 15
|
||||
|
@ -962,37 +940,58 @@ static void nt26k_init_thread_entry(void *parameter)
|
|||
LOG_D ("%s device imsi number: %s", device->name, imsi);
|
||||
|
||||
rt_memcpy (nt26k.imsi, imsi, NT26K_IMSI_LEN);
|
||||
|
||||
Flash_Sys_Cfg (kIotImsiId, nt26k.imsi, NT26K_IMSI_LEN);
|
||||
}
|
||||
|
||||
/* check signal strength */
|
||||
rt_thread_mdelay (1);
|
||||
/*网络注册 */
|
||||
for (i = 0; i < CSQ_RETRY; i++)
|
||||
{
|
||||
|
||||
if (at_obj_exec_cmd(device->client, resp, "AT+CSQ") == RT_EOK)
|
||||
if (at_obj_exec_cmd (device->client, resp, "AT+CREG=2") == RT_EOK)
|
||||
{
|
||||
int signal_strength = 0, err_rate = 0;
|
||||
|
||||
if (at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %d,%d", &signal_strength, &err_rate) > 0)
|
||||
if (at_resp_get_line_by_kw (resp, "OK") > 0)
|
||||
{
|
||||
if ((signal_strength != 99) && (signal_strength != 0))
|
||||
{
|
||||
LOG_D("%s device signal strength: %d, channel bit err_rate: %d",
|
||||
device->name, signal_strength, err_rate);
|
||||
nt26k.rssi = signal_strength;
|
||||
LOG_D ("%s device network registration success.", device->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rt_thread_mdelay (1000);
|
||||
}
|
||||
if (i == CSQ_RETRY)
|
||||
{
|
||||
LOG_E("%s device signal strength check failed", device->name);
|
||||
LOG_D ("%s device network registration failed.", device->name);
|
||||
result = -RT_ERROR;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
// /* check signal strength */
|
||||
// for (i = 0; i < CSQ_RETRY; i++)
|
||||
// {
|
||||
|
||||
// if (at_obj_exec_cmd(device->client, resp, "AT+CSQ") == RT_EOK)
|
||||
// {
|
||||
// int signal_strength = 0, err_rate = 0;
|
||||
|
||||
// if (at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %d,%d", &signal_strength, &err_rate) > 0)
|
||||
// {
|
||||
// if ((signal_strength != 99) && (signal_strength != 0))
|
||||
// {
|
||||
// LOG_D("%s device signal strength: %d, channel bit err_rate: %d",
|
||||
// device->name, signal_strength, err_rate);
|
||||
// nt26k.rssi = signal_strength;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// rt_thread_mdelay(1000);
|
||||
// }
|
||||
// if (i == CSQ_RETRY)
|
||||
// {
|
||||
// LOG_E("%s device signal strength check failed", device->name);
|
||||
// result = -RT_ERROR;
|
||||
// goto __exit;
|
||||
// }
|
||||
|
||||
/* check the GPRS network is registered */
|
||||
for (i = 0; i < CEREG_RETRY; i++)
|
||||
{
|
||||
|
@ -1062,9 +1061,6 @@ static void nt26k_init_thread_entry(void *parameter)
|
|||
result = RT_EOK;
|
||||
}
|
||||
}
|
||||
Flash_Sys_Cfg(kIotImsiId, nt26k.imsi, NT26K_IMSI_LEN);
|
||||
Flash_Sys_Cfg(kIotImeiId, nt26k.imei, NT26K_IMEI_LEN);
|
||||
Flash_Sys_Cfg(kIotIccidId, nt26k.iccid, NT26K_ICCID_LEN);
|
||||
/* initialize successfully */
|
||||
result = RT_EOK;
|
||||
break;
|
||||
|
@ -1424,7 +1420,7 @@ const struct at_device_ops nt26k_device_ops =
|
|||
nt26k_control,
|
||||
};
|
||||
|
||||
int nt26k_device_class_register(void)
|
||||
static int nt26k_device_class_register (void)
|
||||
{
|
||||
struct at_device_class *class = RT_NULL;
|
||||
|
||||
|
@ -1440,7 +1436,7 @@ int nt26k_device_class_register(void)
|
|||
return at_device_class_register (class, AT_DEVICE_CLASS_NT26K);
|
||||
}
|
||||
|
||||
// INIT_DEVICE_EXPORT(nt26k_device_class_register);
|
||||
INIT_DEVICE_EXPORT(nt26k_device_class_register);
|
||||
#endif //! IOT_MODULE_SWITCH
|
||||
|
||||
#endif /* AT_DEVICE_USING_NT26K */
|
||||
|
|
|
@ -640,9 +640,6 @@ void Flash_SetProductTimeLimit(rt_uint16_t year, rt_uint8_t mon, rt_uint8_t day,
|
|||
}
|
||||
|
||||
Flash_Write_ConfigInfo (page_buf);
|
||||
|
||||
TuFlashProductTimeLimitFrame ReadLimitTime;
|
||||
Flash_GetProductTimeLimit(&ReadLimitTime, id);
|
||||
}
|
||||
|
||||
void Set_ExpirationTime (rt_uint16_t days)
|
||||
|
@ -664,14 +661,6 @@ void Set_ExpirationTime(rt_uint16_t days)
|
|||
Flash_SetProductTimeLimit (DateTime.year, DateTime.month, DateTime.day,
|
||||
DateTime.hour, DateTime.minute, DateTime.second,
|
||||
kExpirationTimeId);
|
||||
|
||||
if (Flash_GetProductTimeLimit(&LimitTime, kExpirationTimeId) == READY)
|
||||
{
|
||||
LOG_D("到期时间:%04d-%02d-%02d,%02d:%02d:%02d",
|
||||
LimitTime.Struct.year, LimitTime.Struct.month,
|
||||
LimitTime.Struct.day, LimitTime.Struct.hour,
|
||||
LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -773,7 +762,6 @@ void BSP_Flash_EraseRecodrs(void)
|
|||
{
|
||||
Flash_ErasePage_Records (record, i);
|
||||
}
|
||||
// LOG_D("/**BSP_Flash_First_Init (%d)**/", record);
|
||||
}
|
||||
Flash_ErasePage_ConfigInfo();
|
||||
}
|
||||
|
@ -794,6 +782,15 @@ int BSP_Flash_Init(void)
|
|||
|
||||
Flash_Write (FLASH_INIT_FLAG_ADDR, flash_init_flag,
|
||||
sizeof (flash_init_flag));
|
||||
Flash_Set_WorkDuration (work_duration);
|
||||
LOG_D ("work_duration:%d", Flash_Get_WorkDuration());
|
||||
|
||||
Convert_To_Hex (&sever_info, sever_data);
|
||||
|
||||
if (Flash_Set_Sever_Data (sever_data) <= 0)
|
||||
{
|
||||
LOG_D ("Flash_Set_Sever_Data error!");
|
||||
}
|
||||
|
||||
Flash_SetProductTimeLimit (2025, 1, 10, 13, 50, 20, kFactoryTimeId);
|
||||
Set_ExpirationTime (MAX_EXPIRATION_DAYS);
|
||||
|
@ -808,27 +805,13 @@ int BSP_Flash_Init(void)
|
|||
sci.emagnetic_switch = SYS_EMV_SWITCH;
|
||||
sci.relay_switch = SYS_RELAY_SWITCH;
|
||||
|
||||
Flash_Set_WorkDuration(0);
|
||||
LOG_D("work_duration:%d", Flash_Get_WorkDuration());
|
||||
|
||||
Convert_To_Hex(&sever_info, sever_data);
|
||||
for (size_t i = 0; i < sizeof(sever_data); i++)
|
||||
{
|
||||
LOG_D("%02x", sever_data[i]);
|
||||
}
|
||||
|
||||
if (Flash_Set_Sever_Data(sever_data) <= 0)
|
||||
{
|
||||
LOG_D("Flash_Set_Sever_Data error!");
|
||||
}
|
||||
|
||||
Flash_Write (FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci,
|
||||
(sizeof (sys_config_info) - 50));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
// INIT_BOARD_EXPORT(BSP_Flash_Init);
|
||||
INIT_PREV_EXPORT (BSP_Flash_Init);
|
||||
#endif
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
|
@ -845,6 +828,7 @@ static void TEST_Flash_GetMaxIndex_Records(int argc, char **argv)
|
|||
LOG_E ("TEST_Flash_GetMaxIndex_Records --use _cmd_ [record](0~6)");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_GetMaxIndex_Records,
|
||||
"TEST_Flash_GetMaxIndex_Records");
|
||||
|
||||
|
@ -860,6 +844,7 @@ static void TEST_Flash_Erase_Records(int argc, char **argv)
|
|||
LOG_E ("TEST_Flash_Erase_Records --use _cmd_ [record](0~6)");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_Erase_Records, "TEST_Flash_Erase_Records");
|
||||
|
||||
static void TEST_Flash_Write_Record (int argc, char **argv)
|
||||
|
@ -880,6 +865,7 @@ static void TEST_Flash_Write_Record(int argc, char **argv)
|
|||
LOG_E ("TEST_Flash_Write_Record --use _cmd_ [record(0~6)] [num]");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_Write_Record, "TEST_Flash_Write_Record");
|
||||
|
||||
static void TEST_Flash_GetNum_Records (int argc, char **argv)
|
||||
|
@ -902,6 +888,7 @@ static void TEST_Flash_GetNum_Records(int argc, char **argv)
|
|||
LOG_E ("TEST_Flash_GetNum_Records --use _cmd_ [record](0~6)");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_GetNum_Records, "TEST_Flash_GetNum_Records");
|
||||
|
||||
static void TEST_Flash_GetProductTimeLimit (int argc, char **argv)
|
||||
|
@ -918,6 +905,7 @@ static void TEST_Flash_GetProductTimeLimit(int argc, char **argv)
|
|||
"TEST_Flash_GetProductTimeLimit --use _cmd_ [id(0:FACTORY; 1:EXPIRATION)]");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_GetProductTimeLimit,
|
||||
"TEST_Flash_GetProductTimeLimit");
|
||||
|
||||
|
@ -940,6 +928,7 @@ static void TEST_Flash_SetProductTimeLimit(int argc, char **argv)
|
|||
"TEST_Flash_SetProductTimeLimit --use _cmd_ [y] [m] [d] [h] [m] [s] [id(0:FACTORY; 1:EXPIRATION)]");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_SetProductTimeLimit,
|
||||
"TEST_Flash_SetProductTimeLimit");
|
||||
|
||||
|
@ -954,6 +943,7 @@ void Set_FactoryRtcTime(void)
|
|||
RtcDateTime.day, RtcDateTime.hour, RtcDateTime.minute,
|
||||
RtcDateTime.second, kFactoryTimeId);
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (Set_FactoryRtcTime, "Use RTC time Set_FactoryRtcTime");
|
||||
|
||||
static void TEST_Flash_Set_ExpirationTime (int argc, char **argv)
|
||||
|
@ -968,6 +958,7 @@ static void TEST_Flash_Set_ExpirationTime(int argc, char **argv)
|
|||
LOG_E ("TEST_Flash_Set_ExpirationTime --use _cmd_ [days]");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_Set_ExpirationTime, "TEST_Flash_Set_ExpirationTime");
|
||||
|
||||
static void TEST_Flash_Get_Sys_Info (int argc, char **argv)
|
||||
|
@ -982,6 +973,7 @@ static void TEST_Flash_Get_Sys_Info(int argc, char **argv)
|
|||
LOG_E ("TEST_Flash_Get_Sys_Info ");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (TEST_Flash_Get_Sys_Info, "TEST_Flash_Get_Sys_Info");
|
||||
|
||||
#endif
|
||||
|
|
|
@ -229,51 +229,61 @@ uint8_t IS_H308_EndOfLife(void)
|
|||
return H308.end_of_life;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UART4_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
USART_InitTypeDef USART_InitStructure = {0};
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
lwrb_init(&uart4_rx_rb, uart4_rx_rb_data, sizeof(uart4_rx_rb_data));
|
||||
|
||||
USART_DeInit(UART4); // 寄存器恢复默认值
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = 9600;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_Init(UART4, &USART_InitStructure);
|
||||
|
||||
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
USART_Cmd(UART4, ENABLE);
|
||||
LOG_I("UART4 Init");
|
||||
}
|
||||
|
||||
static void h308_thread_entry(void *param)
|
||||
{
|
||||
// strstr要用,静态的才能算正确偏移
|
||||
rt_err_t ret;
|
||||
static uint8_t str[UART4_RX_RB_LENGTH] = {0};
|
||||
static uint8_t h308_rx_timout_cnt = 0;
|
||||
static uint8_t h308_err_cnt = 0;
|
||||
|
||||
rt_err_t ret;
|
||||
|
||||
H308.alarm_value = Flash_Get_SysCfg(kAlarmLValueId); // 获取系统报警阈值
|
||||
LOG_D("报警阈值:%d", H308.alarm_value);
|
||||
LOG_D("h308_thread_entry");
|
||||
LOG_D("报警阈值:%d%LEL", H308.alarm_value);
|
||||
|
||||
H308_PWR_OFF;
|
||||
rt_thread_mdelay(1000);
|
||||
H308_PWR_ON;
|
||||
|
||||
TuFlashProductTimeLimitFrame LimitTime;
|
||||
if (Flash_GetProductTimeLimit(&LimitTime, kExpirationTimeId) == READY)
|
||||
{
|
||||
// 计算出 到期时间对应的RTC秒数
|
||||
H308.expiration_seconds = DateTime2Seconds(LimitTime.Struct.year,
|
||||
LimitTime.Struct.month, LimitTime.Struct.day, LimitTime.Struct.hour,
|
||||
LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
LOG_D("h308_expiration_time:%04d-%02d-%02d,%02d:%02d",
|
||||
LimitTime.Struct.year, LimitTime.Struct.month, LimitTime.Struct.day,
|
||||
LimitTime.Struct.hour, LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
}
|
||||
|
||||
if (Flash_GetNum_Records(kRecordSensoEndOfLife) == 1)
|
||||
{
|
||||
LOG_W("寿命已到期");
|
||||
H308.end_of_life = 1;
|
||||
}
|
||||
//这里应该等下iot模组更新网络,不然可能不准确,但如果从未更新时,截至日期小于1天才会有影响,所以可不等待
|
||||
rt_thread_mdelay(5000);//这里等的原因是,等待4G更新网络,其二是传感器需要10s的启动时间
|
||||
// 寿命到期检测
|
||||
if (IS_H308_EndOfLife())
|
||||
{
|
||||
if (Flash_GetNum_Records(kRecordSensoEndOfLife) == 0)
|
||||
{
|
||||
Flash_Write_Record(kRecordSensoEndOfLife);
|
||||
}
|
||||
Send_Laser_Alarm_Event(kSensorFailureEvent);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
ret = rt_sem_take(uart4_rx_ok_sem, 3000);
|
||||
|
@ -285,7 +295,7 @@ static void h308_thread_entry(void *param)
|
|||
|
||||
if (len >= 44)
|
||||
{
|
||||
ret = H308_GetFrameData(str, len, &H308.Data);
|
||||
ret = H308_GetFrameData((const char *)str, len, &H308.Data);
|
||||
LOG_I("str:[%s]", str);
|
||||
if (ret == 0)
|
||||
{
|
||||
|
@ -335,57 +345,12 @@ static void h308_thread_entry(void *param)
|
|||
}
|
||||
}
|
||||
|
||||
void UART4_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||
USART_InitTypeDef USART_InitStructure = {0};
|
||||
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||
|
||||
lwrb_init(&uart4_rx_rb, uart4_rx_rb_data, sizeof(uart4_rx_rb_data));
|
||||
|
||||
USART_DeInit(UART4); // 寄存器恢复默认值
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = 9600;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_Init(UART4, &USART_InitStructure);
|
||||
|
||||
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
USART_Cmd(UART4, ENABLE);
|
||||
LOG_I("UART4 Init");
|
||||
}
|
||||
|
||||
int BSP_H308_Init(void)
|
||||
{
|
||||
UART4_Init();
|
||||
|
||||
rt_pin_mode(H308_PWR_PIN, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(H308_RST_PIN, PIN_MODE_OUTPUT);
|
||||
H308_PWR_OFF;
|
||||
H308_RST_OFF;
|
||||
H308_PWR_ON;
|
||||
|
||||
uart4_rx_ok_sem = rt_sem_create("uart4_rx", 0, RT_IPC_FLAG_FIFO);
|
||||
if (uart4_rx_ok_sem == RT_NULL)
|
||||
|
@ -398,7 +363,7 @@ int BSP_H308_Init(void)
|
|||
{
|
||||
LOG_E("uart4_rx_timer create failed");
|
||||
}
|
||||
|
||||
UART4_Init();
|
||||
rt_err_t ret = rt_thread_init(&h308_thread,
|
||||
"h308_thread",
|
||||
h308_thread_entry,
|
||||
|
@ -419,7 +384,7 @@ int BSP_H308_Init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
// INIT_PREV_EXPORT(BSP_H308_Init);
|
||||
INIT_PREV_EXPORT(BSP_H308_Init);
|
||||
|
||||
void UART4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void UART4_IRQHandler(void)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @Author : stark1898y 1658608470@qq.com
|
||||
* @Date : 2024-09-04 17:33:57
|
||||
* @LastEditors: mbw && 1600520629@qq.com
|
||||
* @LastEditTime: 2025-01-13 09:30:42
|
||||
* @LastEditTime: 2025-01-15 08:53:20
|
||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_hr.c
|
||||
* @Description :
|
||||
*
|
||||
|
@ -36,7 +36,6 @@ static lwrb_t uart5_tx_rb;
|
|||
static rt_uint8_t uart5_tx_rb_data[UART5_TX_RB_LENGTH];
|
||||
|
||||
static rt_sem_t uart5_rx_ok_sem;
|
||||
static rt_sem_t uart5_rx_parity_err_sem;
|
||||
|
||||
static rt_timer_t uart5_timer;
|
||||
uint8_t hr_rx_flag = 0; // 接收缓冲区中,已经收到的数据包数量
|
||||
|
@ -492,22 +491,16 @@ int Process_Factor_Cmd(rt_uint8_t cmd)
|
|||
static void hr_thread_entry(void *param)
|
||||
{
|
||||
LOG_D("hr_thread_entry");
|
||||
uint8_t rx_buff[64] = {0};
|
||||
char rx_buff[64] = {0};
|
||||
lwrb_reset(&uart5_rx_rb);
|
||||
lwrb_reset(&uart5_tx_rb);
|
||||
|
||||
while (1)
|
||||
{
|
||||
rt_sem_take(uart5_rx_ok_sem, RT_WAITING_FOREVER);
|
||||
if (rt_sem_trytake(uart5_rx_parity_err_sem) == 0)
|
||||
{
|
||||
LOG_D("uart5_rx_parity_err_sem");
|
||||
lwrb_free(&uart5_rx_rb);
|
||||
continue;
|
||||
}
|
||||
uint8_t len = lwrb_get_full(&uart5_rx_rb);
|
||||
lwrb_read(&uart5_rx_rb, rx_buff, len);
|
||||
LOG_HEX("hr_rx_data:", 16, &rx_buff[0], len);
|
||||
|
||||
|
||||
if (rt_strstr(rx_buff, "[getParameter]") != RT_NULL)
|
||||
{
|
||||
|
@ -522,7 +515,7 @@ static void hr_thread_entry(void *param)
|
|||
{
|
||||
if (len >= HOST_FRAME_MIN_LEN)
|
||||
{
|
||||
TsFrameData *HostFrameData = HR_GetFrameData(rx_buff, len);
|
||||
TsFrameData *HostFrameData = HR_GetFrameData((rt_uint8_t *)rx_buff, len);
|
||||
if (HostFrameData != RT_NULL)
|
||||
{
|
||||
LOG_HEX("HostFrameData", 16, &HostFrameData->data[0], HostFrameData->len); // 数据段
|
||||
|
@ -534,6 +527,7 @@ static void hr_thread_entry(void *param)
|
|||
}
|
||||
}
|
||||
lwrb_reset(&uart5_rx_rb);
|
||||
LOG_HEX("hr_rx_data:", 16, (rt_uint8_t *)&rx_buff[0], len);
|
||||
rt_memset(rx_buff, 0, len);
|
||||
}
|
||||
}
|
||||
|
@ -594,12 +588,6 @@ int BSP_HR_Init(void)
|
|||
{
|
||||
LOG_E("uart5_rx_ok_sem create failed");
|
||||
}
|
||||
uart5_rx_parity_err_sem = rt_sem_create("uart5_rx_pe", 0, RT_IPC_FLAG_PRIO);
|
||||
if (uart5_rx_parity_err_sem == RT_NULL)
|
||||
{
|
||||
LOG_E("uart5_rx_parity_err_sem create failed");
|
||||
}
|
||||
|
||||
uart5_timer = rt_timer_create("uart5_timeout", uart5_timeout, RT_NULL, 50, RT_TIMER_FLAG_PERIODIC);
|
||||
if (uart5_timer == RT_NULL)
|
||||
{
|
||||
|
@ -634,10 +622,7 @@ void UART5_IRQHandler(void)
|
|||
GET_INT_SP();
|
||||
rt_interrupt_enter();
|
||||
unsigned char data;
|
||||
if (USART_GetITStatus(UART5, USART_IT_PE) != RESET)
|
||||
{
|
||||
rt_sem_release(uart5_rx_parity_err_sem);
|
||||
}
|
||||
|
||||
if (USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
|
||||
{
|
||||
data = USART_ReceiveData(UART5);
|
||||
|
|
|
@ -1574,7 +1574,7 @@ int BSP_Nt26k_Thread_Init (void)
|
|||
|
||||
// INIT_APP_EXPORT(BSP_Nt26k_Thread_Init);
|
||||
|
||||
int nt26k_device_register (void)
|
||||
static int nt26k_device_register (void)
|
||||
{
|
||||
struct at_device_nt26k *nt26k = &_dev;
|
||||
|
||||
|
@ -1585,6 +1585,6 @@ int nt26k_device_register (void)
|
|||
(void *)nt26k);
|
||||
}
|
||||
|
||||
// INIT_COMPONENT_EXPORT(nt26k_device_register);
|
||||
INIT_COMPONENT_EXPORT(nt26k_device_register);
|
||||
|
||||
#endif // IOT_MODULE_SWITCH
|
||||
|
|
Loading…
Reference in New Issue