public void ParseCommand(PacketCommand command, SerialDataChannel channel) { if (command.PacketID == PhysLoggerPacketCommandID.GetHWSignatures) { var parts = command.PayLoadString.Split(new char[] { '=' }); if (parts[0] == "ver") { if (parts[1] == PhysLoggerHWSignature.PhysLogger1_0.ToString()) { HWProps = new PhysLogger1_0HWProperties(); HWProps.OnNewGainValues += HWProps_OnNewGainValues; new PacketCommand(PhysLoggerPacketCommandID.BeginFire, new byte[] { 1 }).SendCommand(channel); } else { return; } OnSignatureUpdate(this, new EventArgs()); } else { if (HWProps != null) { if (HWProps.UpdateProp(parts)) { OnSignatureUpdate?.Invoke(this, new EventArgs()); } } } } if (HWProps.Signature == PhysLoggerHWSignature.Unknown) { new PacketCommand(PhysLoggerPacketCommandID.GetHWSignatures).SendCommand(channel); return; } if (command.PacketID == PhysLoggerPacketCommandID.DataPacket) { float t = 0; float[] values = null; HWProps.HandleDataPacket(command, ref t, ref values); if (values != null) { NewPointReceived(t, values); } } }
public bool SetChannelType(int index, ChannelType cType, SerialDataChannel channel) { new PacketCommand(PhysLoggerPacketCommandID.ChangeChannelGain, new byte[] { (byte)index, (byte)cType }).SendCommand(channel); return(true); }
public bool ChangeChannelGain(int index, int gain, SerialDataChannel channel) { new PacketCommand(PhysLoggerPacketCommandID.ChangeChannelGain, new byte[] { (byte)index, (byte)gain }).SendCommand(channel); return(true); }
public void ParseCommand(PacketCommandMini command, SerialDataChannel channel) { if (command.PacketID == PhysLoggerPacketCommandID.GetHWSignatures) { PhysLoggerHWSignature newSignature = PhysLoggerHWSignature.Unknown; if (Signature != PhysLoggerHWSignature.Unknown) { OnSignatureUpdate(Signature, newSignature); return; } else { var parts = command.PayLoadString.Split(new char[] { '=' }); if (parts[0] == "ver") { if (parts[1] == PhysLoggerHWSignature.PhysLogger1_0.ToString()) { newSignature = PhysLoggerHWSignature.PhysLogger1_0; new PacketCommandMini(PhysLoggerPacketCommandID.BeginFire, new byte[] { 1 }).SendCommand(channel); } else if (parts[1] == PhysLoggerHWSignature.PhysLogger1_1.ToString()) { newSignature = PhysLoggerHWSignature.PhysLogger1_1; new PacketCommandMini(PhysLoggerPacketCommandID.GetI2CInstruments, new byte[] { 1 }).SendCommand(channel); new PacketCommandMini(PhysLoggerPacketCommandID.BeginFire, new byte[] { 1 }).SendCommand(channel); } else if (parts[1] == PhysLoggerHWSignature.PhysLogger1_2.ToString()) { newSignature = PhysLoggerHWSignature.PhysLogger1_2; new PacketCommandMini(PhysLoggerPacketCommandID.GetI2CInstruments, new byte[] { 1 }).SendCommand(channel); new PacketCommandMini(PhysLoggerPacketCommandID.BeginFire, new byte[] { 1 }).SendCommand(channel); } else { return; } OnSignatureUpdate(Signature, newSignature); return; } } } if (Signature == PhysLoggerHWSignature.Unknown) { new PacketCommandMini(PhysLoggerPacketCommandID.GetHWSignatures).SendCommand(channel); return; } if (command.PacketID == PhysLoggerPacketCommandID.DataPacket) { float t = 0; float[] values = null; PlotLabel[] labels = null; HandleDataPacket(command, ref t, ref values, ref labels); if (values != null) { NewPointReceived(t, values, labels); } } else if (command.PacketID == PhysLoggerPacketCommandID.i2cInstrumentSignature) { AddI2CInstrument(command.PayLoad[0], command.PayLoad[1]); } else if (command.PacketID == PhysLoggerPacketCommandID.ChangeSamplingTime) { var ts = BitConverter.ToUInt32(command.PayLoad, 0); OnSamplingRateChanged.Invoke(1 / (float)ts * 1000); } else { if (command.PacketID == PhysLoggerPacketCommandID.GetValue) { if (command.PayLoad[0] == 0) // get float TBC { messageTBC += Encoding.UTF8.GetString(command.PayLoad, 1, command.PayLoadLength - 1); return; } else if (command.PayLoad[0] == 1) // get float { string m = messageTBC + Encoding.UTF8.GetString(command.PayLoad, 1, command.PayLoadLength - 1); float v = 0; try { v = GetValueFromUser(m); } catch { return; } var com = new PacketCommandMini(PhysLoggerPacketCommandID.GetValue); com.PayLoad = Encoding.UTF8.GetBytes(v.ToString()); CommandSendRequest(com); messageTBC = ""; return; } else if (command.PayLoad[0] == 2) // get Console Key { if (!LConsole.IsActive) { try { LConsole.Show(); } catch { LConsole = new Forms.PhysLoggerUpdaterConsole(); LConsole.Show(); } } LConsole.WriteLine(Encoding.UTF8.GetString(command.PayLoad, 1, command.PayLoadLength - 1)); string s = LConsole.ReadKey(); var com = new PacketCommandMini(PhysLoggerPacketCommandID.GetValue); com.PayLoad = Encoding.UTF8.GetBytes(s); if (s == "") { com.PayLoad = new byte[] { 0 } } ; CommandSendRequest(com); return; } else { HandleMiscCommand(command); } } if (command.PacketID == PhysLoggerPacketCommandID.SetValue) { if (command.PayLoad[0] == 1) { HandleIncomingUserMessage(messageTBC + Encoding.UTF8.GetString(command.PayLoad, 1, command.PayLoadLength - 1), false); messageTBC = ""; } else if (command.PayLoad[0] == 2) // force console print { HandleIncomingUserMessage(messageTBC + Encoding.UTF8.GetString(command.PayLoad, 1, command.PayLoadLength - 1), true); messageTBC = ""; } else if (command.PayLoad[0] == 3) // force console println { HandleIncomingUserMessage(messageTBC + Encoding.UTF8.GetString(command.PayLoad, 1, command.PayLoadLength - 1) + "\r\n", true); messageTBC = ""; } else if (command.PayLoad[0] == 4) // ConsolMessageTBC { messageTBC += Encoding.UTF8.GetString(command.PayLoad, 1, command.PayLoadLength - 1); return; } else if (command.PayLoad[0] == 5) // console may exit { if (LConsole.IsActive) { LConsole.SafeExit(); } return; } else if (command.PayLoad[0] == 6) // Disconnect Request { RequestDisconnect(); return; } else { HandleMiscCommand(command); } } HandleMiscCommand(command); } }