public void AutomatinisSOS() { msg.AlarmState = false; msg.Locked = null; msg.vidausTemp = null; msg.CarNmb = null; msg.ComputerMsg = null; msg.EngineState = false; msg.degalai = null; msg.vidausTemp = null; msg.Isclient = true; msg.IsLogin = null; msg.LightState = null; msg.OpenWindows = null; msg.laukoTemp = null; msg.Password = null; msg.Username = userName.Text; if (SOSCallOptions.BackColor == Color.Green) { msg.SOSSkambutis = true; } else { msg.SOSSkambutis = false; } var message = new ScsRawDataMessage(Serial.ObjectToByteArray(msg)); client.SendMessage(message); }
private void Updator() { float temp; msg.IsLogin = false; msg.degalai = float.TryParse(degalaiAmount.Text, out temp) ? temp : (float?)null; msg.laukoTemp = float.TryParse(laukoTemp.Text, out temp) ? temp : (float?)null; msg.vidausTemp = float.TryParse(vidausTemp.Text, out temp) ? temp : (float?)null; msg.variklioTemp = float.TryParse(variklioTemp.Text, out temp) ? temp : (float?)null; msg.krituliuKiekis = krituliuKiekis.Text; msg.rida = float.TryParse(rida.Text, out temp) ? temp : (float?)null; msg.vidGreitis = float.TryParse(vidutinisGreitis.Text, out temp) ? temp : (float?)null; msg.degaluSanaudos = float.TryParse(degaluSanaudos.Text, out temp) ? temp : (float?)null; msg.momentinisGreitis = float.TryParse(momentinisGreitis.Text, out temp) ? temp : (float?)null; msg.AlarmState = alarm; msg.Locked = (locked.Checked) ? true : false; msg.OpenWindows = (windowsOpened.Checked) ? true : false; msg.LightState = (lightsOn.Checked) ? true : false; msg.EngineState = (engineOn.Checked) ? true : false; var message = new ScsRawDataMessage(Serial.ObjectToByteArray(msg)); client.SendMessage(message); }
public bool MonitorSystemSelfCal() { List <string> aaa = new List <string>(); byte[] sendByte = new byte[16]; sendByte[0] = 85; sendByte[1] = 170; sendByte[2] = 16; sendByte[3] = 5; sendByte[4] = 1; byte[] dd = Getbytes(sendByte); sendByte[14] = dd[1]; sendByte[15] = dd[0]; byte[] readByte = new byte[16]; var text = new ScsRawDataMessage(sendByte, "sp_checkself"); if (Client.CommunicationState == CommunicationStates.Connected) { Client.SendMessage(text); } else { _eventAggregator.GetEvent <InfoEventArgs>().Publish("射频TCP网络连接异常!\n"); } return(true); }
public void Send(string packet) { if (!IsDisposing) { ScsRawDataMessage rawMessage = new ScsRawDataMessage(_encryptor.Encrypt(packet)); SendMessage(rawMessage); } }
public void SendPacket(string packet, byte priority = 10) { if (!IsDisposing && packet != null && packet != string.Empty) { ScsRawDataMessage rawMessage = new ScsRawDataMessage(_encryptor.Encrypt(packet)); SendMessage(rawMessage, priority); } }
public void SendPacket(string packet) { if (!IsDisposing) { ScsRawDataMessage rawMessage = new ScsRawDataMessage(_encryptor.Encrypt(packet)); //Logger.Debug(packet, -1); SendMessage(rawMessage); } }
public void SendPacket(string packet, byte priority = 10) { if (IsDisposing || string.IsNullOrEmpty(packet)) { return; } var rawMessage = new ScsRawDataMessage(_encryptor.Encrypt(packet)); SendMessage(rawMessage, priority); }
/// <summary> /// Build message from a byte array received from remote application /// </summary> /// <param name="receivedBytes">Received bytes from remote application</param> /// <returns></returns> public IEnumerable <IScsMessage> CreateMessages(byte[] receivedBytes) { receiveMemoryStream.Write(receivedBytes, 0, receivedBytes.Length); var messageList = new List <IScsMessage>(); var msg = new ScsRawDataMessage(receivedBytes); messageList.Add(msg); return(messageList); }
public bool SendPacket(string packet) { try { ScsRawDataMessage rawMessage = new ScsRawDataMessage(_encryptor.Encrypt(packet)); SendMessage(rawMessage); return(true); } catch (Exception e) { Logger.Log.ErrorFormat(Language.Instance.GetMessageFromKey("PACKET_FAILURE"), packet, ClientId, e.Message); return(false); } }
/// <summary> /// This will be triggered when the underlying NetworkClient receives a packet. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnNetworkClientMessageReceived(object sender, MessageEventArgs e) { ScsRawDataMessage message = e.Message as ScsRawDataMessage; if (message == null) { return; } if (message.MessageData.Any() && message.MessageData.Length > 2) { _receiveQueue.Enqueue(message.MessageData); } lastPacketReceive = e.ReceivedTimestamp.Ticks; }
/// <summary> /// 标校控制 /// </summary> /// <param name="isAnswer"></param> /// <param name="IsSingleSignal"></param> /// <param name="outputFreq"></param> /// <param name="ATTValue"></param> /// <returns></returns> public bool SetCalibration(bool isAnswer, bool IsSingleSignal, double outputFreq, double ATTValue) { byte[] sendByte = new byte[16]; sendByte[0] = 85; sendByte[1] = 170; sendByte[2] = 16; sendByte[3] = 3; if (isAnswer) { sendByte[4] = 1; } if (!IsSingleSignal) { sendByte[5] = 1; } else { sendByte[5] = 0; } outputFreq = (outputFreq - 30.0) * 0.1 + 1.0; byte[] ads = BitConverter.GetBytes((int)outputFreq); sendByte[6] = ads[1]; sendByte[7] = ads[0]; // sendByte[8] = (byte)(ATTValue - 1.0); sendByte[8] = (byte)ATTValue; byte[] dd = this.Getbytes(sendByte); sendByte[14] = dd[1]; sendByte[15] = dd[0]; byte[] readByte = new byte[16]; if (Client.CommunicationState == TcpSocket.Scs.Communication.CommunicationStates.Connected) { var text = new ScsRawDataMessage(sendByte); Client.SendMessage(text); } else { MessageBox.Show("设备已断开连接!"); } bool result = true; return(result); }
public bool CtrlFreq(bool isAnswer, double freq) { try { byte[] sendByte = new byte[16]; sendByte[0] = 85; sendByte[1] = 170; sendByte[2] = 16; sendByte[3] = 2; sendByte[4] = 0; if (isAnswer) { sendByte[4] = 1; } freq = (freq - 30.0) * 100.0 + 1.0; byte[] freqByte = BitConverter.GetBytes((int)freq); for (int i = 0; i < 4; i++) { sendByte[5 + i] = freqByte[3 - i]; } byte[] dd = this.Getbytes(sendByte); sendByte[14] = dd[1]; sendByte[15] = dd[0]; byte[] readByte = new byte[16]; if (Client.CommunicationState == TcpSocket.Scs.Communication.CommunicationStates.Connected) { var text = new ScsRawDataMessage(sendByte); Client.SendMessage(text); } else { MessageBox.Show("设备已断开连接!"); } return(true); } catch { _eventAggregator.GetEvent <InfoEventArgs>().Publish("指令下发出现异常!\n"); } return(true); }
/// <summary> /// 通道控制 /// </summary> /// <param name="channel"></param> /// <param name="isAnswer"></param> /// <param name="IsCalibrationSignal"></param> /// <param name="IFBWNumber"></param> /// <param name="GainRF"></param> /// <param name="GainIF1"></param> /// <param name="GainIF2"></param> /// <returns></returns> public bool SetChannelIFBWgain(int channel, bool isAnswer, int IsCalibrationSignal, int IFBWNumber, double GainRF, double GainIF1, double GainIF2) { byte[] sendByte = new byte[16]; sendByte[0] = 85; sendByte[1] = 170; sendByte[2] = 16; sendByte[3] = 1; if (isAnswer) { sendByte[4] = 1; } sendByte[5] = (byte)channel; int bitynumber = IsCalibrationSignal; if (IFBWNumber == 1) { bitynumber += 2; } sendByte[6] = (byte)bitynumber; sendByte[7] = (byte)GainRF; sendByte[8] = (byte)GainIF1; sendByte[9] = (byte)GainIF2; byte[] dd = this.Getbytes(sendByte); sendByte[14] = dd[1]; sendByte[15] = dd[0]; byte[] readByte = new byte[16]; int count = 0; var text = new ScsRawDataMessage(sendByte); if (Client.CommunicationState == TcpSocket.Scs.Communication.CommunicationStates.Connected) { Client.SendMessage(text); } else { MessageBox.Show("射频TCP网络连接已断开!"); } return(true); }
private void logIn_Click(object sender, EventArgs e) { logIn.Enabled = false; msg.Isclient = false; msg.IsLogin = true; msg.CarNmb = carNmb.Text; float temp; msg.degalai = float.TryParse(degalaiAmount.Text, out temp) ? temp : (float?)null; msg.laukoTemp = float.TryParse(laukoTemp.Text, out temp) ? temp : (float?)null; msg.vidausTemp = float.TryParse(vidausTemp.Text, out temp) ? temp : (float?)null; msg.AlarmState = alarm; msg.Locked = (locked.Checked) ? true : false; msg.OpenWindows = (windowsOpened.Checked) ? true : false; msg.LightState = (lightsOn.Checked) ? true : false; msg.EngineState = (engineOn.Checked) ? true : false; Task.Factory.StartNew(() => { try { client.Connect(); var message = new ScsRawDataMessage(Serial.ObjectToByteArray(msg)); client.SendMessage(message); while (true) { Updator(); Thread.Sleep(5000); } } catch { logIn.Enabled = true; panel5.Visible = true; MessageBox.Show("Serveris nepasiekiamas!"); } }); }
public void OnSendData(byte length, byte mark, byte data) { var modeByte = new List <byte>(); modeByte.Add(0x7e); //帧头 modeByte.Add(length); //帧长度 modeByte.Add(mark); //帧标识 modeByte.Add(data); //数据 //和校验 var andValue = (byte)(length + mark + data); modeByte.Add(andValue); modeByte.Add(0xf5);//帧尾 var t1 = string.Join("", modeByte); var t2 = CommonHelper.ByteToString(modeByte.ToArray()); var text = new ScsRawDataMessage(modeByte.ToArray(), "k1"); if (Client.CommunicationState == TcpSocket.Scs.Communication.CommunicationStates.Connected) { Client.SendMessage(text); } }
private void windowsClosed_CheckedChanged(object sender, EventArgs e) { msg.SOSSkambutis = null; msg.AlarmState = null; msg.Locked = null; msg.vidausTemp = null; msg.CarNmb = null; msg.ComputerMsg = null; msg.EngineState = null; msg.degalai = null; msg.vidausTemp = null; msg.Isclient = true; msg.IsLogin = null; msg.LightState = null; msg.OpenWindows = (windowsClosed.Checked) ? false : true; msg.laukoTemp = null; msg.Password = null; msg.Username = userName.Text; var message = new ScsRawDataMessage(Serial.ObjectToByteArray(msg)); client.SendMessage(message); }
private void AlarmOff() { msg.SOSSkambutis = null; msg.AlarmState = false; msg.Locked = null; msg.vidausTemp = null; msg.CarNmb = null; msg.ComputerMsg = null; msg.EngineState = (engineOn.Checked) ? true : false; msg.degalai = null; msg.vidausTemp = null; msg.Isclient = true; msg.IsLogin = null; msg.LightState = null; msg.OpenWindows = null; msg.laukoTemp = null; msg.Password = null; msg.Username = userName.Text; var message = new ScsRawDataMessage(Serial.ObjectToByteArray(msg)); client.SendMessage(message); }
private void logIn_Click(object sender, EventArgs e) { logIn.Enabled = false; msg.Isclient = true; msg.IsLogin = true; msg.Username = userName.Text; msg.Password = password.Text; Task.Factory.StartNew(() => { try { client.Connect(); var message = new ScsRawDataMessage(Serial.ObjectToByteArray(msg)); client.SendMessage(message); } catch { logIn.Enabled = true; MessageBox.Show("Serveris nepasiekiamas!"); } }); }
private static void Client_MessageReceived(object sender, MessageEventArgs e) { // Pass received data to the parser IScsServerClient client = sender as IScsServerClient; ScsRawDataMessage message = e.Message as ScsRawDataMessage; if (client != null && message != null && message.MessageData != null) { ClientInfo info = infos[client.ClientId]; if (info != null) { try { info.parser.AppendBytes(message.MessageData); } catch (Exception ex) { // Catch parsing error in order not to close connection to client Console.WriteLine(ex.ToString()); Console.WriteLine(string.Format("Received message: {0}", RFPPFHelper.ByteArrayToHexString(message.MessageData))); } } } }
protected override IScsMessage DeserializeMessage(byte[] bytes) { IScsMessage retMsg = null; string msgId = null; byte [] bytMsgId = new byte [ConstData.tokenStringLength]; Buffer.BlockCopy(bytes, 1, bytMsgId, 0, ConstData.tokenStringLength); msgId = Encoding.ASCII.GetString(bytMsgId); if (msgId.Equals(ConstData.emptyGuidString)) { msgId = null; } string replyMsgId = null; byte [] bytReplyMsgId = new byte [ConstData.tokenStringLength]; Buffer.BlockCopy(bytes, 1 + ConstData.tokenStringLength, bytReplyMsgId, 0, ConstData.tokenStringLength); replyMsgId = Encoding.ASCII.GetString(bytReplyMsgId); if (replyMsgId.Equals(ConstData.emptyGuidString)) { replyMsgId = null; } byte msgTypeCodec = bytes[0]; switch ((int)msgTypeCodec) { case ((int)MsgType.ScsRaw_Msg): { if (0 < bytes.Length - (1 + ConstData.tokenStringLength * 2)) { byte[] content = new byte[bytes.Length - (1 + ConstData.tokenStringLength * 2)]; Buffer.BlockCopy(bytes, 1 + ConstData.tokenStringLength * 2, content, 0, content.Length); retMsg = new ScsRawDataMessage(content); } else { retMsg = new ScsRawDataMessage(); } ((ScsRawDataMessage)retMsg).MessageId = msgId; ((ScsRawDataMessage)retMsg).RepliedMessageId = replyMsgId; break; } case ((int)MsgType.ScsText_Msg): { if (0 < bytes.Length - (1 + ConstData.tokenStringLength * 2)) { byte[] bytContent = new byte[bytes.Length - (1 + ConstData.tokenStringLength * 2)]; Buffer.BlockCopy(bytes, 1 + ConstData.tokenStringLength * 2, bytContent, 0, bytContent.Length); string content = Encoding.UTF8.GetString(bytContent); retMsg = new ScsTextMessage(content); } else { retMsg = new ScsTextMessage(); } ((ScsTextMessage)retMsg).MessageId = msgId; ((ScsTextMessage)retMsg).RepliedMessageId = replyMsgId; break; } case ((int)MsgType.ScsPing_Msg): { // N / A retMsg = new ScsPingMessage(); ((ScsPingMessage)retMsg).MessageId = msgId; ((ScsPingMessage)retMsg).RepliedMessageId = replyMsgId; break; } default: { throw new NotImplementedException(); } } return(retMsg); }