Esempio n. 1
0
        public void Callback(CRTPResponse response)
        {
            if(StatusChecker(response.Status))
                return;

            var port = (PortAllocation) response.Header.Port;

            switch (port)
            {
                case PortAllocation.Log:
                    if (LogEvent != null)
                        LogEvent(this, new EventArgs<CRTPResponse>(response));
                    break;

                case PortAllocation.Console:
                    if (ConsoleEvent != null)
                    {
                        var s = Encoding.ASCII.GetString(response.Data, 0, response.Data.Length);

                        ConsoleEvent(this, new EventArgs<string>(s));
                    }
                    break;

            //                default:
            //                    throw new ArgumentOutOfRangeException("response", "the port was out of range");
            }
        }
Esempio n. 2
0
        private void ToCEvent(CRTPResponse response)
        {
            LoggingCmd cmd = (LoggingCmd) response.Data[0];

            if(cmd == LoggingCmd.ToCItem)
            {
                _itemReplies.Enqueue(new ToCItem(response.Data));
            }
            else if(cmd == LoggingCmd.ToCInfo)
            {
                _infoReplies.Enqueue(new InfoReply(response.Data));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Method that sends a packet on the current channel
        /// </summary>
        /// <param name="packet">The packet to send, for example a CRTPCommand</param>
        /// <returns>Returns whatever data the crazy flie decided to send back in its ack payload</returns>
        public CRTPResponse SendPacket(CRTPPacket packet)
        {
            //transform packet to byte array
            var send = packet.CreatePacket();

            int len;
            //write packet to radio
            ErrorCode e = _writer.Write(send, 1000, out len);

            //TODO: Check if write ever returns OK instead
            if (e != ErrorCode.None)
            {
                throw new SendPacketException(e, "Error in writing to endpoint");
            }

            var buffer = new byte[64];

            e = _reader.Read(buffer, 1000, out len);

            if (e != ErrorCode.None)
            {
                throw new SendPacketException(e, "Error in reading from endpoint");
            }

            Array.Resize(ref buffer, len);

            var response = new CRTPResponse(buffer);

            return response;
        }