public int SendHttpPost(string host, string path, int port, SPWF04SxConnectionSecurityType connectionSecurity) { if (this.activeHttpCommand != null) { throw new InvalidOperationException(); } this.activeHttpCommand = this.GetCommand() .AddParameter(host) .AddParameter(path) .AddParameter(port.ToString()) .AddParameter(connectionSecurity == SPWF04SxConnectionSecurityType.None ? "0" : "2") .AddParameter(null) .AddParameter(null) .AddParameter(null) .AddParameter(null) .Finalize(SPWF04SxCommandIds.HTTPPOST); this.EnqueueCommand(this.activeHttpCommand); var result = this.activeHttpCommand.ReadString(); if (connectionSecurity == SPWF04SxConnectionSecurityType.Tls && result == string.Empty) { result = this.activeHttpCommand.ReadString(); if (result.IndexOf("Loading:") == 0) { result = this.activeHttpCommand.ReadString(); } } return(result.Split(':') is var parts && parts[0] == "Http Server Status Code" ? int.Parse(parts[1]) : throw new Exception($"Request failed: {result}")); }
protected void EnqueueCommand(SPWF04SxCommand cmd) { lock (this.pendingCommands) { this.pendingCommands.Enqueue(cmd); this.ReadyNextCommand(); } }
private void ReadyNextCommand() { lock (this.pendingCommands) { if (this.pendingCommands.Count != 0) { var cmd = (SPWF04SxCommand)this.pendingCommands.Dequeue(); cmd.SetPayloadBuffer(this.readPayloadBuffer); this.activeCommand = cmd; } else { this.activeCommand = null; } } }
protected void FinishCommand(SPWF04SxCommand cmd) { if (this.activeCommand != cmd) { throw new ArgumentException(); } lock (this.pendingCommands) { cmd.Reset(); this.commandPool.Release(cmd); this.ReadyNextCommand(); } }
public int ReadHttpResponse(byte[] buffer, int offset, int count) { if (this.activeHttpCommand == null) { throw new InvalidOperationException(); } var len = this.activeHttpCommand.ReadBuffer(buffer, offset, count); if (len == 0) { this.FinishCommand(this.activeHttpCommand); this.activeHttpCommand = null; } return(len); }
public void TurnOff() { if (!this.running) { return; } this.reset.SetDriveMode(GpioPinDriveMode.Output); this.reset.Write(GpioPinValue.Low); this.running = false; this.worker.Join(); this.worker = null; this.pendingCommands.Clear(); this.readPayloadBuffer.Reset(); this.netifSockets.Clear(); this.nextSocketId = 0; this.activeCommand = null; this.activeHttpCommand = null; this.commandPool.ResetAll(); }