feat: 新增全功率运行时间段(FPO)功能
- bsp.h: LayoutPara_t 新增 FPOTimeStart/FPOTime 字段, 移除BOM, 声明TimeGet - main.h: 声明 IsFullPowerTime - main.c: 新增 IsFullPowerTime() 判断函数(支持跨天), 睡眠条件加FPO检查, AppInit中FPO参数初始化与校验 - SGCP.h: 新增 GWTOMD_CMD_SET_FPO=0x0A, GW_STATUS_SET_FPO 枚举, 声明 ToGWSetFPORes - SGCP.c: 实现 ToGWSetFPORes() 回应帧, GWTOMD_CMD_SET_FPO 接收处理(校验/存Flash), 两个GwRevLoopHandler新增GW_STATUS_SET_FPO case - UartDebug.c: 新增 fpocfg 调试命令(配置后向网关发送0x0A通知), para输出FPO信息, DEBUG_CMD_CNT 17->18 - bsp.c: TimeGet 去除UTC+8偏移(RTC已存本地时间)
This commit is contained in:
+4
-1
@@ -98,6 +98,7 @@ typedef enum {
|
||||
GW_STATUS_CALI,
|
||||
GW_STATUS_READ_SENSOR,
|
||||
GW_STATUS_SET_COL_TIME,
|
||||
GW_STATUS_SET_FPO,//设置全功率运行时间段
|
||||
GW_STATUS_SYNC_TIME,
|
||||
GW_STATUS_UPLOAD_SENSOR,//主动上报模式时会使用该状态
|
||||
GW_STATUS_WAIT_UPLOAD,//主动上报模式时会使用该状态
|
||||
@@ -125,7 +126,8 @@ typedef enum {
|
||||
GWTOMD_CMD_LOGIN = 0x00, //0x00,设备注册
|
||||
GWTOMD_CMD_CALI = 0x01, //0x01, 校准指令
|
||||
GWTOMD_CMD_READ_UPLOAD_SENSOR = 0x02, //0x02,读取数据指令or上传数据指令
|
||||
GWTOMD_CMD_SET_COL_TIME = 0x05, //0x05,设置采集时间间隔
|
||||
GWTOMD_CMD_SET_FPO = 0x0A, //0x0A, 设置全功率运行时间段(低功耗设备)
|
||||
GWTOMD_CMD_SET_COL_TIME = 0x05, //0x05,设置采集时间间隔
|
||||
GWTOMD_CMD_SYNC_TIME = 0x06, //0x06,时间同步
|
||||
GWTOMD_CMD_SET_LASER = 0x08,//打开or关闭激光
|
||||
GWTOMD_CMD_SIGNAL = 0x09,
|
||||
@@ -281,6 +283,7 @@ typedef struct {
|
||||
extern SGCP_t SGCP;
|
||||
|
||||
void SGCP1mSRoutine(void);
|
||||
void ToGWSetFPORes(void);
|
||||
|
||||
void GwRevLoopHandler(void);
|
||||
void MasRevLoopHandler(void);
|
||||
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
#ifndef _BSP_H
|
||||
#ifndef _BSP_H
|
||||
#define _BSP_H
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -225,6 +225,8 @@ typedef struct {
|
||||
uint16_t ReportInterval; //上报时间间隔,设置范围,30*N秒,10<=N<=1440(默认1200秒,N=40)
|
||||
uint8_t ERInterval; //紧急上报时间间隔,设置范围,30*N秒,2<=N<=10(默认120秒,N=4)
|
||||
uint8_t ERTime; //紧急上报时长,设置范围,30*N秒,20<=N<=240(默认1200秒,N=40)
|
||||
uint8_t FPOTimeStart; //每天全功率工作时间起始点时间,设置范围0~23小时整点时间(默认0点整)
|
||||
uint8_t FPOTime; //每天全功率工作时间时长,设置范围0~24小时(默认0小时)
|
||||
uint32_t TimeStamp; //网关返回RTC时间戳
|
||||
}__attribute__((packed))LayoutPara_t,*LayoutPara;//上位机下发的配置参数
|
||||
|
||||
@@ -279,6 +281,7 @@ uint32_t GetSysTick(void);
|
||||
void delay_ms(uint32_t ms);
|
||||
void Delay(uint32_t time);
|
||||
void RTCInit(uint8_t sec);
|
||||
void TimeGet(struct tm *cTime);
|
||||
void LPTimer0_ON(uint16_t _100ms);
|
||||
void LPTimer0_OFF(void);
|
||||
void WakeUpInit(void);
|
||||
|
||||
@@ -107,6 +107,7 @@ extern AppDetect_t App;
|
||||
|
||||
void MainDBGOnOff(bool OnOff);
|
||||
void DataDBGOnOff(bool OnOff);
|
||||
bool IsFullPowerTime(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+140
-23
@@ -652,6 +652,46 @@ SGCP.GWRS485Rx.sCmdMDToGW = (GWTOMD_CMD_M)GFHeader->Cmd;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 网关设置全功率运行时间段指令回应
|
||||
**
|
||||
** \param 无(回显已配置的 FPOTimeStart 与 FPOTime,与接收格式一致)
|
||||
**
|
||||
** \retval 无
|
||||
******************************************************************************/
|
||||
void ToGWSetFPORes(void)
|
||||
{
|
||||
uint8_t Pack[256];
|
||||
uint16_t Crc16;
|
||||
uint8_t Len;
|
||||
|
||||
GatewayFrameHeader GFHeader = (GatewayFrameHeader)Pack;
|
||||
|
||||
GFHeader->Header = 0x7B;
|
||||
memcpy(&GFHeader->GWAddr[0], &GatewayMAC[0], sizeof(GFHeader->GWAddr));
|
||||
memcpy(&GFHeader->MDAddr[0], &LocalMAC[0], sizeof(GFHeader->MDAddr));
|
||||
GFHeader->Cmd = GWTOMD_CMD_SET_FPO;
|
||||
GFHeader->PayloadLen = 2;
|
||||
|
||||
Len = sizeof(GatewayFrameHeader_t);
|
||||
|
||||
Pack[Len++] = App.Para.Layout.FPOTimeStart;
|
||||
Pack[Len++] = App.Para.Layout.FPOTime;
|
||||
|
||||
Crc16 = CRC_Modbus(CRC16_BASE, Pack, Len);
|
||||
Pack[Len++] = Crc16 & 0x00ff;
|
||||
Pack[Len++] = (Crc16 >> 8) & 0x00ff;
|
||||
|
||||
SGCP.GWRS485Rx.sCmdMDToGW = (GWTOMD_CMD_M)GFHeader->Cmd;
|
||||
#if(SGCP_SELECT == 1 || SGCP_SELECT == 2)
|
||||
Sx1276LoRaSendBuffer(Pack, Len);
|
||||
#endif
|
||||
#if(SGCP_SELECT == 3)
|
||||
LPUart0SendArray(Pack, Len);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 网关时间同步指令回应
|
||||
@@ -981,29 +1021,69 @@ static void GWRevHandler(void)
|
||||
}
|
||||
else if(PayLoadLen == 10)
|
||||
{
|
||||
App.Para.Layout.CollectTime = LPay->CollectTime/30;
|
||||
App.Para.Layout.ReportInterval = LPay->ReportInterval * 2;
|
||||
App.Para.Layout.ERInterval = LPay->ERInterval * 2;
|
||||
App.Para.Layout.ERTime = LPay->ERTime * 2;
|
||||
App.Para.Layout.TimeStamp = LPay->TimeStamp;
|
||||
|
||||
DBG_LOG("The parameters have been updated. CI:%ds, RI:%dmin, EI:%dmin, ET:%dmin\r\n",
|
||||
LPay->CollectTime,
|
||||
LPay->ReportInterval,
|
||||
LPay->ERInterval,
|
||||
LPay->ERTime);
|
||||
|
||||
int8_t TimeDiff;//时间差
|
||||
int RTCTimes = TimeTs();
|
||||
TimeDiff = App.Para.Layout.TimeStamp - RTCTimes;
|
||||
if(TimeDiff > 1 || TimeDiff < -1)
|
||||
{
|
||||
TimeSync(App.Para.Layout.TimeStamp); //向通讯单元RTC时间寄存器写入时间网关下发的时间
|
||||
}
|
||||
SGCP.UploadOk = true;
|
||||
SGCP.NextGWStatus = GW_STATUS_UPLOAD_SENSOR;
|
||||
App.Para.Layout.CollectTime = LPay->CollectTime/30;
|
||||
App.Para.Layout.ReportInterval = LPay->ReportInterval * 2;
|
||||
App.Para.Layout.ERInterval = LPay->ERInterval * 2;
|
||||
App.Para.Layout.ERTime = LPay->ERTime * 2;
|
||||
App.Para.Layout.TimeStamp = LPay->TimeStamp;
|
||||
|
||||
DBG_LOG("The parameters have been updated. CI:%ds, RI:%dmin, EI:%dmin, ET:%dmin\r\n",
|
||||
LPay->CollectTime,
|
||||
LPay->ReportInterval,
|
||||
LPay->ERInterval,
|
||||
LPay->ERTime);
|
||||
|
||||
int8_t TimeDiff;//时间差
|
||||
int RTCTimes = TimeTs();
|
||||
TimeDiff = App.Para.Layout.TimeStamp - RTCTimes;
|
||||
if(TimeDiff > 1 || TimeDiff < -1)
|
||||
{
|
||||
TimeSync(App.Para.Layout.TimeStamp); //向通讯单元RTC时间寄存器写入时间网关下发的时间
|
||||
}
|
||||
SGCP.UploadOk = true;
|
||||
SGCP.NextGWStatus = GW_STATUS_UPLOAD_SENSOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;}
|
||||
|
||||
case GWTOMD_CMD_SET_FPO:{
|
||||
if(SGCP.LoginOk == true)
|
||||
{
|
||||
uint8_t Start = PayLoad[0];
|
||||
uint8_t Duration = PayLoad[1];
|
||||
if(Start > 23)
|
||||
{
|
||||
DBG_LOG("FPOTimeStart Err\r\n");
|
||||
if(SGCP.GWStatus == GW_STATUS_WAIT_UPLOAD)
|
||||
{
|
||||
SGCP.UploadOk = true;
|
||||
SGCP.NextGWStatus = GW_STATUS_IDLE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(Duration > 24)
|
||||
{
|
||||
DBG_LOG("FPOTime Err\r\n");
|
||||
if(SGCP.GWStatus == GW_STATUS_WAIT_UPLOAD)
|
||||
{
|
||||
SGCP.UploadOk = true;
|
||||
SGCP.NextGWStatus = GW_STATUS_IDLE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(SGCP.GWStatus == GW_STATUS_WAIT_UPLOAD)
|
||||
{
|
||||
SGCP.UploadOk = true;
|
||||
SGCP.NextGWStatus = GW_STATUS_SET_FPO;
|
||||
}
|
||||
else
|
||||
{
|
||||
SGCP.GWStatus = GW_STATUS_SET_FPO;
|
||||
}
|
||||
App.Para.Layout.FPOTimeStart = Start;
|
||||
App.Para.Layout.FPOTime = Duration;
|
||||
SAVE_APP_PARA((uint32_t *)&App.Para);
|
||||
}
|
||||
break;}
|
||||
|
||||
@@ -1471,6 +1551,25 @@ void GwRevLoopHandler(void)
|
||||
SGCP.GW1mSDelayCnt = 5000;
|
||||
break;}
|
||||
|
||||
case GW_STATUS_SET_FPO:{
|
||||
PrintfMess();
|
||||
if(SGCP.BroadCmd == true)
|
||||
{
|
||||
SGCP.BroadCmd = false;
|
||||
DBG_LOG("Broad FPO Set as %02d:00 ~ %02d:00\r\n", App.Para.Layout.FPOTimeStart,
|
||||
(App.Para.Layout.FPOTimeStart + App.Para.Layout.FPOTime) % 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
ToGWSetFPORes();
|
||||
DBG_LOG("Alone FPO Set as %02d:00 ~ %02d:00\r\n", App.Para.Layout.FPOTimeStart,
|
||||
(App.Para.Layout.FPOTimeStart + App.Para.Layout.FPOTime) % 24);
|
||||
}
|
||||
SGCP.GWStatus = GW_STATUS_WAIT_SUBIDLE;
|
||||
SGCP.NextSubStatus = SUB_STATUS_BROADCAST_SET_COLTIME;
|
||||
SGCP.GW1mSDelayCnt = 5000;
|
||||
break;}
|
||||
|
||||
case GW_STATUS_SYNC_TIME:{
|
||||
PrintfMess();
|
||||
if(SGCP.BroadCmd == true)
|
||||
@@ -1795,6 +1894,24 @@ void GwRevLoopHandler(void)
|
||||
SGCP.GWStatus = GW_STATUS_IDLE;
|
||||
break;}
|
||||
|
||||
case GW_STATUS_SET_FPO:{
|
||||
PrintfMess();
|
||||
if(SGCP.BroadCmd == true)
|
||||
{
|
||||
SGCP.BroadCmd = false;
|
||||
DBG_LOG("Broad FPO Set as %02d:00 ~ %02d:00\r\n", App.Para.Layout.FPOTimeStart,
|
||||
(App.Para.Layout.FPOTimeStart + App.Para.Layout.FPOTime) % 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
ToGWSetFPORes();
|
||||
DBG_LOG("Alone FPO Set as %02d:00 ~ %02d:00\r\n", App.Para.Layout.FPOTimeStart,
|
||||
(App.Para.Layout.FPOTimeStart + App.Para.Layout.FPOTime) % 24);
|
||||
}
|
||||
/*GWRevHandler函数中已经缓存了接收到的全功率运行时间段*/
|
||||
SGCP.GWStatus = GW_STATUS_IDLE;
|
||||
break;}
|
||||
|
||||
case GW_STATUS_SYNC_TIME:{
|
||||
PrintfMess();
|
||||
if(SGCP.BroadCmd == true)
|
||||
@@ -1920,8 +2037,8 @@ void LORA_RxCallBack(uint8_t *rBuff, uint8_t rlen)
|
||||
{
|
||||
if (rlen > 0 && rBuff[0] == 0x7B && memcmp(&rBuff[7],&LocalMAC[0],6) == 0) // 如果接收到了数据,并且设备地址相同则处理接收到的数据
|
||||
{
|
||||
//< 处理接收到的数据
|
||||
memcpy(SGCP.GatewayBuff, rBuff, rlen);
|
||||
//< 处理接收到的数据
|
||||
memcpy(SGCP.GatewayBuff, rBuff, rlen);
|
||||
SGCP.GatewayBuffLen = rlen;
|
||||
GWRevHandler();//网关数据接收处理
|
||||
}
|
||||
|
||||
+1
-1
@@ -647,7 +647,7 @@ void TimeGet(struct tm *cTime)
|
||||
cTime->tm_year = BCDToDec(RtcDateTime.u8Year) + 100;
|
||||
cTime->tm_mon = BCDToDec(RtcDateTime.u8Month) - 1;
|
||||
cTime->tm_mday = BCDToDec(RtcDateTime.u8Day);
|
||||
cTime->tm_hour = BCDToDec(RtcDateTime.u8Hour) + 8;
|
||||
cTime->tm_hour = BCDToDec(RtcDateTime.u8Hour);
|
||||
cTime->tm_min = BCDToDec(RtcDateTime.u8Minute);
|
||||
cTime->tm_sec = BCDToDec(RtcDateTime.u8Second);
|
||||
cTime->tm_isdst = 0;
|
||||
|
||||
+38
-1
@@ -132,6 +132,9 @@ static void AppInit(void)
|
||||
App.Para.Layout.ReportInterval = 40;
|
||||
App.Para.Layout.ERInterval = 4;
|
||||
App.Para.Layout.ERTime = 40;
|
||||
|
||||
App.Para.Layout.FPOTime = 0;
|
||||
App.Para.Layout.FPOTimeStart = 0;
|
||||
}
|
||||
|
||||
if(App.Para.BLPara.LoraFreq < 410000000 || App.Para.BLPara.LoraFreq > 525000000)
|
||||
@@ -157,6 +160,12 @@ static void AppInit(void)
|
||||
if(App.Para.Layout.ERTime > 240 || App.Para.Layout.ERTime < 20) {
|
||||
App.Para.Layout.ERTime = 40;
|
||||
}
|
||||
if(App.Para.Layout.FPOTimeStart > 23 || App.Para.Layout.FPOTimeStart < 0) {
|
||||
App.Para.Layout.FPOTimeStart = 0;
|
||||
}
|
||||
if(App.Para.Layout.FPOTime > 24 || App.Para.Layout.FPOTime < 0) {
|
||||
App.Para.Layout.FPOTime = 0;
|
||||
}
|
||||
if(App.Para.LaserTimerMinutes < 0 || App.Para.LaserTimerMinutes > 240)
|
||||
App.Para.LaserTimerMinutes = 10;
|
||||
SGCP.LaserTimerMinutes = App.Para.LaserTimerMinutes;
|
||||
@@ -316,6 +325,33 @@ static void ReadDataLoopHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool IsFullPowerTime(void)
|
||||
{
|
||||
uint8_t Duration = App.Para.Layout.FPOTime;
|
||||
uint8_t Start = App.Para.Layout.FPOTimeStart;
|
||||
uint8_t Hour;
|
||||
struct tm cTime;
|
||||
|
||||
if(Duration == 0)
|
||||
return false;
|
||||
|
||||
TimeGet(&cTime);
|
||||
Hour = (uint8_t)(cTime.tm_hour % 24);
|
||||
|
||||
if(Start + Duration <= 24)
|
||||
{
|
||||
if(Hour >= Start && Hour < Start + Duration)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t WrapEnd = Start + Duration - 24;
|
||||
if(Hour >= Start || Hour < WrapEnd)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void AppLoopHandler(void)
|
||||
{
|
||||
switch(App.Status) {
|
||||
@@ -385,7 +421,8 @@ static void AppLoopHandler(void)
|
||||
&& App.TD1mSDelayCnt == 0
|
||||
&& App.ReadData1mSDelayCnt == 0
|
||||
&& SGCP.LaserOnOff == false
|
||||
&& App.AttTestMode == false)
|
||||
&& App.AttTestMode == false
|
||||
&& IsFullPowerTime() == false)
|
||||
{
|
||||
//App.Status = APP_STATUS_ACTION;
|
||||
App.Status = APP_STATUS_OFF;
|
||||
|
||||
Reference in New Issue
Block a user