Пример #1
0
        private object GetParamValue(string dataHex, IotParam param)
        {
            try
            {
                var length = param.Type == "C" ? 1 : param.Length;
                var val    = dataHex.Substring(2 * param.Start, 2 * length);
                if (val != "EEEE" && val != "EE")
                {
                    switch (param.Type)
                    {
                    case "I":
                        return(NaryHelper.YmHexToInt(val));

                    case "B":
                        return(NaryHelper.HexToInt(val) > 0);

                    case "C":
                        return(BinaryHelper.GetHexBit(val, param.Length));

                    default:
                        return(NaryHelper.YmHexToDouble(val));
                    }
                }
                return("异常");
            }
            catch
            {
                return(null);
            }
        }
Пример #2
0
        public async Task Login(string mac, string body)
        {
            var iotData = GetData(mac);

            iotData.Online        = true;
            iotData.LastLoginTime = DateTime.Now;
            iotData.Save();

            await iotDataHub.Clients.Group(mac).SendAsync("Send", iotData);

            var ctx = new RequestContext("iot", "exe_iot_login")
                      .SetParam(new
            {
                mac,
                softver = NaryHelper.YmHexToDouble(body.Substring(0, 4)),
                hardver = NaryHelper.YmHexToDouble(body.Substring(4, 4)),
                wifi    = EncodingHelper.HexToBytes(body.Substring(8)).ToStr("")
            });
            await Session.ExecuteAsync(ctx);

            var json = SerializeHelper.ToJson(ctx.Params);

            logger.LogDebug($"IotService-LOGIN: {json}");
            LogRec(mac, iotData.Device.Sbno, "登录", "Login", body, json);
        }
Пример #3
0
        static void Main(string[] args)
        {
            var value = -444.77;
            var ymHex = value.ToYmHex(6);

            Console.WriteLine(ymHex);

            value = NaryHelper.YmHexToDouble(ymHex);
            Console.WriteLine(value);

            Console.ReadLine();
        }