1.Introduction to Development Package
This development is mainly aimed at AOVX products, a toolkit for decoding device uplink data and packaging platform downlink control commands. The target framework used is. NET Framework 4.5.2. If your development program is not using this framework, you can obtain the framework source code of the development package and modify the target framework of the toolkit. The modification method is as follows:
1.1.Modifying the Objective Framework
Select the project in the tool source code and click on “Properties”
Then find the same framework for your project in the target framework drop-down box.
2. Source Code Description
2.1. Introduction to Source Code
The toolkit includes a total of 3 projects:
Jt808CommandEncoder: When sending control commands to platform devices, package the platform’s downstream commands, and then the system that manages device access can distribute the packaged data to the devices.
Jt808DataParser: When the system that manages device access receives data reported by the device, it can call the parsing data method in this project to decode the data reported by the device to the platform and parse it into JSON format strings.
Test: testing tool used to verify data decoding and downstream command packaging.
2.2.Jt808CommandEncoder
CommandEncoder: It is the entry method class for platform downstream command packages.
Method encapsulation is based on the command message ID. Each message ID is encapsulated into two different return types of messages, while others return a hex string and byte [].
2.2.1 0x8103(Set deive parameters)
public static string setDeviceParameterForHex(string deviceId, int msgFlowId, Dictionary<Int32,Object> dicParameters)
public static byte[] setDeviceParameterForBytes(string deviceId, int msgFlowId, Dictionary<Int32, Object> dicParameters)
Method: setDeviceParameterForHex: Package the command and return a hexadecimal string
Method: setDeviceParameterForBytes: Package the command and return a byte array
Parameter 1: deviceId: Device S/N code, which is the 12 digit number of the device
Parameter 2: msgFlowId: The serial number of the instruction issued (2 bytes (1~65535)), which needs to be stored to match the device’s response to this command
Parameter 3: dicParameters: Issue parameter dictionary; Among them, the key corresponds to the “parameter ID” in the following figure
Value corresponds to the parameter ID that needs to be set.
2.2.2 0x8104(Query deive parameters)
public static string queryDeviceParameterForHex(string deviceId, int msgFlowId)
public static byte[] queryDeviceParameterForBytes(string deviceId, int msgFlowId)
Method: queryDeviceParameterForHex: Package the command and return a hexadecimal string.
Method: queryDeviceParameterForBytes: Package the command and return a byte array.
Parameter 1: deviceId: Device S/N code, which is the 12 digit number of the device.
Parameter 2: msgFlowId: Serial number of the issued instruction (2 bytes (1~65535)), which needs to be stored to match the device’s response to this command.
2.2.3 0x8105(Device control commands)
public static string deviceControlCommandForHex(string deviceId, int msgFlowId, Dictionary<int, Object> dicParameter)
public static byte[] deviceControlCommandForBytes(string deviceId, int msgFlowId, Dictionary<int, Object> dicParameter)
Method: queryDeviceParameterForHex: Package the command and return a hexadecimal string.
Method: queryDeviceParameterForBytes: Package the command and return a byte array.
Parameter 1: deviceId: Device S/N code, which is the 12 digit number of the device.
Parameter 2: msgFlowId: Serial number of the issued instruction (2 bytes (1~65535)), which needs to be stored to match the device’s response to this command.
Parameter 3: dicParameters: Command parameter dictionary; Where: key corresponds to the “command word” in the following figure.
Value corresponds to a specific parameter of the corresponding command word.
If the command word is 4 or 5, then value corresponds to null or "".
If the command word is 32, then value corresponds to a dictionary<String, String>, where key is TYPE, MODE, VERSION, PROTOCOL, URL, MD5;Value is their corresponding content.
If the command word is 33, then value is 0 (on) or 1 (off).
If the command word is 34, then value is 0 (off) or 1 (on).
If the command word is 35, then value corresponds to a dictionary Dictionary<String, String>, CHANNEL, MODE;Value is their corresponding content.
If the command word is 36, then value corresponds to the AT command string.
2.3.Jt808DataParser
DataParser:It is the device uplink data decoding entry method class.
If a hexadecimal string is passed in, use
public static string receiveData(string strData)
Parse hexadecimal strings into JSON strings and output.
If byte [] is passed in, use
public static string receiveData(byte[] bytes)
Parse byte[] into JOSN strings and output
The unified format returned by the decoding method is:
public class Result
{
/// <summary>
/// Device ID
/// </summary>
public string DeviceID { get; set; }
/// <summary>
/// Message type
/// </summary>
public string MsgType { get; set; }
/// <summary>
/// Message serial number
/// </summary>
public int MsgFlowId { get; set; }
/// <summary>
/// Message body(Json)
/// </summary>
public object DataBody { get; set; }
/// <summary>
/// Need reply content
/// </summary>
public string ReplyMsg { get; set; }
}
Depending on the MsgType, the entity class corresponding to the DataBody will be different.
ReplyMsg is whether the platform needs to respond to this message. If data needs to be responded to, ReplyMsg is the corresponding response content (hexadecimal string). If no response is needed, ReplyMsg is a null value.
2.3.1.MsgType=0x0200
Then the DataBody is LocationData
public class LocationData
{
/// <summary>
/// Device packaging time,(UTC+0)
/// </summary>
public string GpsTime { get; set; }
/// <summary>
/// latitude
/// </summary>
public double Latitude { get; set; }
/// <summary>
/// Longitude
/// </summary>
public double Longitude { get; set; }
/// <summary>
/// Location type(1:GNSS located;0:Not located)
/// </summary>
public int LocationType { get; set; }
/// <summary>
/// Speed(km/h)
/// </summary>
public int Speed { get; set; }
/// <summary>
/// Direction(0~360)
/// </summary>
public int Direction { get; set; }
/// <summary>
/// Mileage(km)
/// </summary>
public long Mileage { get; set; }
/// <summary>
/// Altitude(m)
/// </summary>
public int Altitude { get; set; }
/// <summary>
/// ACC
/// </summary>
public int ACC { get; set; }
/// <summary>
/// Gnss signal
/// </summary>
public int GpsSignal { get; set; }
/// <summary>
/// GSM signal
/// </summary>
public int GSMSignal { get; set; }
/// <summary>
/// Alarm value list
/// </summary>
public List<int> AlarmTypeList { get; set; }
/// <summary>
/// Expansion Information Map
/// </summary>
public Dictionary<string, Object> ExtraInfoMap { get; set; }
}
2.3.2.MsgType=0x0001
Then the DataBody is GeneralResponse
public class GeneralResponse
{
/// <summary>
/// Response serial number
/// </summary>
public int ResponseSequence { get; set; }
/// <summary>
/// Response message ID
/// </summary>
public string ResponseID { get; set; }
/// <summary>
/// Response result
/// </summary>
public int Result { get; set; }
}
2.3.3.MsgType=0x0002
Then DataBody is null, 0x0002 is the heartbeat packet
2.3.4.MsgType=0x0100
Then the DataBody is DeviceRegistration
public class DeviceRegistration
{
public int ProvinceId { get; set; }
public int CityId { get; set; }
public string ProducerId { get; set; }
public string DeviceType { get; set; }
public string DeviceID { get; set; }
public int LicensePlateColor { get; set; }
public string VehicleNo { get; set; }
}
2.3.5.MsgType=0x0102
Then the DataBody is String, and the content is the device authentication code
2.3.6.MsgType=0x0104
Then the DataBody is DeviceParameter
public class DeviceParameter
{
/// <summary>
/// Response serial number
/// </summary>
public int ReplyMsgFlowId { get; set; }
/// <summary>
/// Number of response parameters
/// </summary>
public int ItemCount { get; set; }
/// <summary>
/// Response parameter list
/// </summary>
public Dictionary<string,object> ItemMap { get; set; }
}
2.3.7.MsgType=0x0900
Then the DataBody is TransparentMessage
public class TransparentMessage
{
/// <summary>
/// Transparent message type
/// </summary>
public int MsgType;
/// <summary>
/// Transparent message content
/// </summary>
public string MsgContent;
}
2.4.Test
Testing tools
“Uplink decoding” is the decoding of data reported by devices.
On the left is the unpacking instructions, which introduce the subcontracting of the original data.
On the right is parsing the raw data into JSON strings.
“Downlink encoding” is the grouping of instruction data.
The above is the command package I used to set the primary IP for the device:
Server APN:CMIOT
APN username:TEST
APN password:123456
Main server address:124.223.60.234
Server port:6608
Encoded message below: will show the command content for packaging.
7E8103003C7300579323640001050000001005434D494F540000001104544553540000001206313233343536000000130F3132342E3232332E3036302E3233340000001804000019D0F37E
最后编辑:admin 更新时间:2024-10-08 16:49