Exemplo n.º 1
0
        public void Initialize()
        {
            GpioController gpioController = GpioController.GetDefault();
            GpioPin        powerPin       = gpioController.InitGpioPin(4, GpioPinDriveMode.Output, GpioSharingMode.Exclusive);       //4
            GpioPin        cePin          = gpioController.InitGpioPin(22, GpioPinDriveMode.Output, GpioSharingMode.Exclusive);      //22
            GpioPin        irqPin         = gpioController.InitGpioPin(25, GpioPinDriveMode.InputPullUp, GpioSharingMode.Exclusive); //25

            powerPin.Write(GpioPinValue.Low);
            cePin.Write(GpioPinValue.Low);
            irqPin.Write(GpioPinValue.High);

            DeviceInformationCollection devicesInfo    = DeviceInformation.FindAllAsync(SpiDevice.GetDeviceSelector("SPI0")).GetAwaiter().GetResult();
            SpiDevice             spiDevice            = SpiDevice.FromIdAsync(devicesInfo[0].Id, new SpiConnectionSettings(0)).GetAwaiter().GetResult();
            ICommandProcessor     commandProcessor     = new CommandProcessor(spiDevice);
            ILoggerFactoryAdapter loggerFactoryAdapter = new DebugOutLoggerFactoryAdapter(LogLevel.All, true, true, true, "MM/dd/yyyy hh:mm:ss fffff");

            _radio           = new Radio(commandProcessor, loggerFactoryAdapter, powerPin, cePin, irqPin);
            _sendReceiveRole = new SenderReceiverRole();
            _sendReceiveRole.AttachRadio(_radio);
            _sendReceiveRole.DataArrived   += DataArrived;;
            _sendReceiveRole.SendAddress    = SendAddress;
            _sendReceiveRole.ReceiveAddress = ReceiveAddress;
            _sendReceiveRole.Start();

            ThreadPoolTimer.CreatePeriodicTimer(Handler, TimeSpan.FromSeconds(5));
            WaitForData();
        }
Exemplo n.º 2
0
        public static void ClassInitialize(TestContext testContext)
        {
            GpioController gpioController = GpioController.GetDefault();

            _irqPin = gpioController.InitGpioPin(25, GpioPinDriveMode.InputPullUp);
            _cePin  = gpioController.InitGpioPin(22, GpioPinDriveMode.Output);

            DeviceInformationCollection devicesInfo = DeviceInformation.FindAllAsync(SpiDevice.GetDeviceSelector("SPI0")).GetAwaiter().GetResult();

            _spiDevice            = SpiDevice.FromIdAsync(devicesInfo[0].Id, new SpiConnectionSettings(0)).GetAwaiter().GetResult();
            _commandProcessor     = new CommandProcessor(_spiDevice); // new MockCommandProcessor();
            _loggerFactoryAdapter = new NoOpLoggerFactoryAdapter();

            _radio = new Radio(_commandProcessor, _loggerFactoryAdapter, _cePin, _irqPin);
        }
        public void Initialize()
        {
            GpioController gpioController = GpioController.GetDefault();
            GpioPin        powerPin       = gpioController.InitGpioPin(4, GpioPinDriveMode.Output, GpioSharingMode.Exclusive);
            GpioPin        cePin          = gpioController.InitGpioPin(22, GpioPinDriveMode.Output, GpioSharingMode.Exclusive);
            GpioPin        irqPin         = gpioController.InitGpioPin(25, GpioPinDriveMode.InputPullUp, GpioSharingMode.Exclusive);

            powerPin.Write(GpioPinValue.Low);
            cePin.Write(GpioPinValue.Low);
            irqPin.Write(GpioPinValue.High);

            DeviceInformationCollection devicesInfo = DeviceInformation.FindAllAsync(SpiDevice.GetDeviceSelector("SPI0")).GetAwaiter().GetResult();
            SpiDevice         spiDevice             = SpiDevice.FromIdAsync(devicesInfo[0].Id, new SpiConnectionSettings(0)).GetAwaiter().GetResult();
            ICommandProcessor commandProcessor      = new CommandProcessor(spiDevice);

            ILoggerFactoryAdapter loggerFactoryAdapter = new DebugOutLoggerFactoryAdapter(LogLevel.All, true, true, true, "MM/dd/yyyy hh:mm:ss fffff");

            _radio = new Radio(commandProcessor, loggerFactoryAdapter, powerPin, cePin, irqPin);

            //SenderTest();
            //ReceiverTest();
            SenderReceiverTest();
        }