示例#1
0
        private static string Parse(AtResponse response)
        {
            if (!response.IsOk)
                throw new XBeeException("Failed to read node identifier");

            return Arrays.ToString(response.Value);
        }
示例#2
0
        public static ApiModes Parse(AtResponse response)
        {
            if (!response.IsOk)
                throw new XBeeException("Attempt to query AP parameter failed");

            return (ApiModes) response.Value[0];
        }
示例#3
0
        public static string Parse(AtResponse response)
        {
            if (!response.IsOk)
                throw new XBeeException("Attempt to query HV parameter failed");

            return ByteUtils.ToBase16(response.Value);
        }
示例#4
0
文件: WxService.cs 项目: njmjr/WeChat
        public void SendTemplateMessage(TemplateMessage request, TemplateMessageResponse response)
        {
            AtResponse wxr = GetAcc();

            if (String.IsNullOrEmpty(wxr.Expires_in))
            {
                throw new WeChatException("GET_ACCESSTOKEN_FAIL", "获取AccessToken失败");
            }

            Hashtable s1 = new Hashtable {
                { @"keynote1", request.keynote1 }, { @"keynote2", request.keynote2 }
            };
            string    data = XmlAndJsonToHash.HashTableToXml(s1);
            Hashtable s2   = new Hashtable
            {
                { @"touser", request.touser },
                { @"template_id", request.template_id },
                { @"url", request.url },
                { @"data", data }
            };
            string     postData = XmlAndJsonToHash.HashTableToXml(s2);
            String     wxResult = HttpRequestUtil.HttpPost(string.Format(TemplateMessageUrl, wxr.Access_token), postData);
            TmResponse tr       = JsonHelper.Deserialize <TmResponse>(wxResult);

            if (tr.errmsg.ToUpper() == "OK")
            {
                response.errcode = tr.errcode;
                response.errmsg  = tr.errmsg;
                response.ResponseStatus.ErrorCode = "OK";
            }
            else
            {
                throw new WeChatException("SendTemplateMessage_fail", "发送模板消息失败");
            }
        }
示例#5
0
        public static HardwareVersions Parse(AtResponse response)
        {
            if (!response.IsOk)
                throw new XBeeException("Attempt to query remote HV parameter failed");

            return (HardwareVersions)response.Value[0];
        }
示例#6
0
        public static DiscoverResult Parse(AtResponse response)
        {
            if (response.Command != (ushort) AtCmd.NodeDiscover)
                throw new ArgumentException("This method is only applicable for the ND command");

            // empty response is received after the last disovered node
            // this happens only with Wpan nodes, not Zigbee
            if (response.Value == null || response.Value.Length == 0)
                return null;

            var input = new InputStream(response.Value);

            var frame = new DiscoverResult
            {
                NodeInfo = new NodeInfo
                {
                    NetworkAddress = new XBeeAddress16(input.Read(2)),
                    SerialNumber = new XBeeAddress64(input.Read(8)),
                },
                Rssi = -1 * input.Read()
            };

            byte ch;

            // NI is terminated with 0
            while ((ch = input.Read()) != 0)
                if (ch > 32 && ch < 126)
                    frame.NodeInfo.NodeIdentifier += (char)ch;

            return frame;
        }
示例#7
0
        public static DiscoverResult Parse(AtResponse response)
        {
            if (response.Command != (ushort) AtCmd.NodeDiscover)
                throw new ArgumentException("This method is only applicable for the ND command");

            var input = new InputStream(response.Value);

            var frame = new DiscoverResult
            {
                NodeInfo = new NodeInfo
                {
                    NetworkAddress = new XBeeAddress16(input.Read(2)),
                    SerialNumber = new XBeeAddress64(input.Read(8))
                }
            };

            byte ch;

            // NI is terminated with 0
            while ((ch = input.Read()) != 0)
                if (ch > 32 && ch < 126)
                    frame.NodeInfo.NodeIdentifier += (char)ch;

            frame.Parent = new XBeeAddress16(input.Read(2));
            frame.NodeType = (NodeType) input.Read();
            frame.Status = input.Read();
            frame.ProfileId = input.Read(2);
            frame.MfgId = input.Read(2);

            return frame;
        }
