Skip to content

Commit

Permalink
Merge pull request #50 from hideakitai/feature/bump-arxcontainer-to-v…
Browse files Browse the repository at this point in the history
…0.6.0

feat: bump arxcontainer to v0.6.0
  • Loading branch information
hideakitai committed Feb 11, 2024
2 parents fd80df8 + 8032494 commit dca9bae
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 56 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,40 @@ jobs:
- name: WiFi
verbose: true

build-wifis3:
name: "Build Test (WiFiS3): ${{matrix.board.arch}}:${{matrix.board.name}}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
board:
- vendor: arduino
arch: renesas_uno
name: unor4wifi
include:
- index: https://downloads.arduino.cc/packages/package_index.json
board:
vendor: arduino
steps:
- uses: actions/checkout@v4
- name: compile example sketchs
uses: arduino/compile-sketches@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fqbn: ${{matrix.board.vendor}}:${{matrix.board.arch}}:${{matrix.board.name}}
platforms: |
- name: ${{matrix.board.vendor}}:${{matrix.board.arch}}
source-url: ${{matrix.index}}
sketch-paths: |
- examples/arduino/OscWiFi
libraries: |
- source-path: ./
- name: ArxContainer
- name: ArxSmartPtr
- name: ArxTypeTraits
- name: DebugLog
verbose: true

