public static void TreatTelegram(IMsgUart msg) { try { MsgTelegram100 tel = (MsgTelegram100)msg; LocalRepository localRepository = LocalRepository.GetInstance(); if (tel.StatusPump != (int)localRepository.Pump.Status) { if (tel.StatusPump == 1) { localRepository.Pump.TurnOnPump(); } else { localRepository.Pump.TurnOffPump(); } } if (tel.OperationMode == (int)OperationMode.Automatic) { localRepository.Pump.OperationMode = OperationMode.Automatic; } else { localRepository.Pump.OperationMode = OperationMode.Manual; } } catch (Exception e) { } }
private IMsgUart CreateMsg(RegisterTypeByPosition registerType, ushort[] registers) { IMsgUart msg = null; switch (registerType) { case RegisterTypeByPosition.PumpStatus: case RegisterTypeByPosition.OperationMode: int pumpStauts = registers[(int)RegisterTypeByPosition.PumpStatus]; int operationMode = registers[(int)RegisterTypeByPosition.OperationMode]; msg = new MsgTelegram100(pumpStauts, operationMode); break; case RegisterTypeByPosition.MinWaterTankLevel1: case RegisterTypeByPosition.MinWaterTankLevel2: int minWaterTankLevel1 = registers[(int)RegisterTypeByPosition.MinWaterTankLevel1]; int minWaterTankLevel2 = registers[(int)RegisterTypeByPosition.MinWaterTankLevel2]; msg = new MsgTelegram101(minWaterTankLevel1, minWaterTankLevel2); break; case RegisterTypeByPosition.WaterTankLevel1: case RegisterTypeByPosition.WaterTankLevel2: int waterTankLevel1 = registers[(int)RegisterTypeByPosition.WaterTankLevel1]; int waterTankLevel2 = registers[(int)RegisterTypeByPosition.WaterTankLevel2]; msg = new MsgTelegram102(waterTankLevel1, waterTankLevel2); break; } return(msg); }