道路运输车辆卫星定位系统JT/T808服务实现和压测
? ? ? ? 在工作上的需要接觸道路運(yùn)輸車輛衛(wèi)星定位系統(tǒng)相關(guān)應(yīng)用,由于自己對網(wǎng)絡(luò)服務(wù)的編寫比較感興趣,所以利用空閑時(shí)間實(shí)現(xiàn)了JT/T808的一些協(xié)議和相關(guān)服務(wù)(不得不說這種協(xié)議的設(shè)計(jì)在解釋的確導(dǎo)致性能上的損耗,特別針地托管語言的C#來說就更加容易導(dǎo)致性能問題,不過對于現(xiàn)有硬件資源來說一臺(tái)簡配的PC支撐上幾萬個(gè)終端那還是沒什么壓力的).主要基于興趣來寫所以JT/T808只實(shí)現(xiàn)了幾個(gè)常用的協(xié)議:0x0002,0x0200,0x0100等.
????? ? 為了更好地進(jìn)行模擬測試還實(shí)現(xiàn)了一個(gè)簡單的JT/T808模擬器方便進(jìn)行一些簡單的測試 ?
? ? ? ?
消息封裝
?????? ? 一個(gè)好的消息封裝會(huì)給消息擴(kuò)展帶來極大的方便和效率(不過不得不面對資源損耗的加大).Beetle.JT808采用對象結(jié)合特性的方式來描述一個(gè)JT808消息,特別對于一個(gè)多位組合的屬性也通過對象化來表現(xiàn),這樣可以上使用者使用起來更方便和簡單.
/// <summary>/// 終端注冊/// </summary>[MessageType(ID = 0x0100)]public class Register {/// <summary>/// 標(biāo)示終端安裝車輛所在的省域,0保留,由平臺(tái)取默認(rèn)值。省域ID采用GB/T 2260中規(guī)定的行政區(qū)劃代碼六位中前兩位/// </summary>[UInt16Handler]public ushort Province { get; set; }/// <summary>/// 標(biāo)示終端安裝車輛所在的市域和縣域,0保留, 由平臺(tái)取默認(rèn)值。市縣域ID采用GB/T 2260中規(guī)定的行政區(qū)劃代碼六位后四位/// </summary>[UInt16Handler]public ushort City { get; set; }/// <summary>/// 五個(gè)字節(jié),終端制造商編碼。/// </summary>[ASCIIHandler(5)]public string Provider { get; set; }/// <summary>/// 八個(gè)字節(jié),此終端型號(hào)由制造商自行定義,位數(shù)不是八位的,補(bǔ)空格。/// </summary>[ASCIIHandler(8)]public string DeviceNumber { get; set; }/// <summary>/// 七個(gè)字節(jié),由大寫字母和數(shù)字組成,此終端ID由制造商自行定義/// </summary>[ASCIIHandler(7)]public string DeviceID { get; set; }/// <summary>/// 車牌顏色,按照J(rèn)T/T 415-2006的5.4.12/// </summary>[ByteHandler]public byte Color { get; set; }/// <summary>/// 公安交通管理部門頒發(fā)的機(jī)動(dòng)車號(hào)牌/// </summary>[GBKHandler]public string PlateNumber { get; set; }} }服務(wù)器封裝
????? ? 有服務(wù)端封裝上也是采購消息事件來驅(qū)動(dòng)消息邏輯的處理,這樣在擴(kuò)展消息處理上也非常方便
protected virtual void OnPostion(Message msg, Messages.Postion e, Beetle.Express.IChannel channel){channel.Name = msg.SIM;channel["GPS_INFO"] = e;if (Loger.Enabled(LogType.DEBUG))Loger.Process(LogType.DEBUG, "{0} postion lng:{1}/lat:{2} time:{3}", msg.SIM, e.Longitude, e.Latitude, e.Time);ReturnCenterResponse(msg, channel);}protected virtual void OnRegister(Message msg, Messages.Register e, Beetle.Express.IChannel channel){if (Loger.Enabled(LogType.DEBUG))Loger.Process(LogType.DEBUG, "{0} registed platenumber:{1}", msg.SIM, e.PlateNumber);Message result = MessageFactory.CreateMessage<RegisterResponse>(msg.SIM);RegisterResponse response = result.GetBody<RegisterResponse>();response.BusinessNO = msg.BussinessNO;response.Result = RegisterStatus.Success;response.Signature = Guid.NewGuid().ToString("N");result.Send(channel);}protected virtual void OnSignature(Message msg, Messages.ClientSignature e, Beetle.Express.IChannel channel){if (Loger.Enabled(LogType.DEBUG))Loger.Process(LogType.DEBUG, "{0} signature {1}", msg.SIM, e.Signature);ReturnCenterResponse(msg, channel);}protected virtual void OnNotImplement(Message msg, Messages.MessageNotImplement e, Beetle.Express.IChannel channel){if (Loger.Enabled(LogType.DEBUG))Loger.Process(LogType.DEBUG, "{0} message:{1} not implement!", msg.SIM, e.MessageID);ReturnCenterResponse(msg, channel);}壓測結(jié)果
????? ? 雖然對服務(wù)功能進(jìn)行了大量的抽象封裝,在效率上會(huì)有很大的開銷損耗.但在現(xiàn)有的硬件資源下并不會(huì)存在多大問題.以下是模擬10000個(gè)終端設(shè)備每5秒提交一條車輛行駛信息的測試情況:
? ? ? ? 服務(wù)端是一臺(tái)虛擬化的4核,16G內(nèi)存的電腦.
? ? ? ? 行車信息:
Messages.Postion postion = new Messages.Postion();postion.Direction = (ushort)ran.Next(ushort.MinValue, ushort.MaxValue);postion.Height = (ushort)ran.Next(ushort.MinValue, ushort.MaxValue);postion.Latitude = (uint)ran.Next(0, 2000000);postion.Longitude = (uint)ran.Next(0, 2000000);postion.Speed = (ushort)ran.Next(ushort.MinValue, ushort.MaxValue);postion.Time = DateTime.Now;postion.FuelGauge.Value = (ushort)ran.Next(ushort.MinValue, ushort.MaxValue);postion.Milometer.Value = (uint)ran.Next(0, 2000000);postion.Speedometer.Value = (ushort)ran.Next(10, 200);Client.Postion(postion);? ? ? ? 服務(wù)器壓力17小時(shí)后的結(jié)果:
? ? ? ? ?
? ? ? ? ?測試終端情況:
? ? ? ? ?
?
總結(jié)
以上是生活随笔為你收集整理的道路运输车辆卫星定位系统JT/T808服务实现和压测的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BFC与IFC概念理解+布局规则+形成方
- 下一篇: PAT Broken Keyboard