/// <summary>
        /// Command CFGG to retrieve the current connection string saved in the chip.
        /// </summary>
        /// <returns>Connection String</returns>
        public async Task <string> GetConnectionStringFromChip()
        {
            if (_UARTService == null)
            {
                return(string.Empty);
            }

            TaskCompletionSource <FourByFourReception> signalEventPoke = new TaskCompletionSource <FourByFourReception>();

            UARTPacketEventHandler handler = null;

            handler += (sender, e) =>
            {
                if (e.ResponsePacket.Command == FourByFourConstants.CMD_GET_CONFIG)
                {
                    signalEventPoke.SetResult(e.ResponsePacket);
                    _UARTService.UARTPacketReceived -= handler;
                }
            };
            _UARTService.UARTPacketReceived += handler;


            if (_UARTService.SendPacket(new GetConfigCommand()))
            {
                FourByFourReception reception = await TimeoutAsyncEvent.TimeoutAfter(signalEventPoke.Task, TIMEOUT);

                _UARTService.UARTPacketReceived -= handler;

                return(((GetConfigReception)reception).ConnectionString);
            }
            else
            {
                Log.Error("GetConfigCommand failed.");
                _UARTService.UARTPacketReceived -= handler;
            }
            return(string.Empty);
        }
        /// <summary>
        /// Command CFGS to set the connection string in the chip appconfig store.
        /// </summary>
        /// <param name="connectionString"></param>
        /// <returns>True if the connection string was successfully set.</returns>
        public async Task <bool> SetConfigOnChip(string connectionString)
        {
            if (_UARTService == null)
            {
                return(false);
            }

            TaskCompletionSource <FourByFourReception> signalEventPoke = new TaskCompletionSource <FourByFourReception>();

            UARTPacketEventHandler handler = null;

            handler += (sender, e) =>
            {
                if (e.ResponsePacket.Command == FourByFourConstants.CMD_SET_CONFIG)
                {
                    signalEventPoke.SetResult(e.ResponsePacket);
                    _UARTService.UARTPacketReceived -= handler;
                }
            };
            _UARTService.UARTPacketReceived += handler;


            if (_UARTService.SendPacket(new SetConfigCommand(connectionString)))
            {
                FourByFourReception reception = await TimeoutAsyncEvent.TimeoutAfter(signalEventPoke.Task, TIMEOUT);

                _UARTService.UARTPacketReceived -= handler;

                return(reception.State == ReceptionState.Success);
            }
            else
            {
                Log.Error("SetConfigCommand failed.");
                _UARTService.UARTPacketReceived -= handler;
            }
            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Main Constructor
 /// </summary>
 /// <param name="packet"></param>
 public UARTPacketEventArgs(FourByFourReception packet)
 {
     ResponsePacket = packet;
 }
 /// <summary>
 /// Fires a new UARTPacketReceived event once a packet was successfully processed and recognized
 /// </summary>
 /// <param name="responsePacked">FourByFourReception packet</param>
 private void NewResponsePacketReceived(FourByFourReception responsePacked)
 {
     UARTPacketReceived?.Invoke(this, new UARTPacketEventArgs(responsePacked));
 }