示例#1
0
        /// <summary>
        /// Received a command packet
        /// </summary>
        /// <param name="commandPacket">Command packet received</param>
        protected override void OnCommandPacketReceived(CommandPacket commandPacket)
        {
            if (commandPacket == null)
                return;
            
            PACKET_TYPE packetType = (PACKET_TYPE)commandPacket.CommandId;            
            switch (packetType)
            {
                case PACKET_TYPE.MESSAGE_PACKET:
                    {
                        MESSAGE_ID msgId = (MESSAGE_ID)commandPacket.GetParameterDWORD();
                        CommandPacket cmd = new CommandPacket();
                        cmd.CommandId = (uint)PACKET_TYPE.MESSAGE_PACKET;

                        AddCommLog(msgId.ToString());
                        switch (msgId)
                        {
                            case MESSAGE_ID.AGENT_ACK_MSG:
                                cmd.AddParameterDWORD((uint)MESSAGE_ID.AGENT_INITIALIZE_MSG);
                                SendCommand(cmd);        
                                break;

                            case MESSAGE_ID.AGENT_INITIALIZE_MSG:
                                SendDeviceLogging();
                                break;

                            case MESSAGE_ID.AGENT_UNINITIALIZE_MSG:
                                cmd.AddParameterDWORD((uint)MESSAGE_ID.AGENT_INITIALIZE_MSG);
                                SendCommand(cmd);
                                break;

                            case MESSAGE_ID.AGENT_LOGGING_ON_MSG:
                                break;

                            case MESSAGE_ID.AGENT_LOGGING_OFF_MSG:
                                break;

                            case MESSAGE_ID.COM_OPEN_MSG:
                                break;

                            case MESSAGE_ID.AGENT_PING_MSG:
                                break;

                            case MESSAGE_ID.COM_CLOSE_MSG:
                                cmd.AddParameterDWORD((uint)MESSAGE_ID.AGENT_UNINITIALIZE_MSG);
                                SendCommand(cmd);
                                break;
                        }
                    }
                    break;               

                case PACKET_TYPE.HCI_DATA_PACKET:
                    {
                        CommandPacketParameter cpp;
                        while ((cpp = commandPacket.GetNextParameter()) != null)
                        {
                            switch (cpp.Type)
                            {
                                case CommandPacketParameterType.Bytes:
                                    OnDeviceDataReceived(cpp.BytesParameter);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    break;               
            }            
        }        
示例#2
0
 protected override void OnStart()
 {
     // send the first message to device...
     CommandPacket cmd = new CommandPacket();
     cmd.CommandId = (uint)PACKET_TYPE.MESSAGE_PACKET;
     cmd.AddParameterDWORD((uint)MESSAGE_ID.AGENT_ACK_MSG);
     SendCommand(cmd);
 }
示例#3
0
 private void WatchDogTimerEvent(object source, ElapsedEventArgs e)
 {
     if (Connected)
     {
         // send to device...
         CommandPacket cmd = new CommandPacket();
         cmd.CommandId = (uint)PACKET_TYPE.MESSAGE_PACKET;
         cmd.AddParameterDWORD((uint)MESSAGE_ID.AGENT_PING_MSG);
         SendCommand(cmd);                
     }
     else
     {
         ctrlPanelData.CloseDevice();
     }
 }
示例#4
0
        private bool OnDeviceDataReceived(byte[] bytes)
        {
            int length = bytes.Length;
            if (length > 0) 
            {
                HCI_TYPE hciType = (HCI_TYPE)bytes[0];

                // send command/data to bluetooth device...
                int lastError = 0;
                int ret = BthRuntime.SendHCICommand(devId, bytes, (uint)bytes.Length);

                string result = GlobalData.OK;
                if (ret == 0)
                {
                    lastError = Marshal.GetLastWin32Error();
                    string errMsg = new System.ComponentModel.Win32Exception(lastError).Message;
                    result = string.Format("Fail: {0} ({1})", lastError, errMsg);
                }

                // send error code to device...
                CommandPacket cmd = new CommandPacket();
                cmd.CommandId = (uint)PACKET_TYPE.HCI_DATA_ERROR_PACKET;
                cmd.AddParameterDWORD((uint)lastError);
                SendCommand(cmd);

                // add log entry.
                AddCommLog(hciType.ToString(), bytes, bytes.Length, result);
            }

            return false;            
        }
示例#5
0
 private void SendDeviceLogging()
 {
     CommandPacket cmd = new CommandPacket();
     cmd.CommandId = (uint)PACKET_TYPE.MESSAGE_PACKET;
     MESSAGE_ID cmdId = ctrlPanelData.DeviceLogging ? MESSAGE_ID.AGENT_LOGGING_ON_MSG : MESSAGE_ID.AGENT_LOGGING_OFF_MSG;
     cmd.AddParameterDWORD((uint)cmdId);
     SendCommand(cmd);
 }