321 lines
8.5 KiB
C#
321 lines
8.5 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
|
|||
|
namespace MotoRepeater
|
|||
|
{
|
|||
|
public enum MessageBusCmds
|
|||
|
{
|
|||
|
InitAllCall = 101,
|
|||
|
InitPrivateCall = 102,
|
|||
|
InitGroupCall = 103,
|
|||
|
EndAllCall = 111,
|
|||
|
EndPrivateCall = 112,
|
|||
|
EndGroupCall = 113,
|
|||
|
PollRequest = 154,
|
|||
|
RadioEmergencyReceived = 138,
|
|||
|
AppServerEmergency = 134,
|
|||
|
EmergencyACK = 238,
|
|||
|
RadioEnableDisableRequest = 150,
|
|||
|
RadioEnableDisableStatusRequest = 151,
|
|||
|
RadioEnableDisableStatusBroadcast = 250,
|
|||
|
ARSReceived = 130,
|
|||
|
LocationReceived = 131,
|
|||
|
PollResponseReceived = 231,
|
|||
|
SMSReceived = 132,
|
|||
|
CallStatusBroadcast = 125,
|
|||
|
ChannelQueryRequest = 94,
|
|||
|
ChannelBroadcast = 124
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
public sealed class ARSStatus
|
|||
|
{
|
|||
|
|
|||
|
private readonly String name;
|
|||
|
private readonly int value;
|
|||
|
|
|||
|
public static readonly ARSStatus ON = new ARSStatus(1, "ON");
|
|||
|
public static readonly ARSStatus OFF = new ARSStatus(0, "OFF");
|
|||
|
|
|||
|
private ARSStatus(int value, String name)
|
|||
|
{
|
|||
|
this.name = name;
|
|||
|
this.value = value;
|
|||
|
}
|
|||
|
|
|||
|
public override String ToString()
|
|||
|
{
|
|||
|
return name;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public enum MotoTRBOcmd
|
|||
|
{
|
|||
|
SET_REPORT_INTERVAL = 0x01,
|
|||
|
SEND_SMS = 0x02,
|
|||
|
SEND_POLL = 0x03
|
|||
|
};
|
|||
|
|
|||
|
public class htCell_t
|
|||
|
{
|
|||
|
public string lat, lng, spd; // GPS data
|
|||
|
public DateTime location_time;
|
|||
|
public double radius;
|
|||
|
public string di;
|
|||
|
public DateTime activity_time; // = min(gpstime, arstime)
|
|||
|
public string suid;
|
|||
|
public byte requestID;
|
|||
|
public bool triggered;
|
|||
|
public double d_lat, d_lng;
|
|||
|
}
|
|||
|
|
|||
|
public enum Result_Codes_ENUM
|
|||
|
{
|
|||
|
SUCCESS = 0x0,
|
|||
|
UNSUPPORTED_VERSION = 0x8,
|
|||
|
SYNTAX_ERROR = 0xA,
|
|||
|
PROTOCOL_ELEMENT_NOT_SUPPORTED = 0xB,
|
|||
|
PROTOCOL_ELEMENT_VALUE_OUT_OF_RANGE = 0xD,
|
|||
|
QUERY_INFO_NOT_ATTAINABLE = 0xF,
|
|||
|
QUERY_INFO_NOT_CURRENTLY_ATTAINABLE = 0x10,
|
|||
|
NO_SUCH_REQUEST = 0x15,
|
|||
|
DUPLICATE_REQUEST_ID = 0x16,
|
|||
|
/*
|
|||
|
BAD_GPS_GEOMETRY = 0x201,
|
|||
|
IRRS_RES_INSUFF_DATA = 0x1005,
|
|||
|
IRRS_RES_NO_PROVIDERS = 0x1006
|
|||
|
* */
|
|||
|
};
|
|||
|
|
|||
|
public enum Document_Identifiers_ENUM
|
|||
|
{
|
|||
|
Immediate_Location_Request = 0x04,
|
|||
|
Immediate_Location_Request_NoCDT = 0x05,
|
|||
|
Immediate_Location_Report = 0x06,
|
|||
|
Immediate_Location_Report_NoCDT = 0x07,
|
|||
|
Triggered_Location_Request = 0x08,
|
|||
|
Triggered_Location_Request_NoCDT = 0x09,
|
|||
|
Triggered_Location_Answer = 0x0A,
|
|||
|
Triggered_Location_Answer_NoCDT = 0x0B,
|
|||
|
Triggered_Location_Report = 0x0C,
|
|||
|
Triggered_Location_Report_NoCDT = 0x0D,
|
|||
|
Triggered_Location_Stop_Request = 0x0E,
|
|||
|
Triggered_Location_Stop_Request_NoCDT = 0x0F,
|
|||
|
Triggered_Location_Stop_Answer = 0x10,
|
|||
|
Triggered_Location_Stop_Answer_NoCDT = 0x11,
|
|||
|
Unsolicited_Location_Report = 0x12,
|
|||
|
Unsolicited_Location_Report_NoCDT = 0x13,
|
|||
|
Location_Protocol_Request_NoCDT = 0x14,
|
|||
|
Location_Protocol_Report_NoCDT = 0x15
|
|||
|
};
|
|||
|
|
|||
|
// -------------------------------------------------------------------
|
|||
|
// ARS Service
|
|||
|
// -------------------------------------------------------------------
|
|||
|
public enum header_event
|
|||
|
{
|
|||
|
Unqualified_Event = 0x00,
|
|||
|
Initial_Event = 0x01,
|
|||
|
Refresh_Event = 0x02,
|
|||
|
UNKNOWN = 0x03
|
|||
|
}
|
|||
|
|
|||
|
// -------------------------------------------------------------------
|
|||
|
// Location Service
|
|||
|
// -------------------------------------------------------------------
|
|||
|
|
|||
|
|
|||
|
public enum Common_Element_Tokens_ENUM
|
|||
|
{
|
|||
|
request_id = 0x22,
|
|||
|
request_id1 = 0x23,
|
|||
|
request_id2 = 0x24
|
|||
|
};
|
|||
|
public enum Query_Request_Messages_Tokens_ENUM
|
|||
|
{
|
|||
|
interval = 0x31,
|
|||
|
oneshot_trigger = 0x33,
|
|||
|
periodic_trigger = 0x34,
|
|||
|
request_altitude = 0x54,
|
|||
|
request_altitude_acc = 0x55,
|
|||
|
request_altitude_acc1 = 0x56,
|
|||
|
request_direction_hor = 0x57,
|
|||
|
request_hor_acc = 0x5F,
|
|||
|
request_hor_acc1 = 0x60,
|
|||
|
request_lev_conf = 0x61,
|
|||
|
request_protocol_version = 0x3F,
|
|||
|
request_speed_hor = 0x62,
|
|||
|
request_speed_vrt = 0x64,
|
|||
|
require_max_info_age = 0x42,
|
|||
|
require_altitude = 0x66,
|
|||
|
require_altitude_acc = 0x67,
|
|||
|
require_altitude_acc1 = 0x68,
|
|||
|
require_direction_hor = 0x69,
|
|||
|
require_hor_acc = 0x71,
|
|||
|
require_hor_acc1 = 0x72,
|
|||
|
require_lev_conf = 0x73,
|
|||
|
require_speed_hor = 0x74,
|
|||
|
require_speed_vrt = 0x76,
|
|||
|
ret_info = 0x50,
|
|||
|
ret_info1 = 0x51,
|
|||
|
ret_info2 = 0x52,
|
|||
|
ret_info3 = 0x53,
|
|||
|
trg_condition = 0x4A,
|
|||
|
SU_IPv4 = 0x26,
|
|||
|
impl_spec_data = 0x40
|
|||
|
};
|
|||
|
|
|||
|
public enum Report_Messages_Tokens_ENUM
|
|||
|
{
|
|||
|
circle_2d = 0x51,
|
|||
|
circle_3d = 0x54,
|
|||
|
circle_3d1 = 0x55,
|
|||
|
direction_hor = 0x56,
|
|||
|
info_time = 0x34,
|
|||
|
info_time1 = 0x35,
|
|||
|
lev_conf = 0x65,
|
|||
|
point_2d = 0x66,
|
|||
|
point_3d = 0x69,
|
|||
|
point_3d1 = 0x6A,
|
|||
|
protocol_version = 0x36,
|
|||
|
result = 0x37,
|
|||
|
result1 = 0x38,
|
|||
|
result2 = 0x39,
|
|||
|
speed_hor = 0x6C,
|
|||
|
speed_vrt = 0x70,
|
|||
|
SU_IPv4 = 0x26
|
|||
|
};
|
|||
|
|
|||
|
public enum Attribute_Tokens_ENUM
|
|||
|
{
|
|||
|
result_code = 0x22,
|
|||
|
result_code1 = 0x23,
|
|||
|
ret_info_accuracy = 0x50,
|
|||
|
ret_info_accuracy1 = 0x51,
|
|||
|
ret_info_no_req_id = 0x52,
|
|||
|
ret_info_no_req_id1 = 0x53,
|
|||
|
ret_info_time = 0x54,
|
|||
|
ret_info_time1 = 0x55
|
|||
|
};
|
|||
|
|
|||
|
public class MotoTRBOcmdMsg
|
|||
|
{
|
|||
|
public string m_suid;
|
|||
|
public int m_cmd;
|
|||
|
public string m_payload;
|
|||
|
public Int32 m_seqID; //seqID when it was last sent
|
|||
|
public DateTime m_time; //time when it was last sent
|
|||
|
}
|
|||
|
public class ArsMSG
|
|||
|
{
|
|||
|
public string suid;
|
|||
|
public string msg;
|
|||
|
|
|||
|
public string imei;
|
|||
|
public string gatewayID;
|
|||
|
}
|
|||
|
|
|||
|
public class gpsMSG
|
|||
|
{
|
|||
|
public byte[] data = null;
|
|||
|
}
|
|||
|
|
|||
|
public class SMSmsg
|
|||
|
{
|
|||
|
public string suid;
|
|||
|
public string msg;
|
|||
|
public bool conf; //sent confirmation
|
|||
|
public uint DBmsg_id;//message ID from database (for message confirmation)
|
|||
|
public int seq_no;
|
|||
|
public bool req_conf;
|
|||
|
DateTime added;
|
|||
|
public DateTime waitConfSMSList_time;
|
|||
|
|
|||
|
public SMSmsg()
|
|||
|
{
|
|||
|
req_conf = true;
|
|||
|
conf = false;
|
|||
|
added = DateTime.Now;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class POLLmsg
|
|||
|
{
|
|||
|
public int DBid;
|
|||
|
public string suid;
|
|||
|
public DateTime created;
|
|||
|
public DateTime read;
|
|||
|
public DateTime sent;
|
|||
|
public DateTime response;
|
|||
|
public string lat;
|
|||
|
public string lng;
|
|||
|
public string speed;
|
|||
|
public Int32 requestID;
|
|||
|
}
|
|||
|
|
|||
|
public struct header_T
|
|||
|
{
|
|||
|
public bool ext, ext2, ack, cntl;
|
|||
|
public byte pdu_type;
|
|||
|
public byte seq_no;
|
|||
|
public byte encoding;
|
|||
|
public byte header;
|
|||
|
public string message;
|
|||
|
}
|
|||
|
|
|||
|
public class InterthreadMessageQueue<T>
|
|||
|
{
|
|||
|
System.Collections.Generic.Queue<T> _queue = new
|
|||
|
System.Collections.Generic.Queue<T>();
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Post a message to the queue.
|
|||
|
/// </summary>
|
|||
|
public void PostItem(T item)
|
|||
|
{
|
|||
|
lock (_queue)
|
|||
|
{
|
|||
|
_queue.Enqueue(item);
|
|||
|
if (_queue.Count == 1)
|
|||
|
Monitor.Pulse(_queue);
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Retrieve a message from the queue.
|
|||
|
/// </summary>
|
|||
|
/// <param name="maxWait">Number of milliseconds to block ifnothing is available. -1 means "block indefinitely"</param>
|
|||
|
/// <returns>The next item in the queue, or default(T) if queue is empty</returns>
|
|||
|
public T GetItem(int maxWait)
|
|||
|
{
|
|||
|
lock (_queue)
|
|||
|
{
|
|||
|
if (_queue.Count == 0)
|
|||
|
{
|
|||
|
if (maxWait == 0)
|
|||
|
return default(T);
|
|||
|
Monitor.Wait(_queue, maxWait);
|
|||
|
if (_queue.Count == 0)
|
|||
|
return default(T);
|
|||
|
}
|
|||
|
return _queue.Dequeue();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public int Count
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
lock (_queue)
|
|||
|
{
|
|||
|
return _queue.Count;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|