public override void HandleMessage(ADMMessage message) { //check if the transmit pin is viable if (_transmitPin == ArduinoPin.BOARD_SPECIFIED && message.HasValue("TP")) { int tp = message.GetInt("TP"); ConfigurePin(tp, PinMode.PwmOutput); Mgr.UpdateDevice(this); _transmitPin = tp; } base.HandleMessage(message); }
public override void HandleMessage(ADMMessage message) { base.HandleMessage(message); if (!IsConnected) { return; } switch (message.Type) { case Messaging.MessageType.DATA: if (message.HasValues("Code", "Protocol", "Bits")) { long ircode = message.GetLong("Code"); int protocol = message.GetInt("Protocol"); int bits = message.GetInt("Bits"); processCode(ircode, protocol, bits); } break; } }
//React to data coming from ADM protected override void HandleADMMessage(ADMMessage message, ArduinoDeviceManager adm) { ArduinoDevice dev; EngineRoomMessageSchema schema = new EngineRoomMessageSchema(message); switch (message.Type) { case MessageType.DATA: if (message.Sender == null) { dev = adm.GetDeviceByBoardID(message.TargetID); if (dev is DS18B20Array) { schema.AddDS18B20Array((DS18B20Array)dev); foreach (var sensor in ((DS18B20Array)dev).ConnectedSensors) { //outputSampleData(sensor.Sampler.GetSubjectData(sensor)); if (Output2Console) { Console.WriteLine("------------------------------> Average temp {0}: {1}", sensor.ID, sensor.AverageTemperature); } } } if (dev is WaterTanks.FluidTank) { schema.AddWaterTanks(_waterTanks); WaterTanks.FluidTank ft = ((WaterTanks.FluidTank)dev); schema.AddWaterTank(ft); if (Output2Console) { Console.WriteLine("****************>: Water Tank {0} distance / average distance / percent / percent full: {1} / {2} / {3} / {4}", ft.ID, ft.Distance, ft.AverageDistance, ft.Percentage, ft.PercentFull); } } } else { dev = adm.GetDevice(message.Sender); if (dev == _pompaCelup) { schema.AddPump(_pompaCelup); if (Output2Console) { Console.WriteLine("+++++++++++++++> Pump {0} {1}", dev.ID, _pompaCelup.IsOn); } } if (dev == _pompaSolar) { schema.AddPump(_pompaSolar); _erdb.LogEvent(_pompaSolar.IsOn ? EngineRoomServiceDB.LogEventType.ON : EngineRoomServiceDB.LogEventType.OFF, _pompaSolar.ID, "Pompa Solar"); if (Output2Console) { Console.WriteLine("+++++++++++++++> Pump {0} {1}", dev.ID, _pompaSolar.IsOn); } } if (dev is Engine.OilSensorSwitch) { Engine.OilSensorSwitch os = (Engine.OilSensorSwitch)dev; schema.AddOilSensor(os); if (Output2Console) { Console.WriteLine("+++++++++++++++> Oil Sensor {0} {1}", os.ID, os.IsOn); } } } break; case MessageType.COMMAND_RESPONSE: dev = adm.GetDeviceByBoardID(message.TargetID); if (dev is RPMCounter) { RPMCounter rpm = (RPMCounter)dev; schema.AddRPM(rpm); message.Type = MessageType.DATA; //change the type so that it's more meaingful for listeners... //TODO: remove if (Output2Console) { Console.WriteLine("===============================> RPM {0}: {1}", rpm.ID, rpm.AverageRPM); } } break; case MessageType.NOTIFICATION: break; case MessageType.CONFIGURE_RESPONSE: dev = adm.GetDeviceByBoardID(message.TargetID); if (dev is DS18B20Array) { Tracing?.TraceEvent(TraceEventType.Information, 0, "Temperature array {0} on board {1} configured {2} sensors on one wire pin {3}", dev.ID, adm.BoardID, ((DS18B20Array)dev).ConnectedSensors.Count, message.GetInt(DS18B20Array.PARAM_ONE_WIRE_PIN)); } break; case MessageType.PING_RESPONSE: //Console.WriteLine("Ping received from {0} ... gives AI={1}, FM={2}, MS={3}", adm.BoardID, message.GetValue("AI"), message.GetValue("FM"), message.GetValue("MS")); ; break; case MessageType.ERROR: try { _erdb.LogEvent(EngineRoomServiceDB.LogEventType.ERROR, message.HasValue("ErrorSource") ? message.GetString("ErrorSource") : adm.PortAndNodeID, message.Value); } catch (Exception e) { Tracing?.TraceEvent(TraceEventType.Error, 0, e.Message); } break; } base.HandleADMMessage(message, adm); }