SafeDispatch/MotoRepeaterCore/DataBaseInterface.cs

432 lines
18 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SafeMobileLib;
namespace MotoRepeater
{
interface DataBaseInterface
{
//String ID { get; set; }
/// <summary>
/// Method used to send, to the Database, a poll response received from the repeater
/// </summary>
/// <param name="radioID">Radio ID which sent the poll</param>
/// <param name="locationTime">Time of the poll</param>
/// <param name="speed">Speed of the unit at the time of the poll</param>
/// <param name="latitude">Latitude of the poll</param>
/// <param name="longitude">Longitude of the poll</param>
void PollResponseReceived(Int64 radioID, DateTime locationTime, int speed, double latitude, double longitude, Int64 seqID);
/// <summary>
/// Method used to send, to the Database, a location response received from the repeater
/// </summary>
/// <param name="radioID">Radio ID which sent the location</param>
/// <param name="locationTime">Time of the location</param>
/// <param name="speed">Speed of the unit at the time of the location</param>
/// <param name="latitude">Latitude of the location</param>
/// <param name="longitude">Longitude of the location</param>
void LocationResponseReceived(Int64 radioID, DateTime locationTime, int speed, double latitude, double longitude);
/// <summary>
/// Method used to send, to the Database, a location response received from the repeater
/// </summary>
/// <param name="locationArgs">Location Arguments as received from the repeater/field radio</param>
void LocationReceived(LocationEventArgs locationArgs);
/// <summary>
/// Method used to send to the Database the ARS state received from the repeater
/// </summary>
/// <param name="radioID">Radio ID which sent the ars</param>
/// <param name="isON">ARS state which can be true for ON state, and false for OFF state</param>
void ARSStateReceived(Int64 radioID, bool isON);
/// <summary>
/// Method used when a sms is received from a field radio
/// </summary>
/// <param name="radioID">Radio ID which sent the sms</param>
/// <param name="received">Message encrypter as byte array</param>
void SMSReceived(Int64 radioID, byte[] received);
void SMSReceived(Int64 radioID, string message);
/// <summary>
/// Method used when a sms is acknowledged
/// </summary>
/// <param name="received">Message ACK encrypter as byte array</param>
void SMSAckReceived(byte[] received, string seq_no);
/// <summary>
/// Method used when a telemetry is received from a field radio
/// </summary>
/// <param name="radioID">Radio ID which sent the telemetry</param>
/// <param name="received">Message encrypter as byte array</param>
void TelemetryReceived(Int64 radioID, byte[] received);
/// <summary>
/// Method used when a telemetry is received from a field radio
/// </summary>
/// <param name="telemetryArgs">Telemetry arguments with GPIO, Radio ID and others</param>
void TelemetryReceived(TelemetryReceivedEventArgs telemetryArgs);
/// <summary>
/// Method used when a field radio changes its status to enable/disable
/// </summary>
/// <param name="radioID">Radio ID which had sent its status</param>
/// <param name="slot">Slot on which the radio reported</param>
/// <param name="isEnabled">Status of the field radio which can be true for enabled, or false for disabled</param>
void RadioEnableDisableStatusReceived(Int64 radioID, Wireline.SlotNumber slot, bool isEnabled);
/// <summary>
/// Method used when an emergency is received
/// </summary>
/// <param name="radioID">RadioID which had sent the emergency</param>
/// <param name="slot">Slot on which the radio reported</param>
void EmergencyReceived(Int64 radioID, Wireline.SlotNumber slot);
/// <summary>
/// Method used when the call status of the repeater had changed as a consecuence of a call started, hanged or eneded
/// </summary>
/// <param name="sourceID">Field radio/Peer ID which initiated the call</param>
/// <param name="targertID">Field radio/Peer ID for which the call is intended</param>
/// <param name="callType">Call type [see CallType enum for accepted values]</param>
/// <param name="callStatus">Call status [see CallStatus enum for accepted values]</param>
/// <param name="slot">Slot on which the call is/was running</param>
void CallStatusBroadcastReceived(Int64 sourceID, Int64 targertID, CallType callType, CallStatus callStatus, Wireline.SlotNumber slot);
/// <summary>
/// Method used to insert in the database an event received from the tallysman
/// </summary>
/// <param name="tallysmanArgs">Tallysman Arguments as received from tallysman device</param>
void TallysmanEventReceived(TallysmanEventArgs tallysmanArgs);
/// <summary>
/// Method used when the AppServer needs to know which radio Gateways are alive
/// </summary>
/// <param name="radioGWID">Radio Gateway of the MotoRepeater Gateway received from the App Server</param>
void SendChannelBroadcastMessage(Int64 radioGWID);
/// <summary>
/// Get the reporting interval from the Database for a particular unit
/// </summary>
/// <param name="radioID">Radio Id of the unit for which I should
/// find the reporting interval</param>
/// <returns></returns>
int GetReportingIntervalForUnit(string radioID);
/// <summary>
/// Find if the unit is assigned to this gateway or not
/// </summary>
/// <param name="radioID">Radio Id of the unit which needs to be checked </param>
/// <returns>True if the unit is assigned, otherwise false</returns>
bool UnitIsAssignedToGw(string radioID);
/// <summary>
/// Triggered when the application is closing. This will handle the gateway threads ending
/// </summary>
void Stop();
#region EVENTS
event EventHandler<ChannelQueryEventArgs> OnChannelQuery;
event EventHandler<EmergencyAckEventArgs> OnEmergencyAckRequest;
event EventHandler<RadioEnableDisableRequestEventArgs> OnRadioEnableDisableRequest;
event EventHandler<PollRequestEventArgs> OnPollRequestReceived;
event EventHandler<SMSRequestEventArgs> OnSMSRequestReceived;
event EventHandler<SMSRequestEventArgs> OnGroupSMSRequestReceived;
event EventHandler<TelemetryRequestEventArgs> 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
};
}
}
}