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:
+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