Beispiel #1
0
 public RadioRegister(bool continuousCarrierTransmitEnabled, bool pllLockEnabled, DataRateEnum dataRate, OutputPowerEnum outputPower)
 {
     ContinuousCarrierTransmitEnabled = continuousCarrierTransmitEnabled;
     PllLockEnabled = pllLockEnabled;
     DataRate       = dataRate;
     OutputPower    = outputPower;
 }
Beispiel #2
0
        public Module(PinNumberEnum chipEnable, SpiChannelEnum channel, [NotNull] Address address, [NotNull] Address broadcastAddress, byte radioChannel,
                      bool sendContinuously         = false, bool readRetransmissionsCount = false,
                      OutputPowerEnum outputPower   = OutputPowerEnum.P0dbm, DataRateEnum dataRate    = DataRateEnum.S1Mbps,
                      byte autoRetransmitRetryLimit = 10, AutoRetransmitDelayEnum autoRetransmitDelay = AutoRetransmitDelayEnum.T2000us,
                      int spiSpeed = Nrf.DefaultSpiSpeed)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }
            if (broadcastAddress == null)
            {
                throw new ArgumentNullException(nameof(broadcastAddress));
            }

            Packet.BaseAddress = address;

            Address          = address;
            BroadcastAddress = broadcastAddress;

            _sendContinuously         = sendContinuously;
            _readRetransmissionsCount = readRetransmissionsCount;

            _nrf = new Nrf(chipEnable, channel, spiSpeed);

            if (!_nrf.IsConnected)
            {
                throw new InvalidOperationException("NRF doesn't seem to be connected.");
            }

            _nrf.WriteRegister(new ConfigurationRegister(false, false, false, true, CrcLengthEnum.TwoBytes, PowerStateEnum.Down, TransceiverModeEnum.Receiver));
            _nrf.WriteRegister(new AutoAcknowledgmentRegister(true, true, false, false, false, false));
            _nrf.WriteRegister(new ReceiverAddressRegister(true, true, false, false, false, false));
            _nrf.WriteRegister(new AddressWidthRegister(AddressWidthEnum.FiveBytes));
            _nrf.WriteRegister(new AutoRetransmissionRegister(autoRetransmitDelay, autoRetransmitRetryLimit));
            _nrf.WriteRegister(new FrequencyChannelRegister(radioChannel));
            _nrf.WriteRegister(new RadioRegister(false, false, dataRate, outputPower));
            _nrf.WriteRegister(new FeatureRegister(false, false, true));
            _nrf.WriteRegister(new DynamicPayloadLengthRegister(false, false, false, false, false, false));

            _nrf.Flush();

            _nrf.SetPipeReceiveAddress(1, Address);

            _nrf.ModifyRegister <ConfigurationRegister>(RegisterEnum.Configuration, register => register.TransceiverMode = TransceiverModeEnum.Transmitter);

            _nrf.SetupDelay();

            _nrf.ChangePowerState(PowerStateEnum.Up);

            // Standby-I

            _worker = new BackgroundWorker
            {
                WorkerSupportsCancellation = true,
            };

            _worker.DoWork             += Work;
            _worker.RunWorkerCompleted += WorkCompleted;
        }