private void Test() { //var str = \"{\\"stat\\":{\\"time\\":\\"2019-10-25 07:05:33 UTC\\",\\"lati\\":\\"31.231013\\",\\"long\\":\\"121.200607\\",\\"alti\\":\\"30.200000\\",\\"rxnb\\":0,\\"rxok\\":0,\\"rxfw\\":0,\\"ackr\\":100.0,\\"dwnb\\":0,\\"txnb\\":0,\\"batt\\":0,\\"poe\\":0,\\"net\\":1,\\"traffic\\":780539002,\\"ver\\":\\"V3.0.864.862.868_Release\\"}}\"; //var str = "{\"rxpk\":[{\"tmst\":196287580,\"chan\":5,\"rfch\":1,\"freq\":474.100000,\"stat\":1,\"modu\":\"LORA\",\"datr\":\"SF12BW125\",\"codr\":\"4/5\",\"lsnr\":-12.5,\"rssi\":-124,\"size\":50,\"data\":\"gHMAEHCADwsB3P7NADg1Rsj2FLImBtz/9e3hVNzniwoMGUhlyC4KI8Lsvt1VKSuSyVM=\"}]}"; var str = "{\"rxpk\":[{\"tmst\":438505452,\"chan\":2,\"rfch\":0,\"freq\":473.500000,\"stat\":1,\"modu\":\"LORA\",\"datr\":\"SF12BW125\",\"codr\":\"4/5\",\"lsnr\":-14.0,\"rssi\":-119,\"size\":50,\"data\":\"gGEAEHCACwABRaWG3UZsomFqt4sxJmt0JGNFCS3PWweysY1Vi+94PmFTmoycmDxCviA=\"}]}"; //var str = "{\"txpk\":{\"imme\":true,\"freq\":864.123456,\"rfch\":0,\"powe\":14,\"modu\":\"LORA\",\"datr\":\"SF11BW125\",\"codr\":\"4/6\",\"ipol\":false,\"size\":32,\"data\":\"H3P3N2i9qc4yt7rK7ldqoeCVJGBybzPY5h1Dd7P7p8v\"}}"; var js = new JsonParser(str).Decode() as IDictionary <String, Object>; //var st = JsonHelper.Convert<StatModel>(js[\"stat\"]); //Console.WriteLine(st.ToJson(true)); var st = StatModel.Read(js["stat"]); if (st != null) { Console.WriteLine(st.ToJson(true)); } var dt = RxPacket.Read(js["rxpk"]); if (dt.Length > 0) { Console.WriteLine(dt.ToJson(true)); var dp = dt[0]; if (!dp.Data.IsNullOrEmpty()) { Packet pk = dp.Data.ToBase64(); Console.WriteLine(pk.ToHex(64)); Console.WriteLine(pk.ToStr()); var pm = new PHYMessage(); pm.Read(pk.GetStream(), null); Console.WriteLine(pm.ToJson(true)); var nwkSkey = "4B463EFED018F099FE3F05108618FDDA".ToHex(); //var appSkey = "19E52095515EBD0C2FD596DD96FD0833".ToHex(); var appSkey = "778960777F7B4CBAC857C06DEE818844".ToHex(); var buf = pm.Decrypt(nwkSkey, appSkey); Console.WriteLine(buf.ToHex()); Console.WriteLine(buf.ToStr()); } } var tx = TxPacket.Read(js["txpk"]); if (tx != null) { Console.WriteLine(tx.ToJson(true)); } }
/// <summary>上行数据</summary> /// <param name="data"></param> protected virtual void PushData(Packet data) { var str = data.ToStr(); var js = new JsonParser(str).Decode() as IDictionary <String, Object>; //var st = JsonHelper.Convert<StatModel>(js[\"stat\"]); var st = StatModel.Read(js["stat"]); if (st != null) { Console.WriteLine(st.ToJson(true)); } var rxs = RxPacket.Read(js["rxpk"]); if (rxs.Length > 0) { OnPushPacket(rxs, js); } //var tx = TxPacket.Read(js["txpk"]); //if (tx != null) Console.WriteLine(tx.ToJson(true)); }