/// <summary> /// Called when a response is received against a sent request /// </summary> /// <param name="coapResp">The CoAPResponse object</param> private void OnCoAPSessionResponseReceived(CoAPResponse coapResp) { __TimedOut = false; string tokenRx = "";// (coapResp.Token != null && coapResp.Token.Value != null) ? AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value) : ""; if (coapResp != null) { if (coapResp.Token != null) { tokenRx = AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value); } } try { FileLogger.Write("Received response from server - token = " + tokenRx); FileLogger.Write(coapResp.ToString()); } catch { } if (tokenRx == __Token) { int classCode = ((coapResp.Code.Value & 0xE0) >> 5); if (classCode == 2) { __SessionRequestSucceeded = true; FileLogger.Write("Session request completed successfully"); } else { FileLogger.Write("Session call code " + coapResp.Code.Value.ToString()); //Will come here if an error occurred.. } __Done.Set(); } }
/// <summary> /// Called when a response is received against a sent request /// </summary> /// <param name="coapResp">The CoAPResponse object</param> private void OnCoAPResponseReceived(CoAPResponse coapResp) { string tokenRx = "";// (coapResp.Token != null && coapResp.Token.Value != null) ? AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value) : ""; if (coapResp != null) { if (coapResp.Token != null) { tokenRx = AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value); } } try { FileLogger.Write("Received response from server - token = " + tokenRx); FileLogger.Write(coapResp.ToString()); } catch { } if (tokenRx == __Token) { if (BreakIfError(coapResp.Code.Value)) { return; } if (coapResp.Code.Value == CoAPMessageCode.CHANGED) { __Response = coapResp; __Done.Set(); } else { // Will come here if an error occurred. // For now, let the request time out. } } }
/// <summary> /// Called when a response is received against a sent request /// </summary> /// <param name="coapResp">The CoAPResponse object</param> private void OnCoAPResponseReceived(CoAPResponse coapResp) { string tokenRx = (coapResp.Token != null && coapResp.Token.Value != null) ? AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value) : ""; FileLogger.Write("Received response from server - token = " + tokenRx); FileLogger.Write(coapResp.ToString()); if (tokenRx == __Token) { if (BreakIfError(coapResp.Code.Value)) { return; } if (coapResp.Code.Value == CoAPMessageCode.CONTENT) { ArrayList options = coapResp.Options.GetOptions((ushort)CoAPHeaderOption.CONTENT_FORMAT); if (options.Count > 0) { CoAPContentFormatOption ccformat = new CoAPContentFormatOption(); bool proceed = false; foreach (CoAPHeaderOption o in options) { ccformat = new CoAPContentFormatOption(AbstractByteUtils.ToUInt16(o.Value)); if (ccformat.IsValid()) { proceed = true; break; } } if (proceed) { if (ccformat.Value == CoAPContentFormatOption.TEXT_PLAIN) { string result = AbstractByteUtils.ByteToStringUTF8(coapResp.Payload.Value); __PingResult = result; } if (ccformat.Value == CoAPContentFormatOption.APPLICATION_OCTET_STREAM) { string result = HdkUtils.BytesToHexView(coapResp.Payload.Value); __PingResult = result; } if (ccformat.Value == CoAPContentFormatOption.APPLICATION_JSON) { string result = HdkUtils.BytesToHexView(coapResp.Payload.Value); __PingResult = result; } __Response = coapResp; __Done.Set(); } } } else { //Will come here if an error occurred.. } } }
/// <summary> /// Process GET responses related to observe. /// </summary> /// <param name="coapResp">the CoAPResponse object that we are going to report</param> private void HandleObserveResponse(CoAPResponse coapResp) { string toAdd = ""; try { toAdd = coapResp.ToString(); // Setting the text in a method that may have to be Invoked. SetText(txtResult, txtResult.Text + toAdd); } catch (Exception oops) { FileLogger.Write(oops.Message); FileLogger.Write(oops.StackTrace); } }
/// <summary> /// Called when a response is received against a sent request /// </summary> /// <param name="coapResp">The CoAPResponse object</param> private void OnCoAPResponseReceived(CoAPResponse coapResp) { string tokenRx = (coapResp.Token != null && coapResp.Token.Value != null) ? AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value) : ""; FileLogger.Write("Received response from server - token = " + tokenRx); FileLogger.Write(coapResp.ToString()); __Response = coapResp; if (tokenRx == __Token) { if (BreakIfError(coapResp.Code.Value)) { return; } if (coapResp.Code.Value == CoAPMessageCode.DELETED) { __Done.Set(); } else { //Will come here if an error occurred.. } } }
/// <summary> /// Called when a response is received against a sent request /// </summary> /// <param name="coapResp">The CoAPResponse object</param> private void OnCoAPDiscoveryResponseReceived(CoAPResponse coapResp) { __TimedOut = false; string tokenRx = "";// (coapResp.Token != null && coapResp.Token.Value != null) ? AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value) : ""; if (coapResp != null) { if (coapResp.Token != null) { tokenRx = AbstractByteUtils.ByteToStringUTF8(coapResp.Token.Value); } } try { FileLogger.Write("Received response from server - token = " + tokenRx); FileLogger.Write(coapResp.ToString()); } catch { } if (tokenRx == __Token) { if (BreakIfError(coapResp.Code.Value)) { this.ErrorResult = coapResp.Code.ToString(); return; } if (coapResp.Code.Value == CoAPMessageCode.CONTENT) { // Looks like we have the expected response. // Check the content format and figure out how to store the response. ArrayList options = coapResp.Options.GetOptions((ushort)CoAPHeaderOption.CONTENT_FORMAT); if (options.Count > 0) { CoAPContentFormatOption ccformat = new CoAPContentFormatOption(); bool proceed = false; foreach (CoAPHeaderOption o in options) { ccformat = new CoAPContentFormatOption(AbstractByteUtils.ToUInt16(o.Value)); if (ccformat.IsValid()) { proceed = true; break; } } // The header options match what we expected. // Set the discovery result. if (proceed) { if (ccformat.Value == CoAPContentFormatOption.APPLICATION_LINK_FORMAT) { string discovery = AbstractByteUtils.ByteToStringUTF8(coapResp.Payload.Value); __DiscoveryResult = discovery; } __Response = coapResp; __Done.Set(); } } } else { //Will come here if an error occurred.. } } }