示例#8
0
 /// <summary>
 ///   TODO: Update Comments
 ///
 /// </summary>
 /// <param name="response" type="NETMF.OpenSource.XBee.Api.AtResponse">
 ///     <para>
 ///
 ///     </para>
 /// </param>
 public static void Parse(AtResponse response)
 {
     if (!response.IsOk)
     {
         throw new XBeeException("Failed to save settings");
     }
 }
示例#9
0
        public static HardwareVersions Parse(AtResponse response)
        {
            if (!response.IsOk)
            {
                throw new XBeeException("Attempt to query remote HV parameter failed");
            }

            return((HardwareVersions)response.Value[0]);
        }
示例#10
0
        public static ApiModes Parse(AtResponse response)
        {
            if (!response.IsOk)
            {
                throw new XBeeException("Attempt to query AP parameter failed");
            }

            return((ApiModes)response.Value[0]);
        }
示例#11
0
        private static string Parse(AtResponse response)
        {
            if (!response.IsOk)
            {
                throw new XBeeException("Failed to read node identifier");
            }

            return(Arrays.ToString(response.Value));
        }
示例#12
0
文件: WxService.cs 项目: njmjr/WeChat
        private AtResponse GetAcc()
        {
            var        appId     = ConfigurationManager.AppSettings["APPID"];
            var        appsecret = ConfigurationManager.AppSettings["APPSECRET"];
            String     wxResult  = HttpRequestUtil.HttpGet(string.Format(AccessTokenUrl, appId, appsecret));
            AtResponse wxr       = JsonHelper.Deserialize <AtResponse>(wxResult);

            return(wxr);
        }
示例#13
0
        public static string Parse(AtResponse response)
        {
            if (!response.IsOk)
            {
                throw new XBeeException("Attempt to query HV parameter failed");
            }

            return(ByteUtils.ToBase16(response.Value));
        }
示例#14
0
        private static XBeeAddress64 Parse(AtResponse sl, AtResponse sh)
        {
            if (!sh.IsOk || !sl.IsOk)
                throw new XBeeException("Failed to read serial number");

            var data = new OutputStream();
            data.Write(sh.Value);
            data.Write(sl.Value);

            return new XBeeAddress64(data.ToArray());
        }
示例#15
0
        private static XBeeAddress64 Parse(AtResponse sl, AtResponse sh)
        {
            if (!sh.IsOk || !sl.IsOk)
            {
                throw new XBeeException("Failed to read serial number");
            }

            var data = new OutputStream();

            data.Write(sh.Value);
            data.Write(sl.Value);

            return(new XBeeAddress64(data.ToArray()));
        }
示例#16
0
        public static IoSampleResponse ParseIsSample(AtResponse response)
        {
            if (response.Command != (ushort)Common.AtCmd.ForceSample)
            {
                throw new ArgumentException("This is only applicable to the 'IS' AT command");
            }

            var input  = new InputStream(response.Value);
            var sample = new IoSampleResponse();

            //sample.ParseIoSample(input);

            return(sample);
        }
示例#17
0
文件: WxService.cs 项目: njmjr/WeChat
        public void GetAccessToken(AccessToken request, AccessTokenResponse response)
        {
            AtResponse wxr = GetAcc();

            if (String.IsNullOrEmpty(wxr.Expires_in))
            {
                response.ResponseStatus.ErrorCode = wxr.Errcode;
                response.ResponseStatus.Message   = wxr.Errmsg;
            }
            else
            {
                response.AccessToken = wxr.Access_token;
                response.ExpiresIn   = wxr.Expires_in;
                response.ResponseStatus.ErrorCode = "OK";
            }
        }
示例#18
0
        public static DiscoverResult Parse(AtResponse response)
        {
            if (response.Command != (ushort)AtCmd.NodeDiscover)
            {
                throw new ArgumentException("This method is only applicable for the ND command");
            }

            // empty response is received after the last disovered node
            // this happens only with Wpan nodes, not Zigbee
            if (response.Value == null || response.Value.Length == 0)
            {
                return(null);
            }

            var input = new InputStream(response.Value);

            var frame = new DiscoverResult
            {
                NodeInfo = new NodeInfo
                {
                    NetworkAddress = new XBeeAddress16(input.Read(2)),
                    SerialNumber   = new XBeeAddress64(input.Read(8)),
                },
                Rssi = -1 * input.Read()
            };

            byte ch;

            // NI is terminated with 0
            while ((ch = input.Read()) != 0)
            {
                if (ch > 32 && ch < 126)
                {
                    frame.NodeInfo.NodeIdentifier += (char)ch;
                }
            }

            return(frame);
        }
示例#19
0
        public static DiscoverResult Parse(AtResponse response)
        {
            if (response.Command != (ushort)AtCmd.NodeDiscover)
            {
                throw new ArgumentException("This method is only applicable for the ND command");
            }

            var input = new InputStream(response.Value);

            var frame = new DiscoverResult
            {
                NodeInfo = new NodeInfo
                {
                    NetworkAddress = new XBeeAddress16(input.Read(2)),
                    SerialNumber   = new XBeeAddress64(input.Read(8))
                }
            };

            byte ch;

            // NI is terminated with 0
            while ((ch = input.Read()) != 0)
            {
                if (ch > 32 && ch < 126)
                {
                    frame.NodeInfo.NodeIdentifier += (char)ch;
                }
            }

            frame.Parent    = new XBeeAddress16(input.Read(2));
            frame.NodeType  = (NodeType)input.Read();
            frame.Status    = input.Read();
            frame.ProfileId = input.Read(2);
            frame.MfgId     = input.Read(2);

            return(frame);
        }
示例#20
0
        /*
         * Returns error code from response
         * Assumes AT+CMEE=1 (numeric) mode
         */
        public static AtCmeError GetCmeError(AtResponse response)
        {
            if (response.Success)
            {
                return(AtCmeError.CME_SUCCESS);
            }

            if (response.FinalResponse == null || !response.FinalResponse.StartsWith("+CME ERROR:"))
            {
                return(AtCmeError.CME_ERROR_NON_CME);
            }

            if (!AtTokenizer.TokenizeStart(response.FinalResponse, out string tokenizerResponse))
            {
                return(AtCmeError.CME_ERROR_NON_CME);
            }

            if (!AtTokenizer.TokenizeNextInt(tokenizerResponse, out _, out int ret))
            {
                return(AtCmeError.CME_ERROR_NON_CME);
            }

            return((AtCmeError)ret);
        }
示例#21
0
        public static IoSampleResponse ParseIsSample(AtResponse response)
        {
            if (response.Command != (ushort) Common.AtCmd.ForceSample)
                throw new ArgumentException("This is only applicable to the 'IS' AT command");

            var input = new InputStream(response.Value);
            var sample = new IoSampleResponse();
            //sample.ParseIoSample(input);

            return sample;
        }
示例#22
0
 /// <summary>
 ///   TODO: Update Comments
 ///     
 /// </summary>
 /// <param name="response" type="NETMF.OpenSource.XBee.Api.AtResponse">
 ///     <para>
 ///         
 ///     </para>
 /// </param>
 public static void Parse(AtResponse response)
 {
     if (!response.IsOk)
         throw new XBeeException("Failed to save settings");
 }
示例#23
0
 protected int GetDiscoverTimeout(AtResponse response)
 {
     // ms + 1 extra second
     return(UshortUtils.ToUshort(response.Value) * 100 + 1000);
 }