From 2382c82730c454eee977c8f65b767f978d7c24bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E9=A9=AC=5F666?=
<13089258+pony-six-hundred-and-sixty-six@user.noreply.gitee.com>
Date: Wed, 8 Jan 2025 11:43:58 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=89=80=E6=9C=89NB=E5=92=8C4g?=
=?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=AF=8D=E6=94=B9=E4=B8=BAIot,=E5=B9=B6?=
=?UTF-8?q?=E5=9C=A8=E6=AF=8F=E6=AC=A1=E4=B8=8A=E6=8A=A5=E6=97=B6=E5=8A=A0?=
=?UTF-8?q?=E4=BA=86=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA,=E4=BB=A5?=
=?UTF-8?q?=E5=8F=8A=E7=A7=80=E5=98=8E=E4=BA=86=E5=8F=91=E9=80=81=E9=80=BB?=
=?UTF-8?q?=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.cproject | 848 +++++++++---
.mrs/JT-DT-YD4N02A_RTT_MRS-4G.mrs-workspace | 26 +
.mrs/launch.json | 65 +
.project | 67 +-
.template | 7 +-
JT-DT-YD4N02A_RTT_MRS-4G.launch | 62 +
JT-DT-YD4N02A_RTT_MRS-4G.wvproj | 866 +++++++++++-
applications/main.c | 51 +-
applications/user_sys.c | 2 +-
applications/user_sys.h | 2 +-
bsp/inc/bsp_flash.h | 26 +-
bsp/inc/bsp_rtc.h | 4 +-
bsp/src/at_device_nt26k.c | 1378 +++++++++----------
bsp/src/bsp_flash.c | 38 +-
bsp/src/bsp_h308.c | 10 +-
bsp/src/bsp_hr.c | 12 +-
bsp/src/bsp_led.c | 9 +-
bsp/src/bsp_nt26k.c | 104 +-
bsp/src/bsp_rtc.c | 9 +-
libcpu/cpu/cpuport.c | 2 +-
20 files changed, 2441 insertions(+), 1147 deletions(-)
create mode 100644 .mrs/JT-DT-YD4N02A_RTT_MRS-4G.mrs-workspace
create mode 100644 .mrs/launch.json
create mode 100644 JT-DT-YD4N02A_RTT_MRS-4G.launch
diff --git a/.cproject b/.cproject
index 847ec5a..82ae2e4 100644
--- a/.cproject
+++ b/.cproject
@@ -1,201 +1,651 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.mrs/JT-DT-YD4N02A_RTT_MRS-4G.mrs-workspace b/.mrs/JT-DT-YD4N02A_RTT_MRS-4G.mrs-workspace
new file mode 100644
index 0000000..de77c58
--- /dev/null
+++ b/.mrs/JT-DT-YD4N02A_RTT_MRS-4G.mrs-workspace
@@ -0,0 +1,26 @@
+{
+ "folders": [
+ {
+ "path": "."
+ },
+ {
+ "name": "JT-DT-YD4N02A_RTT_MRS-4G",
+ "path": "../"
+ }
+ ],
+ "settings": {
+ "mrs.workspace.type": "project",
+ "files.associations": {
+ "*.c": "c",
+ "*.h": "cpp",
+ "*.hxx": "cpp",
+ "*.hpp": "cpp",
+ "*.c++": "cpp",
+ "*.cpp": "cpp",
+ "*.cxx": "cpp",
+ "*.cc": "cpp",
+ "*.hh": "cpp",
+ "*.h++": "cpp"
+ }
+ }
+}
\ No newline at end of file
diff --git a/.mrs/launch.json b/.mrs/launch.json
new file mode 100644
index 0000000..e193649
--- /dev/null
+++ b/.mrs/launch.json
@@ -0,0 +1,65 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "mrs-debugger",
+ "request": "launch",
+ "name": "JT-DT-YD4N02A_RTT_MRS-4G",
+ "cwd": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-4G",
+ "openOCDCfg": {
+ "useLocalOpenOCD": true,
+ "executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
+ "configOptions": [
+ "-f \"c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/wch-riscv.cfg\" -c \"chip_id CH32V30x\""
+ ],
+ "gdbport": 3333,
+ "telnetport": 4444,
+ "tclport": 6666,
+ "host": "localhost",
+ "port": 3333,
+ "skipDownloadBeforeDebug": false,
+ "enablePageEraser": false,
+ "enableNoZeroWaitingAreaFlash": false
+ },
+ "gdbCfg": {
+ "executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/Toolchain/RISC-V Embedded GCC12/bin/riscv-wch-elf-gdb.exe",
+ "commands": [
+ "set mem inaccessible-by-default off",
+ "set architecture riscv:rv32",
+ "set remotetimeout unlimited",
+ "set disassembler-options xw"
+ ],
+ "options": []
+ },
+ "startup": {
+ "initCommands": {
+ "initReset": true,
+ "initResetType": "init",
+ "armSemihosting": false,
+ "additionalCommands": []
+ },
+ "loadedFiles": {
+ "executableFile": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-4G\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf",
+ "symbolFile": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-4G\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf",
+ "executableFileOffset": 0,
+ "symbolFileOffset": 0
+ },
+ "runCommands": {
+ "runReset": true,
+ "runResetType": "halt",
+ "additionalCommands": [],
+ "setBreakAt": "handle_reset",
+ "continue": true,
+ "setProgramCounterAt": 0
+ },
+ "debugInRAM": false
+ },
+ "svdpath": "c:\\MounRiver\\MounRiver_Studio2\\resources\\app\\resources\\win32\\components\\WCH\\SDK\\default/RISC-V/CH32V307/NoneOS/CH32V307xx.svd",
+ "output": {
+ "showDebugGDBTrace": true,
+ "saveDebugOutputToFile": false,
+ "showDebugOutputTimestamps": true
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.project b/.project
index cb5fa3a..76bc70e 100644
--- a/.project
+++ b/.project
@@ -1,37 +1,34 @@
- JT-DT-YD4N02A_RTT_MRS-4G
-
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
-
-
-
- 1595986042669
-
- 22
-
- org.eclipse.ui.ide.multiFilter
- 1.0-name-matches-false-false-*.wvproj
-
-
-
-
+ JT-DT-YD4N02A_RTT_MRS-4G
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
+
+
+
+ 6
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.wvproj
+
+
+
+
\ No newline at end of file
diff --git a/.template b/.template
index b0cd872..106833f 100644
--- a/.template
+++ b/.template
@@ -9,10 +9,15 @@ Description============ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO POR
Mcu Type=CH32V30x
Address=0x08000000
Target Path=obj\JT-DT-YD4N02A_RTT_MRS-4G.hex
+Exe Path=
+Exe Arguments=
CLKSpeed=1
-DebugInterfaceMode=-1
+DebugInterfaceMode=0
Erase All=true
Program=true
Verify=true
Reset=true
SDIPrintf=false
+Disable Power Output=false
+Clear CodeFlash=false
+Disable Code-Protect=false
\ No newline at end of file
diff --git a/JT-DT-YD4N02A_RTT_MRS-4G.launch b/JT-DT-YD4N02A_RTT_MRS-4G.launch
new file mode 100644
index 0000000..aa24d59
--- /dev/null
+++ b/JT-DT-YD4N02A_RTT_MRS-4G.launch
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JT-DT-YD4N02A_RTT_MRS-4G.wvproj b/JT-DT-YD4N02A_RTT_MRS-4G.wvproj
index 2cd99d9..0e92a81 100644
--- a/JT-DT-YD4N02A_RTT_MRS-4G.wvproj
+++ b/JT-DT-YD4N02A_RTT_MRS-4G.wvproj
@@ -1,2 +1,864 @@
-iCZ ?"ǁrF<.ſ?/XOĿChQN$*EBk!2t+buhnUb]xll|
-+" 10000)
{
+ SYS_EventInit();
BSP_SYS_Init();
// 读取历史记录总数
Flash_GetTotalRecord(&TotalRecords);
- SYS_EventInit();
work_duration = Flash_Get_WorkDuration();
rt_timer_init(&work_cnt_timer,
"work_cnt_timer",
@@ -205,9 +212,8 @@ int main(void)
// 检测上电/掉电复位标志
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) // TODO:这块超级电容会造成掉电重启,并且标志是上电复位,只能通过其超级电容造成复位时事件创建失败进行判断,不治本
{
- Send_Laser_Alarm_Event(kPowerOnEvent);
- TotalRecords.power_on++;
RCC_ClearFlag();
+ Send_Laser_Alarm_Event(kPowerOnEvent);
}
else
{
@@ -217,9 +223,10 @@ int main(void)
else
{
LOG_D("欠压复位\r\n");
+ RCC_ClearFlag();
NVIC_SystemReset(); // 直接重启系统
+
}
-
while (1)
{
if (is_event_initialized)
@@ -262,13 +269,22 @@ int main(void)
LED_G_PREAT;
BEEP_PREAT_OK;
Send_Laser_Alarm_Event(kNormalDetectionEvents);
- // Preheat_Sensor(0);//先改成闪烁一下直接进入正常检测模式
}
else if (received_event & Get_Sys_Event_Flag(kNormalDetectionEvents)) // 正常检测
{
SysControl.last_status = SysControl.status;
SysControl.status = kNormalDetectionEvents;
+ if (SysControl.last_status == kSelfCheckEvent)
+ {
+ rt_thread_mdelay(5000);
+ LOG_I("自检电磁阀动作");
+ EMV_CLOSE_VALVE;
+ LOG_I("自检风机动作");
+ relay_state_flag = 1;
+ rt_thread_mdelay(500);
+ relay_state_flag = 0;
+ }
if (H308.detection_flag == kH308Alarm)
{
LED_G_NORMAL;
@@ -289,16 +305,6 @@ int main(void)
{
LOG_D("正常检测模式");
}
- if (SysControl.last_status == kSelfCheckEvent)
- {
- rt_thread_mdelay(5000);
- LOG_I("自检电磁阀动作");
- EMV_CLOSE_VALVE;
- LOG_I("自检风机动作");
- relay_state_flag = 1;
- rt_thread_mdelay(500);
- relay_state_flag = 0;
- }
}
else if (received_event & Get_Sys_Event_Flag(kAlarmExceptionEvent)) // 浓度异常
{
@@ -336,7 +342,6 @@ int main(void)
Flash_Write_Record(kRecordAlarmRcy);
- // BSP_Set_Relay_Status(0);
relay_state_flag = 0;
BEEP_STOP;
@@ -349,7 +354,7 @@ int main(void)
else if (received_event & Get_Sys_Event_Flag(kFaultEvent)) // 故障
{
LOG_D("故障模式");
- if (Flash_GetNum_Records(kRecordSensoEndOfLife) != 1)
+ if (Flash_GetNum_Records(kRecordSensoEndOfLife) != 1)//当设备失效时,只上报设备失效的故障,其他故障不上报
{
SysControl.last_status = SysControl.status;
SysControl.status = kFaultEvent;
@@ -404,7 +409,7 @@ int main(void)
#if (IOT_MODULE_SWITCH == 1)
Nt26k_Send_Event(kNt26kPowerDownEvent);
#endif
- // 等待30s,要是还没断电就重启
+ // 等待20s,要是还没断电就重启
for (uint8_t i = 0; i < 20; i++)
{
rt_thread_mdelay(1000);
@@ -417,7 +422,6 @@ int main(void)
LOG_D("自检模式");
SysControl.last_status = SysControl.status;
- LOG_D("Self Check Mode SysControl.last_status:%d", SysControl.last_status);
SysControl.status = kSelfCheckEvent;
_Self_Check_Mode();
@@ -437,7 +441,6 @@ int main(void)
{
Flash_Write_Record(kRecordSensoEndOfLife);
}
-// BEEP_END_OF_LIFE;
LED_Y_END_OF_LIFE;
}
}
@@ -480,7 +483,7 @@ 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));
+ rt_kprintf("JT-DT-YD4N02A Software version: V%02X\r\n", (uint8_t)Flash_Get_SysCfg(kSwVerId));
}
MSH_CMD_EXPORT(SYS_SW_Version, "软件版本");
diff --git a/applications/user_sys.c b/applications/user_sys.c
index 0055f07..3221f10 100644
--- a/applications/user_sys.c
+++ b/applications/user_sys.c
@@ -235,7 +235,7 @@ rt_uint32_t IMEI_Delay(void)
rt_uint32_t imei_delay = 0;
unsigned int random_number = 0;
- Get_Nb_Imei(imei_str, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei_str, FLASH_NB_IMEI_LEN);
// 提取 IMEI 的最后 5 位作为种子
rt_strncpy(randon_char, &imei_str[0] + FLASH_NB_IMEI_LEN - 5, 5);
random_number = atoi(randon_char);
diff --git a/applications/user_sys.h b/applications/user_sys.h
index 5a84b57..1125062 100644
--- a/applications/user_sys.h
+++ b/applications/user_sys.h
@@ -19,7 +19,7 @@
#define SYS_HW_VERSION 0X10
#define SYS_SW_VERSION 0X13
-#define SYS_IOT_UPLOAD_CYCLE_MIN (0X3C00) // 高位在前,低位在后
+#define SYS_IOT_UPLOAD_CYCLE_MIN (0X0A00) // 高位在前,低位在后
#define SYS_ALARM_VALVE 0X0A
#define SYS_IOT_URL "8.130.117.149"
#define SYS_IOT_PORT "7137"
diff --git a/bsp/inc/bsp_flash.h b/bsp/inc/bsp_flash.h
index 224db22..4281866 100644
--- a/bsp/inc/bsp_flash.h
+++ b/bsp/inc/bsp_flash.h
@@ -220,14 +220,14 @@ typedef enum
kSwVerId,
kAlarmLValueId,
kAlarmHValueId,
- kNbUploadCycleId,
- kNbRetryId,
+ kIotUploadCycleId,
+ kIotRetryId,
kTempAlarmThresholdId, // 温度报警阈值
kEmagneticSwitchId, // 电磁阀功能开启
kRelaySwitchId, // 继电器功能开启
- kNbImeiId,
- kNbImsiId,
- kNbIccidId,
+ kIotImeiId,
+ kIotImsiId,
+ kIotIccidId,
kCnt
} TeFlashCfgInfoId;
@@ -239,13 +239,13 @@ typedef struct __attribute__((packed))
rt_uint8_t alarm_l_value; // 报警低阈值
rt_uint8_t alarm_h_value; // 报警高阈值
rt_uint8_t temp_alarm_threshold;//温度报警阈值
- rt_uint16_t nb_upload_cycle; // NB上传周期
- rt_uint8_t nb_retry; // 重试次数
+ rt_uint16_t iot_upload_cycle; // NB上传周期
+ rt_uint8_t iot_retry; // 重试次数
rt_uint8_t emagnetic_switch;
rt_uint8_t relay_switch;
- rt_uint8_t nb_imei[15]; // IMEI
- rt_uint8_t nb_imsi[15]; // IMSI
- rt_uint8_t nb_iccid[20]; // ICCID
+ rt_uint8_t iot_imei[15]; // IMEI
+ rt_uint8_t iot_imsi[15]; // IMSI
+ rt_uint8_t iot_iccid[20]; // ICCID
} sys_config_info;
struct flash_sever_info
@@ -255,9 +255,9 @@ struct flash_sever_info
};
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);
-int Get_Nb_Iccid(char *buf, rt_size_t len);
+int Get_IotImei(char *buf, rt_size_t len);
+int Get_IotImsi(char *buf, rt_size_t len);
+int Get_IotIccid(char *buf, rt_size_t len);
rt_uint8_t Flash_GetNum_Records(TeRecord record);
diff --git a/bsp/inc/bsp_rtc.h b/bsp/inc/bsp_rtc.h
index 7cac0c9..4cb25de 100644
--- a/bsp/inc/bsp_rtc.h
+++ b/bsp/inc/bsp_rtc.h
@@ -20,7 +20,7 @@ typedef struct __attribute__((packed))
{
uint16_t year; // 年份设置,取值范围为
uint8_t month; // 日期设置,取值范围为1~31
- uint8_t day; // 月份设置,取值范围为1~12
+ uint16_t day; // 月份设置,取值范围为1~12
uint8_t hour; /* 小时设置 */
uint8_t minute; /* 分钟设置 */
@@ -39,7 +39,7 @@ void RTC_GetTime(void);
uint8_t RTC_GetWeek(uint16_t year, uint8_t month, uint8_t day);
void RTC_SetTime(rt_uint16_t syear, rt_uint8_t smon
, rt_uint8_t sday, rt_uint8_t hour, rt_uint8_t min, rt_uint8_t sec);
-
+void RTC_ShowTime(void);
int BSP_RTC_Init(void);
void Timestamp_To_Rtc_DateTime(time_t timestamp, TsRtcDateTime *rtc_dt);
#endif //!__BSP_RTC_H__
diff --git a/bsp/src/at_device_nt26k.c b/bsp/src/at_device_nt26k.c
index 1673a9d..2b80e49 100644
--- a/bsp/src/at_device_nt26k.c
+++ b/bsp/src/at_device_nt26k.c
@@ -2,7 +2,7 @@
* @Author : stark1898y 1658608470@qq.com
* @Date : 2024-09-04 13:33:49
* @LastEditors: mbw && 1600520629@qq.com
- * @LastEditTime: 2025-01-05 17:26:10
+ * @LastEditTime: 2025-01-07 15:39:42
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\bsp\src\at_device_nt26k.c
* @Description :
*
@@ -17,8 +17,7 @@
* Date Author Notes
* 2019-12-13 qiyongzhong first version
*/
-
-#include
+// #include
#include
#include "bsp_flash.h"
#include
@@ -34,16 +33,16 @@
#if IOT_MODULE_SWITCH == 1
-#define NT26K_POWER_OFF RT_FALSE
-#define NT26K_POWER_ON RT_TRUE
-#define NT26K_POWER_ON_TIME 3
-#define NT26K_POWER_OFF_TIME 4
+#define NT26K_POWER_OFF RT_FALSE
+#define NT26K_POWER_ON RT_TRUE
+#define NT26K_POWER_ON_TIME 3
+#define NT26K_POWER_OFF_TIME 4
#define AT_CLIENT_RECV_BUFF_LEN 512
-#define AT_DEFAULT_TIMEOUT 5000
+#define AT_DEFAULT_TIMEOUT 5000
#ifdef AT_DEVICE_USING_NT26K
#define NT26K_WAIT_CONNECT_TIME 5000
#define NT26K_THREAD_STACK_SIZE 4096
-#define NT26K_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 2)
+#define NT26K_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 2)
char data_buf[AT_CLIENT_RECV_BUFF_LEN] = {0};
@@ -52,410 +51,373 @@ nt26k_sys_info nt26k = {0};
struct rt_completion nt26k_init_complate;
volatile rt_uint8_t socket_id = 0;
-rt_err_t Nt26k_Reset(struct at_device *device)
-{
- LOG_I("NT26K Reset");
- rt_pin_mode(NT26K_RST_PIN, PIN_MODE_OUTPUT);
- rt_pin_write(NT26K_RST_PIN, PIN_LOW);
- rt_thread_mdelay(10);
- rt_pin_write(NT26K_RST_PIN, PIN_HIGH);
- rt_thread_mdelay(50);
- rt_pin_write(NT26K_RST_PIN, PIN_LOW);
+// 将本地时间转换为对应时区时间
+void Time_Zone_Conversion (TsRtcDateTime *timeInfo) {
+ // 根据时区差异进行转换,这里时区差为8小时,没有分钟差异。
+ timeInfo->hour += RT_LIBC_DEFAULT_TIMEZONE; // 小时部分加8小时
+ if (timeInfo->hour >= 24) { // 如果超过24小时,则天数加1,小时数减24。
+ timeInfo->day++;
+ timeInfo->hour -= 24;
+ if (timeInfo->day > 365) {
+ timeInfo->year += 1;
+ }
+ }
+}
+
+rt_err_t Nt26k_Reset (struct at_device *device) {
+ LOG_I ("NT26K Reset");
+ rt_pin_mode (NT26K_RST_PIN, PIN_MODE_OUTPUT);
+ rt_pin_write (NT26K_RST_PIN, PIN_LOW);
+ rt_thread_mdelay (10);
+ rt_pin_write (NT26K_RST_PIN, PIN_HIGH);
+ rt_thread_mdelay (50);
+ rt_pin_write (NT26K_RST_PIN, PIN_LOW);
return RT_EOK;
}
-static int nt26k_power_on(struct at_device *device)
-{
- struct at_device_nt26k *nt26k = RT_NULL;
-
- nt26k = (struct at_device_nt26k *)device->user_data;
- nt26k->power_status = RT_TRUE;
-
- /* not nead to set pin configuration for nt26k device power on */
- if (nt26k->pwr_en_pin == -1)
- {
- return (RT_EOK);
- }
-
- rt_pin_write(nt26k->pwr_en_pin, PIN_LOW);
- rt_thread_mdelay(10);
- rt_pin_write(nt26k->pwr_en_pin, PIN_HIGH);
- return (RT_EOK);
-}
-
-static rt_err_t nt26k_power_off(struct at_device *device)
-{
+static int nt26k_power_on (struct at_device *device) {
struct at_device_nt26k *nt26k = RT_NULL;
nt26k = (struct at_device_nt26k *)device->user_data;
- if (nt26k->power_status != RT_FALSE)
- {
- rt_pin_mode(nt26k->pwr_en_pin, PIN_MODE_OUTPUT);
- rt_pin_write(nt26k->pwr_en_pin, PIN_HIGH);
+ nt26k->power_status = RT_TRUE;
+
+ /* not nead to set pin configuration for nt26k device power on */
+ if (nt26k->pwr_en_pin == -1) {
+ return (RT_EOK);
+ }
+
+ rt_pin_write (nt26k->pwr_en_pin, PIN_LOW);
+ rt_thread_mdelay (10);
+ rt_pin_write (nt26k->pwr_en_pin, PIN_HIGH);
+ return (RT_EOK);
+}
+
+static rt_err_t nt26k_power_off (struct at_device *device) {
+ struct at_device_nt26k *nt26k = RT_NULL;
+
+ nt26k = (struct at_device_nt26k *)device->user_data;
+ if (nt26k->power_status != RT_FALSE) {
+ rt_pin_mode (nt26k->pwr_en_pin, PIN_MODE_OUTPUT);
+ rt_pin_write (nt26k->pwr_en_pin, PIN_HIGH);
}
return RT_EOK;
}
#ifdef TEST_ENABLE
-void TEST_Nt26k_Reset()
-{
- Nt26k_Reset(RT_NULL);
+void TEST_Nt26k_Reset() {
+ Nt26k_Reset (RT_NULL);
}
-MSH_CMD_EXPORT(TEST_Nt26k_Reset, "test_nt26k_reset");
+
+MSH_CMD_EXPORT (TEST_Nt26k_Reset, "test_nt26k_reset");
#endif
-static int nt26k_sleep(struct at_device *device)
-{
- at_response_t resp = RT_NULL;
+static int nt26k_sleep (struct at_device *device) {
+ at_response_t resp = RT_NULL;
struct at_device_nt26k *nt26k = RT_NULL;
nt26k = (struct at_device_nt26k *)device->user_data;
- if (!nt26k->power_status) // power off
+ if (!nt26k->power_status) // power off
{
return (RT_EOK);
}
- if (nt26k->sleep_status) // is sleep status
+ if (nt26k->sleep_status) // is sleep status
{
return (RT_EOK);
}
- resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
- if (resp == RT_NULL)
- {
- LOG_D("no memory for resp create.");
- at_delete_resp(resp);
+ resp = at_create_resp (64, 0, rt_tick_from_millisecond (300));
+ if (resp == RT_NULL) {
+ LOG_D ("no memory for resp create.");
+ at_delete_resp (resp);
return (-RT_ERROR);
}
/* enable sleep mode */
// Sleep1
- if (at_obj_exec_cmd(device->client, resp, "AT+ECPMUCFG=1,2") != RT_EOK)
+ if (at_obj_exec_cmd (device->client, resp, "AT+ECPMUCFG=1,2") != RT_EOK)
{
- LOG_D("enable sleep fail.\"AT+ECPMUCFG=1,2\" execute fail.");
- at_delete_resp(resp);
+ LOG_D ("enable sleep fail.\"AT+ECPMUCFG=1,2\" execute fail.");
+ at_delete_resp (resp);
return (-RT_ERROR);
}
/* enable PSM mode */
- if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=1,,,,\"00100010\"") != RT_EOK)
+ if (at_obj_exec_cmd (device->client, resp, "AT+CPSMS=1,,,,\"00100010\"") != RT_EOK)
{
- LOG_D("enable sleep fail.\"AT+CPSMS=1,,,,\"00100010\" execute fail.");
- at_delete_resp(resp);
+ LOG_D ("enable sleep fail.\"AT+CPSMS=1,,,,\"00100010\" execute fail.");
+ at_delete_resp (resp);
return (-RT_ERROR);
}
nt26k->sleep_status = RT_TRUE;
- at_delete_resp(resp);
+ at_delete_resp (resp);
return (RT_EOK);
}
-static int nt26k_wakeup(struct at_device *device)
-{
+static int nt26k_wakeup (struct at_device *device) {
struct at_device_nt26k *nt26k = RT_NULL;
nt26k = (struct at_device_nt26k *)device->user_data;
- if (nt26k->pwr_key_pin != -1)
- {
- rt_pin_write(nt26k->pwr_key_pin, PIN_LOW);
- rt_thread_mdelay(100);
- rt_pin_write(nt26k->pwr_key_pin, PIN_HIGH);
+ if (nt26k->pwr_key_pin != -1) {
+ rt_pin_write (nt26k->pwr_key_pin, PIN_LOW);
+ rt_thread_mdelay (100);
+ rt_pin_write (nt26k->pwr_key_pin, PIN_HIGH);
nt26k->sleep_status = RT_TRUE;
}
return (RT_EOK);
}
-static void urc_tcp_recv(struct at_client *client, const char *data, rt_size_t size)
-{
- int len = 0;
- rt_uint16_t crc16 = 0;
- rt_uint16_t rec_crc16 = 0;
- char crc16_buf[6] = {0};
+static void urc_tcp_recv (struct at_client *client, const char *data, rt_size_t size) {
+ int len = 0;
+ rt_uint16_t crc16 = 0;
+ rt_uint16_t rec_crc16 = 0;
+ char crc16_buf[6] = {0};
rt_uint8_t recv_byte_buf[AT_CLIENT_RECV_BUFF_LEN] = {0};
- rt_memset(data_buf, 0, sizeof(data_buf));
+ rt_memset (data_buf, 0, sizeof (data_buf));
- if (sscanf(data, "+QIURC: \"recv\",%*d,%d,%s", &len, data_buf) == 2)
- {
- HexStrToBytes(data_buf, recv_byte_buf, len * 2);
- LOG_D("nt26k recv data: %s", data_buf);
- crc16 = crc1021(data_buf, len * 2 - 10); // 去掉帧尾三个字节和2个字节的校验值,字符长度为10
+ if (sscanf (data, "+QIURC: \"recv\",%*d,%d,%s", &len, data_buf) == 2) {
+ HexStrToBytes (data_buf, recv_byte_buf, len * 2);
+ LOG_D ("nt26k recv data: %s", data_buf);
+ crc16 = crc1021 (data_buf, len * 2 - 10); // 去掉帧尾三个字节和2个字节的校验值,字符长度为10
- rt_strncpy(crc16_buf, data_buf + len * 2 - 10, 4);
- LOG_D("nt26k crc16: %04s", crc16_buf);
- rec_crc16 = strtol(crc16_buf, NULL, 16);
- if (crc16 != rec_crc16) // 看下数据接收的是否正确
- {
- LOG_E("nt26k recv data error {crc16 [%x]!= rec_crc16[%x]}", crc16, rec_crc16);
- }
- else
+ rt_strncpy (crc16_buf, data_buf + len * 2 - 10, 4);
+ LOG_D ("nt26k crc16: %04s", crc16_buf);
+ rec_crc16 = strtol (crc16_buf, NULL, 16);
+ if (crc16 != rec_crc16) // 看下数据接收的是否正确
{
+ LOG_E ("nt26k recv data error {crc16 [%x]!= rec_crc16[%x]}", crc16, rec_crc16);
+ } else {
/*比较数组的长度和结构体的长度是否一致,如果不一致则数据解析错误,如果一致复制数组值到结构体中*/
- if (len == sizeof(struct Nt26kRecvData))
- {
- rt_memset(nt26k_ops.recv, 0, sizeof(struct Nt26kRecvData)); // 清空结构体
- rt_memcpy(nt26k_ops.recv, recv_byte_buf, sizeof(struct Nt26kRecvData));
- if (nt26k_ops.recv->recv_data.event_type != INSTRUCTION_HEART_BEAT)//加这个的原因就是如果有指令下发,会出现两个信号量,指令会执行两次,所以排除心跳包才释放信号量
+ if (len == sizeof (struct Nt26kRecvData)) {
+ rt_memset (nt26k_ops.recv, 0, sizeof (struct Nt26kRecvData)); // 清空结构体
+ rt_memcpy (nt26k_ops.recv, recv_byte_buf, sizeof (struct Nt26kRecvData));
+ if (nt26k_ops.recv->recv_data.event_type != INSTRUCTION_HEART_BEAT) // 加这个的原因就是如果有指令下发,会出现两个信号量,指令会执行两次,所以排除心跳包才释放信号量
{
- rt_sem_release(nt26k_recv_sem);
- }
- }
- else
- {
- LOG_E("nt26k recv data error {len [%d]!= sizeof(struct Nt26kRecvData)[%d]}", len, sizeof(struct Nt26kRecvData));
+ rt_sem_release (nt26k_recv_sem);
+ }
+ } else {
+ LOG_E ("nt26k recv data error {len [%d]!= sizeof(struct Nt26kRecvData)[%d]}", len, sizeof (struct Nt26kRecvData));
}
}
}
- rt_memset(recv_byte_buf, 0, sizeof(recv_byte_buf));
+ rt_memset (recv_byte_buf, 0, sizeof (recv_byte_buf));
}
-static void urc_device_reset(struct at_client *client, const char *data, rt_size_t size)
-{
- LOG_D("device reset");
+static void urc_device_reset (struct at_client *client, const char *data, rt_size_t size) {
+ LOG_D ("device reset");
nt26k_conncet_tcp_flag = 0;
- rt_sem_release(nt26k_disconnect_sem);
+ rt_sem_release (nt26k_disconnect_sem);
}
-static void urc_tcp_disconnect(struct at_client *client, const char *data, rt_size_t size)
-{
+static void urc_tcp_disconnect (struct at_client *client, const char *data, rt_size_t size) {
size_t id;
- if (sscanf(data, "+QIURC: \"closed\",%d", &id) == 1)
- {
- if (id == socket_id)
- {
- LOG_W("socket %d disconnect", id);
+ if (sscanf (data, "+QIURC: \"closed\",%d", &id) == 1) {
+ if (id == socket_id) {
+ LOG_W ("socket %d disconnect", id);
nt26k_conncet_tcp_flag = 0;
- rt_sem_release(nt26k_disconnect_sem);
+ rt_sem_release (nt26k_disconnect_sem);
}
}
}
static const struct at_urc urc_table[] = {
- {"+QIURC: \"recv\"", "\r\n", urc_tcp_recv},
- {"boot.rom", "\r\n", urc_device_reset}, // 这个是软件复位时,
- {"Lierda", "\r\n", urc_device_reset}, // 这个时硬件复位时回复
+ {"+QIURC: \"recv\"", "\r\n", urc_tcp_recv },
+ {"boot.rom", "\r\n", urc_device_reset }, // 这个是软件复位时,
+ {"Lierda", "\r\n", urc_device_reset }, // 这个时硬件复位时回复
{"+QIURC: \"closed\"", "\r\n", urc_tcp_disconnect}, // tcp连接断开
};
-void show_resp_info(at_response_t resp)
-{
- RT_ASSERT(resp);
+
+void show_resp_info (at_response_t resp) {
+ RT_ASSERT (resp);
/* Print response line buffer */
const char *line_buffer = RT_NULL;
- for (rt_size_t line_num = 1; line_num <= resp->line_counts; line_num++)
- {
- if ((line_buffer = at_resp_get_line(resp, line_num)) != RT_NULL)
- LOG_I("line %d buffer : %s", line_num, line_buffer);
+ for (rt_size_t line_num = 1; line_num <= resp->line_counts; line_num++) {
+ if ((line_buffer = at_resp_get_line (resp, line_num)) != RT_NULL)
+ LOG_I ("line %d buffer : %s", line_num, line_buffer);
else
- LOG_I("Parse line buffer error!");
+ LOG_I ("Parse line buffer error!");
}
return;
}
-int at_device_nt26k_disconnect_tcp(struct at_device *device)
-{
+int at_device_nt26k_disconnect_tcp (struct at_device *device) {
#define NT26K_CLOSE_REP_TIME (5 * AT_DEFAULT_TIMEOUT)
- if (nt26k_conncet_tcp_flag)
- {
- at_response_t resp = at_create_resp(AT_CLIENT_RECV_BUFF_LEN, 0, NT26K_CLOSE_REP_TIME);
- if (resp == RT_NULL)
- {
- LOG_E("No memory for response structure!");
- at_delete_resp(resp);
+ if (nt26k_conncet_tcp_flag) {
+ at_response_t resp = at_create_resp (AT_CLIENT_RECV_BUFF_LEN, 0, NT26K_CLOSE_REP_TIME);
+ if (resp == RT_NULL) {
+ LOG_E ("No memory for response structure!");
+ at_delete_resp (resp);
return -RT_ENOMEM;
}
- if (at_obj_exec_cmd(device->client, resp, TCP_CLOSE_SOCKET, socket_id) != RT_EOK)
- {
- at_delete_resp(resp);
+ if (at_obj_exec_cmd (device->client, resp, TCP_CLOSE_SOCKET, socket_id) != RT_EOK) {
+ at_delete_resp (resp);
return -RT_ERROR;
}
nt26k_conncet_tcp_flag = 0;
- rt_sem_release(nt26k_disconnect_sem);
- at_delete_resp(resp);
+ rt_sem_release (nt26k_disconnect_sem);
+ at_delete_resp (resp);
}
return RT_EOK;
}
-static int at_device_nt26k_connect_tcp(struct at_device *device)
-{
- int err_code = 0;
+static int at_device_nt26k_connect_tcp (struct at_device *device) {
+ int err_code = 0;
if (nt26k_conncet_tcp_flag)
return RT_EOK;
- ASSERT(device);
- rt_uint8_t retry = (rt_uint8_t)Flash_Get_SysCfg(kNbRetryId);
- at_response_t resp = at_create_resp(64, 4, AT_DEFAULT_TIMEOUT);
- if (resp == RT_NULL)
- {
- LOG_E("No memory for response structure!");
- at_delete_resp(resp);
+ ASSERT (device);
+ rt_uint8_t retry = (rt_uint8_t)Flash_Get_SysCfg (kIotRetryId);
+ at_response_t resp = at_create_resp (64, 4, AT_DEFAULT_TIMEOUT);
+ if (resp == RT_NULL) {
+ LOG_E ("No memory for response structure!");
+ at_delete_resp (resp);
return -RT_ENOMEM;
}
- if (Flash_Get_Sever_Data(&sever_info) != RT_EOK)
- {
- LOG_E("Get Sever Data Failed");
- at_delete_resp(resp);
+ if (Flash_Get_Sever_Data (&sever_info) != RT_EOK) {
+ LOG_E ("Get Sever Data Failed");
+ at_delete_resp (resp);
return RT_ERROR;
}
- for (size_t i = 0; i < retry; i++)
- {
- if (at_obj_exec_cmd(device->client, resp, TCP_CONNECT_CMD, sever_info.server_url, sever_info.server_port) == RT_EOK)
- {
- if (at_resp_parse_line_args_by_kw(resp, "+QIOPEN:", "+QIOPEN:%d,%d", &socket_id, &err_code) > 0)
- {
- if (err_code == 0)
- {
- LOG_D("nt26k connect to tcp server success");
+ for (size_t i = 0; i < retry; i++) {
+ if (at_obj_exec_cmd (device->client, resp, TCP_CONNECT_CMD, sever_info.server_url, sever_info.server_port) == RT_EOK) {
+ if (at_resp_parse_line_args_by_kw (resp, "+QIOPEN:", "+QIOPEN:%d,%d", &socket_id, &err_code) > 0) {
+ if (err_code == 0) {
+ LOG_D ("nt26k connect to tcp server success");
nt26k_conncet_tcp_flag = 1;
- at_delete_resp(resp);
+ at_delete_resp (resp);
return RT_EOK;
- }
- else
- {
- LOG_E("nt26k connect to tcp server failed. error code: %d",err_code);
+ } else {
+ LOG_E ("nt26k connect to tcp server failed. error code: %d", err_code);
}
}
}
- rt_thread_mdelay(5000);
+ rt_thread_mdelay (5000);
}
- at_device_nt26k_disconnect_tcp(device);
- rt_sem_release(nt26k_disconnect_sem);
- at_delete_resp(resp);
+ at_device_nt26k_disconnect_tcp (device);
+ rt_sem_release (nt26k_disconnect_sem);
+ at_delete_resp (resp);
return RT_ERROR;
}
-int at_send_data(struct at_device *device, const char *data, rt_size_t size)
-{
+int at_send_data (struct at_device *device, const char *data, rt_size_t size) {
#define NT26K_SEND_RESP_TIME (3000)
- const char *line_buffer = RT_NULL;
- rt_uint8_t retry = 0;
- at_response_t resp = at_create_resp(AT_CLIENT_RECV_BUFF_LEN / 4, 2, NT26K_SEND_RESP_TIME);
- rt_uint8_t max_retry_count = (rt_uint8_t)Flash_Get_SysCfg(kNbRetryId);
- if (resp == RT_NULL)
- {
- LOG_E("no memory for nt26k device(%s) response structure.", device->name);
- at_delete_resp(resp);
+ const char *line_buffer = RT_NULL;
+ rt_uint8_t retry = 0;
+ at_response_t resp = at_create_resp (AT_CLIENT_RECV_BUFF_LEN / 4, 2, NT26K_SEND_RESP_TIME);
+ rt_uint8_t max_retry_count = (rt_uint8_t)Flash_Get_SysCfg (kIotRetryId);
+ if (resp == RT_NULL) {
+ LOG_E ("no memory for nt26k device(%s) response structure.", device->name);
+ at_delete_resp (resp);
return -RT_ERROR;
}
- while (retry < max_retry_count)
- {
- rt_thread_mdelay(IMEI_Delay());//获取一个随机延时
- if (at_obj_exec_cmd(device->client, resp, TCP_SEND_DATA, socket_id, data) == RT_EOK)
- {
- if ((line_buffer = at_resp_get_line(resp, 2)) != RT_NULL)
- {
- if (rt_strstr(line_buffer, "SEND OK") != RT_NULL)
- {
- LOG_D("send data success, socket_id: %d", socket_id);
- at_delete_resp(resp);
+ while (retry < max_retry_count) {
+ rt_thread_mdelay (IMEI_Delay()); // 获取一个随机延时
+ if (at_obj_exec_cmd (device->client, resp, TCP_SEND_DATA, socket_id, data) == RT_EOK) {
+ if ((line_buffer = at_resp_get_line (resp, 2)) != RT_NULL) {
+ if (rt_strstr (line_buffer, "SEND OK") != RT_NULL) {
+ LOG_D ("send data success, socket_id: %d", socket_id);
+ at_delete_resp (resp);
return RT_EOK;
}
- }
+ }
}
retry++;
- rt_thread_mdelay(1000);
+ rt_thread_mdelay (1000);
}
- at_delete_resp(resp);
+ at_delete_resp (resp);
return -RT_ERROR;
}
-int nt26k_check_link_status(struct at_device *device)
-{
- at_response_t resp = RT_NULL;
+int nt26k_check_link_status (struct at_device *device) {
+ at_response_t resp = RT_NULL;
struct at_device_nt26k *nt26k = RT_NULL;
- int result = -RT_ERROR;
+ int result = -RT_ERROR;
nt26k = (struct at_device_nt26k *)device->user_data;
- if (!nt26k->power_status) // power off
+ if (!nt26k->power_status) // power off
{
- LOG_D("the power is off,power on device");
- device->class->device_ops->control(device, AT_DEVICE_CTRL_POWER_ON, RT_NULL); // 开启设备
+ LOG_D ("the power is off,power on device");
+ device->class->device_ops->control (device, AT_DEVICE_CTRL_POWER_ON, RT_NULL); // 开启设备
}
- if (nt26k->sleep_status) // is sleep status
+ if (nt26k->sleep_status) // is sleep status
{
- if (nt26k->pwr_key_pin != -1)
- {
- rt_pin_write(nt26k->pwr_key_pin, PIN_LOW);
- rt_thread_mdelay(100);
- rt_pin_write(nt26k->pwr_key_pin, PIN_HIGH);
- rt_thread_mdelay(100);
+ if (nt26k->pwr_key_pin != -1) {
+ rt_pin_write (nt26k->pwr_key_pin, PIN_LOW);
+ rt_thread_mdelay (100);
+ rt_pin_write (nt26k->pwr_key_pin, PIN_HIGH);
+ rt_thread_mdelay (100);
- rt_pin_write(nt26k->pwr_key_pin, PIN_LOW);
+ rt_pin_write (nt26k->pwr_key_pin, PIN_LOW);
}
}
- resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
- if (resp == RT_NULL)
- {
- LOG_D("no memory for resp create.");
- at_delete_resp(resp);
+ resp = at_create_resp (64, 0, rt_tick_from_millisecond (300));
+ if (resp == RT_NULL) {
+ LOG_D ("no memory for resp create.");
+ at_delete_resp (resp);
return (-RT_ERROR);
}
result = -RT_ERROR;
- if (at_obj_exec_cmd(device->client, resp, "AT+CEREG?") == RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CEREG?") == RT_EOK) {
int link_stat = 0;
- if (at_resp_parse_line_args_by_kw(resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0)
- {
- if (link_stat == 1 || link_stat == 5)
- {
+ if (at_resp_parse_line_args_by_kw (resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0) {
+ if (link_stat == 1 || link_stat == 5) {
result = RT_EOK;
}
}
}
- if (nt26k->sleep_status) // is sleep status
+ if (nt26k->sleep_status) // is sleep status
{
- if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=1,,,,\"00100010\"") != RT_EOK)
- {
- LOG_D("startup entry into sleep fail.");
+ if (at_obj_exec_cmd (device->client, resp, "AT+CPSMS=1,,,,\"00100010\"") != RT_EOK) {
+ LOG_D ("startup entry into sleep fail.");
}
}
- at_delete_resp(resp);
+ at_delete_resp (resp);
return (result);
}
/* ============================= nt26k network interface operations ============================= */
/* set nt26k network interface device status and address information */
-int nt26k_netdev_set_info(struct netdev *netdev)
-{
+int nt26k_netdev_set_info (struct netdev *netdev) {
#define NT26K_INFO_RESP_SIZE 128
-#define NT26K_INFO_RESP_TIMO rt_tick_from_millisecond(1000)
+#define NT26K_INFO_RESP_TIMO rt_tick_from_millisecond (1000)
int result = RT_EOK;
ip_addr_t addr;
- at_response_t resp = RT_NULL;
+ at_response_t resp = RT_NULL;
struct at_device *device = RT_NULL;
- RT_ASSERT(netdev);
+ RT_ASSERT (netdev);
- device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
- if (device == RT_NULL)
- {
- LOG_E("get device(%s) failed.", netdev->name);
+ device = at_device_get_by_name (AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
+ if (device == RT_NULL) {
+ LOG_E ("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
/* set network interface device status */
- netdev_low_level_set_status(netdev, RT_TRUE);
- netdev_low_level_set_link_status(netdev, RT_TRUE);
- netdev_low_level_set_dhcp_status(netdev, RT_TRUE);
+ netdev_low_level_set_status (netdev, RT_TRUE);
+ netdev_low_level_set_link_status (netdev, RT_TRUE);
+ netdev_low_level_set_dhcp_status (netdev, RT_TRUE);
- resp = at_create_resp(NT26K_INFO_RESP_SIZE, 0, NT26K_INFO_RESP_TIMO);
- if (resp == RT_NULL)
- {
- LOG_E("no memory for resp create.");
- at_delete_resp(resp);
+ resp = at_create_resp (NT26K_INFO_RESP_SIZE, 0, NT26K_INFO_RESP_TIMO);
+ if (resp == RT_NULL) {
+ LOG_E ("no memory for resp create.");
+ at_delete_resp (resp);
result = -RT_ENOMEM;
goto __exit;
}
@@ -465,36 +427,33 @@ int nt26k_netdev_set_info(struct netdev *netdev)
char dns_server1[DNS_ADDR_SIZE_MAX] = {0}, dns_server2[DNS_ADDR_SIZE_MAX] = {0};
/* send "AT+DNSSERVER?" commond to get DNS servers address */
- if (at_obj_exec_cmd(device->client, resp, "AT+DNSSERVER?") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+DNSSERVER?") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
// LOG_HEX("resp", 16, resp->buf, resp->buf_len);
- int a1 = at_resp_parse_line_args(resp, 2, "PrimaryIpv4Dns:%s", dns_server1);
- int a2 = at_resp_parse_line_args(resp, 3, "SecondaryIpv4Dns:%s", dns_server2);
+ int a1 = at_resp_parse_line_args (resp, 2, "PrimaryIpv4Dns:%s", dns_server1);
+ int a2 = at_resp_parse_line_args (resp, 3, "SecondaryIpv4Dns:%s", dns_server2);
/* parse response data "+QIDNSCFG: ,," */
- if (a1 <= 0 || a2 <= 0)
- {
- LOG_E("%s device prase \"AT+DNSSERVER?\" cmd error.", device->name);
+ if (a1 <= 0 || a2 <= 0) {
+ LOG_E ("%s device prase \"AT+DNSSERVER?\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
- LOG_D("%s device primary DNS server address: %s", device->name, dns_server1);
- LOG_D("%s device secondary DNS server address: %s", device->name, dns_server2);
+ LOG_D ("%s device primary DNS server address: %s", device->name, dns_server1);
+ LOG_D ("%s device secondary DNS server address: %s", device->name, dns_server2);
- inet_aton(dns_server1, &addr);
- netdev_low_level_set_dns_server(netdev, 0, &addr);
+ inet_aton (dns_server1, &addr);
+ netdev_low_level_set_dns_server (netdev, 0, &addr);
- inet_aton(dns_server2, &addr);
- netdev_low_level_set_dns_server(netdev, 1, &addr);
+ inet_aton (dns_server2, &addr);
+ netdev_low_level_set_dns_server (netdev, 1, &addr);
}
__exit:
- if (resp)
- {
- at_delete_resp(resp);
+ if (resp) {
+ at_delete_resp (resp);
}
return result;
@@ -505,242 +464,216 @@ __exit:
*
* @param netdev: nt26k network interface device
*/
-static void nt26k_check_link_status_entry(void *parameter)
-{
+static void nt26k_check_link_status_entry (void *parameter) {
#define NT26K_LINK_DELAY_TIME (60 * RT_TICK_PER_SECOND)
-#define NT26K_LINK_STATUS_OK 1
+#define NT26K_LINK_STATUS_OK 1
int link_status;
struct at_device *device = RT_NULL;
- struct netdev *netdev = (struct netdev *)parameter;
+ struct netdev *netdev = (struct netdev *)parameter;
- device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
- if (device == RT_NULL)
- {
- LOG_E("get device(%s) failed.", netdev->name);
+ device = at_device_get_by_name (AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
+ if (device == RT_NULL) {
+ LOG_E ("get device(%s) failed.", netdev->name);
return;
}
- while (1)
- {
- link_status = nt26k_check_link_status(device);
- if (link_status < 0)
- {
- rt_thread_mdelay(NT26K_LINK_DELAY_TIME);
+ while (1) {
+ link_status = nt26k_check_link_status (device);
+ if (link_status < 0) {
+ rt_thread_mdelay (NT26K_LINK_DELAY_TIME);
continue;
}
/* check the network interface device link status */
- if ((NT26K_LINK_STATUS_OK == link_status) != netdev_is_link_up(netdev))
- {
- netdev_low_level_set_link_status(netdev, (NT26K_LINK_STATUS_OK == link_status));
+ if ((NT26K_LINK_STATUS_OK == link_status) != netdev_is_link_up (netdev)) {
+ netdev_low_level_set_link_status (netdev, (NT26K_LINK_STATUS_OK == link_status));
}
- rt_thread_delay(NT26K_LINK_DELAY_TIME);
+ rt_thread_delay (NT26K_LINK_DELAY_TIME);
}
}
-int nt26k_netdev_check_link_status(struct netdev *netdev)
-{
-#define NT26K_LINK_THREAD_TICK 20
+int nt26k_netdev_check_link_status (struct netdev *netdev) {
+#define NT26K_LINK_THREAD_TICK 20
#define NT26K_LINK_THREAD_STACK_SIZE (1024 + 512)
-#define NT26K_LINK_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX - 2)
+#define NT26K_LINK_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX - 2)
rt_thread_t tid;
char tname[RT_NAME_MAX] = {0};
- RT_ASSERT(netdev);
+ RT_ASSERT (netdev);
- rt_snprintf(tname, RT_NAME_MAX, "%s", netdev->name);
+ rt_snprintf (tname, RT_NAME_MAX, "%s", netdev->name);
/* create nt26k link status polling thread */
- tid = rt_thread_create(tname, nt26k_check_link_status_entry, (void *)netdev,
- NT26K_LINK_THREAD_STACK_SIZE, NT26K_LINK_THREAD_PRIORITY, NT26K_LINK_THREAD_TICK);
- if (tid != RT_NULL)
- {
- rt_thread_startup(tid);
+ tid = rt_thread_create (tname, nt26k_check_link_status_entry, (void *)netdev,
+ NT26K_LINK_THREAD_STACK_SIZE, NT26K_LINK_THREAD_PRIORITY, NT26K_LINK_THREAD_TICK);
+ if (tid != RT_NULL) {
+ rt_thread_startup (tid);
}
return RT_EOK;
}
-static int nt26k_net_init(struct at_device *device);
+static int nt26k_net_init (struct at_device *device);
-static int nt26k_netdev_set_up(struct netdev *netdev)
-{
+static int nt26k_netdev_set_up (struct netdev *netdev) {
struct at_device *device = RT_NULL;
- device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
- if (device == RT_NULL)
- {
- LOG_E("get device(%s) failed.", netdev->name);
+ device = at_device_get_by_name (AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
+ if (device == RT_NULL) {
+ LOG_E ("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
- if (device->is_init == RT_FALSE)
- {
- nt26k_net_init(device);
+ if (device->is_init == RT_FALSE) {
+ nt26k_net_init (device);
device->is_init = RT_TRUE;
- netdev_low_level_set_status(netdev, RT_TRUE);
- LOG_D("network interface device(%s) set up status.", netdev->name);
+ netdev_low_level_set_status (netdev, RT_TRUE);
+ LOG_D ("network interface device(%s) set up status.", netdev->name);
}
return RT_EOK;
}
-static int nt26k_netdev_set_down(struct netdev *netdev)
-{
+static int nt26k_netdev_set_down (struct netdev *netdev) {
struct at_device *device = RT_NULL;
- device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
- if (device == RT_NULL)
- {
- LOG_E("get device(%s) failed.", netdev->name);
+ device = at_device_get_by_name (AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
+ if (device == RT_NULL) {
+ LOG_E ("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
- if (device->is_init == RT_TRUE)
- {
- nt26k_power_off(device);
+ if (device->is_init == RT_TRUE) {
+ nt26k_power_off (device);
device->is_init = RT_FALSE;
- netdev_low_level_set_status(netdev, RT_FALSE);
- LOG_D("network interface device(%s) set down status.", netdev->name);
+ netdev_low_level_set_status (netdev, RT_FALSE);
+ LOG_D ("network interface device(%s) set down status.", netdev->name);
}
return RT_EOK;
}
-static int nt26k_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, ip_addr_t *dns_server)
-{
-#define NT26K_DNS_RESP_LEN 64
-#define NT26K_DNS_RESP_TIMEO rt_tick_from_millisecond(300)
+static int nt26k_netdev_set_dns_server (struct netdev *netdev, uint8_t dns_num, ip_addr_t *dns_server) {
+#define NT26K_DNS_RESP_LEN 64
+#define NT26K_DNS_RESP_TIMEO rt_tick_from_millisecond (300)
- int result = RT_EOK;
- at_response_t resp = RT_NULL;
+ int result = RT_EOK;
+ at_response_t resp = RT_NULL;
struct at_device *device = RT_NULL;
- RT_ASSERT(netdev);
- RT_ASSERT(dns_server);
+ RT_ASSERT (netdev);
+ RT_ASSERT (dns_server);
- device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
- if (device == RT_NULL)
- {
- LOG_E("get device(%s) failed.", netdev->name);
+ device = at_device_get_by_name (AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
+ if (device == RT_NULL) {
+ LOG_E ("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
- resp = at_create_resp(NT26K_DNS_RESP_LEN, 0, NT26K_DNS_RESP_TIMEO);
- if (resp == RT_NULL)
- {
- LOG_D("no memory for resp create.");
- at_delete_resp(resp);
+ resp = at_create_resp (NT26K_DNS_RESP_LEN, 0, NT26K_DNS_RESP_TIMEO);
+ if (resp == RT_NULL) {
+ LOG_D ("no memory for resp create.");
+ at_delete_resp (resp);
result = -RT_ENOMEM;
goto __exit;
}
/* send "AT+QIDNSCFG=[,]" commond to set dns servers */
- if (at_obj_exec_cmd(device->client, resp, "AT+QIDNSCFG=%d,%s",
- dns_num, inet_ntoa(*dns_server)) != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+QIDNSCFG=%d,%s",
+ dns_num, inet_ntoa (*dns_server)) != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
- netdev_low_level_set_dns_server(netdev, dns_num, dns_server);
+ netdev_low_level_set_dns_server (netdev, dns_num, dns_server);
__exit:
- if (resp)
- {
- at_delete_resp(resp);
+ if (resp) {
+ at_delete_resp (resp);
}
return result;
}
#ifdef NETDEV_USING_PING
-static int nt26k_netdev_ping(struct netdev *netdev, const char *host, size_t data_len,
- uint32_t timeout, struct netdev_ping_resp *ping_resp
+static int nt26k_netdev_ping (struct netdev *netdev, const char *host, size_t data_len,
+ uint32_t timeout, struct netdev_ping_resp *ping_resp
#if RT_VER_NUM >= 0x50100
- ,
- rt_bool_t is_bind
+ ,
+ rt_bool_t is_bind
#endif
-)
-{
+) {
#define NT26K_PING_RESP_SIZE 128
-#define NT26K_PING_IP_SIZE 16
-#define NT26K_PING_TIMEO (NT26K_CON_REP_TIME)
+#define NT26K_PING_IP_SIZE 16
+#define NT26K_PING_TIMEO (NT26K_CON_REP_TIME)
- rt_err_t result = RT_EOK;
- int response = -1, recv_data_len, ping_time, ttl;
+ rt_err_t result = RT_EOK;
+ int response = -1, recv_data_len, ping_time, ttl;
char ip_addr[NT26K_PING_IP_SIZE] = {0};
- at_response_t resp = RT_NULL;
- struct at_device *device = RT_NULL;
+ at_response_t resp = RT_NULL;
+ struct at_device *device = RT_NULL;
#if RT_VER_NUM >= 0x50100
- RT_UNUSED(is_bind);
+ RT_UNUSED (is_bind);
#endif
- RT_ASSERT(netdev);
- RT_ASSERT(host);
- RT_ASSERT(ping_resp);
+ RT_ASSERT (netdev);
+ RT_ASSERT (host);
+ RT_ASSERT (ping_resp);
- device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
- if (device == RT_NULL)
- {
- LOG_E("get device(%s) failed.", netdev->name);
+ device = at_device_get_by_name (AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
+ if (device == RT_NULL) {
+ LOG_E ("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
- resp = at_create_resp(NT26K_PING_RESP_SIZE, 4, NT26K_PING_TIMEO);
- if (resp == RT_NULL)
- {
- LOG_E("no memory for resp create");
- at_delete_resp(resp);
+ resp = at_create_resp (NT26K_PING_RESP_SIZE, 4, NT26K_PING_TIMEO);
+ if (resp == RT_NULL) {
+ LOG_E ("no memory for resp create");
+ at_delete_resp (resp);
return -RT_ENOMEM;
}
/* send "AT+QPING=""[,[][,]]" commond to send ping request */
- if (at_obj_exec_cmd(device->client, resp, "AT+QPING=1,\"%s\",%d,1", host, timeout / RT_TICK_PER_SECOND) < 0)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+QPING=1,\"%s\",%d,1", host, timeout / RT_TICK_PER_SECOND) < 0) {
result = -RT_ERROR;
goto __exit;
}
- at_resp_parse_line_args_by_kw(resp, "+QPING:", "+QPING:%d", &response);
+ at_resp_parse_line_args_by_kw (resp, "+QPING:", "+QPING:%d", &response);
/* Received the ping response from the server */
- if (response == 0)
- {
- if (at_resp_parse_line_args_by_kw(resp, "+QPING:", "+QPING:%d,\"%[^\"]\",%d,%d,%d",
- &response, ip_addr, &recv_data_len, &ping_time, &ttl) <= 0)
- {
+ if (response == 0) {
+ if (at_resp_parse_line_args_by_kw (resp, "+QPING:", "+QPING:%d,\"%[^\"]\",%d,%d,%d",
+ &response, ip_addr, &recv_data_len, &ping_time, &ttl) <= 0) {
result = -RT_ERROR;
goto __exit;
}
}
/* prase response number */
- switch (response)
- {
- case 0:
- inet_aton(ip_addr, &(ping_resp->ip_addr));
- ping_resp->data_len = recv_data_len;
- ping_resp->ticks = ping_time;
- ping_resp->ttl = ttl;
- result = RT_EOK;
- break;
- case 569:
- result = -RT_ETIMEOUT;
- break;
- default:
- result = -RT_ERROR;
- break;
+ switch (response) {
+ case 0:
+ inet_aton (ip_addr, &(ping_resp->ip_addr));
+ ping_resp->data_len = recv_data_len;
+ ping_resp->ticks = ping_time;
+ ping_resp->ttl = ttl;
+ result = RT_EOK;
+ break;
+ case 569:
+ result = -RT_ETIMEOUT;
+ break;
+ default:
+ result = -RT_ERROR;
+ break;
}
__exit:
- if (resp)
- {
- at_delete_resp(resp);
+ if (resp) {
+ at_delete_resp (resp);
}
return result;
@@ -762,36 +695,33 @@ const struct netdev_ops nt26k_netdev_ops =
RT_NULL,
};
-static struct netdev *nt26k_netdev_add(const char *netdev_name)
-{
+static struct netdev *nt26k_netdev_add (const char *netdev_name) {
#define ETHERNET_MTU 1380
-#define HWADDR_LEN 8
+#define HWADDR_LEN 8
struct netdev *netdev = RT_NULL;
- netdev = netdev_get_by_name(netdev_name);
- if (netdev != RT_NULL)
- {
+ netdev = netdev_get_by_name (netdev_name);
+ if (netdev != RT_NULL) {
return (netdev);
}
- netdev = (struct netdev *)rt_calloc(1, sizeof(struct netdev));
- if (netdev == RT_NULL)
- {
- LOG_E("no memory for netdev create.");
+ netdev = (struct netdev *)rt_calloc (1, sizeof (struct netdev));
+ if (netdev == RT_NULL) {
+ LOG_E ("no memory for netdev create.");
return RT_NULL;
}
- netdev->mtu = ETHERNET_MTU;
- netdev->ops = &nt26k_netdev_ops;
+ netdev->mtu = ETHERNET_MTU;
+ netdev->ops = &nt26k_netdev_ops;
netdev->hwaddr_len = HWADDR_LEN;
#ifdef SAL_USING_AT
- extern int sal_at_netdev_set_pf_info(struct netdev * netdev);
+ extern int sal_at_netdev_set_pf_info (struct netdev * netdev);
/* set the network interface socket/netdb operations */
- sal_at_netdev_set_pf_info(netdev);
+ sal_at_netdev_set_pf_info (netdev);
#endif
- netdev_register(netdev, netdev_name, RT_NULL);
+ netdev_register (netdev, netdev_name, RT_NULL);
return netdev;
}
@@ -799,162 +729,139 @@ static struct netdev *nt26k_netdev_add(const char *netdev_name)
/* ============================= nt26k device operations ============================= */
/* initialize for nt26k */
-static void nt26k_init_thread_entry(void *parameter)
-{
-#define INIT_RETRY 5
-#define CPIN_RETRY 5
-#define CSQ_RETRY 20
-#define CEREG_RETRY 50
+static void nt26k_init_thread_entry (void *parameter) {
+#define INIT_RETRY 5
+#define CPIN_RETRY 5
+#define CSQ_RETRY 20
+#define CEREG_RETRY 50
#define IPADDR_RETRY 10
int i;
- rt_uint8_t retry_num = INIT_RETRY;
- rt_err_t result = RT_EOK;
- at_response_t resp = RT_NULL;
+ rt_err_t result = RT_EOK;
+ at_response_t resp = RT_NULL;
struct at_device *device = (struct at_device *)parameter;
struct at_client *client = device->client;
- resp = at_create_resp(128, 0, rt_tick_from_millisecond(300));
- if (resp == RT_NULL)
- {
- LOG_E("no memory for resp create.");
- at_delete_resp(resp);
+ resp = at_create_resp (128, 0, rt_tick_from_millisecond (300));
+ if (resp == RT_NULL) {
+ LOG_E ("no memory for resp create.");
+ at_delete_resp (resp);
return;
}
- LOG_D("start init %s device.", device->name);
- nt26k_power_off(device);
- rt_thread_mdelay(100);
- while (retry_num--)
- {
+ LOG_D ("start init %s device.", device->name);
+ nt26k_power_off (device);
+ rt_thread_mdelay (100);
+ while (1) {
/* power on the nt26k device */
- nt26k_power_on(device);
- rt_thread_mdelay(1000);
+ nt26k_power_on (device);
+ rt_thread_mdelay (1000);
/* wait nt26k startup finish, send AT every 500ms, if receive OK, SYNC success*/
- if (at_client_obj_wait_connect(client, NT26K_WAIT_CONNECT_TIME))
- {
+ if (at_client_obj_wait_connect (client, NT26K_WAIT_CONNECT_TIME)) {
result = -RT_ETIMEOUT;
goto __exit;
}
-
- // AT+QSIMDET=0,1
- if (at_obj_exec_cmd(device->client, resp, "AT+QSIMDET=0,1") != RT_EOK)
- {
- result = -RT_ERROR;
- goto __exit;
- }
+
+ // // AT+QSIMDET=0,1
+ // if (at_obj_exec_cmd(device->client, resp, "AT+QSIMDET=0,1") != RT_EOK)
+ // {
+ // result = -RT_ERROR;
+ // goto __exit;
+ // }
/* disable echo */
- if (at_obj_exec_cmd(device->client, resp, "ATE0") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "ATE0") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
/* disable sleep mode */
- if (at_obj_exec_cmd(device->client, resp, "AT+ECPMUCFG=1,0") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+ECPMUCFG=1,0") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
/* disable PSM mode */
- if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=0") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CPSMS=0") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
/*AT+QICFG="dataformat" 设置收发模式*/
- if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"dataformat\",%d,%d",AT_NSONMI_MODE_DEFAULT, AT_NSONMI_MODE_DEFAULT) != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+QICFG=\"dataformat\",%d,%d", AT_NSONMI_MODE_DEFAULT, AT_NSONMI_MODE_DEFAULT) != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
/*设置显示模式*/
- if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"viewmode\",1") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+QICFG=\"viewmode\",1") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
/*设置保活信息*/
- if ( at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,1800,100,3") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,1800,100,3") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
/*设置保活信息*/
- if ( at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"passiveclosed\",1") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+QICFG=\"passiveclosed\",1") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
/* get module version */
- if (at_obj_exec_cmd(device->client, resp, "AT+CGMR") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CGMR") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
- for (i = 0; i < (int)resp->line_counts - 1; i++)
- {
- LOG_D("%s", at_resp_get_line(resp, i + 1));
+ for (i = 0; i < (int)resp->line_counts - 1; i++) {
+ LOG_D ("%s", at_resp_get_line (resp, i + 1));
}
/* set network interface device hardware address(IMEI) */
{
#define NT26K_NETDEV_HWADDR_LEN 8
-#define NT26K_IMEI_LEN 15
+#define NT26K_IMEI_LEN 15
char imei[NT26K_IMEI_LEN] = {0};
/* send "AT+CGSN" commond to get device IMEI */
- if (at_obj_exec_cmd(device->client, resp, "AT+CGSN") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CGSN") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
- if (at_resp_parse_line_args_by_kw(resp, "86", "%s", imei) <= 0)
- {
- LOG_E("%s device prase \"AT+CGSN=1\" cmd error.", device->name);
+ if (at_resp_parse_line_args_by_kw (resp, "86", "%s", imei) <= 0) {
+ LOG_E ("%s device prase \"AT+CGSN=1\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
- LOG_D("%s device IMEI number: %s", device->name, imei);
+ LOG_D ("%s device IMEI number: %s", device->name, imei);
- rt_memcpy(nt26k.imei, imei, NT26K_IMEI_LEN);
- Flash_Sys_Cfg(kNbImeiId, nt26k.imei, NT26K_IMEI_LEN);
+ rt_memcpy (nt26k.imei, imei, NT26K_IMEI_LEN);
+ Flash_Sys_Cfg (kIotImeiId, nt26k.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;
}
- // /* 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++)
- {
+ 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);
+ 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);
+ rt_thread_mdelay (1000);
}
- if (i == CSQ_RETRY)
- {
- LOG_D("%s device network registration failed.", device->name);
+ if (i == CSQ_RETRY) {
+ LOG_D ("%s device network registration failed.", device->name);
result = -RT_ERROR;
goto __exit;
}
@@ -966,22 +873,20 @@ static void nt26k_init_thread_entry(void *parameter)
char iccid[NT26K_ICCID_LEN] = {0};
/* send "AT+ECICCID" commond to get device iccid */
- if (at_obj_exec_cmd(device->client, resp, "AT+QCCID") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+QCCID") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
- if (at_resp_parse_line_args_by_kw(resp, "+QCCID:", "+QCCID:%s", iccid) <= 0)
- {
- LOG_E("%s device prase \"AT+ECICCID\" cmd error.", device->name);
+ if (at_resp_parse_line_args_by_kw (resp, "+QCCID:", "+QCCID:%s", iccid) <= 0) {
+ LOG_E ("%s device prase \"AT+ECICCID\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
- LOG_D("%s device iccid number: %s", device->name, iccid);
+ LOG_D ("%s device iccid number: %s", device->name, iccid);
- rt_memcpy(nt26k.iccid, iccid, NT26K_ICCID_LEN);
- Flash_Sys_Cfg(kNbIccidId, nt26k.iccid, NT26K_ICCID_LEN);
+ rt_memcpy (nt26k.iccid, iccid, NT26K_ICCID_LEN);
+ Flash_Sys_Cfg (kIotIccidId, nt26k.iccid, NT26K_ICCID_LEN);
}
/* set network interface device hardware imsi */
@@ -992,225 +897,206 @@ static void nt26k_init_thread_entry(void *parameter)
char imsi[NT26K_IMSI_LEN] = {0};
/* send "AT+CIMI" commond to get device imsi */
- if (at_obj_exec_cmd(device->client, resp, "AT+CIMI") != RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CIMI") != RT_EOK) {
result = -RT_ERROR;
goto __exit;
}
- if (at_resp_parse_line_args_by_kw(resp, "46", "%s", imsi) <= 0)
- {
- LOG_E("%s device prase \"AT+CIMI\" cmd error.", device->name);
+ if (at_resp_parse_line_args_by_kw (resp, "46", "%s", imsi) <= 0) {
+ LOG_E ("%s device prase \"AT+CIMI\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
- LOG_D("%s device imsi number: %s", device->name, imsi);
+ LOG_D ("%s device imsi number: %s", device->name, imsi);
- rt_memcpy(nt26k.imsi, imsi, NT26K_IMSI_LEN);
- Flash_Sys_Cfg(kNbImsiId, nt26k.imsi, NT26K_IMSI_LEN);
+ rt_memcpy (nt26k.imsi, imsi, NT26K_IMSI_LEN);
+ Flash_Sys_Cfg (kIotImsiId, nt26k.imsi, NT26K_IMSI_LEN);
}
/* check signal strength */
- for (i = 0; i < CSQ_RETRY; i++)
- {
+ 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+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);
+ 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);
+ rt_thread_mdelay (1000);
}
- if (i == CSQ_RETRY)
- {
- LOG_E("%s device signal strength check failed", device->name);
+ 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++)
- {
+ for (i = 0; i < CEREG_RETRY; i++) {
- if (at_obj_exec_cmd(device->client, resp, "AT+CEREG?") == RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CEREG?") == RT_EOK) {
int link_stat = 0;
- if (at_resp_parse_line_args_by_kw(resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0)
- {
- if ((link_stat == 1) || (link_stat == 5))
- {
- LOG_D("%s device GPRS is registered", device->name);
+ if (at_resp_parse_line_args_by_kw (resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0) {
+ if ((link_stat == 1) || (link_stat == 5)) {
+ LOG_D ("%s device GPRS is registered", device->name);
break;
}
}
}
- rt_thread_mdelay(1000);
+ rt_thread_mdelay (1000);
}
- if (i == CEREG_RETRY)
- {
- LOG_E("%s device GPRS is register failed", device->name);
+ if (i == CEREG_RETRY) {
+ LOG_E ("%s device GPRS is register failed", device->name);
result = -RT_ERROR;
goto __exit;
}
-
+ if (at_obj_exec_cmd (device->client, resp, "AT+CCLK?") == RT_EOK) {
+ TsRtcDateTime rtc_dt;
+ int year, mounth, days, hous, min, sec;
+ /*+CCLK:24/11/12,06:08:19+32*/
+ if (at_resp_parse_line_args_by_kw (resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0) {
+ rtc_dt.year = (2000 + year);
+ rtc_dt.month = mounth;
+ rtc_dt.day = days;
+ rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区
+ rtc_dt.minute = min;
+ rtc_dt.second = sec;
+ Time_Zone_Conversion (&rtc_dt); // 时区设置
+ rtc_dt.week = RTC_GetWeek (rtc_dt.year, rtc_dt.month, rtc_dt.day);
+ RTC_SetTime (rtc_dt.year, rtc_dt.month, rtc_dt.day,
+ rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间
+ LOG_I ("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n",
+ rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second);
+ result = RT_EOK;
+ }
+ }
/* initialize successfully */
result = RT_EOK;
break;
- __exit:
- if (result != RT_EOK)
- {
+__exit:
+ if (result != RT_EOK) {
/* power off the nt26k device */
// nt26k_power_off(device);
- rt_thread_mdelay(1000);
+ rt_thread_mdelay (1000);
- LOG_I("%s device initialize retry...", device->name);
+ LOG_I ("%s device initialize retry...", device->name);
}
}
- if (resp)
- {
- at_delete_resp(resp);
+ if (resp) {
+ at_delete_resp (resp);
}
- if (result == RT_EOK)
- {
+ if (result == RT_EOK) {
/* set network interface device status and address information */
// nt26k_netdev_set_info(device->netdev);
/* check and create link staus sync thread */
// nt26k_netdev_check_link_status(device->netdev);
- LOG_I("%s device network initialize success.", device->name);
- rt_completion_done(&nt26k_init_complate); // 通知初始化完成
- }
- else
- {
- LOG_E("%s device network initialize failed(%d).", device->name, result);
+ LOG_I ("%s device network initialize success.", device->name);
+ rt_completion_done (&nt26k_init_complate); // 通知初始化完成
+ } else {
+ LOG_E ("%s device network initialize failed(%d).", device->name, result);
}
}
/* nt26k device network initialize */
-static int nt26k_net_init(struct at_device *device)
-{
+static int nt26k_net_init (struct at_device *device) {
#ifdef AT_DEVICE_NT26K_INIT_ASYN
rt_thread_t tid;
/* 初始化完成量对象 */
- rt_completion_init(&nt26k_init_complate);
+ rt_completion_init (&nt26k_init_complate);
- tid = rt_thread_create("nt26k_net", nt26k_init_thread_entry, (void *)device,
- NT26K_THREAD_STACK_SIZE, NT26K_THREAD_PRIORITY, 20);
- if (tid)
- {
- rt_thread_startup(tid);
- }
- else
- {
- LOG_E("create %s device init thread failed.", device->name);
+ tid = rt_thread_create ("nt26k_net", nt26k_init_thread_entry, (void *)device,
+ NT26K_THREAD_STACK_SIZE, NT26K_THREAD_PRIORITY, 20);
+ if (tid) {
+ rt_thread_startup (tid);
+ } else {
+ LOG_E ("create %s device init thread failed.", device->name);
return -RT_ERROR;
}
#else
- nt26k_init_thread_entry(device);
+ nt26k_init_thread_entry (device);
#endif /* AT_DEVICE_NT26K_INIT_ASYN */
return RT_EOK;
}
// 去除字符串中的 \r 和 \n
-void remove_crlf(char *str)
-{
+void remove_crlf (char *str) {
char *p = str;
- while (*p)
- {
- if (*p == '\r' || *p == '\n')
- {
- memmove(p, p + 1, strlen(p));
- }
- else
- {
+ while (*p) {
+ if (*p == '\r' || *p == '\n') {
+ memmove (p, p + 1, strlen (p));
+ } else {
p++;
}
}
}
-rt_err_t Nt26k_Get_Signal_Info(struct at_device *device)
-{
+rt_err_t Nt26k_Get_Signal_Info (struct at_device *device) {
#define RETRY 20
- rt_err_t result = RT_EOK;
+ rt_err_t result = RT_EOK;
at_response_t resp = RT_NULL;
rt_uint8_t i;
- RT_ASSERT(device);
- resp = at_create_resp(1024, 4, rt_tick_from_millisecond(2000));
- if (resp == RT_NULL)
- {
- LOG_E("no memory for resp create.");
- at_delete_resp(resp);
+ RT_ASSERT (device);
+ resp = at_create_resp (1024, 4, rt_tick_from_millisecond (2000));
+ if (resp == RT_NULL) {
+ LOG_E ("no memory for resp create.");
+ at_delete_resp (resp);
return RT_ERROR;
}
/* check signal strength */
- for (i = 0; i < RETRY; i++)
- {
+ for (i = 0; i < RETRY; i++) {
- if (at_obj_exec_cmd(device->client, resp, "AT+CSQ") == RT_EOK)
- {
+ 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);
+ 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);
+ rt_thread_mdelay (1000);
}
- if (i == RETRY)
- {
- LOG_E("%s device signal strength check failed", device->name);
+ if (i == RETRY) {
+ LOG_E ("%s device signal strength check failed", device->name);
result = -RT_ERROR;
}
/* check signal strength */
//+CESQ:99,99,255,255,28,44
- for (i = 0; i < RETRY; i++)
- {
- if (at_obj_exec_cmd(device->client, resp, "AT+CESQ") == RT_EOK)
- {
+ for (i = 0; i < RETRY; i++) {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CESQ") == RT_EOK) {
rt_uint8_t rsrp = 0, rsrq = 0;
- if (at_resp_parse_line_args_by_kw(resp, "+CESQ:", "+CESQ:%*[^,],%*[^,],%*[^,],%*[^,],%d,%d", &rsrq, &rsrp) > 0)
- {
- if ((rsrp <= 97) && (rsrp > 0) && ((rsrq <= 34) && (rsrq > 0)))
- {
- LOG_D("%s device signal rsrp: %d, rsrq: %d",
- device->name, rsrp, rsrq);
+ if (at_resp_parse_line_args_by_kw (resp, "+CESQ:", "+CESQ:%*[^,],%*[^,],%*[^,],%*[^,],%d,%d", &rsrq, &rsrp) > 0) {
+ if ((rsrp <= 97) && (rsrp > 0) && ((rsrq <= 34) && (rsrq > 0))) {
+ LOG_D ("%s device signal rsrp: %d, rsrq: %d",
+ device->name, rsrp, rsrq);
nt26k.rsrp = rsrp;
nt26k.rsrq = rsrq;
break;
}
}
}
- rt_thread_mdelay(1000);
+ rt_thread_mdelay (1000);
}
- if (i == RETRY)
- {
- LOG_E("%s device signal data failed", device->name);
+ if (i == RETRY) {
+ LOG_E ("%s device signal data failed", device->name);
result = -RT_ERROR;
}
// /* get signal snr, pci */
@@ -1223,213 +1109,184 @@ rt_err_t Nt26k_Get_Signal_Info(struct at_device *device)
// int pci = 0, snr = 0;
// // show_resp_info(resp);
- // // 获取第 2 行的响应
- // const char *line = at_resp_get_line(resp, 2);
+ // // 获取第 2 行的响应
+ // const char *line = at_resp_get_line(resp, 2);
- // if (line != NULL)
- // {
- // snr = Extract_Value(line, key1);
- // pci = Extract_Value(line, key2);
+ // if (line != NULL)
+ // {
+ // snr = Extract_Value(line, key1);
+ // pci = Extract_Value(line, key2);
- // if (snr != 0 && pci != 0)
- // {
- // nt26k.pci = pci;
- // nt26k.snr = snr;
- // LOG_D("pci:%d,snr:%d", nt26k.pci, nt26k.snr);
- // break;
- // }
- // else
- // {
- // LOG_D("Extracted values are invalid: SNR=%d, PCI=%d", snr, pci);
- // }
- // }
- // else
- // {
- // LOG_D("Failed to get line 2 from response");
- // }
- // }
- // else
- // {
- // LOG_D("Failed to execute AT command");
- // }
- // rt_thread_mdelay(2000);
+ // if (snr != 0 && pci != 0)
+ // {
+ // nt26k.pci = pci;
+ // nt26k.snr = snr;
+ // LOG_D("pci:%d,snr:%d", nt26k.pci, nt26k.snr);
+ // break;
+ // }
+ // else
+ // {
+ // LOG_D("Extracted values are invalid: SNR=%d, PCI=%d", snr, pci);
+ // }
+ // }
+ // else
+ // {
+ // LOG_D("Failed to get line 2 from response");
+ // }
+ // }
+ // else
+ // {
+ // LOG_D("Failed to execute AT command");
+ // }
+ // rt_thread_mdelay(2000);
// }
// if (i == RETRY)
// {
- // LOG_E("%s device signal data failed", device->name);
- // result = -RT_ERROR;
+ // LOG_E("%s device signal data failed", device->name);
+ // result = -RT_ERROR;
// }
- at_delete_resp(resp);
+ at_delete_resp (resp);
return result;
}
/* nt26k device network interface attach
* - set network interface device link status
*/
-static int nt26k_init(struct at_device *device)
-{
+static int nt26k_init (struct at_device *device) {
struct at_device_nt26k *nt26k = RT_NULL;
- RT_ASSERT(device);
+ RT_ASSERT (device);
- nt26k = (struct at_device_nt26k *)device->user_data;
- nt26k->power_status = RT_FALSE; // default power is off.
- nt26k->sleep_status = RT_FALSE; // default sleep is disabled.
+ nt26k = (struct at_device_nt26k *)device->user_data;
+ nt26k->power_status = RT_FALSE; // default power is off.
+ nt26k->sleep_status = RT_FALSE; // default sleep is disabled.
/* initialize AT client */
#if RT_VER_NUM >= 0x50100
- at_client_init(nt26k->client_name, nt26k->recv_line_num, nt26k->recv_line_num);
+ at_client_init (nt26k->client_name, nt26k->recv_line_num, nt26k->recv_line_num);
#else
- at_client_init(nt26k->client_name, nt26k->recv_line_num);
+ at_client_init (nt26k->client_name, nt26k->recv_line_num);
#endif
- device->client = at_client_get(nt26k->client_name);
- if (device->client == RT_NULL)
- {
- LOG_E("get AT client(%s) failed.", nt26k->client_name);
+ device->client = at_client_get (nt26k->client_name);
+ if (device->client == RT_NULL) {
+ LOG_E ("get AT client(%s) failed.", nt26k->client_name);
return -RT_ERROR;
}
/* register URC data execution function */
- at_obj_set_urc_table(device->client, urc_table, sizeof(urc_table) / sizeof(urc_table[0]));
+ at_obj_set_urc_table (device->client, urc_table, sizeof (urc_table) / sizeof (urc_table[0]));
#ifdef AT_USING_SOCKET
- nt26k_socket_init(device);
+ nt26k_socket_init (device);
#endif
/* add nt26k device to the netdev list */
- device->netdev = nt26k_netdev_add(nt26k->device_name);
- if (device->netdev == RT_NULL)
- {
- LOG_E("add netdev(%s) failed.", nt26k->device_name);
+ device->netdev = nt26k_netdev_add (nt26k->device_name);
+ if (device->netdev == RT_NULL) {
+ LOG_E ("add netdev(%s) failed.", nt26k->device_name);
return -RT_ERROR;
}
/* initialize nt26k pin configuration */
- if (nt26k->pwr_en_pin != -1)
- {
- rt_pin_mode(nt26k->pwr_en_pin, PIN_MODE_OUTPUT);
+ if (nt26k->pwr_en_pin != -1) {
+ rt_pin_mode (nt26k->pwr_en_pin, PIN_MODE_OUTPUT);
// rt_pin_write(nt26k->pwr_en_pin, PIN_LOW);
}
- if (nt26k->rst_pin != -1)
- {
- rt_pin_mode(nt26k->rst_pin, PIN_MODE_OUTPUT);
+ if (nt26k->rst_pin != -1) {
+ rt_pin_mode (nt26k->rst_pin, PIN_MODE_OUTPUT);
}
- if (nt26k->pwr_key_pin != -1)
- {
- rt_pin_mode(nt26k->pwr_key_pin, PIN_MODE_OUTPUT);
- device->class->device_ops->control(device, AT_DEVICE_CTRL_WAKEUP, RT_NULL);
+ if (nt26k->pwr_key_pin != -1) {
+ rt_pin_mode (nt26k->pwr_key_pin, PIN_MODE_OUTPUT);
+ device->class->device_ops->control (device, AT_DEVICE_CTRL_WAKEUP, RT_NULL);
}
/* initialize nt26k device network */
- return nt26k_netdev_set_up(device->netdev);
+ return nt26k_netdev_set_up (device->netdev);
}
-static int nt26k_deinit(struct at_device *device)
-{
- RT_ASSERT(device);
+static int nt26k_deinit (struct at_device *device) {
+ RT_ASSERT (device);
- return nt26k_netdev_set_down(device->netdev);
+ return nt26k_netdev_set_down (device->netdev);
}
-static int nt26k_control(struct at_device *device, int cmd, void *arg)
-{
+static int nt26k_control (struct at_device *device, int cmd, void *arg) {
int result = -RT_ERROR;
- RT_ASSERT(device);
+ RT_ASSERT (device);
- switch (cmd)
- {
- case AT_DEVICE_CTRL_SLEEP:
- result = nt26k_sleep(device);
- break;
- case AT_DEVICE_CTRL_WAKEUP:
- result = nt26k_wakeup(device);
- break;
- case AT_DEVICE_CTRL_NET_CONN:
- result = at_device_nt26k_connect_tcp(device);
- break;
- case AT_DEVICE_CTRL_NET_DISCONN:
- result = at_device_nt26k_disconnect_tcp(device); // 直接删除Socket
- break;
- case AT_DEVICE_CTRL_GET_SIGNAL:
- result = Nt26k_Get_Signal_Info(device);
- break;
- case AT_DEVICE_CTRL_RESET:
- result = Nt26k_Reset(device);
- break;
- case AT_DEVICE_CTRL_POWER_ON:
- result = nt26k_power_on(device);
- break;
- case AT_DEVICE_CTRL_POWER_OFF:
- result = nt26k_power_off(device);
- break;
- case AT_DEVICE_CTRL_LOW_POWER:
- case AT_DEVICE_CTRL_SET_WIFI_INFO:
- case AT_DEVICE_CTRL_GET_GPS:
- case AT_DEVICE_CTRL_GET_VER:
- LOG_W("not support the control command(%d).", cmd);
- break;
- default:
- LOG_E("input error control command(%d).", cmd);
- break;
+ switch (cmd) {
+ case AT_DEVICE_CTRL_SLEEP:
+ result = nt26k_sleep (device);
+ break;
+ case AT_DEVICE_CTRL_WAKEUP:
+ result = nt26k_wakeup (device);
+ break;
+ case AT_DEVICE_CTRL_NET_CONN:
+ result = at_device_nt26k_connect_tcp (device);
+ break;
+ case AT_DEVICE_CTRL_NET_DISCONN:
+ result = at_device_nt26k_disconnect_tcp (device); // 直接删除Socket
+ break;
+ case AT_DEVICE_CTRL_GET_SIGNAL:
+ result = Nt26k_Get_Signal_Info (device);
+ break;
+ case AT_DEVICE_CTRL_RESET:
+ result = Nt26k_Reset (device);
+ break;
+ case AT_DEVICE_CTRL_POWER_ON:
+ result = nt26k_power_on (device);
+ break;
+ case AT_DEVICE_CTRL_POWER_OFF:
+ result = nt26k_power_off (device);
+ break;
+ case AT_DEVICE_CTRL_LOW_POWER:
+ case AT_DEVICE_CTRL_SET_WIFI_INFO:
+ case AT_DEVICE_CTRL_GET_GPS:
+ case AT_DEVICE_CTRL_GET_VER:
+ LOG_W ("not support the control command(%d).", cmd);
+ break;
+ default:
+ LOG_E ("input error control command(%d).", cmd);
+ break;
}
return result;
}
-// 将本地时间转换为对应时区时间
-void Time_Zone_Conversion(TsRtcDateTime *timeInfo)
-{
- // 根据时区差异进行转换,这里时区差为8小时,没有分钟差异。
- timeInfo->hour += RT_LIBC_DEFAULT_TIMEZONE; // 小时部分加8小时
- if (timeInfo->hour >= 24)
- { // 如果超过24小时,则天数加1,小时数减24。
- timeInfo->day++;
- timeInfo->hour -= 24;
- if (timeInfo->day > 365)
- {
- timeInfo->year += 1;
- }
- }
-}
-
-int Time_Calibration(struct at_device *device)
-{
+int Time_Calibration (struct at_device *device) {
at_response_t resp = RT_NULL;
- RT_ASSERT(device);
- resp = at_create_resp(64, 2, rt_tick_from_millisecond(2000));
- if (resp == RT_NULL)
- {
- LOG_E("no memory for resp create.");
- at_delete_resp(resp);
+ RT_ASSERT (device);
+ resp = at_create_resp (64, 2, rt_tick_from_millisecond (2000));
+ if (resp == RT_NULL) {
+ LOG_E ("no memory for resp create.");
+ at_delete_resp (resp);
return RT_ERROR;
}
- if (at_obj_exec_cmd(device->client, resp, "AT+CCLK?") == RT_EOK)
- {
+ if (at_obj_exec_cmd (device->client, resp, "AT+CCLK?") == RT_EOK) {
TsRtcDateTime rtc_dt;
- ; // 网络时间
+ ; // 网络时间
int year, mounth, days, hous, min, sec;
/*+CCLK:24/11/12,06:08:19+32*/
- if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0)
- {
- rtc_dt.year = (2000 + year);
- rtc_dt.month = mounth;
- rtc_dt.day = days;
- rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区
+ if (at_resp_parse_line_args_by_kw (resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0) {
+ rtc_dt.year = (2000 + year);
+ rtc_dt.month = mounth;
+ rtc_dt.day = days;
+ rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区
rtc_dt.minute = min;
rtc_dt.second = sec;
- Time_Zone_Conversion(&rtc_dt); // 时区设置
- rtc_dt.week = RTC_GetWeek(rtc_dt.year, rtc_dt.month, rtc_dt.day);
- RTC_SetTime(rtc_dt.year, rtc_dt.month, rtc_dt.day,
- rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间
- LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n",
- rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second);
- at_delete_resp(resp);
+ Time_Zone_Conversion (&rtc_dt); // 时区设置
+ rtc_dt.week = RTC_GetWeek (rtc_dt.year, rtc_dt.month, rtc_dt.day);
+ RTC_SetTime (rtc_dt.year, rtc_dt.month, rtc_dt.day,
+ rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间
+ LOG_I ("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n",
+ rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second);
+ at_delete_resp (resp);
return RT_EOK;
}
}
- at_delete_resp(resp);
+ at_delete_resp (resp);
return RT_ERROR;
}
@@ -1440,22 +1297,21 @@ const struct at_device_ops nt26k_device_ops =
nt26k_control,
};
-int nt26k_device_class_register(void)
-{
+int nt26k_device_class_register (void) {
struct at_device_class *class = RT_NULL;
- class = (struct at_device_class *)rt_calloc(1, sizeof(struct at_device_class));
- if (class == RT_NULL)
- {
- LOG_E("no memory for device class create.");
- rt_free(class);
+ class = (struct at_device_class *)rt_calloc (1, sizeof (struct at_device_class));
+ if (class == RT_NULL) {
+ LOG_E ("no memory for device class create.");
+ rt_free (class);
return -RT_ENOMEM;
}
class->device_ops = &nt26k_device_ops;
- return at_device_class_register(class, AT_DEVICE_CLASS_NT26K);
+ return at_device_class_register (class, AT_DEVICE_CLASS_NT26K);
}
-// INIT_DEVICE_EXPORT(nt26k_device_class_register);
-#endif //! IOT_MODULE_SWITCH
-#endif /* AT_DEVICE_USING_NT26K */
+// INIT_DEVICE_EXPORT(nt26k_device_class_register);
+#endif //! IOT_MODULE_SWITCH
+
+#endif /* AT_DEVICE_USING_NT26K */
diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c
index 67781f7..18ea713 100644
--- a/bsp/src/bsp_flash.c
+++ b/bsp/src/bsp_flash.c
@@ -19,13 +19,13 @@
: (id) == kAlarmLValueId ? (&(info)->alarm_l_value) \
: (id) == kAlarmHValueId ? (&(info)->alarm_h_value) \
: (id) == kTempAlarmThresholdId ? (&(info)->temp_alarm_threshold) \
- : (id) == kNbUploadCycleId ? (&(info)->nb_upload_cycle) \
- : (id) == kNbRetryId ? (&(info)->nb_retry) \
+ : (id) == kIotUploadCycleId ? (&(info)->iot_upload_cycle) \
+ : (id) == kIotRetryId ? (&(info)->iot_retry) \
: (id) == kEmagneticSwitchId ? (&(info)->emagnetic_switch) \
: (id) == kRelaySwitchId ? (&(info)->relay_switch) \
- : (id) == kNbImeiId ? ((info)->nb_imei) \
- : (id) == kNbImsiId ? ((info)->nb_imsi) \
- : (id) == kNbIccidId ? ((info)->nb_iccid) \
+ : (id) == kIotImeiId ? ((info)->iot_imei) \
+ : (id) == kIotImsiId ? ((info)->iot_imsi) \
+ : (id) == kIotIccidId ? ((info)->iot_iccid) \
: NULL)
TsTotalRecords TotalRecords;
@@ -82,8 +82,8 @@ static rt_base_t interrupt_value;
/*默认的系统配置*/
rt_uint8_t sys_hw_ver = SYS_HW_VERSION;
rt_uint8_t sys_sw_ver = SYS_SW_VERSION;
-rt_uint8_t sys_nb_retry = 0x03; // 重试次数3次
-rt_uint16_t sys_nb_upload_cycle = SYS_IOT_UPLOAD_CYCLE_MIN; // 60分钟一次 ,低位在前,高为在后,为了和服务器下发时保持一致,有利于读取
+rt_uint8_t sys_iot_retry = 0x03; // 重试次数3次
+rt_uint16_t sys_iot_upload_cycle = SYS_IOT_UPLOAD_CYCLE_MIN; // 60分钟一次 ,低位在前,高为在后,为了和服务器下发时保持一致,有利于读取
rt_uint8_t sys_alarm_h_value = 0x32; // 50
rt_uint8_t sys_alarm_l_value = SYS_ALARM_VALVE; // 10
rt_uint8_t sys_temp_alarm_threshold = 0x32;
@@ -150,7 +150,7 @@ static rt_size_t Flash_Read(rt_uint32_t addr, rt_uint8_t *buf, rt_size_t len)
return read_len;
}
-int Get_Nb_Imei(char *buf, rt_size_t len)
+int Get_IotImei(char *buf, rt_size_t len)
{
if ((*(rt_uint8_t *)FLASH_NB_IMEI_ADDR != 0xE3)&&(*(rt_uint8_t *)FLASH_NB_IMEI_ADDR != 0x39))
{
@@ -171,7 +171,7 @@ int Get_Nb_Imei(char *buf, rt_size_t len)
}
}
-int Get_Nb_Imsi(char *buf, rt_size_t len)
+int Get_IotImsi(char *buf, rt_size_t len)
{
if ((*(rt_uint8_t *)FLASH_NB_IMSI_ADDR != 0xE3)&&(*(rt_uint8_t *)FLASH_NB_IMSI_ADDR != 0x39))
{
@@ -192,7 +192,7 @@ int Get_Nb_Imsi(char *buf, rt_size_t len)
}
}
-int Get_Nb_Iccid(char *buf, rt_size_t len)
+int Get_IotIccid(char *buf, rt_size_t len)
{
if ((*(rt_uint8_t *)FLASH_NB_ICCID_ADDR != 0xE3)&&(*(rt_uint8_t *)FLASH_NB_ICCID_ADDR != 0x39))
{
@@ -729,18 +729,18 @@ rt_uint8_t Flash_Sys_Cfg(TeFlashCfgInfoId id, rt_uint8_t *buf, rt_size_t len)
/*这个返回一两个字节的数,方便提取*/
size_t Flash_Get_SysCfg(TeFlashCfgInfoId id)
{
- rt_uint8_t nb_upload_cycle[2] = {0};
- rt_uint16_t nb_upload;
- if (id != kNbUploadCycleId)
+ rt_uint8_t iot_upload_cycle[2] = {0};
+ rt_uint16_t iot_upload;
+ if (id != kIotUploadCycleId)
{
return *(rt_uint8_t *)hr_sys_cfg_info_addr[id];
}
else
{
- rt_memcpy(&nb_upload_cycle[0], (rt_uint8_t *)hr_sys_cfg_info_addr[id], 2);
- nb_upload = ((nb_upload_cycle[0]<<8) + nb_upload_cycle[1]);
- LOG_D("nb_upload: %d", nb_upload);
- return nb_upload;
+ rt_memcpy(&iot_upload_cycle[0], (rt_uint8_t *)hr_sys_cfg_info_addr[id], 2);
+ iot_upload = ((iot_upload_cycle[0]<<8) + iot_upload_cycle[1]);
+ LOG_D("iot_upload: %d", iot_upload);
+ return iot_upload;
}
}
@@ -833,8 +833,8 @@ int BSP_Flash_Init(void)
sci.sw_ver = sys_sw_ver;
sci.alarm_l_value = sys_alarm_l_value;
sci.alarm_h_value = sys_alarm_h_value;
- sci.nb_upload_cycle = sys_nb_upload_cycle;
- sci.nb_retry = sys_nb_retry;
+ sci.iot_upload_cycle = sys_iot_upload_cycle;
+ sci.iot_retry = sys_iot_retry;
sci.temp_alarm_threshold = sys_temp_alarm_threshold;
sci.emagnetic_switch = sys_emagnetic_switch;
sci.relay_switch = sys_relay_switch;
diff --git a/bsp/src/bsp_h308.c b/bsp/src/bsp_h308.c
index 4039733..a5c39e0 100644
--- a/bsp/src/bsp_h308.c
+++ b/bsp/src/bsp_h308.c
@@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-11-14 10:21:04
* @LastEditors: mbw && 1600520629@qq.com
- * @LastEditTime: 2024-12-30 17:30:15
+ * @LastEditTime: 2025-01-08 11:27:49
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\bsp\src\bsp_h308.c
* @Description:
*
@@ -285,7 +285,7 @@ static void h308_thread_entry(void *param)
if (len >= 44)
{
ret = H308_GetFrameData(str, len, &H308.Data);
- LOG_I("str:[%s]", str);
+ // LOG_I("str:[%s]", str);
if (ret == 0)
{
H308_CheckData();
@@ -313,19 +313,17 @@ static void h308_thread_entry(void *param)
if (h308_rx_timout_cnt)
{
- // LOG_E("h308_rx_timout_cnt:%d", h308_rx_timout_cnt);
h308_rx_timout_cnt = 0;
}
}
- else if (ret == -RT_ETIMEOUT)
+ else if (ret == -RT_ETIMEOUT)//这个主要是考虑传感器未焊接好,或者脱落的情况,国标要求30s内反应 3*5 = 15s,符合国标
{
h308_rx_timout_cnt++;
if (h308_rx_timout_cnt >= 5)
{
- // LOG_E("h308_rx_timout_cnt:%d", h308_rx_timout_cnt);
H308_RST_ON;
rt_thread_mdelay(100);
- H308_RST_OFF;
+ H308_RST_OFF;//复位一下
h308_rx_timout_cnt = 0;
if (H308.detection_flag != kH308Fault)
{
diff --git a/bsp/src/bsp_hr.c b/bsp/src/bsp_hr.c
index 1a926ed..7f1da34 100644
--- a/bsp/src/bsp_hr.c
+++ b/bsp/src/bsp_hr.c
@@ -466,9 +466,9 @@ send:
// }
// rt_uint32_t cnt = (rt_uint32_t)((time_buf[2]<<16)| (time_buf[1] << 8)|time_buf[0]);
// LOG_D("time_buf[2] = %02x time_buf[1] = %02x time_buf[0] = %02x cnt = %04d", time_buf[2], time_buf[1], time_buf[0], cnt);
-// Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
-// Get_Nb_Imsi(imsi, FLASH_NB_IMSI_LEN);
-// Get_Nb_Iccid(iccid, FLASH_NB_ICCID_LEN);
+// Get_IotImei(imei, FLASH_NB_IMEI_LEN);
+// Get_IotImsi(imsi, FLASH_NB_IMSI_LEN);
+// Get_IotIccid(iccid, FLASH_NB_ICCID_LEN);
// rt_sprintf(buf,
// "\r\n[ID :YD4N02/%02d%02d%02d%04d]\r\n"
// "[IMEI:%s]\r\n"
@@ -540,9 +540,9 @@ int Process_Factor_Cmd(rt_uint8_t cmd)
}
rt_uint32_t cnt = (rt_uint32_t)((time_buf[2]<<16)| (time_buf[1] << 8)|time_buf[0]);
LOG_D("time_buf[2] = %02x time_buf[1] = %02x time_buf[0] = %02x cnt = %04d", time_buf[2], time_buf[1], time_buf[0], cnt);
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
- Get_Nb_Imsi(imsi, FLASH_NB_IMSI_LEN);
- Get_Nb_Iccid(iccid, FLASH_NB_ICCID_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImsi(imsi, FLASH_NB_IMSI_LEN);
+ Get_IotIccid(iccid, FLASH_NB_ICCID_LEN);
rt_sprintf(buf,
"\r\n[ID :YD4N02/%02d%02d%02d%04d]\r\n"
"[IMEI:%s]\r\n"
diff --git a/bsp/src/bsp_led.c b/bsp/src/bsp_led.c
index 16d4eaf..1d51b37 100644
--- a/bsp/src/bsp_led.c
+++ b/bsp/src/bsp_led.c
@@ -46,18 +46,19 @@ static void BSP_Led_thread_entry(void *param)
#endif
if (SysControl.status == kNormalDetectionEvents)
{
- if ((power_on_send_flag))
+ if ((nt26k_conncet_tcp_flag))
{
- LED_G_INTERNET;
+ LED_G_NORMAL;
}
- else if ((!power_on_send_flag))
+ else if ((!nt26k_conncet_tcp_flag))
{
- LED_G_NORMAL;
+ LED_G_INTERNET;
}
}
rt_thread_mdelay(1000);
}
}
+
int BSP_LED_Init(void)
{
led_r = agile_led_create(LED_R_PIN, PIN_HIGH, "100,0", 0);
diff --git a/bsp/src/bsp_nt26k.c b/bsp/src/bsp_nt26k.c
index 3d77631..f640043 100644
--- a/bsp/src/bsp_nt26k.c
+++ b/bsp/src/bsp_nt26k.c
@@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-10-09 08:42:14
* @LastEditors: mbw && 1600520629@qq.com
- * @LastEditTime: 2024-12-31 11:01:49
+ * @LastEditTime: 2025-01-08 11:31:58
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\bsp\src\bsp_nt26k.c
* @Description:
*
@@ -758,6 +758,7 @@ const Nt26kEventInfo nt26k_event_info[] = {
*/
int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device, void *param)
{
+ rt_uint8_t max_retry_count = (rt_uint8_t)Flash_Get_SysCfg(kIotRetryId);
struct Nt26k_Ops *nt26k_ops = (struct Nt26k_Ops *)param;
const Nt26kEventInfo *event = RT_NULL;
@@ -771,61 +772,34 @@ int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device,
}
}
- // 处理该事件
- if (event)
+ if (event) // 处理该事件
{
// 打印事件的名称
LOG_D("%s上报\n", event->event_name);
-
- // 如果事件有关联的发送函数,则调用该发送函数
- if (event->send_func)
+ for (size_t i = 0; i < max_retry_count; i++)
{
- int result = event->send_func(device, nt26k_ops);
- if (result != RT_EOK)
+ if (nt26k_conncet_tcp_flag)
{
- LOG_E("nt26k send cmd failed\n");
- Nt26k_Reset(device); // 重启模组
- rt_thread_mdelay(5000);
- if (nt26k_conncet_tcp_flag != 1)
+ // 如果事件有关联的发送函数,则调用该发送函数
+ rt_thread_mdelay(IMEI_Delay());
+ if (event->send_func)
{
- if (device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL) == RT_EOK) // 打开连接
+ RTC_ShowTime();//每次发送打印下时间,容易定位问题
+ int result = event->send_func(device, nt26k_ops);
+ if (result != RT_EOK)
{
- LOG_D("nt26k connect tcp success\n");
- // 重启后重新尝试发送
- result = event->send_func(device, nt26k_ops);
- if (result != RT_EOK)
- {
- LOG_E("nt26k send cmd after module reset failed\n");
-
- if (device->class->device_ops->control(device, AT_DEVICE_CTRL_POWER_OFF, RT_NULL) == RT_EOK) // 打开连接
- {
- rt_thread_mdelay(5000);
- if (device->class->device_ops->control(device, AT_DEVICE_CTRL_POWER_ON, RT_NULL) == RT_EOK)
- {
- LOG_D("模组重新上电\n");
- }
- else
- {
- LOG_E("模组上电失败,重启系统\n");
- Flash_Set_WorkDuration(work_duration); // 重启前保存参数
- NVIC_SystemReset(); // 直接重启系统
- }
- }
- }
+ LOG_E("nt26k send cmd failed\n");
}
else
- {
- LOG_E("nt26k connect tcp failed\n");
- Nt26k_Reset(device); // 重启模组
- }
- }
- else
- {
- LOG_E("NT26K连接标志有BUG\n");
+ return RT_EOK; // 函数执行完毕,返回0
}
}
else
- return RT_EOK;
+ {
+ LOG_D("断网\n");
+ rt_sem_release(nt26k_disconnect_sem);
+ }
+ rt_thread_mdelay(5000);
}
}
// 函数执行完毕,返回0
@@ -877,7 +851,7 @@ void Handle_Self_Check(struct Nt26k_Ops *ops)
{
LOG_D("服务器下发自检指令\n");
char imei[16] = {0};
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
LOG_D("imei:%s\n", imei);
char temp[32] = "0";
@@ -893,7 +867,7 @@ void Handle_Mute(struct Nt26k_Ops *ops)
LOG_D("服务器下发消音指令\n");
char imei[16] = {0};
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
char temp[32] = "0";
String2Hex(temp, imei); // 将字符串转为十六进制字符串
@@ -907,7 +881,7 @@ void Handle_Close_Valve(struct Nt26k_Ops *ops)
LOG_D("服务器下发关闭阀门指令\n");
char imei[16] = {0};
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
char temp[32] = "0";
String2Hex(temp, imei); // 将字符串转为十六进制字符串
EMV_CLOSE_VALVE;
@@ -919,7 +893,7 @@ void Handle_Open_Valve(struct Nt26k_Ops *ops)
LOG_D("服务器下发打开阀门指令\n");
// char imei[16] = {0};
- // Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ // Get_IotImei(imei, FLASH_NB_IMEI_LEN);
// char temp[32] = "0";
// String2Hex(temp, imei); // 将字符串转为十六进制字符串
@@ -936,7 +910,7 @@ void Handle_Open_Relay(struct Nt26k_Ops *ops)
LOG_D("服务器下发打开继电器指令\n");
char imei[16] = {0};
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
char temp[32] = "0";
String2Hex(temp, imei); // 将字符串转为十六进制字符串
relay_state_flag = 1;
@@ -952,7 +926,7 @@ void Handle_Close_Relay(struct Nt26k_Ops *ops)
char imei[16] = {0};
char temp[32] = "0";
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
String2Hex(temp, imei); // 将字符串转为十六进制字符串
relay_state_flag = 0;
@@ -967,7 +941,7 @@ void Handle_Query_Params(struct Nt26k_Ops *ops)
LOG_D("服务器下发查询系统参数\n");
rt_memcpy(data, (rt_uint8_t *)FLASH_HW_VER_ADDR, sizeof(sys_config_info) - 50);
- LOG_D("hw_ver:%02x sw_ver:%02x alarm_low:%02x alarm_high:%02x temp_alarm:%02x nb_upload_cycle:%dmin retry:%02x emagnetic:%02X relay_switch:%02X\n",
+ LOG_D("hw_ver:%02x sw_ver:%02x alarm_low:%02x alarm_high:%02x temp_alarm:%02x iot_upload_cycle:%dmin retry:%02x emagnetic:%02X relay_switch:%02X\n",
data[0], data[1], data[2], data[3], data[4], ((data[5]) | (data[6] << 8)), data[7], data[8], data[9]);
rt_sprintf(str, "0000000000%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
@@ -986,14 +960,14 @@ int Handle_Config_Params(struct Nt26k_Ops *ops)
LOG_D("服务器下发配置参数\n");
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
String2Hex(temp, imei); // 将字符串转为十六进制字符串
rt_memset(data_buf, '0', 32);
rt_memcpy(recv_data, (ops->recv->recv_data.res_data + 5), sizeof(sys_config_info) - 50);
rt_memcpy(flash_info, (rt_uint8_t *)FLASH_HW_VER_ADDR, sizeof(sys_config_info) - 50);
- LOG_D("hw_ver:%02x sw_ver:%02x alarm_low:%02x alarm_high:%02x temp_alarm:%02x nb_upload_cycle:%d min retry:%02x emagnetic:%02X relay_switch:%02X\n",
+ LOG_D("hw_ver:%02x sw_ver:%02x alarm_low:%02x alarm_high:%02x temp_alarm:%02x iot_upload_cycle:%d min retry:%02x emagnetic:%02X relay_switch:%02X\n",
flash_info[0], flash_info[1], flash_info[2], flash_info[3], flash_info[4], (flash_info[5] | (flash_info[6] << 8)), flash_info[7], flash_info[8], recv_data[9]);
LOG_D("recv_data: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n",
recv_data[0], recv_data[1], recv_data[2], recv_data[3], recv_data[4],
@@ -1019,14 +993,14 @@ int Handle_Config_Params(struct Nt26k_Ops *ops)
{
if (BSP_Flash_Write_Info(recv_data, sizeof(sys_config_info) - 50) != 0)
{
- rt_uint16_t nb_upload_time = (uint16_t)Flash_Get_SysCfg(kNbUploadCycleId);
- unsigned long timeout = nb_upload_time * 60 * RT_TICK_PER_SECOND;
+ rt_uint16_t iot_upload_time = (uint16_t)Flash_Get_SysCfg(kIotUploadCycleId);
+ unsigned long timeout = iot_upload_time * 60 * RT_TICK_PER_SECOND;
// rt_timer_stop(nt26k_timer);
rt_timer_control(nt26k_timer, RT_TIMER_CTRL_SET_TIME, (void *)&timeout); // 更新上报周期
// rt_timer_control(nt26k_timer, RT_TIMER_CTRL_GET_TIME, &timeout);
// LOG_D("timeout:%d", timeout/1000/60);
rt_timer_start(nt26k_timer);
- LOG_D("上报周期由%dmin更新为%dmin", ((flash_info[5] << 8) | flash_info[6]), nb_upload_time);
+ LOG_D("上报周期由%dmin更新为%dmin", ((flash_info[5] << 8) | flash_info[6]), iot_upload_time);
if (ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_NT26K, INSTRUCTION_DOWN_CONFIG_PARAMS, temp, RESPONSE_CODE_SUCCESS) == RT_EOK)
{
LOG_D("配置参数写入成功\n");
@@ -1061,7 +1035,7 @@ void Handle_Time_Calibration_Data(struct Nt26k_Ops *ops)
LOG_D("时间校准数据\n");
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
String2Hex(temp, imei); // 将字符串转为十六进制字符串
rt_memcpy(data, ops->recv->recv_data.res_data, sizeof(data));
@@ -1084,7 +1058,7 @@ void Handle_Sever_Addr_Set(struct Nt26k_Ops *ops)
char imei[16] = {0};
char temp[32] = "0";
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
String2Hex(temp, imei); // 将字符串转为十六进制字符串
rt_memcpy(data, (ops->recv->recv_data.res_data + 9), FLASH_SERVER_LEN);
LOG_D("data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x", 0, data[0], 1, data[1], 2, data[2], 3, data[3], 4, data[4], 5, data[5]);
@@ -1107,7 +1081,7 @@ void Handle_Error(struct Nt26k_Ops *ops, rt_err_t ret)
char imei[16] = {0};
char temp[32] = "0";
- Get_Nb_Imei(imei, FLASH_NB_IMEI_LEN);
+ Get_IotImei(imei, FLASH_NB_IMEI_LEN);
String2Hex(temp, imei); // 将字符串转为十六进制字符串
ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_NT26K, ops->recv->cmd, temp, RESPONSE_CODE_PARSE_FAIL);
}
@@ -1227,6 +1201,8 @@ static void Nt26k_Send_Thread_Entry(void *param)
{
LOG_D("nt26k init success\n");
rt_completion_wait(&nt26k_init_complate, RT_WAITING_FOREVER); // wait for nt26k init finish
+ Nt26k_Send_Event(kNt26kTimeCalibrationEvent); // 上电网络连接成功时,更新下时间
+ rt_timer_start(nt26k_upload_timer);
Nt26k_Send_Event(kNt26kPowerOnEvent);
}
while (1)
@@ -1280,8 +1256,6 @@ static void Nt26k_Send_Thread_Entry(void *param)
{
rt_timer_start(nt26k_timer); // 当上电心跳包发送成功时, 开始心跳包周期发送
power_on_send_flag = 1;
- Nt26k_Send_Event(kNt26kTimeCalibrationEvent); // 上电网络连接成功时,更新下时间
- rt_timer_start(nt26k_upload_timer);
}
}
if (power_on_send_flag)
@@ -1448,7 +1422,7 @@ static void Nt26k_Life_Thread_Entry(void *parameter)
}
else
{
- LOG_D("重连网络失败\n");
+ LOG_D("重连网络失败,等待 10s 后重连\n");
rt_thread_mdelay(10000);
rt_sem_release(nt26k_disconnect_sem);
}
@@ -1468,9 +1442,9 @@ int BSP_Nt26k_Thread_Init(void)
rt_err_t ret;
Nt26k_Event_Init();
- rt_uint32_t nb_upload_time = (uint16_t)Flash_Get_SysCfg(kNbUploadCycleId);
- unsigned long timeout = nb_upload_time * 60 * RT_TICK_PER_SECOND;
- LOG_I("上报服务器周期:%d分钟", nb_upload_time);
+ rt_uint32_t iot_upload_time = (uint16_t)Flash_Get_SysCfg(kIotUploadCycleId);
+ unsigned long timeout = iot_upload_time * 60 * RT_TICK_PER_SECOND;
+ LOG_I("上报服务器周期:%d分钟", iot_upload_time);
nt26k_mutex = rt_mutex_create("nt26k_mutex", RT_IPC_FLAG_PRIO);
if (nt26k_mutex == RT_NULL)
{
diff --git a/bsp/src/bsp_rtc.c b/bsp/src/bsp_rtc.c
index debdb25..81afd1b 100644
--- a/bsp/src/bsp_rtc.c
+++ b/bsp/src/bsp_rtc.c
@@ -329,11 +329,6 @@ int BSP_RTC_Init(void)
}
else
{
- // 外部手动复位
- // if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
- // {
- // LOG_D("外部硬件复位信号");
- // }
// 上电/掉电复位标志
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
@@ -442,10 +437,10 @@ void Timestamp_To_Rtc_DateTime(time_t timestamp, TsRtcDateTime *rtc_dt)
#ifdef TEST_ENABLE
-static void RTC_ShowTime(void)
+void RTC_ShowTime(void)
{
RTC_GetTime();
- LOG_D("RTC Timer : %04d-%02d-%02d %02d:%02d:%02d week[%d]", RtcDateTime.year, RtcDateTime.month, RtcDateTime.day,
+ LOG_I("RTC Timer : %04d-%02d-%02d %02d:%02d:%02d week[%d]", RtcDateTime.year, RtcDateTime.month, RtcDateTime.day,
RtcDateTime.hour, RtcDateTime.minute, RtcDateTime.second, RtcDateTime.week);
}
MSH_CMD_EXPORT(RTC_ShowTime, "get rtc timer");
diff --git a/libcpu/cpu/cpuport.c b/libcpu/cpu/cpuport.c
index d738d06..1c352db 100644
--- a/libcpu/cpu/cpuport.c
+++ b/libcpu/cpu/cpuport.c
@@ -11,7 +11,7 @@
#include
#include
#include "ch32v30x.h"
-#include "libcpu/cpu/cpuport.h"
+#include "cpuport.h"
#ifndef RT_USING_SMP
volatile rt_ubase_t rt_interrupt_from_thread = 0;