Amélioré le reset LTE et ajout power relay watchdog

This commit is contained in:
jfmartel 2026-05-02 08:50:16 -04:00
parent 13655e40f4
commit bbfc4e10e2
15 changed files with 9484 additions and 9405 deletions

View File

@ -3,6 +3,7 @@
#include "ChaletPowerRelay.h"
#include "BoardCfg.h"
#include "timer.h"
#include "BatteryMonitor.h"
#define PIN_ACTIVE 1
#define PIN_INACTIVE 0
@ -46,6 +47,12 @@ void ChaletPowerRelayTick()
}
}
//LVD: if battery voltage is too low, turn off the power relay
if(PowerRelayState == CHALET_POWER_RELAY_ON_STATE && GetBatteryVoltage(0) < POWER_RELAY_LVD_VOLTAGE_TRESHOLD)
{
ChaletPowerRelayTurnOff();
}
if(IsTimerExpired(CHALET_POWER_RELAY_AUTOTURNOFF_TIMER))
{
ChaletPowerRelayTurnOff();
@ -59,6 +66,11 @@ void ChaletPowerRelayKickTimer()
bool ChaletPowerRelayTurnOn()
{
//LVD: if battery voltage is too low, turn off the power relay
if(GetBatteryVoltage(0) < POWER_RELAY_LVD_VOLTAGE_TRESHOLD)
{
return false;
}
POWER_RELAY_ON_PIN = PIN_ACTIVE;
TimerStart(CHALET_POWER_RELAY_COIL_TIMER,CHALET_POWER_RELAY_COIL_TIMEOUT);
// PowerRelayState = CHALET_POWER_RELAY_ON_STATE;

View File

@ -10,6 +10,7 @@
#include "define.h"
#define CHALET_OFFLINE_POWER_RELAY_RESET_TIMEOUT 43200 //43,200 = 12 hours in seconds
#define POWER_RELAY_LVD_VOLTAGE_TRESHOLD (float)12.00
enum eChaletPowerRelayState
{

View File

@ -9,7 +9,7 @@
#define LORAWATCHDOG_H
#include "define.h"
#define LORA_WATCHDOG_MODULE_RESET_TIMEOUT 3600000 //1h Time without comm. before we reset the LoRa module
#define LORA_WATCHDOG_MODULE_RESET_TIMEOUT 900000 // 15 minutes //3600000 //1h Time without comm. before we reset the LoRa module
#define LORA_WATCHDOG_REBOOT_TIMEOUT 1200000 //20 minutes Time to reboot after we reset the LoRa module
#define LORA_WATCHDOG_MODULE_OFF_TIMEOUT 4000 //Keep the LoRa module off for 2 seconds when reseting it.

View File

@ -34,15 +34,18 @@ bool mMasterConnected;
bool mMasterSocketError;
bool mAPNConnected;
void InitLTEModule()
void InitLTEModule(bool FunctionnalReset)
{
mLTEModuleSMState = LTE_MODULE_SM_INIT_STATE;
mLTEModuleOperationSMState = LTE_MODULE_OPERATION_INIT_STATE;
mLTEModuleOperationSMSubState = LTE_MODULE_OPERATION_NOMINAL_SUBSTATE;
mNbCmdCharsReceived = 0;
mIsPassthroughEnabled = false;
mModuleSerialDebugEnabled = false;
mPICSerialDebugEnabled = false;
if(FunctionnalReset == false)
{
mModuleSerialDebugEnabled = false;
mPICSerialDebugEnabled = false;
}
mCurrentCmd = LTE_MODULE_NO_CMD;
mIsInitializing = true;
mNbMasterReconnectCount = 0;
@ -54,7 +57,7 @@ void InitLTEModule()
}
int LTEModuleReset()
{
InitLTEModule();
InitLTEModule(true);
return RET_OK;
}

View File

@ -125,7 +125,7 @@ enum eLTEModuleOperationSMEvents
void InitLTEModule();
void InitLTEModule(bool FunctionnalReset);
void LTEModuleSM(int SMEvent);
void TickLTEModule();
void LTEModuleOperationSM(int OperationEvent);

View File

@ -48,6 +48,8 @@ const uint32_t *mBootloaderMagicWord = (uint32_t *) BOOTLOAD_VERSION_ADDRESS;
static BYTE mHelpString[] = "Here is the list of the available commands:\n\r\n\r"
"help : Shows this window\n\r"
"\ncpu [command] Control CPU\n"
" - Available [command] argument are: reboot\n"
"\npower [state] Set chalet's 12V Inverter feed power state. This command controls the main power relay\n"
" - Available [state] argument are: on\n"
" off\n"
@ -74,6 +76,7 @@ static BYTE mHelpString1[] = "\nlte [command] [value] : bootloader mode control
" pic (debug PIC comm only)\n"
" both (debug both PIC and LTE module comm )\n"
" off (disable LTE debug)\n"
" reset (reset the lte module)\n"
"\nHave a good day!\n";
BYTE *mHelpStringPtr;
@ -180,9 +183,31 @@ void ParseNewBuffer(void)
if(strncmp(mCmdString,"help",strlen("help")) == 0)
{
SendTerminalData(mHelpString,strlen(mHelpString));
SendTerminalData(mHelpString1,strlen(mHelpString1));
}
else if(strncmp(mCmdString,"cpu",strlen("cpu")) == 0)
{
if(strlen(mDataString1) == 0)
{
TerminalPrintString("\n[command] parameter is invalid. Type 'help' for more info\n");
return;
}
if(strncmp(mDataString1,"reboot",strlen("reboot")) == 0)
{
TerminalPrintString("\nRebooting CPU... goodbye!!\n");
TurnOFFWiFi();
Sleep(100);
SoftReset();
}
else
{
TerminalPrintString("\n[command] parameter is invalid. Type 'help' for valid values\n");
}
TerminalPrintString("\n");
}
else if(strncmp(mCmdString,"power",strlen("power")) == 0)
{
@ -448,14 +473,15 @@ void ParseNewBuffer(void)
TerminalPrintString("\n[command] parameter is invalid. Type 'help' for more info\n");
return;
}
if(strlen(mDataString2) == 0)
{
TerminalPrintString("\n[value] parameter is invalid. Type 'help' for more info\n");
return;
}
if(strncmp(mDataString1,"passthrough",strlen("passthrough")) == 0)
{
if(strlen(mDataString2) == 0)
{
TerminalPrintString("\n[value] parameter is invalid. Type 'help' for more info\n");
return;
}
if(strncmp(mDataString2,"on",strlen("on")) == 0)
{
LTEEnterSerialPassthrough();
@ -474,6 +500,11 @@ void ParseNewBuffer(void)
}
if(strncmp(mDataString1,"debug",strlen("debug")) == 0)
{
if(strlen(mDataString2) == 0)
{
TerminalPrintString("\n[value] parameter is invalid. Type 'help' for more info\n");
return;
}
if(strncmp(mDataString2,"module",strlen("module")) == 0)
{
if(LTEEnableSerialDebug(true,false) == RET_OK)
@ -518,6 +549,12 @@ void ParseNewBuffer(void)
}
}
if(strncmp(mDataString1,"reset",strlen("reset")) == 0)
{
TerminalPrintString("\nResetting LTE module...\n");
LTEModuleReset();
}
}
else if(strncmp(mCmdString,"debug",strlen(mCmdString)) == 0)
{

View File

@ -186,7 +186,7 @@ int IsBootloaderClientConnected();
#define STATIC_IP_ADDRESS_1 192
#define STATIC_IP_ADDRESS_2 168
#define STATIC_IP_ADDRESS_3 50
#define STATIC_IP_ADDRESS_4 125
#define STATIC_IP_ADDRESS_4 123
#define GATEWAY_ADDRESS_1 192
#define GATEWAY_ADDRESS_2 168

View File

@ -112,7 +112,7 @@ int main(void)
InitSPIFlash();
InitLCDCtrl();
InitLTEModule();
InitLTEModule(false);
LTENetworkInterfaceInit();

View File

@ -1,4 +1,4 @@
#define VERSIONNUMBER "CHALET_V01.02.2" //shall be 15 chars...
#define VERSIONNUMBER "CHALET_V01.02.5" //shall be 15 chars...
//Force DHCP instead of static IP.
//#define VERSIONNUMBER "CHALET_V01.00.1" //shall be 15 chars...

View File

@ -1,5 +1,5 @@
#
#Sun Jul 13 10:51:04 EDT 2025
#Sun Jan 04 10:46:07 EST 2026
ChaletDuinoV2_795F512H_.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc32\\v1.33\\bin
default.languagetoolchain.dir=C\:\\Program Files\\Microchip\\xc32\\v1.33\\bin
proj.dir=D\:\\Main\\PicDev\\Projets\\ChaletLora\\ChaletLora.X
@ -7,7 +7,7 @@ com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=bcd6e5453a11ce86a
ChaletDuinoV2_795F512H_.com-microchip-mplab-mdbcore-ICD3Tool-ICD3DbgToolManager.md5=b8062f7a3afd14c7a6d50c4bb4696d24
default.com-microchip-mplab-nbide-toolchain-xc32-XC32LanguageToolchain.md5=de2d3bc95a22a3f432c2e39f49efafbc
default.com-microchip-mplab-mdbcore-ICD3Tool-ICD3DbgToolManager.md5=b8062f7a3afd14c7a6d50c4bb4696d24
configurations-xml=1473259d34d997cd9f158c9d70cc6d8b
configurations-xml=8f7a212dcf288040446c6f1ac78b94e3
ChaletDuino_775F512H_.com-microchip-mplab-nbide-toolchain-xc32-XC32LanguageToolchain.md5=de2d3bc95a22a3f432c2e39f49efafbc
host.platform=windows
ChaletDuinoV2_795F512H_.com-microchip-mplab-nbide-toolchain-xc32-XC32LanguageToolchain.md5=de2d3bc95a22a3f432c2e39f49efafbc

View File

@ -346,35 +346,6 @@
<property key="trace-symbols" value=""/>
<property key="warn-section-align" value="false"/>
</C32-LD>
<C32CPP>
<property key="additional-warnings" value="false"/>
<property key="addresss-attribute-use" value="false"/>
<property key="check-new" value="false"/>
<property key="eh-specs" value="true"/>
<property key="enable-app-io" value="false"/>
<property key="enable-omit-frame-pointer" value="false"/>
<property key="enable-symbols" value="true"/>
<property key="enable-unroll-loops" value="false"/>
<property key="exceptions" value="true"/>
<property key="exclude-floating-point" value="false"/>
<property key="extra-include-directories" value=""/>
<property key="generate-16-bit-code" value="false"/>
<property key="generate-micro-compressed-code" value="false"/>
<property key="isolate-each-function" value="false"/>
<property key="make-warnings-into-errors" value="false"/>
<property key="optimization-level" value=""/>
<property key="place-data-into-section" value="false"/>
<property key="post-instruction-scheduling" value="default"/>
<property key="pre-instruction-scheduling" value="default"/>
<property key="preprocessor-macros" value=""/>
<property key="rtti" value="true"/>
<property key="strict-ansi" value="false"/>
<property key="toplevel-reordering" value=""/>
<property key="unaligned-access" value=""/>
<property key="use-cci" value="false"/>
<property key="use-iar" value="false"/>
<property key="use-indirect-calls" value="false"/>
</C32CPP>
<C32Global>
<property key="common-include-directories" value=""/>
<property key="gp-relative-option" value=""/>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="11">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="12">
<file>
<url>Source/BootloaderInterface.c</url>
<bookmark id="5">
@ -22,31 +22,43 @@
<key/>
</bookmark>
</file>
<file>
<url>Source/WiFiCtrl.c</url>
<bookmark id="12">
<name/>
<line>407</line>
<key/>
</bookmark>
</file>
<file>
<url>Source/SIM7080GInterface.c</url>
<bookmark id="11">
<name/>
<line>120</line>
<line>123</line>
<key/>
</bookmark>
<bookmark id="10">
<name/>
<line>387</line>
<line>390</line>
<key/>
</bookmark>
<bookmark id="8">
<name/>
<line>631</line>
<line>634</line>
<key/>
</bookmark>
<bookmark id="9">
<name/>
<line>748</line>
<line>751</line>
<key/>
</bookmark>
</file>
</editor-bookmarks>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
<group>
<file>file:/D:/Main/PicDev/Projets/ChaletLora/ChaletLora.X/Source/ChaletPowerRelay.c</file>
<file>file:/D:/Main/PicDev/Projets/ChaletLora/ChaletLora.X/Source/ChaletPowerRelay.h</file>
<file>file:/D:/Main/PicDev/Projets/ChaletLora/ChaletLora.X/Source/versionbuild.h</file>
</group>
</open-files>
</project-private>