creation des niveau de battery, a regler sur banc

This commit is contained in:
dimercur 2023-10-11 16:04:45 +02:00
parent c5250eb3f4
commit 64b8f9fe08
7 changed files with 125 additions and 80 deletions

View file

@ -327,28 +327,16 @@
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.1151842665.1610208999" name="Resource Custom Build Step Output Type"/>
</tool>
</fileInfo>
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.Application/application.c" name="application.c" rcbsApplicability="disable" resourcePath="Application/application.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.983087978">
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.983087978" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.606614377" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o0" valueType="enumerated"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1996673393" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.1184097105" name="application.c" rcbsApplicability="disable" resourcePath="Application/application.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.298003348">
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.298003348" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.235309210" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o0" valueType="enumerated"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1492946438" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
<tool customBuildStep="true" id="org.eclipse.cdt.managedbuilder.ui.rcbs.389963892.995306756" name="Resource Custom Build Step">
<inputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.inputtype.115340338.624270908" name="Resource Custom Build Step Input Type">
<tool customBuildStep="true" id="org.eclipse.cdt.managedbuilder.ui.rcbs.693102693" name="Resource Custom Build Step">
<inputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.inputtype.676361119" name="Resource Custom Build Step Input Type">
<additionalInput kind="additionalinputdependency" paths=""/>
</inputType>
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.1700687045.61103792" name="Resource Custom Build Step Output Type"/>
</tool>
</fileInfo>
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.200947957" name="leds.c" rcbsApplicability="disable" resourcePath="Application/leds.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.155574165">
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.155574165" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.301013410" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o0" valueType="enumerated"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1898228332" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
<tool customBuildStep="true" id="org.eclipse.cdt.managedbuilder.ui.rcbs.2113983486" name="Resource Custom Build Step">
<inputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.inputtype.1308025369" name="Resource Custom Build Step Input Type">
<additionalInput kind="additionalinputdependency" paths=""/>
</inputType>
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.555839812" name="Resource Custom Build Step Output Type"/>
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.789962441" name="Resource Custom Build Step Output Type"/>
</tool>
</fileInfo>
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.53808517" name="batterie.c" rcbsApplicability="disable" resourcePath="Application/batterie.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.1171631638">

View file

