Пример #1
0
 public void registerMessageHandler(ProcessMessageHandler processMessageHandler)
 {
     lock (_processMessageHandlers)
     {
         _processMessageHandlers.Add(processMessageHandler);
     }
 }
Пример #2
0
        public void ReceiveMessage(ProcessMessageHandler callbackFunc = null)
        {
            status += (int)MessageStatus.GetMessage;

            this.ProcessMessageAction = callbackFunc;
            Task.Run(() => PollMessage());
        }
Пример #3
0
        public ConvertController(ProcessMessageHandler webSocket)
        {
            var config = new Configuration();

            this.tempFolder        = config.TempFolder;
            this.convertedFolder   = config.ConvertedFolder;
            this.compresssedFolder = config.CompresssedFolder;
            this.webSocket         = webSocket;
        }
Пример #4
0
 public ConvertController(Configuration config, ProcessMessageHandler webSocket)
 {
     this.FfmpegExecutablePath = config.FfmpegExecutablePath;
     this.MP4BoxExecutablePath = config.MP4BoxExecutablePath;
     this.tempFolder           = config.TempFolder;
     this.convertedFolder      = config.ConvertedFolder;
     this.compresssedFolder    = config.CompresssedFolder;
     this.ffmpeg = new FFMPEG(FfmpegExecutablePath);
     this.ffmpeg.ErrorReceived  += OnErrorReceived;
     this.ffmpeg.ConvertionDone += OnConvertionDone;
     this.webSocket              = webSocket;
 }
Пример #5
0
 public void registerMessageHandler(ProcessMessageHandler processMessageHandler)
 {
     lock (_processMessageHandlers)
     {
         _processMessageHandlers.Add(processMessageHandler);
     }
 }
Пример #6
0
 /// <summary>
 /// Closes and reopens the underlying connection and clears all buffers and queues.
 /// </summary>
 public void Clear()
 {
     lock (_receivedMessageList)
     {
         _connection.Close();
         _receivedMessageList.Clear();
         _processMessage = null;
         _awaitedMessagesQueue = new ConcurrentQueue<FirmataMessage>();
         _awaitedStringsQueue = new ConcurrentQueue<StringRequest>();
         _connection.Open();
     }
 }
Пример #7
0
        private void DeliverMessage(FirmataMessage message)
        {
            _processMessage = null;

            lock (_receivedMessageList)
            {
                if (_receivedMessageList.Count >= MaxQueuelength)
                    throw new OverflowException(Messages.OverflowEx_MsgBufferFull);

                // Remove all unprocessed and timed-out messages.
                while (_receivedMessageList.Count > 0 &&
                    ((DateTime.UtcNow - _receivedMessageList.First.Value.Time).TotalMilliseconds > TimeOut))
                {
                    _receivedMessageList.RemoveFirst();
                }

                _receivedMessageList.AddLast(message);
                Monitor.PulseAll(_receivedMessageList);
            }

            if (MessageReceived != null && message.Type != MessageType.I2CReply)
                MessageReceived(this, new FirmataMessageEventArgs(message));
        }
Пример #8
0
        private void ProcessDigitalStateMessage(int messageByte)
        {
            if (_messageBufferIndex < 2)
            {
                WriteMessageByte(messageByte);
            }
            else
            {
                var currentState = new DigitalPortState
                {
                    Port = _messageBuffer[0] & 0x0F,
                    Pins = _messageBuffer[1] | (messageByte << 7)
                };
                _processMessage = null;

                if (MessageReceived != null)
                    MessageReceived(this, new FirmataMessageEventArgs(new FirmataMessage(currentState, MessageType.DigitalPortState)));

                if (DigitalStateReceived != null)
                    DigitalStateReceived(this, new FirmataEventArgs<DigitalPortState>(currentState));
            }
        }
Пример #9
0
        private void ProcessAnalogStateMessage(int messageByte)
        {
            if (_messageBufferIndex < 2)
            {
                WriteMessageByte(messageByte);
            }
            else
            {
                var currentState = new AnalogState
                {
                    Channel = _messageBuffer[0] & 0x0F,
                    Level = (_messageBuffer[1] | (messageByte << 7))
                };
                _processMessage = null;

                if (MessageReceived != null)
                    MessageReceived(this, new FirmataMessageEventArgs(new FirmataMessage(currentState, MessageType.AnalogState)));

                if (AnalogStateReceived != null)
                    AnalogStateReceived(this, new FirmataEventArgs<AnalogState>(currentState));
            }
        }
Пример #10
0
        private void ProcessCommand(int serialByte)
        {
            _messageBuffer[0] = serialByte;
            _messageBufferIndex = 1;
            MessageHeader header = (MessageHeader)(serialByte & 0xF0);

            switch (header)
            {
                case MessageHeader.AnalogState:
                    _processMessage = ProcessAnalogStateMessage;
                    break;

                case MessageHeader.DigitalState:
                    _processMessage = ProcessDigitalStateMessage;
                    break;

                case MessageHeader.SystemExtension:
                    header = (MessageHeader)serialByte;

                    switch (header)
                    {
                        case MessageHeader.SystemExtension:
                            _processMessage = ProcessSysExMessage;
                            break;

                        case MessageHeader.ProtocolVersion:
                            _processMessage = ProcessProtocolVersionMessage;
                            break;

                        //case MessageHeader.SetPinMode:
                        //case MessageHeader.SystemReset:
                        default:
                            // 0xF? command not supported.
                            throw new NotImplementedException(string.Format(Messages.NotImplementedEx_Command, serialByte));
                    }
                    break;

                default:
                    // Command not supported.
                    throw new NotImplementedException(string.Format(Messages.NotImplementedEx_Command, serialByte));
            }
        }
 public ProcessMessageHandlerShould()
 {
     repository = Substitute.For <IMessageRepository>();
     handler    = new ProcessMessageHandler(repository);
 }