build-wifinina:
name: 'Build Test (WiFiNINA): ${{matrix.board.arch}}:${{matrix.board.name}}'
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion ArduinoOSC/OSCClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace osc {
private:
ElementRef publish_impl(const String& ip, const uint16_t port, const String& addr, ElementRef ref) {
Destination dest {ip, port, addr};
dest_map.insert(make_pair(dest, ref));
dest_map.insert(std::make_pair(dest, ref));
return ref;
}
};
Expand Down
2 changes: 1 addition & 1 deletion ArduinoOSC/OSCServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ namespace osc {

Server<S>& getServer(const uint16_t port) {
if (server_map.find(port) == server_map.end())
server_map.insert(make_pair(port, ServerRef<S>(new Server<S>(port))));
server_map.insert(std::make_pair(port, ServerRef<S>(new Server<S>(port))));
return *(server_map[port].get());
}

Expand Down
10 changes: 5 additions & 5 deletions ArduinoOSC/OscMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace osc {

Message& pushBool(const bool b) {
type_tags += (char)(b ? TYPE_TAG_TRUE : TYPE_TAG_FALSE);
arguments.push_back(make_pair(storage.size(), storage.size()));
arguments.push_back(std::make_pair(storage.size(), storage.size()));
return *this;
}
Message& pushInt32(const int32_t i) { return pushPod(TYPE_TAG_INT32, i); }
Expand All @@ -107,14 +107,14 @@ namespace osc {
Message& pushDouble(const double d) { return pushPod(TYPE_TAG_DOUBLE, d); }
Message& pushString(const String& s) {
type_tags += (char)TYPE_TAG_STRING;
arguments.push_back(make_pair(storage.size(), s.length() + 1));
arguments.push_back(std::make_pair(storage.size(), s.length() + 1));
strcpy(storage.getBytes(s.length() + 1), s.c_str());
return *this;
}
Message& pushBlob(const Blob& b) { return pushBlob(b.data(), b.size()); }
Message& pushBlob(const void* ptr, const size_t num_bytes) {
type_tags += (char)TYPE_TAG_BLOB;
arguments.push_back(make_pair(storage.size(), num_bytes + 4));
arguments.push_back(std::make_pair(storage.size(), num_bytes + 4));
pod2bytes<int32_t>((int32_t)num_bytes, storage.getBytes(4));
if (num_bytes) memcpy(storage.getBytes(num_bytes), ptr, num_bytes);
return *this;
Expand Down Expand Up @@ -222,7 +222,7 @@ namespace osc {
size_t iarg = 0;
while (iarg < type_tags.length()) {
size_t len = getArgSize(type_tags[iarg], arg);
arguments.push_back(make_pair((size_t)(arg - storage.begin()), len));
arguments.push_back(std::make_pair((size_t)(arg - storage.begin()), len));
arg += ceil4(len);
++iarg;
}
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace osc {
template <typename POD>
Message& pushPod(const int tag, const POD& v) {
type_tags += (char)tag;
arguments.push_back(make_pair(storage.size(), sizeof(POD)));
arguments.push_back(std::make_pair(storage.size(), sizeof(POD)));
pod2bytes(v, storage.getBytes(sizeof(POD)));
return *this;
}
Expand Down
26 changes: 13 additions & 13 deletions ArduinoOSC/OscTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,47 +92,47 @@ namespace osc {
template <typename S>
using UdpRef = std::shared_ptr<S>;
template <typename S>
using UdpMap = arx::map<uint16_t, UdpRef<S>, ARDUINOOSC_MAX_SUBSCRIBE_PORTS>;
using UdpMap = arx::stdx::map<uint16_t, UdpRef<S>, ARDUINOOSC_MAX_SUBSCRIBE_PORTS>;

namespace message {
using ArgumentType = arx::pair<size_t, size_t>;
using ArgumentQueue = arx::vector<ArgumentType, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
using ArgumentType = arx::stdx::pair<size_t, size_t>;
using ArgumentQueue = arx::stdx::vector<ArgumentType, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
class Message;
using MessageQueue = arx::vector<Message, ARDUINOOSC_MAX_MSG_QUEUE_SIZE>;
using MessageQueue = arx::stdx::vector<Message, ARDUINOOSC_MAX_MSG_QUEUE_SIZE>;
} // namespace message
#ifndef ARDUINOOSC_DISABLE_BUNDLE
using BundleData = arx::vector<uint32_t, ARDUINOOSC_MAX_MSG_BUNDLE_SIZE>;
using BundleData = arx::stdx::vector<uint32_t, ARDUINOOSC_MAX_MSG_BUNDLE_SIZE>;
#endif
using Blob = arx::vector<char, ARDUINOOSC_MAX_MSG_BYTE_SIZE>;
using Blob = arx::stdx::vector<char, ARDUINOOSC_MAX_MSG_BYTE_SIZE>;

namespace client {
namespace element {
class Base;
using Ref = std::shared_ptr<Base>;
using TupleRef = arx::vector<Ref, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
using TupleRef = arx::stdx::vector<Ref, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
} // namespace element
class Destination;
using ElementRef = element::Ref;
using ElementTupleRef = element::TupleRef;
using DestinationMap = arx::map<Destination, ElementRef, ARDUINOOSC_MAX_PUBLISH_DESTINATION>;
using DestinationMap = arx::stdx::map<Destination, ElementRef, ARDUINOOSC_MAX_PUBLISH_DESTINATION>;
} // namespace client

namespace server {
namespace element {
class Base;
using Ref = std::shared_ptr<Base>;
using TupleRef = arx::vector<Ref, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
using dummy_vector_t = arx::vector<size_t, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
using TupleRef = arx::stdx::vector<Ref, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
using dummy_vector_t = arx::stdx::vector<size_t, ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE>;
} // namespace element
using ElementRef = element::Ref;
using ElementTupleRef = element::TupleRef;
using CallbackMap = arx::map<String, ElementRef, ARDUINOOSC_MAX_SUBSCRIBE_ADDRESS_PER_PORT>;
using CallbackMap = arx::stdx::map<String, ElementRef, ARDUINOOSC_MAX_SUBSCRIBE_ADDRESS_PER_PORT>;
template <typename S>
class Server;
template <typename S>
using ServerRef = std::shared_ptr<Server<S>>;
template <typename S>
using ServerMap = arx::map<uint16_t, ServerRef<S>, ARDUINOOSC_MAX_SUBSCRIBE_PORTS>;
using ServerMap = arx::stdx::map<uint16_t, ServerRef<S>, ARDUINOOSC_MAX_SUBSCRIBE_PORTS>;
} // namespace server

} // namespace osc
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace osc {
struct Storage {
Blob data;

// reserve() makes no sense on arx::vector because capacity is fixed
// reserve() makes no sense on arx::stdx::vector because capacity is fixed
Storage() { data.reserve(200); }

char* getBytes(const size_t sz) {
Expand Down
4 changes: 2 additions & 2 deletions ArduinoOSC/OscUdpMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace osc {
// use first port for PORT_DISCARD if some udp instances exist
if (port == PORT_DISCARD) {
if (udp_map.empty()) {
udp_map.insert(make_pair(port, UdpRef<S>(new S())));
udp_map.insert(std::make_pair(port, UdpRef<S>(new S())));
udp_map[port]->begin(port);
}
return udp_map.begin()->second;
Expand All @@ -53,7 +53,7 @@ namespace osc {
udp_discard_ref->second->stop();
udp_map.erase(udp_discard_ref);
}
udp_map.insert(make_pair(port, UdpRef<S>(new S())));
udp_map.insert(std::make_pair(port, UdpRef<S>(new S())));
udp_map[port]->begin(port);
}
return udp_map[port];
Expand Down
4 changes: 3 additions & 1 deletion ArduinoOSCWiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#if defined(ESP_PLATFORM) || defined(ESP8266) || defined(ARDUINO_AVR_UNO_WIFI_REV2) \
|| defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(ARDUINO_SAMD_MKR1000) \
|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_RASPBERRY_PI_PICO_W)
|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_UNOR4_WIFI)
#define ARDUINOOSC_ENABLE_WIFI
#endif

Expand All @@ -23,6 +23,8 @@
#include <SPI.h>
#include <WiFi101.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_UNOR4_WIFI)
#include <WiFiS3.h>
#endif
#include "ArduinoOSC/ArduinoOSCCommon.h"
using OscWiFiManager = ArduinoOSC::Manager<WiFiUDP>;
Expand Down
45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

OSC subscriber / publisher for Arduino


#### NOTE (>= v0.3.x) : BREAKING API CHANGES

- almost all apis has have changed and got much simpler
Expand All @@ -19,22 +18,21 @@ If you have already installed this library, please follow:
## Feature

- simple usage
- flexible callback registration with lambda
- directly binding osc packet to values
- osc packet sending in one-line
- publishing osc packet in one-line
- flexible callback registration with lambda
- directly binding osc packet to values
- osc packet sending in one-line
- publishing osc packet in one-line
- support basic OSC types based on [oscpkt](http://gruntthepeon.free.fr/oscpkt/html/)
- TF (`bool`: true, false)
- i (`int32_t`)
- h (`int64_t`)
- f (`float`)
- d (`double`)
- s (`string`)
- b (`bundle`)
- TF (`bool`: true, false)
- i (`int32_t`)
- h (`int64_t`)
- f (`float`)
- d (`double`)
- s (`string`)
- b (`bundle`)
- support pattern-matching (wildcards)
- does NOT support timestamp values.


## Usage

### Include ArduinoOSC
Expand Down Expand Up @@ -85,7 +83,7 @@ void loop() {

### Bind OSC to Lambda Arguments and One-Line Send

``` C++
```C++
void setup() {
// WiFi stuff
// ...
Expand All @@ -110,7 +108,7 @@ void loop() {

### Other Way to Subscribe

``` C++
```C++
// OscMessage as lambda argument
OscWiFi.subscribe(recv_port, "/lambda/msg",
[](const OscMessage& m) {
Expand Down Expand Up @@ -144,7 +142,6 @@ OscWiFi.subscribe(recv_port, "/need/reply", []() {
OscWiFi.subscribe(recv_port, "/callback", onOscReceived);
```


## Supported Platform

This library currently supports following platforms and interfaces.
Expand All @@ -155,6 +152,7 @@ Please feel free to send PR or request for more board support!
- ESP32
- ESP8266
- Raspberry Pi Pico W
- Arduino Uno R4 WiFi
- Arduino Uno WiFi Rev2
- Arduino MKR VIDOR 4000
- Arduino MKR WiFi 1010
Expand All @@ -165,7 +163,6 @@ Please feel free to send PR or request for more board support!

- Almost all platforms which has `Ethernet` (and `ETH`) library


## Limitation and Options for NO-STL Boards

STL is used to handle packet data by default, but for following boards/architectures, [ArxContainer](https://github.com/hideakitai/ArxContainer) is used to store the packet data because STL can not be used for such boards.
Expand All @@ -174,15 +171,14 @@ The storage size of such boards for packets, queue of packets, max packet binary
- AVR
- megaAVR


### Usage Recommendation for Arduino Uno (and other boards with tiny memory size)

For the boards which has tiny memory size (e.g. Arduino Uno), I reccomend not to use publisher and subscriber.
Though you can use them on such boards, such rich functions requires more memory.
The reccomended way is to use `send` and `parse` manually.
The example is shown in `examples/arduino/OscEtherUno`, so please consider to use it.

``` C++
```C++
#include <ArduinoOSCEther.h>
// #include <ArduinoOSC.h> // you can use this because Uno supports only Ethernet

Expand Down Expand Up @@ -219,14 +215,13 @@ void loop() {
}
```
### Memory Management (only for NO-STL Boards)
As mentioned above, for such boards like Arduino Uno, the storage sizes are limited.
And of course you can manage them by defining following macros.
But these default values are optimized for such boards, please be careful not to excess your boards storage/memory.
``` C++
```C++
#define ARDUINOOSC_MAX_MSG_ARGUMENT_SIZE 8
#define ARDUINOOSC_MAX_MSG_BYTE_SIZE 128
#define ARDUINOOSC_MAX_MSG_QUEUE_SIZE 1
Expand All @@ -241,22 +236,20 @@ OSC bundle option is disabled for such boards.
If you want to use that, please use this macro and handle packets manually.
`ArduinoOSC` does not use bundle by default.

``` C++
```C++
#define ARDUINOOSC_ENABLE_BUNDLE
#define ARDUINOOSC_MAX_MSG_BUNDLE_SIZE 128
```
### Enable Debug Logger
You can see the debug log when you insert following line before include `ArduinoOSC`.
``` C++
```C++
#define ARDUINOOSC_DEBUGLOG_ENABLE
#include <ArduinoOSC.h>
```


## Dependent Libraries

- [ArxTypeTraits](https://github.com/hideakitai/ArxTypeTraits)
Expand All @@ -268,12 +261,10 @@ You can see the debug log when you insert following line before include `Arduino

- [TeensyDirtySTLErrorSolution v0.1.0](https://github.com/hideakitai/TeensyDirtySTLErrorSolution)


## Special Thanks

- [ofxPubSubOsc](https://github.com/2bbb/ofxPubSubOsc)


## License

MIT
4 changes: 2 additions & 2 deletions examples/arduino/OscEther/OscEther.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

// Ethernet stuff
uint8_t mac[] = {0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45};
const IPAddress ip(192, 168, 1, 201);
const IPAddress ip(192, 168, 0, 201);
// Ethernet with useful options
// const IPAddress dns (192, 168, 1, 1);
// const IPAddress gateway (192, 168, 1, 1);
// const IPAddress subnet (255, 255, 255, 0);

// for ArduinoOSC
const char* host = "192.168.1.200";
const char* host = "192.168.0.200";
const int recv_port = 54321;
const int bind_port = 54345;
const int send_port = 55555;
Expand Down
Loading

0 comments on commit dca9bae

Please sign in to comment.