ArduinoOSC.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef ARDUINOOSC_H
  2. #define ARDUINOOSC_H
  3. #include "ArduinoOSC/OSCServer.h"
  4. #include "ArduinoOSC/OSCClient.h"
  5. #ifdef TEENSYDUINO // dirty
  6. namespace std
  7. {
  8. void __throw_bad_alloc() { _GLIBCXX_THROW_OR_ABORT(bad_alloc()); }
  9. void __throw_length_error(const char* __s __attribute__((unused))) { _GLIBCXX_THROW_OR_ABORT(length_error(_(__s))); }
  10. void __throw_bad_function_call() { _GLIBCXX_THROW_OR_ABORT(bad_function_call()); }
  11. }
  12. #endif
  13. namespace ArduinoOSC
  14. {
  15. bool match(const String& pattern, const String& test, bool full = true)
  16. {
  17. if (full) return oscpkt::fullPatternMatch(pattern.c_str(), test.c_str());
  18. else return oscpkt::partialPatternMatch(pattern.c_str(), test.c_str());
  19. }
  20. template <typename S>
  21. class ArduinoOSCUdp : public OscServerUdp<S>, public OscClientUdp<S>
  22. {
  23. public:
  24. void begin(uint32_t port)
  25. {
  26. stream.begin(port);
  27. this->OscServerUdp<S>::attach(stream);
  28. this->OscClientUdp<S>::attach(stream);
  29. }
  30. private:
  31. S stream;
  32. };
  33. class ArduinoOSCSerial : public OscServerSerial, public OscClientSerial
  34. {
  35. public:
  36. void attach(Stream& s)
  37. {
  38. stream = &s;
  39. this->OscServerSerial::attach(*stream);
  40. this->OscClientSerial::attach(*stream);
  41. }
  42. private:
  43. Stream* stream;
  44. };
  45. }
  46. #if defined (ESP_PLATFORM) || defined (ESP8266)
  47. using OscWiFi = ArduinoOSC::ArduinoOSCUdp<WiFiUDP>;
  48. #elif defined (TEENSYDUINO) || defined (__AVR__)
  49. using OscEthernet = ArduinoOSC::ArduinoOSCUdp<EthernetUDP>;
  50. #endif
  51. using OscSerial = ArduinoOSC::ArduinoOSCSerial;
  52. using OscMessage = ArduinoOSC::OscMessage;
  53. using OscReader = ArduinoOSC::OscReader;
  54. using OscWriter = ArduinoOSC::OscWriter;
  55. #endif // ARDUINOOSC_H