public void Putfile(string filename, string realName) { FileStream fs; m_filename = filename; m_realname = realName; m_fileContent = ""; m_resend_times = 0; using (fs = File.OpenRead(m_filename)) { byte[] b = new byte[fs.Length]; byte[] tmp = new byte[fs.Length << 1]; byte bt; if (fs.Read(b, 0, (int)fs.Length) == fs.Length) { for (UInt32 i = 0; i < b.Length; i++) { bt = (byte)((b[i] >> 4) & 0xF); tmp[i << 1] = (byte)((bt >= 10) ? (bt - 10) + (byte)'A' : bt + (byte)'0'); bt = (byte)(b[i] & 0xF); tmp[(i << 1) + 1] = (byte)((bt >= 10) ? (bt - 10) + (byte)'A' : bt + (byte)'0'); //m_fileContent += b[i].ToString("X2"); } UTF8Encoding temp = new UTF8Encoding(true); m_fileContent = temp.GetString(tmp); m_fileLen = (int)fs.Length; m_fReceived = response_putfile_id; m_fSend("AT+FPUT,NAME=" + realName + ",LEN=" + ((int)b.Length) + FRAME_ENDMARK_ENTER); } } TimerOnStart(); }
public Node(string localPipeName, string remotePipeName, string remoteHostname, ReceivedCallback callback) { lPipeName = localPipeName; rPipeName = remotePipeName; rServer = remoteHostname; this.callback = callback; }
bool response_putfile_id(string buf) { //AT+OK,ID=; char[] charSeparators = new char[] { ',', '=', ';' }; string[] item = buf.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); TimerOnStart(); if (buf.IndexOf(ATC_FAIL) < 0 && item.Length >= 3) { m_fileID = item[2]; m_resend_times = 0; m_fReceived = response_putfile_content; m_fileOffset = 0; m_fileBlockLen = (m_fileContent.Length > m_putBlockMax) ? m_putBlockMax : m_fileContent.Length; m_fSend("AT+FWR,ID=" + m_fileID + ",OFF=0,LEN=" + m_fileBlockLen + "," + m_fileContent.Substring(m_fileOffset, m_fileBlockLen) + FRAME_ENDMARK_ENTER); return(true); } if (m_resend_times++ < 10) { int resend_times = m_resend_times; Putfile(m_filename, m_realname); m_resend_times = resend_times; } else { if (ReceivedEventHandle != null) { //int[] number = new int[3]{0, 0,2}; //ReceivedEventHandle(number); TimerOnStop(); ReceivedEventHandle(new atResult(ATResultType.Failure)); } } return(false); }
public void Getfile(string filename, string realName) { m_filename = filename; m_realname = realName; m_fReceived = response_getfile_id; m_resend_times = 0; m_fSend("AT+FGET,NAME=" + realName + FRAME_ENDMARK_ENTER); TimerOnStart(); }
private void OnMessageReceived(MqttApplicationMessageReceivedEventArgs args) { var topic = args.ApplicationMessage.Topic; var body = Encoding.UTF8.GetString(args.ApplicationMessage.Payload ?? new byte [0]); Message?.Invoke("[MQTT client] received message. " + $"client = {args.ClientId} path = {topic} payload = {body}"); ReceivedCallback?.Invoke(topic, body); }
public void SendReadDb(string addr, bool loop) { m_fReceived = reponse_readDb_content; if (loop) { m_fSend("AT+RDB,ADDR=" + addr + ",LOOP" + FRAME_ENDMARK_ENTER); } else { m_fSend("AT+RDB,ADDR=" + addr + FRAME_ENDMARK_ENTER); } }
private void WaitForConnectionCallBack(IAsyncResult iar) { try { pipeServer = (NamedPipeServerStream)iar.AsyncState; pipeServer.EndWaitForConnection(iar); byte[] buffer = new byte[6]; pipeServer.Read(buffer, 0, 6); byte type = buffer[2]; if (buffer[3] == (byte)(buffer[2] + ((buffer[0] ^ buffer[1])))) { PipeMessage message = new PipeMessage(); int size = (buffer[0] << 8 | buffer[1]); buffer = new byte[size]; pipeServer.Read(buffer, 0, size); message.SetPayload(typeof(byte[]), buffer); if (type == 1) { message.ConvertToString(); } if (type == 2) { message.ConvertToBytes(); } ReceivedCallback.Invoke(message); } pipeServer.Close(); pipeServer = null; pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); pipeServer.BeginWaitForConnection( new AsyncCallback(WaitForConnectionCallBack), pipeServer); } catch { return; } }
bool response_getfile_content(string buf) { //AT+OK,LEN=,file content; char[] charSeparators = new char[] { ',', '=', ';' }; string[] item = buf.Split(charSeparators, StringSplitOptions.RemoveEmptyEntries); TimerOnStart(); if (buf.IndexOf(ATC_FAIL) < 0 && item.Length >= 3) { int len = int.Parse(item[2]); m_resend_times = 0; if (len != 0 && len == item[3].Length) { m_fileOffset += (len / 2); m_fileContent += item[3]; if (ReceivedEventHandle != null) { //int[] number = new int[3]{m_fileOffset, m_fileLen,0}; //ReceivedEventHandle(number); ReceivedEventHandle(new atResult(m_fileOffset, m_fileLen)); } m_fSend("AT+FRD,ID=" + m_fileID + ",OFF=" + m_fileOffset + FRAME_ENDMARK_ENTER); return(true); } else if (len == 0) { //save file byte[] b = new byte[m_fileContent.Length / 2]; byte[] tmp = System.Text.Encoding.ASCII.GetBytes(m_fileContent); byte bt_low; byte bt_hight; for (int i = 0; i < b.Length; i++) { bt_hight = (byte)((tmp[i << 1] >= (byte)'A') ? (tmp[i << 1] - 'A' + 10) : (tmp[i << 1] - (byte)'0')); bt_low = (byte)((tmp[(i << 1) + 1] >= (byte)'A') ? (tmp[(i << 1) + 1] - 'A' + 10) : (tmp[(i << 1) + 1] - (byte)'0')); b[i] = (byte)((bt_hight << 4) | bt_low); } File.WriteAllBytes(m_filename, b); m_fReceived = null; m_fileContent = ""; m_fileID = ""; if (ReceivedEventHandle != null) { Thread.Sleep(50); //int[] number = new int[3]{m_fileOffset, m_fileLen,1}; //ReceivedEventHandle(number); TimerOnStop(); ReceivedEventHandle(new atResult(ATResultType.Success)); } return(true); } } if (m_resend_times++ < 10) { m_fSend("AT+FRD,ID=" + m_fileID + ",OFF=" + m_fileOffset + FRAME_ENDMARK_ENTER); } else { if (ReceivedEventHandle != null) { //int[] number = new int[3]{0, 0,2}; //ReceivedEventHandle(number); TimerOnStop(); ReceivedEventHandle(new atResult(ATResultType.Failure)); } } return(false); }
public void SendUpdateMbCfg() { m_fReceived = null; m_fSend("AT+UPDATE_MBCFG" + FRAME_ENDMARK_ENTER); }
public void SendLog(string port, string type) { m_fReceived = reponse_log_content; m_fSend("AT+LOG," + port + ",TYPE=" + type + FRAME_ENDMARK_ENTER); }
public UDPServer(IPAddress address, uint port, ReceivedCallback callback) : base(address, (int)port) { Callback = callback; }
public void SendOK() { m_fReceived = null; m_fSend("AT+OK" + FRAME_ENDMARK_ENTER); }
public void SendFail() { m_fReceived = null; m_fSend("AT+FAIL" + FRAME_ENDMARK_ENTER); }
public void SendReboot(string target) { m_fReceived = null; m_fSend("AT+REBOOT,TARGET=" + target + FRAME_ENDMARK_ENTER); }
public void SendExit() { m_fReceived = response_message; m_fSend("AT+EXIT" + FRAME_ENDMARK_ENTER); }
public void SendLog(string port) { m_fReceived = reponse_log_content; m_fSend("AT+LOG," + port + FRAME_ENDMARK_ENTER); }
public void SendTelnet() { m_fReceived = null; m_fSend("AT+TELNET" + FRAME_ENDMARK_ENTER); }
public void SendLogc() { m_fReceived = response_message; m_fSend("AT+LOGC" + FRAME_ENDMARK_ENTER); }