//! method for raising decoding success event protected virtual void OnDecoderSuccess(ESCommand ReceivedCommand) { //! raising event OnTelegrahAccessed(); if (m_IfDisposed) { return; } //BatteryManageTelegraphEvent.Invoke(BM_TELEGRAPH_STATE.BM_TELE_RT_SUCCESS, ReceivedCommand); /* * BeginInvoke * ( * SinglePhaseTelegraphEvent, * this, * BM_TELEGRAPH_STATE.BM_TELE_RT_SUCCESS, * ReceivedCommand * ); */ if (null != SinglePhaseTelegraphEvent) { #if __ASYN_TELEGRAPH_REPORT__ BeginInvoke ( SinglePhaseTelegraphEvent, this, BM_TELEGRAPH_STATE.BM_TELE_RT_SUCCESS, ReceivedCommand ); #else SinglePhaseTelegraphEvent.Invoke(this, BM_TELEGRAPH_STATE.BM_TELE_RT_SUCCESS, ReceivedCommand); #endif } Dispose(); }
//! constructor public SinglePhaseTelegraph(ESCommand Command) : base() { if (null != Command) { m_Command = Command; lock (m_Timer) { //! handlinig time out feature switch ((BM_CMD_RT)m_Command.TimeOut) { case BM_CMD_RT.BM_CMD_RT_NO_RESPONSE: //!< command need no response //! set telegraph cancel flag CancelTelegraph(); break; case BM_CMD_RT.BM_CMD_RT_NO_TIME_OUT: //!< Wait forever m_Timer.Enabled = false; break; default: //! time out feature enabled m_Timer.Interval = m_Command.TimeOut; m_Timer.Enabled = false; m_Timer.Elapsed += new ElapsedEventHandler(TimeOutHandler); break; } } } else { //! mark this as an invalid telegraph CancelTelegraph(); } }
private void TestingSinglePhaseTelegraphEvent(SinglePhaseTelegraph tTelegraph, BM_TELEGRAPH_STATE State, ESCommand ReceivedCommand) { tTelegraph.SinglePhaseTelegraphEvent -= new SinglePhaseTelegraphEventHandler(TestingSinglePhaseTelegraphEvent); if (State == BM_TELEGRAPH_STATE.BM_TELE_RT_SUCCESS) { //! raising event OnAdapterAvailableTelegraphAutoDetectionReport (TELEGRAPH_AUTO_DETECT_RESULT.ONE_TELEGRAPH_MATCHED, new String[1] { tTelegraph.Type }); } else { //! raising event OnAdapterAvailableTelegraphAutoDetectionReport (TELEGRAPH_AUTO_DETECT_RESULT.NO_TELEGRAPH_MATCHED, null); } }
public UserTelegraph(ESCommand tCommand, Boolean bMightIgnoreCMDCode) : base(tCommand) { m_bMightIgnoreCMDCode = bMightIgnoreCMDCode; }
//! \brief constructor public UserTelegraph(ESCommand tCommand) : base(tCommand) { }
//! constructor public STK500Telegraph(ESCommand Command) : base(Command) { }
//! 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); }
//! constructor public BatteryManagementTelegraph(ESCommand Command) : base(Command) { }
//! 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 System.Byte Address = 0; System.Byte Command = 0; System.Byte CheckSUM = 0; System.Byte DataLength = 0; System.Byte[] Datas = null; tRequestDrop = false; //! check the frame using (Queue <System.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 ((Byte)'P' != Address) { //! this frame may not sent to pc tRequestDrop = true; qEnumerator.Dispose(); return(0); } } //! get frame source address if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Address = qEnumerator.Current; switch (Address) { case (Byte)'M': //!< Adapter Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_ADAPTER; break; case (Byte)'S': //!< SMBus Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SMBUS; break; case (Byte)'I': //!< SPI Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SPI; break; case (Byte)'R': //!< UART Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_UART; break; case (Byte)'W': //!< Single-wire UART Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_SINGLE_WIRE_UART; break; case (Byte)'T': //!< Printer Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_PRN; break; case (Byte)'E': //!< Loader Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_LOADER; break; case (Byte)'C': //!< Charger Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_CHARGER; break; case (Byte)'D': //!< LCD Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_LCD; break; case (Byte)'A': //!< All Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_ALL; break; case (Byte)'B': Address = (Byte)BM_CMD_ADDR.BM_CMD_ADDR_I2C; break; default: if (Address > 0x7F) { Address &= 0x7F; } else { 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.Address) { case BM_CMD_ADDR.BM_CMD_ADDR_SINGLE_WIRE_UART: case BM_CMD_ADDR.BM_CMD_ADDR_SMBUS: case BM_CMD_ADDR.BM_CMD_ADDR_SPI: case BM_CMD_ADDR.BM_CMD_ADDR_UART: 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; } 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 = m_Command.CopyConstruct(Datas); //!< create a command //! 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); }
//! constructor public SmartBatteryTelegraph(ESCommand Command) : base(Command) { }
//! \brief method for creating a SinglePhaseTelegrah object public abstract SinglePhaseTelegraph CreateSinglePhaseTelegraph(ESCommand Command);
//! \brief implement method for get a SmartBatteryTelegraph public override SinglePhaseTelegraph CreateSinglePhaseTelegraph(ESCommand Command) { XBatteryTelegraph teleSB200 = new XBatteryTelegraph(Command); return(teleSB200); }
//! telegraph method : Decode public override System.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 System.Byte Address = 0; System.Byte Command = 0; System.Byte CheckSUM = 0; System.Byte DataLength = 0; System.Byte[] Datas = null; tRequestDrop = false; //! check the frame using (Queue <System.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 ((Byte)BM_CMD_ADDR.BM_CMD_ADDR_PC != Address) { //! this frame may not sent to pc tRequestDrop = true; qEnumerator.Dispose(); return(0); } } //! get frame source address if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { Address = qEnumerator.Current; 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) { //! this frame not belong to this telegraph tRequestDrop = true; qEnumerator.Dispose(); return(0); } } //! get frame data length if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else { DataLength = qEnumerator.Current; CheckSUM += qEnumerator.Current; Datas = new Byte[DataLength]; //! resize the databuffer: Datas //Array.Resize(ref Datas, 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); } else if (qEnumerator.Current != CheckSUM) { tRequestDrop = true; qEnumerator.Dispose(); return(0); } //! check frame tail if (!qEnumerator.MoveNext()) { qEnumerator.Dispose(); return(0); } else 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.Enabled = false; m_Timer.Stop(); 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 = m_Command.CopyConstruct(Datas); //!< create a command //! 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); }
//! \brief constructor public GSFrameTelegraph(ESCommand tCommand) : base(tCommand) { }