public override Telegraph GetTestTelegraph() { ESCommand tCommand = new ESCommandReadBlock(); tCommand.Address = BM_CMD_ADDR.BM_CMD_ADDR_ADAPTER; tCommand.TimeOut = 500; tCommand.Command = 0x01; tCommand.Description = "BM300 testing telegraph"; return(new BatteryManagementTelegraph(tCommand)); }
public override Telegraph GetTestTelegraph() { ESCommand tCommand = new ESCommandReadBlock(); tCommand.Address = BM_CMD_ADDR.BM_CMD_ADDR_ADAPTER; tCommand.TimeOut = 500; tCommand.Command = (Byte)'t'; tCommand.Description = "ATSB200 testing telegraph"; return(new SmartBatteryTelegraph(tCommand)); }
public override Telegraph GetTestTelegraph() { ESCommand tCommand = new ESCommandReadBlock(); tCommand.AddressValue = 0; tCommand.TimeOut = 500; tCommand.Command = 0x01; tCommand.Description = "GSFrame-Telegraph testing telegraph"; return(new GSFrameTelegraph(tCommand)); }
private Int32 DecodeNormal(ref Queue <System.Byte> InputQueue, ref Boolean tRequestDrop) { //! check input queue if ((null == InputQueue) || (null == m_Command) || (0 == InputQueue.Count)) { return(0); } //! frame address System.Byte Command = 0; UInt16 CheckSUM = 0xFFFF; UInt16 DataLength = 0; System.Byte[] Datas = null; tRequestDrop = false; //! check the frame using (Queue <Byte> .Enumerator qEnumerator = InputQueue.GetEnumerator()) { if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } //! check frame head if (0xAA != qEnumerator.Current) { tRequestDrop = true; qEnumerator.Dispose(); return(0); } Byte[] tLength = new Byte[2]; //! get frame destination address if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { tLength[0] = qEnumerator.Current; Get_CRC(ref CheckSUM, qEnumerator.Current); } //! get data length if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { tLength[1] = qEnumerator.Current; Get_CRC(ref CheckSUM, qEnumerator.Current); DataLength = BitConverter.ToUInt16(tLength, 0); if (0 == DataLength) { qEnumerator.Dispose(); return(0); } DataLength--; Datas = new Byte[DataLength]; } //! get frame command if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Command = qEnumerator.Current; Get_CRC(ref CheckSUM, qEnumerator.Current); if ((m_Command.Command != Command) && (0xAC != Command)) { //! this frame not belong to this telegraph tRequestDrop = true; qEnumerator.Dispose(); return(0); } } //! get data for (System.Int32 n = 0; n < DataLength; n++) { //! get frame data length if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Datas[n] = qEnumerator.Current; Get_CRC(ref CheckSUM, qEnumerator.Current); } } Byte[] tCheckSumBuffer = new Byte[2]; //! get check sum Low Byte if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { tCheckSumBuffer[0] = qEnumerator.Current; } //! get check sum High Byte if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { tCheckSumBuffer[1] = qEnumerator.Current; if (CheckSUM != BitConverter.ToUInt16(tCheckSumBuffer, 0)) { tRequestDrop = true; qEnumerator.Dispose(); return(0); } } /* * //! check frame tail * if ((!qEnumerator.MoveNext()) || (0x55 != qEnumerator.Current)) * { * qEnumerator.Dispose(); * return 0; * } */ if (null != m_Timer) { lock (m_Timer) { try { if (null != m_Timer) { //! start timer m_Timer.Stop(); m_Timer.Enabled = false; m_Timer.Dispose(); m_Timer = null; } } catch (Exception) { } } } } //! decoding success! now, we get all data from queue and create a report ESCommand tempCommand = new ESCommandReadBlock(Datas); //!< create a command //! copy command properies from source command m_Command tempCommand.AddressValue = m_Command.AddressValue; tempCommand.Command = Command; tempCommand.Description = m_Command.Description; tempCommand.ID = m_Command.ID; tempCommand.ResponseMode = m_Command.ResponseMode; tempCommand.TimeOut = m_Command.TimeOut; m_Command = tempCommand; //! raising event OnDecoderSuccess(tempCommand); //! return decode size return(6 + DataLength); }
//! telegraph method : Decode public override Int32 Decode(ref Queue <System.Byte> InputQueue, ref Boolean tRequestDrop) { //! check input queue if ((null == InputQueue) || (null == m_Command) || (0 == InputQueue.Count)) { return(0); } //! frame address Byte Address = 0; Byte Command = 0; Byte CheckSUM = 0; Byte DataLength = 0; Byte[] Datas = null; tRequestDrop = false; //! check the frame using (Queue <Byte> .Enumerator qEnumerator = InputQueue.GetEnumerator()) { if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } //! check frame head if (AT_BM_SYNC != qEnumerator.Current) { tRequestDrop = true; qEnumerator.Dispose(); return(0); } else { CheckSUM += qEnumerator.Current; } //! get frame destination address if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Address = qEnumerator.Current; CheckSUM += qEnumerator.Current; if (Address != m_Command.SubAddress) { //! error tRequestDrop = true; qEnumerator.Dispose(); return(0); } } //! get frame source address if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Address = qEnumerator.Current; if (0x80 != (Address & 0x80)) { //! error tRequestDrop = true; qEnumerator.Dispose(); return(0); } Address &= 0x7E; switch (Address) { case 0x00: //!< adapter / gateway Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_ADAPTER; break; case 0x04: //!< smbus Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SMBUS; break; case 0x06: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SMBUS_PEC; break; case 0x08: //!< I2C Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_I2C; break; case 0x0A: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_I2C_PEC; break; case 0x0C: //!< uart Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_UART; break; case 0x0E: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_UART_PEC; break; case 0x10: //!< single-wire uart Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SINGLE_WIRE_UART; break; case 0x12: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SINGLE_WIRE_UART_PEC; break; case 0x14: //!< spi Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SPI; break; case 0x16: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SPI_PEC; break; case 0x18: //!< charger Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_CHARGER; break; case 0x19: //!< loader Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_LOADER; break; case 0x1A: //!< lcd Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_LCD; break; case 0x1B: //!< printer Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_PRN; break; case 0x24: //!< smbus extend Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SMBUS_EX; break; case 0x26: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SMBUS_PEC_EX; break; case 0x28: //!< I2C extend Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_I2C_EX; break; case 0x2A: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_I2C_PEC_EX; break; case 0x2C: //!< uart extend Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_UART_EX; break; case 0x2E: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_UART_PEC_EX; break; case 0x30: //!< single-wire uart Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SINGLE_WIRE_UART_EX; break; case 0x32: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SINGLE_WIRE_UART_PEC_EX; break; case 0x34: //!< spi Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SPI_EX; break; case 0x36: Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SPI_PEC_EX; break; case 0x7F: //!< all Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_ALL; break; } CheckSUM += qEnumerator.Current; if (m_Command.AddressValue != Address) { //! this frame not belong to this telegraph tRequestDrop = true; qEnumerator.Dispose(); return(0); } } //! get frame command if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Command = qEnumerator.Current; CheckSUM += qEnumerator.Current; Byte temCommand = m_Command.Command; switch (m_Command.Type) { case BM_CMD_TYPE.BM_CMD_TYPE_WORD_READ: case BM_CMD_TYPE.BM_CMD_TYPE_BLOCK_READ: temCommand |= 0x80; break; case BM_CMD_TYPE.BM_CMD_TYPE_WORD_WRITE: case BM_CMD_TYPE.BM_CMD_TYPE_BLOCK_WRITE: temCommand &= 0x7F; break; } if ((temCommand != Command) && (Command != 0x41)) { //! this frame not belong to this telegraph tRequestDrop = true; qEnumerator.Dispose(); return(0); } Command = temCommand; } //! get frame data length if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { DataLength = qEnumerator.Current; CheckSUM += qEnumerator.Current; Datas = new Byte[DataLength]; } //! get data for (System.Int32 n = 0; n < DataLength; n++) { //! get frame data length if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Datas[n] = qEnumerator.Current; CheckSUM += qEnumerator.Current; } } //! get check sum if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } //! verify check sum if (qEnumerator.Current != CheckSUM) { tRequestDrop = true; qEnumerator.Dispose(); return(0); } //! check frame tail if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } if (AT_SB_ENDSYNC != qEnumerator.Current) { tRequestDrop = true; qEnumerator.Dispose(); return(0); } if (null != m_Timer) { lock (m_Timer) { try { if (null != m_Timer) { //! start timer m_Timer.Stop(); m_Timer.Enabled = false; m_Timer.Dispose(); m_Timer = null; } } catch (Exception Err) { Err.ToString(); } } } } //! decoding success! now, we get all data from queue and create a report ESCommand tempCommand = null; //!< create a command if ((Datas.Length > 2) && (BM_CMD_TYPE.BM_CMD_TYPE_WORD_READ) == m_Command.Type) { tempCommand = new ESCommandReadBlock(Datas); } else { tempCommand = m_Command.CopyConstruct(Datas); } //! copy command properies from source command m_Command tempCommand.AddressValue = Address; tempCommand.Command = Command; tempCommand.Description = m_Command.Description; tempCommand.ID = m_Command.ID; tempCommand.ResponseMode = m_Command.ResponseMode; tempCommand.TimeOut = m_Command.TimeOut; m_Command = tempCommand; //! raising event OnDecoderSuccess(tempCommand); //! return decode size return(7 + DataLength); }