private void SendAck(IAvrmcObject avrmc, TcpClient client) { EventType eventType = _eventTypeParser.GetEventType(avrmc); switch (eventType) { case (EventType.SOS): case (EventType.SOSV3): _messageWriter.WriteMessage(_messageBuilder.AvcfgAck(avrmc, 'd'), client); break; case (EventType.TamperDetection): _messageWriter.WriteMessage(_messageBuilder.AvcfgAck(avrmc, 't'), client); break; case (EventType.GeofenceEnter): case (EventType.GeofenceExit): _messageWriter.WriteMessage(_messageBuilder.AvcfgAck(avrmc, 'x'), client); break; case (EventType.AccidentShock): _messageWriter.WriteMessage(_messageBuilder.Ack(avrmc), client); break; default: _messageWriter.WriteMessage(_messageBuilder.Ack(avrmc), client); break; } }
public EventType GetEventType(IAvrmcObject avrmc) { var type = typeof(EventType); if (!type.IsEnum) throw new InvalidOperationException(); foreach (var field in type.GetFields()) { var attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute; if (attribute != null) { if (attribute.Description == avrmc.EventCode) return (EventType)field.GetValue(null); } else { if (field.Name == avrmc.EventCode) return (EventType)field.GetValue(null); } } return EventType.Unknown; }
public string AvcfgAck(IAvrmcObject avrmc, char code) { return string.Format("AVCFG,{0},{1}", "00000000"); }
public string Ack(IAvrmcObject avrmc) { return string.Format("EAVACK,{0},{1}", avrmc.EventCode, avrmc.CheckSum); }