using System; using System.Collections.Generic; using System.Linq; using System.Text; using SafeMobileLib; namespace MotoRepeater { interface DataBaseInterface { //String ID { get; set; } /// /// Method used to send, to the Database, a poll response received from the repeater /// /// Radio ID which sent the poll /// Time of the poll /// Speed of the unit at the time of the poll /// Latitude of the poll /// Longitude of the poll void PollResponseReceived(Int64 radioID, DateTime locationTime, int speed, double latitude, double longitude, Int64 seqID); /// /// Method used to send, to the Database, a location response received from the repeater /// /// Radio ID which sent the location /// Time of the location /// Speed of the unit at the time of the location /// Latitude of the location /// Longitude of the location void LocationResponseReceived(Int64 radioID, DateTime locationTime, int speed, double latitude, double longitude); /// /// Method used to send, to the Database, a location response received from the repeater /// /// Location Arguments as received from the repeater/field radio void LocationReceived(LocationEventArgs locationArgs); /// /// Method used to send to the Database the ARS state received from the repeater /// /// Radio ID which sent the ars /// ARS state which can be true for ON state, and false for OFF state void ARSStateReceived(Int64 radioID, bool isON); /// /// Method used when a sms is received from a field radio /// /// Radio ID which sent the sms /// Message encrypter as byte array void SMSReceived(Int64 radioID, byte[] received); void SMSReceived(Int64 radioID, string message); /// /// Method used when a sms is acknowledged /// /// Message ACK encrypter as byte array void SMSAckReceived(byte[] received, string seq_no); /// /// Method used when a telemetry is received from a field radio /// /// Radio ID which sent the telemetry /// Message encrypter as byte array void TelemetryReceived(Int64 radioID, byte[] received); /// /// Method used when a telemetry is received from a field radio /// /// Telemetry arguments with GPIO, Radio ID and others void TelemetryReceived(TelemetryReceivedEventArgs telemetryArgs); /// /// Method used when a field radio changes its status to enable/disable /// /// Radio ID which had sent its status /// Slot on which the radio reported /// Status of the field radio which can be true for enabled, or false for disabled void RadioEnableDisableStatusReceived(Int64 radioID, Wireline.SlotNumber slot, bool isEnabled); /// /// Method used when an emergency is received /// /// RadioID which had sent the emergency /// Slot on which the radio reported void EmergencyReceived(Int64 radioID, Wireline.SlotNumber slot); /// /// Method used when the call status of the repeater had changed as a consecuence of a call started, hanged or eneded /// /// Field radio/Peer ID which initiated the call /// Field radio/Peer ID for which the call is intended /// Call type [see CallType enum for accepted values] /// Call status [see CallStatus enum for accepted values] /// Slot on which the call is/was running void CallStatusBroadcastReceived(Int64 sourceID, Int64 targertID, CallType callType, CallStatus callStatus, Wireline.SlotNumber slot); /// /// Method used to insert in the database an event received from the tallysman /// /// Tallysman Arguments as received from tallysman device void TallysmanEventReceived(TallysmanEventArgs tallysmanArgs); /// /// Method used when the AppServer needs to know which radio Gateways are alive /// /// Radio Gateway of the MotoRepeater Gateway received from the App Server void SendChannelBroadcastMessage(Int64 radioGWID); /// /// Get the reporting interval from the Database for a particular unit /// /// Radio Id of the unit for which I should /// find the reporting interval /// int GetReportingIntervalForUnit(string radioID); /// /// Find if the unit is assigned to this gateway or not /// /// Radio Id of the unit which needs to be checked /// True if the unit is assigned, otherwise false bool UnitIsAssignedToGw(string radioID); /// /// Triggered when the application is closing. This will handle the gateway threads ending /// void Stop(); #region EVENTS event EventHandler OnChannelQuery; event EventHandler OnEmergencyAckRequest; event EventHandler OnRadioEnableDisableRequest; event EventHandler OnPollRequestReceived; event EventHandler OnSMSRequestReceived; event EventHandler OnGroupSMSRequestReceived; event EventHandler OnTelemetryRequestReceived; #endregion } public class PollRequestEventArgs : EventArgs { public String RadioID { get; set; } public int SeqID { get; set; } } public class EmergencyAckEventArgs : EventArgs { public Int64 RadioID { get; set; } public Wireline.SlotNumber Slot { get; set; } } public class RadioEnableDisableRequestEventArgs : EventArgs { public Int64 RadioID { get; set; } public Boolean Enabled { get; set; } public Wireline.SlotNumber Slot { get; set; } } public class SMSRequestEventArgs : EventArgs { public String RadioID { get; set; } public String GroupID { get; set; } public Boolean isACKWanted { get; set; } public String message { get; set; } public Int64 seqID { get; set; } } public class TelemetryRequestEventArgs : EventArgs { public String RadioID { get; set; } public String GPIO { get; set; } public String Type { get; set; } public Int64 seqID { get; set; } } public class ChannelQueryEventArgs : EventArgs { public Int64 RadioGwID { get; set; } } public class TelemetryReceivedEventArgs : EventArgs { public String RadioID { get; set; } public String GPIO { get; set; } public String Type { get; set; } public Int64 seqID { get; set; } public TelemetryReceivedEventArgs() { RadioID = ""; GPIO = ""; Type = ""; seqID = 0; } } public class LocationEventArgs : EventArgs { public Int64 RadioID { get; set; } public Int64 GPSTime { get; set; } public Double Speed { get; set; } public Double Latitude { get; set; } public Double Longitude { get; set; } public Double Altitude { get; set; } public Double LevelOfConfidence { get; set; } public Int64 seqID { get; set; } public LocationEventArgs() { RadioID = 0; GPSTime = DateTime.UtcNow.DateTo70Format(); Speed = 0; Latitude = 0; Longitude = 0; Altitude = 0; seqID = 0; } } public class TallysmanEventArgs : EventArgs { public sealed class TallysmanEventType { private readonly String name; private readonly int value; public static readonly TallysmanEventType IMMEDIATE = new TallysmanEventType(1, "IMMEDIATE"); public static readonly TallysmanEventType PTT = new TallysmanEventType(2, "PTT"); public static readonly TallysmanEventType TURN = new TallysmanEventType(3, "TURN"); public static readonly TallysmanEventType SPEEDING = new TallysmanEventType(4, "SPEEDING"); public static readonly TallysmanEventType IGNITION_ON = new TallysmanEventType(5, "IGNITION_ON"); public static readonly TallysmanEventType IGNITION_OFF = new TallysmanEventType(6, "IGNITION_OFF"); public static readonly TallysmanEventType RADIO_ON = new TallysmanEventType(7, "RADIO_ON"); public static readonly TallysmanEventType RADIO_OFF = new TallysmanEventType(8, "RADIO_OFF"); public static readonly TallysmanEventType STOPPED = new TallysmanEventType(9, "STOPPED"); public static readonly TallysmanEventType MOVING = new TallysmanEventType(10, "MOVING"); public static readonly TallysmanEventType GPS_FIX = new TallysmanEventType(11, "GPS_FIX"); public static readonly TallysmanEventType GPS_NO_FIX = new TallysmanEventType(12, "GPS_NO_FIX"); public static readonly TallysmanEventType DISTANCE = new TallysmanEventType(13, "DISTANCE"); public static readonly TallysmanEventType VIO = new TallysmanEventType(14, "VIO"); public static readonly TallysmanEventType PERIODIC = new TallysmanEventType(15, "PERIODIC"); public static readonly TallysmanEventType CIRCLE_WAYPOINT_IN = new TallysmanEventType(16, "CIRCLE_WAYPOINT_IN"); public static readonly TallysmanEventType EMERGENCY = new TallysmanEventType(17, "EMERGENCY"); public static readonly TallysmanEventType CHANNEL_CHANGED = new TallysmanEventType(18, "CHANNEL_CHANGED"); public static readonly TallysmanEventType TRACKING = new TallysmanEventType(19, "TRACKING"); public static readonly TallysmanEventType SAFE_AREA = new TallysmanEventType(20, "SAFE_AREA"); public static readonly TallysmanEventType RSSI = new TallysmanEventType(21, "RSSI"); public static readonly TallysmanEventType USER_INPUT = new TallysmanEventType(22, "USER_INPUT"); public static readonly TallysmanEventType POLYGON_WAYPOINT_IN = new TallysmanEventType(23, "POLYGON_WAYPOINT_IN"); public static readonly TallysmanEventType POLYGON_WAYPOINT_OUT = new TallysmanEventType(24, "POLYGON_WAYPOINT_OUT"); public static readonly TallysmanEventType CIRCLE_WAYPOINT_OUT = new TallysmanEventType(25, "CIRCLE_WAYPOINT_OUT"); public static readonly TallysmanEventType BUS_STOP = new TallysmanEventType(26, "BUS_STOP"); public static readonly TallysmanEventType PERIODIC1 = new TallysmanEventType(27, "PERIODIC1"); public static readonly TallysmanEventType PERIODIC2 = new TallysmanEventType(28, "PERIODIC2"); public static readonly TallysmanEventType PERIODIC3 = new TallysmanEventType(29, "PERIODIC3"); public static readonly TallysmanEventType PERIODIC4 = new TallysmanEventType(30, "PERIODIC4"); public static readonly TallysmanEventType VIO1 = new TallysmanEventType(31, "VIO1"); public static readonly TallysmanEventType VIO2 = new TallysmanEventType(32, "VIO2"); public static readonly TallysmanEventType VIO3 = new TallysmanEventType(33, "VIO3"); public static readonly TallysmanEventType VIO4 = new TallysmanEventType(34, "VIO4"); public static readonly TallysmanEventType DISTANCE1 = new TallysmanEventType(35, "DISTANCE1"); public static readonly TallysmanEventType DISTANCE2 = new TallysmanEventType(36, "DISTANCE2"); private TallysmanEventType(int value, String name) { this.name = name; this.value = value; } public static TallysmanEventType GetEventType(int type) { switch (type) { case 1: return IMMEDIATE; case 2: return PTT; case 3: return TURN; case 4: return SPEEDING; case 5: return IGNITION_ON; case 6: return IGNITION_OFF; case 7: return RADIO_ON; case 8: return RADIO_OFF; case 9: return STOPPED; case 10: return MOVING; case 11: return GPS_FIX; case 12: return GPS_NO_FIX; case 13: return DISTANCE; case 14: return VIO; case 15: return PERIODIC; case 16: return CIRCLE_WAYPOINT_IN; case 17: return EMERGENCY; case 18: return CHANNEL_CHANGED; case 19: return TRACKING; case 20: return SAFE_AREA; case 21: return RSSI; case 22: return USER_INPUT; case 23: return POLYGON_WAYPOINT_IN; case 24: return POLYGON_WAYPOINT_OUT; case 25: return CIRCLE_WAYPOINT_OUT; case 26: return BUS_STOP; case 27: return PERIODIC1; case 28: return PERIODIC2; case 29: return PERIODIC3; case 30: return PERIODIC4; case 31: return VIO1; case 32: return VIO2; case 33: return VIO3; case 34: return VIO4; case 35: return DISTANCE1; case 36: return DISTANCE2; } return BUS_STOP; } public override String ToString() { return name; } } public Int64 Id { get; set; } public TallysmanEventType EventType { get; set; } public Int64 RadioID { get; set; } public Double GPSFixTime { get; set; } public Double EventTime { get; set; } public Double Speed { get; set; } public Double Latitude { get; set; } public Double Longitude { get; set; } public Double Altitude { get; set; } public Double LevelOfConfidence { get; set; } public Double Bearing { get; set; } public Double HorizontalAccuracy { get; set; } public Double VerticalAccuracy { get; set; } public Double Odometer { get; set; } public Int64 RunTime { get; set; } public Int64 IdleTime { get; set; } public Int32 VioStatus { get; set; } public Int32 VioChanged { get; set; } public Double AverageSpeed { get; set; } public Int64 WaypointId { get; set; } public String FirmwareVersion { get; set; } public Double RSSI { get; set; } public Int64 VitalId { get; set; } public Int64 LogID { get; set; } public TallysmanEventArgs() { Id = 0; EventType = TallysmanEventType.BUS_STOP; RadioID = 0; GPSFixTime = 0; EventTime = 0; Speed = 0; Latitude = 0; Longitude = 0; Altitude = -1; LevelOfConfidence = -1; Bearing = -1; HorizontalAccuracy = 0; VerticalAccuracy = 0; Odometer = 0; RunTime = 0; IdleTime = 0; VioStatus = 0; VioChanged = 0; AverageSpeed = 0; WaypointId = 0; FirmwareVersion = ""; RSSI = 0; VitalId = 0; LogID = 0; } public TallysmanMsg GetTallysmanMessage() { return new TallysmanMsg() { Id = this.Id, EventType = this.EventType.ToString(), RadioID = this.RadioID, GPSFixTime = this.GPSFixTime, EventTime = this.EventTime, Speed = this.Speed, Latitude = this.Latitude, Longitude = this.Longitude, Altitude = this.Altitude, LevelOfConfidence = this.LevelOfConfidence, Bearing = this.Bearing, HorizontalAccuracy = this.HorizontalAccuracy, VerticalAccuracy = this.VerticalAccuracy, Odometer = this.Odometer, RunTime = this.RunTime, IdleTime = this.IdleTime, VioStatus = this.VioStatus, VioChanged = this.VioChanged, AverageSpeed = this.AverageSpeed, WaypointId = this.WaypointId, FirmwareVersion = this.FirmwareVersion, RSSI = this.RSSI, VitalId = this.VitalId, LogId = this.LogID }; } } }