Example #1
0
void CContainer::GetLiquidTanksWeightAckResponse(int TransactionId, PVOID Data, unsigned DataLength, TGenericCockie Cockie)
{
    TOCBLiquidTanksWeightResponse *StatusMsg = static_cast<TOCBLiquidTanksWeightResponse *>(Data);

    // Get a pointer to the instance
    CContainer *InstancePtr = reinterpret_cast<CContainer *>(Cockie);

    //Verify size of message
    if(DataLength != sizeof(TOCBLiquidTanksWeightResponse))
    {
        CQLog::Write(LOG_TAG_EOL, "Container \"GetLiquidTanksWeightAckResponse\" length error");
        return;
    }

    if(static_cast<int>(StatusMsg->MessageID) != OCB_LIQUID_TANK_WEIGHT)
    {
        FrontEndInterface->NotificationMessage("Container \"GetLiquidTanksWeightAckResponse\" message id error");
        CQLog::Write(LOG_TAG_EOL, "Container \"GetLiquidTanksWeightAckResponse\" message id error (0x%X)", (int)StatusMsg->MessageID);
        return;
    }
    float Weights[TOTAL_NUMBER_OF_CONTAINERS_INCLUDING_WASTE] =
        INIT_MSG_VALUES_W_ARRAY(StatusMsg, Weight);

    // Updating the Weights of the liquid tanks
    for(int i = FIRST_TANK_INCLUDING_WASTE_TYPE; i < LAST_TANK_INCLUDING_WASTE_TYPE; i++)
        InstancePtr->m_TanksArray[i]->SetTankWeight(Weights[i]);

    // Write the new weights the Log only if one of the 'Printed' weights is different atleast in 40 gr
    bool NeedToWriteWeightsToLog = false;

    for(int i = FIRST_TANK_INCLUDING_WASTE_TYPE; i < TOTAL_NUMBER_OF_CONTAINERS; i++)
    {
        if(InstancePtr->m_TanksArray[i]->IsPrintWeightNecessary())
            NeedToWriteWeightsToLog = true;
    }

    int WeightArray[TOTAL_NUMBER_OF_CONTAINERS_INCLUDING_WASTE];
    QString tmp = "Liquids weight: ";
    for(int i = FIRST_TANK_INCLUDING_WASTE_TYPE; i < LAST_TANK_INCLUDING_WASTE_TYPE; i++)
    {
        WeightArray[i] = InstancePtr->GetTankWeightInGram((TTankIndex)i);
        tmp += TankToStr((TTankIndex)i) + " = " + QFloatToStr(WeightArray[i]) + "; ";
    }
    InstancePtr->UpdateLiquidTankInserted(TYPE_TANK_WASTE, (InstancePtr->m_TanksArray[TYPE_TANK_WASTE]->GetTankWeightInGram(true) > WASTE_IS_EMPTY));
    if(NeedToWriteWeightsToLog)
        CQLog::Write(LOG_TAG_EOL, tmp);

    for(int i = FIRST_TANK_TYPE; i < LAST_TANK_TYPE; i++)
    {
        // Update the front end with the status of the containers
        FrontEndInterface->UpdateStatus(FE_CURRENT_TANK_STATUS_BASE + i,
                                        (int)(WeightArray[i] > (InstancePtr->m_ParamsMgr->WeightLevelLimitArray[TankToStaticChamber((TTankIndex)i)]
                                                + WEIGHT_ERROR_WARNNING_DELTA)));

        WeightArray[i] -= InstancePtr->m_ParamsMgr->WeightLevelLimitArray[TankToStaticChamber((TTankIndex)i)];
        // Update the front end with the current weight
        FrontEndInterface->UpdateStatus(FE_CURRENT_TANK_WEIGHT_BASE + i,
                                        ((WeightArray[i] > 0) && (! InstancePtr->IsTankInOverconsumption((TTankIndex)i))) ? WeightArray[i] : 0);

        // Update the front end with the relative weight
        FrontEndInterface->UpdateStatus(FE_CURRENT_TANK_RELATIVE_WEIGHT_BASE + i,
                                        WeightArray[i] * 100 /
                                        InstancePtr->m_ParamsMgr->CartridgeFullWeight);
    }
    // Update the front end with the status of the containers
    FrontEndInterface->UpdateStatus(FE_CURRENT_TANK_STATUS_WASTE_TANK,
                                    (int)(WeightArray[TYPE_TANK_WASTE] < (InstancePtr->m_ParamsMgr->WeightLevelLimitArray[TYPE_CHAMBER_WASTE]
                                            - WASTE_WEIGHT_ERROR_WARNNING_DELTA)));

    FrontEndInterface->UpdateStatus(FE_TANK_EXISTENCE_STATUS_WASTE_TANK, (int)(InstancePtr->IsActiveLiquidTankInserted((int)TYPE_CHAMBER_WASTE)));

    // Update the front end with the current weight
    FrontEndInterface->UpdateStatus(FE_CURRENT_TANK_WEIGHT_WASTE_TANK, WeightArray[TYPE_TANK_WASTE] > 0 ? WeightArray[TYPE_TANK_WASTE] : 0);

    // Display a service alert in case the waste cartride is full
    if(WeightArray[TYPE_TANK_WASTE] > (InstancePtr->m_ParamsMgr->WeightLevelLimitArray[TYPE_CHAMBER_WASTE] - WASTE_WEIGHT_ERROR_WARNNING_DELTA))
    {
        if(!InstancePtr->m_WasteAlert)
        {
            FrontEndInterface->UpdateStatus(FE_SERVICE_ALERT, WASTE_CARTRIDGE_ALERT_ID, true);
            InstancePtr->m_WasteAlert  = true;
            InstancePtr->m_WasteIsFull = true;
        }
    }
    else
    {
        if(InstancePtr->m_WasteAlert)
        {
            FrontEndInterface->UpdateStatus(FE_CLEAR_SERVICE_ALERT, 0, true);
            InstancePtr->m_WasteAlert  = false;
            InstancePtr->m_WasteIsFull = false;
        }
    }
}//GetLiquidTanksWeightAckResponse