@ -29,7 +29,7 @@ typedef enum {
typedef struct {
APPLICATION_State state;
uint8_t cmd;
uint16_t batteryVoltage;
uint16_t batteryState;
char batteryUpdate;
char inCharge;
int32_t distance;
@ -143,7 +143,7 @@ void APPLICATION_MainThread(void* params) {
cmdSendAnswer(ANS_OK);
break;
case CMD_GET_BATTERY:
cmdSendBatteryLevel(systemInfos.batteryVoltage);
cmdSendBatteryLevel(systemInfos.batteryState);
break;
case CMD_GET_VERSION:
cmdSendVersion();
@ -177,25 +177,28 @@ void APPLICATION_MainThread(void* params) {
break;
/* TODO
* Revoir la gestion de la batterie ici
*/
// case MSG_ID_BAT_CHARGE_OFF:
// case MSG_ID_BAT_CHARGE_COMPLETE:
// systemInfos.batteryVoltage = *((uint16_t*)msg.data);
// systemInfos.batteryUpdate = 1;
//
// if (msg.id == MSG_ID_BAT_CHARGE_COMPLETE)
// systemInfos.inCharge =1;
// else
// systemInfos.inCharge =0;
// break;
//
// case MSG_ID_BAT_CHARGE_ON:
// systemInfos.inCharge =1;
// break;
case MSG_ID_MOTEURS_STOP:
case MSG_ID_BAT_ADC_ERR:
/* depart en panic: error 2 */
break;
case MSG_ID_BAT_CHARGE_ERR:
/* depart en panic: error 3 */
break;
case MSG_ID_BAT_CHARGE_COMPLETE:
case MSG_ID_BAT_CHARGE_LOW:
case MSG_ID_BAT_CHARGE_MED:
case MSG_ID_BAT_CHARGE_HIGH:
systemInfos.batteryUpdate=1;
systemInfos.inCharge=1;
systemInfos.batteryState = msg.id;
break;
case MSG_ID_BAT_CRITICAL_LOW:
case MSG_ID_BAT_LOW:
case MSG_ID_BAT_MED:
case MSG_ID_BAT_HIGH:
systemInfos.batteryUpdate=1;
systemInfos.batteryState = msg.id;
break;
case MSG_ID_MOTEURS_END_OF_MOUVMENT:
systemInfos.endOfMouvement= 1;
break;
@ -218,18 +221,43 @@ void APPLICATION_StateMachine() {
APPLICATION_TransitionToNewState(stateInCharge);
}
/* TODO
* Revoir la gestion de la batterie ici
*/
// if (systemInfos.batteryUpdate) {
// ledState = APPLICATION_BatteryLevel(systemInfos.batteryVoltage, systemInfos.state);
//
// if (ledState == leds_niveau_bat_0)
// APPLICATION_TransitionToNewState(stateLowBatDisable);
// else if (systemInfos.state==stateStartup) {
// MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
// }
// }
if (systemInfos.batteryUpdate) {
ledState = leds_off;
if (systemInfos.batteryState==MSG_ID_BAT_CRITICAL_LOW) {
ledState = leds_bat_critical_low;
APPLICATION_TransitionToNewState(stateLowBatDisable);
} else if (systemInfos.state == stateInCharge) {
switch (systemInfos.batteryState) {
case MSG_ID_BAT_CHARGE_COMPLETE:
ledState= leds_bat_charge_complete;
break;
case MSG_ID_BAT_CHARGE_HIGH:
ledState= leds_bat_charge_high;
break;
case MSG_ID_BAT_CHARGE_MED:
ledState= leds_bat_charge_med;
break;
case MSG_ID_BAT_CHARGE_LOW:
ledState= leds_bat_charge_low;
break;
}
} else if (systemInfos.state==stateStartup) {
switch (systemInfos.batteryState) {
case MSG_ID_BAT_HIGH:
ledState= leds_bat_high;
break;
case MSG_ID_BAT_MED:
ledState= leds_bat_med;
break;
case MSG_ID_BAT_LOW:
ledState= leds_bat_low;
break;
}
}
LEDS_Set(ledState);
}
if (systemInfos.cmd != CMD_NONE) {
/* a newer command just arrived, process it
@ -317,7 +345,7 @@ void APPLICATION_StateMachine() {
void APPLICATION_TransitionToNewState(APPLICATION_State new_state) {
LEDS_State ledState = leds_off;
uint32_t data;
int32_t data;
switch (new_state) {
case stateStartup:
@ -325,20 +353,20 @@ void APPLICATION_TransitionToNewState(APPLICATION_State new_state) {
break;
case stateIdle:
ledState = leds_idle;
MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
LEDS_Set(ledState);
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP, APPLICATION_Mailbox, (void*)NULL);
systemTimeout.watchdogEnabled=0;
break;
case stateRun:
ledState = leds_run;
MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
LEDS_Set(ledState);
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP, APPLICATION_Mailbox, (void*)NULL);
break;
case stateInMouvement:
ledState = leds_run;
MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
LEDS_Set(ledState);
if (systemInfos.cmd == CMD_MOVE) {
data = systemInfos.distance;
@ -349,19 +377,20 @@ void APPLICATION_TransitionToNewState(APPLICATION_State new_state) {
}
break;
case stateInCharge:
ledState = APPLICATION_BatteryLevel(systemInfos.batteryVoltage, systemInfos.inCharge);
MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
/* les leds sont gerées dans APPLICATION_StateMachine */
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP, APPLICATION_Mailbox, (void*)NULL);
systemTimeout.watchdogEnabled=0;
break;
case stateWatchdogDisable:
ledState = leds_erreur_1;
MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
LEDS_Set(ledState);
systemTimeout.watchdogEnabled=0;
break;
case stateLowBatDisable:
ledState = leds_bat_critical_low;
LEDS_Set(ledState);
//MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledState);
systemTimeout.watchdogEnabled=0;
vTaskDelay(pdMS_TO_TICKS(4000)); // wait 4s

View file

@ -117,20 +117,49 @@ int BATTERIE_LireTension(uint16_t *val) {
return 0;
}
const uint8_t BATTERIE_NiveauBatteryNormal[5] = {
0
};
/*
* Il faut considerer ces valeurs comme les seuils de baculement dans une categorie
* ou une autre
*
* Seuil : critical low high
* Tension batterie: 2.9 critic 3.1 low 3.3 med 3.6 high 4.2
*
*/
#define BATTERIE_LEVEL_CRITICAL 200
#define BATTERIE_LEVEL_LOW 300
#define BATTERIE_LEVEL_HIGH 500
const uint8_t BATTERIE_NiveauBatteryCharge[5] = {
0
};
#define BATTERIE_LEVEL_CHARGE_LOW 400
#define BATTERIE_LEVEL_CHARGE_HIGH 700
uint16_t BATTERIE_BatteryLevel(uint8_t voltage, BATTERIE_StatusChargerTypedef chargerStatus) {
uint16_t msgId=0;
/* TODO: A faire
* Pour l'instant, testons les niveaux de batterie
*/
switch (chargerStatus) {
case CHARGEUR_CHARGE_COMPLETE:
msgId = MSG_ID_BAT_CHARGE_COMPLETE;
break;
case CHARGEUR_IN_CHARGE:
if (voltage<=BATTERIE_LEVEL_CHARGE_LOW)
msgId = MSG_ID_BAT_CHARGE_LOW;
else if (voltage>=BATTERIE_LEVEL_CHARGE_HIGH)
msgId = MSG_ID_BAT_CHARGE_HIGH;
else
msgId = MSG_ID_BAT_CHARGE_MED;
break;
case CHARGEUR_NOT_PLUGGED:
if (voltage<=BATTERIE_LEVEL_CRITICAL)
msgId = MSG_ID_BAT_CRITICAL_LOW;
else if (voltage<=BATTERIE_LEVEL_LOW)
msgId = MSG_ID_BAT_LOW;
else if (voltage>=BATTERIE_LEVEL_HIGH)
msgId = MSG_ID_BAT_HIGH;
else
msgId = MSG_ID_BAT_MED;
break;
default:
msgId = MSG_ID_BAT_CHARGE_ERR;
}
return msgId;
}

View file

@ -247,18 +247,17 @@ void cmdSendString(char *str) {
MESSAGE_SendMailbox(XBEE_Mailbox, MSG_ID_XBEE_ANS, APPLICATION_Mailbox, (char*) answer);
}
void cmdSendBatteryLevel(char level) {
void cmdSendBatteryLevel(uint16_t batteryState) {
char* answer;
char localLevel=level;
if (localLevel<0) localLevel=0;
else if (localLevel>2) localLevel=2;
switch (localLevel) {
case 2:
switch (batteryState) {
case MSG_ID_BAT_CHARGE_COMPLETE:
case MSG_ID_BAT_CHARGE_HIGH:
case MSG_ID_BAT_HIGH:
answer = cmdAddChecksum("2\r");
break;
case 1:
case MSG_ID_BAT_CHARGE_MED:
case MSG_ID_BAT_MED:
answer = cmdAddChecksum("1\r");
break;
default:

View file

@ -81,7 +81,7 @@ typedef struct __attribute__((packed)) {
CMD_Generic* cmdDecode(char* cmd, uint8_t length);
void cmdSendAnswer(uint8_t ans);
void cmdSendString(char* str);
void cmdSendBatteryLevel(char level);
void cmdSendBatteryLevel(uint16_t batteryState);
void cmdSendVersion(void);
void cmdSendBusyState(uint8_t state);

View file

@ -46,6 +46,7 @@ extern QueueHandle_t XBEE_Mailbox;
#define MSG_ID_MOTEURS_STOP 0x40
#define MSG_ID_MOTEURS_MOVE 0x41
#define MSG_ID_MOTEURS_TURN 0x42
#define MSG_ID_MOTEURS_END_OF_MOUVMENT 0x43
#define MSG_ID_XBEE_CMD 0x50
#define MSG_ID_XBEE_ANS 0x51

View file

@ -75,13 +75,12 @@ void TESTS_BasicTests(void* params) {
char str[100];
ledsState = leds_run;
MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledsState); // show program is running
LEDS_Set(ledsState); // show program is running
switch (TESTS_Nbr) {
case LEDS_Tests: //Leds tests
while (ledsState<=leds_state_unknown) {
//MESSAGE_SendMailbox(LEDS_Mailbox, MSG_ID_LED_ETAT, APPLICATION_Mailbox, (void*)&ledsState);
LEDS_Set(ledsState);
vTaskDelay(pdMS_TO_TICKS(TESTS_PERIODE)); // wait 10s
ledsState++;