Beispiel #1
0
        public async Task <Bytes> SendAndGetPacket(Bytes packet, byte repeat_count, ushort delay_ms, uint timeout_ms, byte retry_count, ushort preamble_ext_ms)
        {
            try
            {
                await Connect();

                var data      = Manchester.Encode(packet.ToArray());
                var cmdParams = new Bytes()
                                .Append((byte)0)
                                .Append(repeat_count)
                                .Append(delay_ms)
                                .Append((byte)0)
                                .Append(timeout_ms)
                                .Append(retry_count)
                                .Append(preamble_ext_ms)
                                .Append(data);
                var result = await this.SendCommand(RileyLinkCommandType.SendAndListen, cmdParams, 5000);

                if (result != null)
                {
                    var decoded = new Bytes(Manchester.Decode(result.Sub(2).ToArray()));
                    return(result.Sub(0, 2).Append(decoded));
                }
                else
                {
                    return(null);
                }
            }
            catch (OmnipyException) { throw; }
            catch (Exception e)
            {
                throw new PacketRadioException("Error while sending and receiving data with RL", e);
            }
        }
Beispiel #2
0
        public async Task <Bytes> GetPacket(uint timeout = 5000)
        {
            try
            {
                await Connect();

                var cmdParams = new Bytes((byte)0);
                cmdParams.Append(timeout);

                var result = await this.SendCommand(RileyLinkCommandType.SendAndListen, cmdParams, (int)timeout + 500);

                if (result != null)
                {
                    return(result.Sub(0, 2).Append(Manchester.Decode(result.Sub(2).ToArray())));
                }
                else
                {
                    return(null);
                }
            }
            catch (OmnipyException) { throw; }
            catch (Exception e)
            {
                throw new PacketRadioException("Error while receiving data with RL", e);
            }
        }
Beispiel #3
0
        public async Task SendPacket(Bytes packet, byte repeat_count, ushort delay_ms, ushort preamble_ext_ms)
        {
            try
            {
                await Connect();

                Debug.WriteLine($"SEND radio packet: {packet}");
                var data      = Manchester.Encode(packet.ToArray());
                var cmdParams = new Bytes((byte)0).Append(repeat_count);
                cmdParams.Append(delay_ms);
                cmdParams.Append(preamble_ext_ms);
                cmdParams.Append(data);
                await this.SendCommand(RileyLinkCommandType.SendAndListen, cmdParams, 30000);
            }
            catch (OmnipyException) { throw; }
            catch (Exception e)
            {
                throw new PacketRadioException("Error while sending data with RL", e);
            }
        }