/** * @file ifs.h * * @date Jul 8, 2019 * @author Shlomo * * @date 26.8.2019 * @author Shai */ #include "PMR/Diagnostics/CartridgeSlot.pb-c.h" #include "PMR/Diagnostics/CartridgeTagContent.pb-c.h" #include "common/utilities/RfidTagContent.h" #include #include #include #include "include.h" #include "Modules/Waste/Waste.h" #include "Modules/IFS/ifs.h" #include "Modules/AlarmHandling/AlarmHandling.h" #include "CartridgeValidationRequest.pb-c.h" #include "CartridgeValidationResponse.pb-c.h" #include #include "drivers/Valves/Valve.h" #include "Modules/Waste/Waste.h" bool IFS_TimeOutAlarm(bool status); bool ColorMatch(); bool MidTankValvesAction(bool action); //RfidTagContent TagContent[MAX_CARTRIDGES]; NFC_Tag NFCTag[MAX_CARTRIDGES]; //void TagInitialize(RfidTagContent* TagContent); void IFS_Init(void) { int i; for (i=0;i= IFS_info.MidTank_capacity + CARTRIDGE_CAPATICY) { IFS_info.Ink.time_out = 0; WHS_info.event = IFS_MidTankFull; return IFS_MidTankFull; } //#endif /*** first TimeOut ***/ if (IFS_info.Ink.time_out == CARTRIDGE_INK_TIMEOUT) { ReportWithPackageFilter(WasteFilter,"------------ first IFS_info.Ink.time_out -----------------", __FILE__, __LINE__, (IFS_info.Ink.time_out * SECONDS_5), RpMessage, MidTank_Pressure, 0); //IFS_info.Ink.time_out = 0; //return IFS_info.event = IFS_Timeout; REPORT_MSG(WHS_emptying," ------------ IFS_Timeout close valves----------------- "); // try again : // start timeout // close and open the correct valves MidTankValvesAction(Cartridge_MidTank_OFF); } if (IFS_info.Ink.time_out == (CARTRIDGE_INK_TIMEOUT + 1)) //need to open the valve for second chance { ReportWithPackageFilter(WasteFilter,"------------ IFS_Timeout open valves for second timeout -----------------", __FILE__, __LINE__, (IFS_info.Ink.time_out * SECONDS_5), RpMessage, MidTank_Pressure, 0); MidTankValvesAction(Cartridge_MidTank_ON); } if (IFS_info.Ink.time_out >= (CARTRIDGE_INK_TIMEOUTx2 + 1)) { REPORT_MSG(WHS_full," ------------ IFS_Timeout_Second_Time ----------------- "); IFS_info.Ink.time_out = 0; WHS_info.event = IFS_Timeout_Second; return IFS_Timeout_Second; } return ret; } /** * * @brief IFS Time Out Alarm * * @return OK */ bool IFS_TimeOutAlarm(bool status) { bool ret = OK; switch (IFS_info.Ink.cart_color) //todo enter the correct color from RFID { case 1 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_1_FILL_TIMEOUT, status); break; case 2 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_2_FILL_TIMEOUT, status); break; case 3 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_3_FILL_TIMEOUT, status); break; case 4 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_4_FILL_TIMEOUT, status); break; case 5 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_5_FILL_TIMEOUT, status); break; case 6 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_6_FILL_TIMEOUT, status); break; case 7 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_7_FILL_TIMEOUT, status); break; case 8 : AlarmHandlingSetAlarm( EVENT_TYPE__MID_TANK_8_FILL_TIMEOUT, status); break; default: //wrong color ret = notOK; break; } return ret; } /** * * @brief MidTank Valves Action * the MidTank have 2 Valves: * 1. Ink Color Valve to get INK from the INK Cartridge to Midtank * 2. Air valve to get INK in the Midtank we have to open the Air valve so the air can go out * * @return action to open the Valve use: Cartridge_MidTank_ON/Atm_MidTank_ON * to close the Valve use : Cartridge_MidTank_OFF/Atm_MidTank_OFF */ bool MidTankValvesAction(bool action) //Cartridge_MidTank_ON of Cartridge_MidTank_OFF { bool ret = false; if (action == Cartridge_MidTank_ON) { Enable_MidTank_Pressure_Reading(IFS_info.Ink.cart_color); } else { Disable_MidTank_Pressure_Reading(IFS_info.Ink.cart_color); } Valve_Set(IDS_Id_to_AirValve[IFS_info.Ink.cart_color], action ); //Atm_MidTank_OFF/ON Valve_Set(IDS_Id_to_CartrideValve[IFS_info.Ink.cart_color], action ); //Atm_MidTank_OFF/ON ret = true; return ret; } bool ColorMatch() { bool ret = false; ret = true; return ret; } char CartridgeRequestToken[36+1]; int CartridgeRequestId = 0x01010101; /** * * @brief create message to PPC * temporary message RFID will replace that message. * send a request to PPC to know the MidTank number * @return OK */ uint32_t ReadCartridgeData(cartridge_name cart_name) { //this function triggers reading and validation of the cartridge information // for now it sends a request to the tablet to inquire for the ink color/midtank id MessageContainer responseContainer; CartridgeValidationRequest ValidationReq = CARTRIDGE_VALIDATION_REQUEST__INIT; Cartridge CartridgeData; strcpy(CartridgeRequestToken,"Happy days are coming to us, soon"); memcpy(&CartridgeRequestToken[32],&CartridgeRequestId,sizeof(CartridgeRequestId)); CartridgeRequestId++; cartridge__init(&CartridgeData); CartridgeData.has_slot = true; CartridgeData.slot = CARTRIDGE_SLOT__Ink; CartridgeData.tag = 0; CartridgeData.has_index = false; ValidationReq.has_action = true; ValidationReq.action = CARTRIDGE_ACTION__Inserted; ValidationReq.cartridge = &CartridgeData; responseContainer = createContainer(MESSAGE_TYPE__CartridgeValidationRequest, CartridgeRequestToken, true, &ValidationReq, &cartridge_validation_request__pack, &cartridge_validation_request__get_packed_size); //------------------------------------------------------------------------------------------- uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); size_t container_size = message_container__pack(&responseContainer, container_buffer); REPORT_MSG(WHS_full," ------------ IFS: send message_container__pack ----------------- "); my_free(responseContainer.data.data); SendChars((char*)container_buffer, container_size); return OK; } /** * * @brief PPC answers the MidTank number and call WasteTankCBFunction() function. * temporary message RFID will replace that message. * * @return OK */ bool CartridgeValidationResponseFunc(MessageContainer* requestContainer) { bool ret = notOK; CartridgeValidationResponse* response = cartridge_validation_response__unpack(NULL, requestContainer->data.len, requestContainer->data.data); // check the message: // 1. the pointer is not NULL !!! // 2. the index is out of rang if (response == NULL) { REPORT_MSG(WHS_filling," ------------ IFS_filling message from PPC is null!!! ----------------- "); // write to log error return ret; } if (response->index < NUM_OF_MIDTANKS) { IFS_info.Ink.cart_color = response->index; // midtank 1-8 ReportWithPackageFilter(WasteFilter,"------------ IFS get message response->index is -----------------", __FILE__, __LINE__, response->index, RpMessage, 0, 0); WHS_info.event = IFS_INK_authentication_pass; } else { ReportWithPackageFilter(WasteFilter,"------------ IFS get message response->index is out of rang -----------------", __FILE__, __LINE__, response->index, RpMessage, 0, 0); WHS_info.event = IFS_INK_authentication_fail; } WasteTankCBFunction();//call cart is ok ret = OK; return ret; } /** * * @brief that response is from STUB. replace the PPC * use stub : Poweroff_progress.cs from P:\Users - Public\Shai_Frieder * ProgressRequest progressRequest = new ProgressRequest(); * progressRequest.Amount = 0xCC; //porgress id is 0xCC * progressRequest.Delay = 1; //midtank number from 0-7 * * * @return OK */ void ResponseDemo(int MidtankId) { WHS_info.event = IFS_INK_authentication_pass; //global mid tank id = MidtankId; IFS_info.Ink.cart_color = MidtankId; WasteTankCBFunction();//call cart is ok } bool INKCartridgeAuthentication(cartridge_name cart_name) { bool ret = notOK; // TBD; switch (cart_name) { case INK_cartridge: IFS_info.Ink.autheticate = PASSED; //todo //Pannel_Leds(CART_1, MODE_ON); break; default: //WHS_info.cartridge_1.autheticate = FAILED; //todo // WHS_info.cartridge_2.autheticate = FAILED; //todo //Pannel_Leds(CART_2, MODE_OFF); //Pannel_Leds(CART_3, MODE_OFF); break; } ret = OK; return ret; }