using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SipComponent.Simoco { static class SP6 { // Short data (Over-the-Air) PDU // byte 0 - Rezerved (Header) 0 // byte 1 - Type (Header) 0 (Management) // byte 2...end - Management payload // Management payload // byte 2 - Protocol Control 0 // byte 3 - Type 0 - GPS, 1 - Device Status, 255 - Ping // byte 4 - Command depends on Tpe // byte 5...end - Parameters private static void AddManagementShortData(byte[] data, byte type, byte command) { data[3] = type; data[4] = command; } public static byte GetType(byte[] managementShortData) { return managementShortData[3]; } public static byte GetCommand(byte[] managementShortData) { return managementShortData[4]; } public static AlarmType GetAlarmType(byte[] deviceStatusReport) { // bytes 5..6 User Status // bytes 7..10 Alarm Conditions Flags // bytes 11..14 GPS Latitude // bytes 15..18 GPS Longitude return (AlarmType)BitConverter.ToUInt32(deviceStatusReport, 7); } public static void GetGPSFromStatusReport(byte[] deviceStatusReport, out double latitude, out double longitude) { byte[] latitudeBytes = new byte[4]; byte[] longitudeBytes = new byte[4]; Array.Copy(deviceStatusReport, 11, latitudeBytes, 0, 4); Array.Reverse(latitudeBytes); Array.Copy(deviceStatusReport, 15, longitudeBytes, 0, 4); Array.Reverse(longitudeBytes); latitude = BitConverter.ToInt32(latitudeBytes, 0) / 10000000.0; longitude = BitConverter.ToInt32(longitudeBytes, 0) / 10000000.0; } public static byte[] PingCommand(params byte[] arbitraryData) { // lungimea in oceti = 5 + arbitrary data int n = 5 + arbitraryData.Length; byte[] ping = new byte[n]; AddManagementShortData(ping, 0xFF, 0); Array.Copy(arbitraryData, 0, ping, 5, arbitraryData.Length); return ping; } public static byte[] GPSRequestCommand() { byte[] GPSRequest = new byte[5]; AddManagementShortData(GPSRequest, 0, 1); return GPSRequest; } public static byte[] StatusRequestCommand() { byte[] StatusRequest = new byte[5]; AddManagementShortData(StatusRequest, 1, 0); return StatusRequest; } public static byte[] CapabilityRequestCommand() { byte[] deviceCapabilityRequest = new byte[5]; AddManagementShortData(deviceCapabilityRequest, 1, 3); return deviceCapabilityRequest; } } /// /// Contains a list of Alarm types /// public enum AlarmType : uint { /// /// Alarm generated by pressing a button /// USER_GENERATED = 0x01000000, /// /// MAN DOWN /// MAN_DOWN = 0x02000000, /// /// LONE WORKER /// LONE_WORKER = 0x04000000, /// /// NO ALARM /// NO_ALARM = 0x00000000 } }