private ValloxVariable GetVariableItem(byte variable) { ValloxVariable foundVariable = null; foreach (ValloxVariable valloxVariable in _variables) { if (valloxVariable.Id == variable) { foundVariable = valloxVariable; break; } } if (foundVariable == null) { string description = GetVariableDescription(variable); foundVariable = new ValloxVariable(variable, description); _variables.Add(foundVariable); } return(foundVariable); }
/// <summary> /// Intrepret approved message /// </summary> /// <param name="domain"></param> /// <param name="sender"></param> /// <param name="receiver"></param> /// <param name="command"></param> /// <param name="value"></param> private void Interpret(Byte domain, Byte sender, Byte receiver, Byte command, Byte value) { string senderString = Vallox.ConvertAddress(sender); UpdateStatistics(senderString, sender, true, false); string receiverString = Vallox.ConvertAddress(receiver); UpdateStatistics(receiverString, receiver, false, true); if (receiver == Vallox.Adress.Panel1 || receiver == Vallox.Adress.Panel8 || receiver == _senderId || receiver == Vallox.Adress.Panels) // TODO: right now 0x20 0x21 0x22 are received { Byte variable = command; ValloxVariable variableItem = GetVariableItem(variable); variableItem.Value = value; switch (variable) { case Vallox.Variable.FanSpeed: { int fanSpeed = Vallox.ConvertFanSpeed(value); WriteLine("Fan speed {0}", fanSpeed); FanSpeed = fanSpeed; break; } case Vallox.Variable.Humidity: { WriteLine("Humidity {0}%", value); Humidity = value; break; } case Vallox.Variable.Co2High: { WriteLine("CO2 high {0}", value); Co2High = value; break; } case Vallox.Variable.Co2Low: { WriteLine("CO2 low {0}", value); Co2Low = value; break; } case Vallox.Variable.HumiditySensor1: { WriteLine("%RH1 {0}", value); HumiditySensor1 = value; break; } case Vallox.Variable.HumiditySensor2: { WriteLine("%RH2 {0}", value); HumiditySensor2 = value; break; } case Vallox.Variable.TempOutside: { int temperature = Vallox.ConvertTemp(value); WriteLine("Temperature outside {0}°", temperature); TempOutside = temperature; break; } case Vallox.Variable.TempExhaust: { int temperature = Vallox.ConvertTemp(value); WriteLine("Temperature exhaust {0}°", temperature); TempExhaust = temperature; break; } case Vallox.Variable.TempInside: { int temperature = Vallox.ConvertTemp(value); WriteLine("Temperature inside {0}°", temperature); TempInside = temperature; break; } case Vallox.Variable.TempIncomming: { int temperature = Vallox.ConvertTemp(value); WriteLine("Temperature incomming {0}°", temperature); TempIncomming = temperature; break; } case Vallox.Variable.Select: { WriteLine("Select {0}", value); bool powerState; bool co2AdjustState; bool humidityAdjustState; bool heatingState; bool filterGuardIndicator; bool heatingIndicator; bool faultIndicator; bool serviceReminderIndicator; Vallox.ConvertSelect(value, out powerState, out co2AdjustState, out humidityAdjustState, out heatingState, out filterGuardIndicator, out heatingIndicator, out faultIndicator, out serviceReminderIndicator); PowerState = powerState; Co2AdjustState = co2AdjustState; HumidityAdjustState = humidityAdjustState; HeatingState = heatingState; FilterGuardIndicator = filterGuardIndicator; HeatingIndicator = heatingIndicator; FaultIndicator = faultIndicator; ServiceReminderIndicator = serviceReminderIndicator; break; } case Vallox.Variable.HeatingSetPoint: { int temperature = Vallox.ConvertTemp(value); WriteLine("Heating set point temperature {0}°", temperature); HeatingSetPoint = temperature; break; } case Vallox.Variable.FanSpeedMax: { int fanSpeed = Vallox.ConvertFanSpeed(value); WriteLine("Fan speed max {0}", fanSpeed); FanSpeedMax = fanSpeed; break; } case Vallox.Variable.ServiceReminder: { WriteLine("Service reminder {0}", value); ServiceReminder = value; break; } case Vallox.Variable.PreHeatingSetPoint: { int temperature = Vallox.ConvertTemp(value); WriteLine("Pre heating set point {0}°", temperature); PreHeatingSetPoint = temperature; break; } case Vallox.Variable.InputFanStop: { int temperature = Vallox.ConvertTemp(value); WriteLine("Input fan stop below temp {0}°", temperature); InputFanStopThreshold = temperature; break; } case Vallox.Variable.FanSpeedMin: { int fanSpeed = Vallox.ConvertFanSpeed(value); WriteLine("Fan speed min {0}", fanSpeed); FanSpeedMin = fanSpeed; break; } case Vallox.Variable.Program: { WriteLine("Program {0}", value); int adjustmentIntervalMinutes; bool automaticHumidityLevelSeekerState; Vallox.BoostSwitchMode boostSwitchMode; Vallox.RadiatorType radiatorType; bool cascadeAdjust; Vallox.ConvertProgram(value, out adjustmentIntervalMinutes, out automaticHumidityLevelSeekerState, out boostSwitchMode, out radiatorType, out cascadeAdjust); AdjustmentIntervalMinutes = adjustmentIntervalMinutes; AutomaticHumidityLevelSeekerState = automaticHumidityLevelSeekerState; BoostSwitchMode = boostSwitchMode; RadiatorType = radiatorType; CascadeAdjust = cascadeAdjust; break; } case Vallox.Variable.BasicHumidityLevel: { WriteLine("Basic humidity level {0}%", value); BasicHumidityLevel = value; break; } case Vallox.Variable.HrcBypass: { int temperature = Vallox.ConvertTemp(value); WriteLine("HRC bypass {0}°", temperature); HrcBypassThreshold = temperature; break; } case Vallox.Variable.DcFanInputAdjustment: { WriteLine("DC fan input adjustment {0}%", value); DcFanInputAdjustment = value; break; } case Vallox.Variable.DcFanOutputAdjustment: { WriteLine("DC fan output adjustment {0}%", value); DcFanOutputAdjustment = value; break; } case Vallox.Variable.CellDefrosting: { int temperature = Vallox.ConvertTemp(value); WriteLine("Cell defrosting below temperature {0}°", temperature); CellDefrostingThreshold = temperature; break; } case Vallox.Variable.Co2SetPointUpper: { WriteLine("CO2 set point upper {0}", value); Co2SetPointUpper = value; break; } case Vallox.Variable.Co2SetPointLower: { WriteLine("CO2 set point lower {0}", value); Co2SetPointLower = value; break; } case Vallox.Variable.Program2: { WriteLine("Program2 {0}", value); Vallox.MaxSpeedLimitMode maxSpeedLimitMode; Vallox.ConvertProgram2(value, out maxSpeedLimitMode); MaxSpeedLimitMode = maxSpeedLimitMode; break; } case Vallox.Variable.Unknown: { WriteLine("Unkown at {0} {1}", DateTime.Now.ToShortTimeString(), value); break; } case Vallox.Variable.Flags1: { WriteLine("Flags1 {0}", value); break; } case Vallox.Variable.Flags2: { WriteLine("Flags2 {0}", value); break; } case Vallox.Variable.Flags3: { WriteLine("Flags3 {0}", value); break; } case Vallox.Variable.Flags4: { WriteLine("Flags4 {0}", value); break; } case Vallox.Variable.Flags5: { WriteLine("Flags5 {0}", value); break; } case Vallox.Variable.Flags6: { WriteLine("Flags6 {0}", value); break; } case Vallox.Variable.IoPortFanSpeedRelays: { WriteLine("IoPortFanSpeedRelays {0}", value); break; } case Vallox.Variable.IoPortMultiPurpose1: { WriteLine("IoPortMultiPurpose1 {0}", value); break; } case Vallox.Variable.IoPortMultiPurpose2: { WriteLine("IoPortMultiPurpose2 {0}", value); break; } case Vallox.Variable.MachineInstalledC02Sensor: { WriteLine("MachineInstalledC02Sensor {0}", value); break; } case Vallox.Variable.PostHeatingOnCounter: { WriteLine("PostHeatingOnCounter {0}", value); break; } case Vallox.Variable.PostHeatingOffTime: { WriteLine("PostHeatingOffTime {0}", value); break; } case Vallox.Variable.PostHeatingTargetValue: { WriteLine("PostHeatingTargetValue {0}", value); break; } case Vallox.Variable.FirePlaceBoosterCounter: { WriteLine("FirePlaceBoosterCounter {0}", value); break; } case Vallox.Variable.LastErrorNumber: { WriteLine("LastErrorNumber {0}", value); break; } case Vallox.Variable.MaintenanceMonthCounter: { WriteLine("MaintenanceMonthCounter {0}", value); break; } case Vallox.Variable.SuspendBus: { WriteLine("Suspend bus for C02 sensor cummunication at {0} {1}", DateTime.Now.ToShortTimeString(), value); break; } case Vallox.Variable.ResumeBus: { WriteLine("Resume bus for all devices at {0} {1}", DateTime.Now.ToShortTimeString(), value); break; } default: { WriteLine("Unknown command {0:X02} {1}", command, value); break; } } } else { if (command == 0) { string variable = Vallox.ConvertVariable(value); WriteLine("{0:X02} --> {1:X02}: get {2}", senderString, receiverString, variable); } else { string variable = Vallox.ConvertVariable(command); WriteLine("{0:X02} --> {1:X02}: set {2} = 0x{3:X02}", senderString, receiverString, variable, value); } } }