/// <summary> /// We Parse and trigger the events here /// </summary> /// <param name="Packet">The packet</param> protected override void parseData(CFAPacket Packet) { switch (Packet.Command) { //Response to Ping Command case 0x40: break; //Return from Read 8 Bytes of Data case 0x4A: break; //Fan Report case 0x81: break; //Temp Report case 0x82: break; //Reporting and Status case 0x1E: break; default: //Nothing :( break; } //end switch base.parseData(Packet); }
protected override void parseData(CFAPacket Packet) { base.parseData(Packet); }
private void processIncomingQueue() { bool checkAgain = false; lock (_incomingQueueLock) { if (_incomingBytes.Count < 4) { return; } byte command = _incomingBytes.Peek(); int maskedCommand = command & 0x3F; if (maskedCommand < 0 || maskedCommand > 35) { // Invalid packet _incomingBytes.Dequeue(); checkAgain = true; } else { byte packetLength = _incomingBytes.ElementAt(1); int totalLength = packetLength + 4; if (packetLength > 22) { // Invalid packet _incomingBytes.Dequeue(); checkAgain = true; } else if (_incomingBytes.Count >= totalLength) { // We have enough data for a full packet // Let's process it now. //Create a new packet CFAPacket _Packet = new CFAPacket() { Command = command, DataLength = packetLength, Data = new byte[packetLength] }; //Read in all data packets for (int i = 0; i < _Packet.DataLength; i++) { _Packet.Data[i] = _incomingBytes.ElementAt(i + 2); } //Read the CRC byte[] _crcByte = new byte[2]; _crcByte[0] = _incomingBytes.ElementAt(totalLength - 2); _crcByte[1] = _incomingBytes.ElementAt(totalLength - 1); _Packet.CRC = BitConverter.ToUInt16(_crcByte, 0); List <byte> _tempBytes = new byte[] { command, packetLength }.Concat(_Packet.Data).ToList(); CRC.CalculateCRC(ref _tempBytes); if (_crcByte[0] == _tempBytes.ElementAt(_tempBytes.Count - 2) && _crcByte[1] == _tempBytes.Last()) { for (int i = 0; i < totalLength; i++) { _incomingBytes.Dequeue(); } this.parseData(_Packet); } else { _incomingBytes.Dequeue(); } // Check for additional packets checkAgain = true; } } } if (checkAgain) { processIncomingQueue(); } }
public CFAPacketEventArgs(CFAPacket Packet) { this.Packet = Packet; }
/// <summary> /// These will trigger event that are common in all 3 CFA usb lcds /// </summary> /// <param name="Packet">That Packet</param> protected virtual void parseData(CFAPacket Packet) { if (PacketRecived != null) { PacketRecived(this, Packet); } switch (Packet.Command) { //Ping Command Return case 0x40: break; //Hardware Firmware Version return case 0x41: if (HardwareFirmwareVersion != null) { this.HardwareFirmwareVersion(this, new CFAHardwareFirmwareEventArgs(ASCIIEncoding.ASCII.GetString(Packet.Data))); } break; //Write User Flash Area case 0x42: break; //Read user Flash Area case 0x43: if (ReadUserFlash != null) { this.ReadUserFlash(this, new CFAReadUserFlashEventArgs(Packet.Data)); } break; //Response from Store Current State case 0x44: break; //Response from Reboot CFA,Reset host, Power Off host case 0x45: break; //Response from Clear LCDd case 0x46: break; //Return from set special charater data case 0x49: break; //Response from Read 8 bytes of lcd memeroy data case 0x4A: if (ReadData != null) { int _address = Packet.Data[0]; byte[] _data = new byte[Packet.DataLength - 1]; Array.Copy(Packet.Data, 1, _data, 0, Packet.DataLength - 1); this.ReadData(this, new CFAReadDataEventArgs(_data, _address)); } break; //Response from Set Cursor Position case 0x4B: break; //Response from Set Cursor Style case 0x4C: break; //Response from Set Cursor Contrast case 0x4D: break; //Response from Set LCD / Keypad Backlight case 0x4E: break; //Response from Send Command directly to lcd controller case 0x56: break; //Response from read reporting and status case 0x5E: if (ReportingAndStatus != null) { CFAReportingAndStatusEventArgs _eventArgs = new CFAReportingAndStatusEventArgs(); _eventArgs.Fans = IntToEnum <Binary>(Packet.Data[0]); _eventArgs.Sensors1_8 = IntToEnum <Binary>(Packet.Data[1]); _eventArgs.Sensors9_15 = IntToEnum <Binary>(Packet.Data[2]); _eventArgs.Sensors16_23 = IntToEnum <Binary>(Packet.Data[3]); _eventArgs.Sensors24_32 = IntToEnum <Binary>(Packet.Data[4]); _eventArgs.KeyPresses = Packet.Data[5]; _eventArgs.KeyReleases = Packet.Data[6]; _eventArgs.ATXPowerSwitch = IntToEnum <Binary>(Packet.Data[7]); _eventArgs.WatchdogCounter = Packet.Data[8]; _eventArgs.Fan1Glitch = Packet.Data[9]; _eventArgs.Fan2Glitch = Packet.Data[10]; _eventArgs.Fan3Glitch = Packet.Data[11]; _eventArgs.Fan4Glitch = Packet.Data[12]; _eventArgs.Contrast = Packet.Data[13]; _eventArgs.Backlight = Packet.Data[14]; this.ReportingAndStatus(this, _eventArgs); } break; //Response from Send Data to LCD case 0x5F: break; //Response from set baud rate case 0x61: //We switch after we get the packet that the device has switched _sp.BaudRate = _baudRateChange; this._baudRate = _baudRateChange; _baudRateChange = 0; break; #region KeyPressed //Key Pressed Packet case 0x80: if (Packet.DataLength != 1) { //We got an error.... } int _keyByte = Packet.Data[0]; //Less then or equall to 6 = KeyPress if (_keyByte <= 6) { if (KeyPressed != null) { KeyPressed(this, new CFAKeyEventArgs(this.IntToEnum <Keys>(_keyByte))); } } //grater then 6 = KeyRelease, Must be less then or equall to 12 if (_keyByte > 6 && _keyByte <= 12) { if (KeyReleased != null) { KeyReleased(this, new CFAKeyEventArgs(this.IntToEnum <Keys>(_keyByte - 6))); } } //For CFA633 presses if (_keyByte > 12 && _keyByte <= 16) { if (KeyPressed != null) { KeyPressed(this, new CFAKeyEventArgs(this.IntToEnum <Keys>(_keyByte))); } } //for CFA633 releases if (_keyByte > 16 && _keyByte <= 20) { if (KeyReleased != null) { KeyReleased(this, new CFAKeyEventArgs(this.IntToEnum <Keys>(_keyByte - 4))); } } break; #endregion } }