jp112

AskSinSniffer328P_SSD1306

Feb 15th, 2020
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //- -----------------------------------------------------------------------------------------------------------------------
  2. // AskSin++
  3. // 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
  4. // 2019-05-24 jp112sdl Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
  5. //- -----------------------------------------------------------------------------------------------------------------------
  6.  
  7. #include <SPI.h>
  8. #define EI_NOTEXTERNAL
  9. #include <EnableInterrupt.h>
  10. #include <AskSinPP.h>
  11. #include <Device.h>
  12. #include <Register.h>
  13. //#include "Ssd1306.h"
  14.  
  15. #define RSSI_POLL_INTERVAL 750 //milliseconds
  16.  
  17. // all library classes are placed in the namespace 'as'
  18. using namespace as;
  19.  
  20. // define all device properties
  21. const struct DeviceInfo PROGMEM devinfo = {
  22.   {0xFF, 0xFF, 0xFF},     // Device ID
  23.   "..........",           // Device Serial
  24.   {0x00, 0x00},           // Device Model
  25.   0x10,                   // Firmware Version
  26.   as::DeviceType::Remote, // Device Type
  27.   {0x00, 0x00}            // Info Bytes
  28. };
  29.  
  30. typedef AskSin<StatusLed<4>, NoBattery, Radio<LibSPI<10>, 2>> HalType;
  31.  
  32. class SnifferDevice : public Device<HalType, DefList0>, Alarm {
  33.     DefList0 l0;
  34.   public:
  35.     typedef Device<HalType, DefList0> BaseDevice;
  36. #ifdef SSD1306_H_
  37.     DisplayType<3, 0x3C> display;
  38. #endif
  39.     SnifferDevice (const DeviceInfo& i, uint16_t addr) : BaseDevice(i, addr, l0, 0), Alarm(0), l0(addr)  {}
  40.     virtual ~SnifferDevice () {}
  41.  
  42.     virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) {
  43.       set(millis2ticks(RSSI_POLL_INTERVAL));
  44.       clock.add(*this);
  45.       this->radio().pollRSSI();
  46.       DPRINT(":"); DHEX(this->radio().rssi());DPRINTLN(";");
  47. #ifdef SSD1306_H_
  48.       display.printFull(this->radio().rssi());
  49. #endif
  50.     }
  51.  
  52.     virtual bool process(Message& msg) {
  53.       DPRINT(F(":"));
  54.       DHEX(radio().rssi());
  55.       DHEX(msg.length());
  56.       DHEX(msg.count());
  57.       DHEX(msg.flags());
  58.       DHEX(msg.type());
  59.       msg.from().dump();
  60.       msg.to().dump();
  61.       for (uint8_t l = 0; l < msg.length() - 9; l++) DHEX(msg.buffer()[l + 9]);
  62.       DPRINTLN(";");
  63.       this->led().ledOn(millis2ticks(100));
  64.       return true;
  65.     }
  66.  
  67.     bool init (HalType& hal) {
  68.       HMID id;
  69.       this->setHal(hal);
  70.       this->getDeviceID(id);
  71.       hal.init(id);
  72.       hal.config(this->getConfigArea());
  73.       sysclock.add(*this);
  74.       return false;
  75.     }
  76. };
  77.  
  78. HalType hal;
  79. SnifferDevice sdev(devinfo, 0x20);
  80.  
  81. void setup () {
  82.   DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
  83. #ifdef SSD1306_H_
  84.   sdev.display.init();
  85. #endif
  86.   sdev.init(hal);
  87. }
  88.  
  89. void loop() {
  90.   hal.runready();
  91.   sdev.pollRadio();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment