From 724dab28d80f080c366a9638f0e3a03211dc6a4c Mon Sep 17 00:00:00 2001 From: Ronen Sberlo Date: Tue, 7 Jul 2020 13:25:08 +0300 Subject: waste new module --- .../Embedded/Modules/Control/MillisecTask.c | 3 + .../Embedded/Modules/General/GeneralHardware.c | 6 +- .../Embedded_SW/Embedded/Modules/General/Safety.c | 18 +- .../Embedded/Modules/Stubs_Handler/Progress.c | 11 + .../Embedded_SW/Embedded/Modules/Waste/Waste_ex.h | 41 +++ .../Embedded/Modules/Waste/Waste_maint.c | 363 +++++++++++++++++++++ .../Embedded/Modules/Waste/Waste_maint.h | 0 7 files changed, 424 insertions(+), 18 deletions(-) create mode 100644 Software/Embedded_SW/Embedded/Modules/Waste/Waste_maint.h (limited to 'Software/Embedded_SW/Embedded/Modules') diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index dc15202a6..4ad5336d9 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -43,6 +43,7 @@ #include "modules/thread/thread_ex.h" #include "modules/ifs/ifs.h" #include "modules/ids/ids_ex.h" +#include "modules/waste/waste_ex.h" #include "modules/Diagnostics/Diagnostics.h" #include "Modules/General/MachineStatus.h" @@ -765,6 +766,8 @@ uint32_t MillisecLowLoop(uint32_t tick) } */ } + //call waste state machine + Waste_StateMachine_OneSecond_Call(); } if (Tensecond_Tick) { diff --git a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c index e2ade95c3..27ed8d0e9 100644 --- a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c +++ b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c @@ -165,8 +165,12 @@ uint32_t HWConfigurationInit(void) #ifndef DISPESER_TEST if (WHS_Type == WHS_TYPE_NEW) newWHS_init(); - WHS_init(); + //WHS_init(); // remove call to old WHS #endif + + // Waste Init (WHS) + Waste_Init(); + ADC_MUX_Init(); GeneralHwReady = true; diff --git a/Software/Embedded_SW/Embedded/Modules/General/Safety.c b/Software/Embedded_SW/Embedded/Modules/General/Safety.c index 400b083e4..89ac8d020 100644 --- a/Software/Embedded_SW/Embedded/Modules/General/Safety.c +++ b/Software/Embedded_SW/Embedded/Modules/General/Safety.c @@ -46,7 +46,7 @@ uint32_t Safety_Main_State(uint32_t IfIndex, uint32_t BusyFlag) bool mDrierDoorAlarmState = false; bool mAirFlowAlarmState = false; bool mAirFilterAlarmState = false; - bool mWasteOverflowAlarmState = false; + //bool mWasteOverflowAlarmState = false; #ifdef CONTROL_DEBUG uint32_t tempp,tempq,delta; uint32_t sys_ticks_start = msec_millisecondCounter,sys_ticks_end,max = 0,dev = 0; @@ -91,16 +91,6 @@ uint32_t Safety_Main_State(uint32_t IfIndex, uint32_t BusyFlag) mDrierDoorAlarmState = true; DrierDoorAlarmState = true; } - else - { - //if (WHS_GPI_WASTE_OVERFULL()) - cannot read this switch - { - //report and handle waste overflow - AlarmHandlingSetAlarm(EVENT_TYPE__WASTE_CONTAINER_OVERFLOW, true); - mWasteOverflowAlarmState = true; - WasteOverflowAlarmState = true; - } - } } } @@ -234,12 +224,6 @@ uint32_t Safety_Main_State(uint32_t IfIndex, uint32_t BusyFlag) AlarmHandlingSetAlarm(EVENT_TYPE__AIR_FILTER_NOT_INSTALLED, false); AirFilterAlarmState = mAirFilterAlarmState; } - if ((mWasteOverflowAlarmState != WasteOverflowAlarmState)|| (mWasteOverflowAlarmState == false)) - { - //alarm went off - AlarmHandlingSetAlarm(EVENT_TYPE__WASTE_CONTAINER_OVERFLOW, false); - WasteOverflowAlarmState = mWasteOverflowAlarmState; - } #ifdef CONTROL_DEBUG tempq = HibernateRTCSSGet(); if (tempq < tempp) diff --git a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c index fd9c5b404..4a7008a7a 100644 --- a/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c +++ b/Software/Embedded_SW/Embedded/Modules/Stubs_Handler/Progress.c @@ -31,6 +31,7 @@ #include "Modules/Control/MillisecTask.h" #include "modules/thread/thread_ex.h" #include "modules/heaters/heaters_ex.h" +#include "modules/waste/waste_ex.h" #include #include #include "Drivers/I2C_Communication/Head_Card/IO_Ports/Head_IO.h" @@ -1040,6 +1041,16 @@ void Stub_ProgressRequest(MessageContainer* requestContainer) } else + if(request->amount == 0xB8) //fast refresh for pressure + { + if (request->delay == 1) {//init waste + Waste_Init(); + LOG_ERROR(request->delay,"Waste_Init"); + } + response.progress = request->delay; + response.has_progress = true; + } + else if(request->amount == 0xC3) //suspend I2C task { if (request->delay == 0) diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_ex.h b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_ex.h index 8b1378917..2fdd3a479 100644 --- a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_ex.h +++ b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_ex.h @@ -1 +1,42 @@ +#ifndef WASTE_MAINT_H +#define WASTE_MAINT_H + +typedef enum { + CartridgeStateOUT, + CartridgeStateIN, + CartridgeStateSELECTED, + CartridgeStateACTIVE, + CartridgeStateFULL +}CartridgeStateEnum; + +typedef enum { + WasteCartridge_upper, + WasteCartridge_middle, + WasteCartridge_lower, + MaxWasteCartridges +}WasteCartridgeEnum; + +typedef enum{ + WasteTankStateIdle, + WasteTankStateFull, + WasteTankStateEmptying, + WasteTankStatePaused +}WasteTankStateEnum; + +extern bool DoorState; +/////////////////////////////// Cartridges ////////////////////////////////////// +void cartCART_INSERTED (WasteCartridgeEnum); //{called from polling function. validate, set state to IN) +void cartCART_EXTRACTED(WasteCartridgeEnum); //{called from polling function. set state to out, if was ACTIVE – notify waste module) +WasteCartridgeEnum cartSELECT_CART(void); //{ if there is no SELECTED cartridge select the first cartridge in IN state. If there is none, return -1} +void cartFILLING_START(void); //{set state of SELECTED to ACTIVE} +void cartFILLING_END(void); //{set state of ACTIVE to FULL} +CartridgeStateEnum cartGetState (WasteCartridgeEnum); +bool cartGetPresence (WasteCartridgeEnum CartId); +bool cartCart_door();//Polled by polling function. Notify waste. Poll each 1 second. During active filling poll each 100msec + +void Waste_Init(); +void Waste_StateMachine(void); +void Waste_StateMachine_OneSecond_Call(void); + +#endif diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_maint.c b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_maint.c index e69de29bb..58651e243 100644 --- a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_maint.c +++ b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_maint.c @@ -0,0 +1,363 @@ +#include +#include +#include "include.h" +#include "Modules/Control/control.h" // use for FPGA IO +#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"//#include "FPGA_GPIO.h" // use for FPGA IO +#include "drivers/Valves/Valve.h" +#include "Common/report/report.h" +#include "Modules/Waste/Waste_ex.h" +#include +#include "Drivers/I2C_Communication/RFID_NFC/logi-tag/LT_RFID.h" +#include "Drivers/I2C_Communication/RFID_NFC/NFC.h" +//#include + +#include +#include "Modules/AlarmHandling/AlarmHandling.h" +#include "StateMachines/Initialization/PowerOffSequence.h" +#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h" +#include "CartridgeValidationRequest.pb-c.h" +#include "CartridgeValidationResponse.pb-c.h" +#include "Modules/General/buttons.h" +#include "Modules/IFS/ifs.h" +#include +#include +#include + +bool DoorState = OPEN; +uint32_t timeout_counter = 0; +int wasteLevel = 0; +WasteCartridgeEnum SelectedCard = MaxWasteCartridges; +CartridgeStateEnum CartState[MaxWasteCartridges]; +uint32_t Cartridge_Cover_Control; +button *CartLed[MaxWasteCartridges] = {0, &cart2, &cart3}; +WasteTankStateEnum WasteTankState = WasteTankStateIdle; + +#define WASTE_CARTRIDGE_SIZE 1500 +#define WASTE_LEVEL_OVERFLOW 2700 +#define WASTE_LEVEL_FULL 2300 +#define WASTE_LEVEL_EMPTY 900 +#define WASTE_EMPTING_TIMEOUT 1200 +double wasteLevelOverflow = WASTE_LEVEL_OVERFLOW; +double wasteLevelFull = WASTE_LEVEL_FULL; +double wasteLevelEmpty = WASTE_LEVEL_EMPTY; +double wasteLevelOverFlow = WASTE_LEVEL_OVERFLOW; + +#define WHS_DEBUG + +/////////////////////////////// Cartridges ////////////////////////////////////// +void Waste_StateMachine(void); +void cartCART_INSERTED (WasteCartridgeEnum CartId) +{ + assert (CartIdcolor = colorON; + + Report("Cartridges Cart inserted", __FILE__, __LINE__, CartId, RpMessage, CartState[CartId], 0); +} +void cartCART_EXTRACTED(WasteCartridgeEnum CartId) //{called from polling function. set state to out, if was ACTIVE – notify waste module) +{ + assert (CartIdcolor = colorOFF; + +} +WasteCartridgeEnum cartSELECT_CART(void) //{ if there is no SELECTED cartridge select the first cartridge in IN state. If there is none, return -1} +{ + Report("Cartridges select cart", __FILE__, __LINE__, CartState[WasteCartridge_middle], RpMessage, CartState[WasteCartridge_lower], 0); + if ((CartState[WasteCartridge_middle] == CartridgeStateSELECTED)||(CartState[WasteCartridge_middle] == CartridgeStateACTIVE)) + return WasteCartridge_middle; + if ((CartState[WasteCartridge_lower] == CartridgeStateSELECTED)||(CartState[WasteCartridge_lower] == CartridgeStateACTIVE)) + return WasteCartridge_lower; + //no selected/active cartridge yet + if (CartState[WasteCartridge_middle] == CartridgeStateIN) { + CartState[WasteCartridge_middle] = CartridgeStateSELECTED; + return WasteCartridge_middle; + } + if (CartState[WasteCartridge_lower] == CartridgeStateIN) { + CartState[WasteCartridge_lower] = CartridgeStateSELECTED; + return WasteCartridge_lower; + } + return MaxWasteCartridges; +} + +void cartFILLING_START(void) //{set state of SELECTED to ACTIVE} +{ + if (CartState[WasteCartridge_middle] == CartridgeStateSELECTED) { + Report("Cartridges middle Cart active", __FILE__, __LINE__, WasteCartridge_middle, RpMessage, CartState[WasteCartridge_middle], 0); + CartState[WasteCartridge_middle] = CartridgeStateACTIVE; + CartLed[WasteCartridge_middle]->color = BLINK; + } else if (CartState[WasteCartridge_lower] == CartridgeStateSELECTED) { + Report("Cartridges lower Cart active", __FILE__, __LINE__, WasteCartridge_lower, RpMessage, CartState[WasteCartridge_lower], 0); + CartState[WasteCartridge_lower] = CartridgeStateACTIVE; + CartLed[WasteCartridge_lower]->color = BLINK; + } else { + Report("Cartridges start with no selected cartridge", __FILE__, __LINE__, CartState[WasteCartridge_middle], RpMessage, CartState[WasteCartridge_lower], 0); + } +} + +void cartFILLING_END(void) +{ + //{set state of ACTIVE to FULL} + if (CartState[WasteCartridge_middle] == CartridgeStateACTIVE) { + CartState[WasteCartridge_middle] = CartridgeStateFULL; + CartLed[WasteCartridge_middle]->color = colorOFF; + } else if (CartState[WasteCartridge_lower] == CartridgeStateACTIVE) { + CartState[WasteCartridge_lower] = CartridgeStateFULL; + CartLed[WasteCartridge_lower]->color = colorOFF; + } else { + Report("Cartridges end with no active cartridge", __FILE__, __LINE__, CartState[WasteCartridge_middle], RpMessage, CartState[WasteCartridge_lower], 0); + } +} + +CartridgeStateEnum cartGetState(WasteCartridgeEnum CartId) +{ + assert (CartId 50)) { + Report("Waste_StateMachine_OneSecond_Call", __FILE__, WasteTankState, SelectedCard, RpMessage, wasteLevel, 0); + prev_state = WasteTankState; + prev_wasteLevel = wasteLevel; + } + + //call state machine + Waste_StateMachine(); + + if(init) + init = 0; + +#ifdef WHS_DEBUG + wasteLevel += 50; +#endif +} + +void Waste_StateMachine(void) +{ + uint32_t activeCart; + switch (WasteTankState) + { + case WasteTankStateIdle: + if (wasteLevel > wasteLevelOverFlow) { + AlarmHandlingSetAlarm( EVENT_TYPE__WASTE_CONTAINER_OVERFLOW, true); + } else { + AlarmHandlingSetAlarm( EVENT_TYPE__WASTE_CONTAINER_OVERFLOW, false); + } + if (cartNotAllFull() == true) { + AlarmHandlingSetAlarm( EVENT_TYPE__ALL_WASTE_CARTRIDGES_FULL, false); + } + if (wasteLevel > wasteLevelFull) { + //check if power down in process + if ( PowerOffInProcessGetState() ) { + Report("Power-down in process", __FILE__, __LINE__, 0, RpMessage, 0, 0); + break; + } + + //check door + if (DoorState == OPEN) { + Report("Close cartridge cover", __FILE__, __LINE__, DoorState, RpMessage, 0, 0); + break; + } + + // select cartridge + SelectedCard = cartSELECT_CART(); + if (SelectedCard == MaxWasteCartridges) { + Report("No Available cart", __FILE__, __LINE__, SelectedCard, RpMessage, 0, 0); + AlarmHandlingSetAlarm( EVENT_TYPE__NO_WASTE_CARTRIDGE_AVAILABLE, true); + break; + } else { + AlarmHandlingSetAlarm( EVENT_TYPE__NO_WASTE_CARTRIDGE_AVAILABLE, false); + } + + //check RFID? (TBD) + + //move to next state + WasteTankState = WasteTankStateFull; + Report("move to WasteTankStateFull", __FILE__, __LINE__, DoorState, RpMessage, WasteTankState, 0); + } + break; + case WasteTankStateFull: + //set cart Active + cartFILLING_START(); + + // set valve selection + activeCart = cartGetActiveCart(); + Valve_Set(VALVE_WASTE_TANK, activeCart); + Report("WasteTankStateEmptying set valve", __FILE__, __LINE__, activeCart, RpMessage, 0, 0); + + // RFID change status - TBD + + // set count down + timeout_counter = 1; + + // set emptying limit + wasteLevelEmpty = wasteLevel - WASTE_CARTRIDGE_SIZE; + + // start a timer to observe door opening + Cartridge_Cover_Control = AddControlCallback("Cartridge Cover Door", Waste_DoorOpenDuringEmptying, 100, cartCart_door, 0, 0, 0); + Report("add control Cartridge Cover Door", __FILE__, __LINE__, 0, RpMessage, 0, 0); + + SetWastePump(OPEN); + Report("WasteTankStateEmptying set Pump Open", __FILE__, __LINE__, activeCart, RpMessage, 0, 0); + + //start emptying + WasteTankState = WasteTankStateEmptying; + break; + case WasteTankStateEmptying: + // if time out or emptying done - idle + if (timeout_counter++ > WASTE_EMPTING_TIMEOUT) { + SetWastePump(CLOSE); + cartFILLING_END(); + // RFID change status - TBD + WasteTankState = WasteTankStateIdle; + Report("WasteTankStateEmptying TimeOut", __FILE__, __LINE__, 0, RpMessage, 0, 0); + AlarmHandlingSetAlarm( EVENT_TYPE__WASTE_CONTAINER_EMPTYING_TIMEOUT, true); + RemoveControlCallback(Cartridge_Cover_Control, Waste_DoorOpenDuringEmptying); + } else if (wasteLevel < wasteLevelEmpty) { + SetWastePump(CLOSE); + cartFILLING_END(); + // RFID change status - TBD + WasteTankState = WasteTankStateIdle; + RemoveControlCallback(Cartridge_Cover_Control, Waste_DoorOpenDuringEmptying); + if (cartNotAllFull() == false) + AlarmHandlingSetAlarm( EVENT_TYPE__ALL_WASTE_CARTRIDGES_FULL, true); + Report("WasteTankStateEmptying done", __FILE__, __LINE__, 0, RpMessage, 0, 0); + } +#ifdef WHS_DEBUG + wasteLevel -= 100; + timeout_counter += 10; +#endif + break; + case WasteTankStatePaused: + Report("WasteTankStatePaused...", __FILE__, __LINE__, 0, RpMessage, 0, 0); + break; + default: + Report("wrong state", __FILE__, WasteTankState, 0, RpMessage, SelectedCard, 0); + break; + } +} diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_maint.h b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_maint.h new file mode 100644 index 000000000..e69de29bb -- cgit v1.3.1