target.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/ArduinoHelpers.h>
  4. #include <helpers/sensors/LocationProvider.h>
  5. class WM1110LocationProvider : public LocationProvider {
  6. public:
  7. long getLatitude() override { return 0; }
  8. long getLongitude() override { return 0; }
  9. long getAltitude() override { return 0; }
  10. long satellitesCount() override { return 0; }
  11. bool isValid() override { return false; }
  12. long getTimestamp() override { return 0; }
  13. void sendSentence(const char* sentence) override {}
  14. void reset() override {}
  15. void begin() override {}
  16. void stop() override {}
  17. void loop() override {}
  18. bool isEnabled() override { return false; }
  19. };
  20. WioWM1110Board board;
  21. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
  22. WRAPPER_CLASS radio_driver(radio, board);
  23. VolatileRTCClock rtc_clock;
  24. WM1110LocationProvider location_provider;
  25. EnvironmentSensorManager sensors(location_provider);
  26. #ifndef LORA_CR
  27. #define LORA_CR 5
  28. #endif
  29. #ifdef RF_SWITCH_TABLE
  30. static const uint32_t rfswitch_dios[Module::RFSWITCH_MAX_PINS] = {
  31. RADIOLIB_LR11X0_DIO5,
  32. RADIOLIB_LR11X0_DIO6,
  33. RADIOLIB_LR11X0_DIO7,
  34. RADIOLIB_LR11X0_DIO8,
  35. RADIOLIB_NC
  36. };
  37. static const Module::RfSwitchMode_t rfswitch_table[] = {
  38. // mode DIO5 DIO6 DIO7 DIO8
  39. { LR11x0::MODE_STBY, {LOW, LOW, LOW, LOW }},
  40. { LR11x0::MODE_RX, {HIGH, LOW, LOW, HIGH }},
  41. { LR11x0::MODE_TX, {HIGH, HIGH, LOW, HIGH }},
  42. { LR11x0::MODE_TX_HP, {LOW, HIGH, LOW, HIGH }},
  43. { LR11x0::MODE_TX_HF, {LOW, LOW, LOW, LOW }},
  44. { LR11x0::MODE_GNSS, {LOW, LOW, HIGH, LOW }},
  45. { LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW }},
  46. END_OF_MODE_TABLE,
  47. };
  48. #endif
  49. bool radio_init() {
  50. board.enableSensorPower(true);
  51. #ifdef LR11X0_DIO3_TCXO_VOLTAGE
  52. float tcxo = LR11X0_DIO3_TCXO_VOLTAGE;
  53. #else
  54. float tcxo = 1.8f;
  55. #endif
  56. SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
  57. SPI.begin();
  58. int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
  59. if (status != RADIOLIB_ERR_NONE) {
  60. Serial.print("ERROR: radio init failed: ");
  61. Serial.println(status);
  62. return false; // fail
  63. }
  64. radio.setCRC(2);
  65. radio.explicitHeader();
  66. #ifdef RF_SWITCH_TABLE
  67. radio.setRfSwitchTable(rfswitch_dios, rfswitch_table);
  68. #endif
  69. #ifdef RX_BOOSTED_GAIN
  70. radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
  71. #endif
  72. return true; // success
  73. }
  74. uint32_t radio_get_rng_seed() {
  75. return radio.random(0x7FFFFFFF);
  76. }
  77. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  78. radio.setFrequency(freq);
  79. radio.setSpreadingFactor(sf);
  80. radio.setBandwidth(bw);
  81. radio.setCodingRate(cr);
  82. }
  83. void radio_set_tx_power(uint8_t dbm) {
  84. radio.setOutputPower(dbm);
  85. }
  86. mesh::LocalIdentity radio_new_identity() {
  87. RadioNoiseListener rng(radio);
  88. return mesh::LocalIdentity(&rng); // create new random identity
  89. }