diff options
author | Federico Fissore <f.fissore@arduino.cc> | 2013-07-18 14:07:39 +0200 |
---|---|---|
committer | Federico Fissore <f.fissore@arduino.cc> | 2013-07-18 14:07:39 +0200 |
commit | 92cb63b843604f07a153c5eb893582638250a3c3 (patch) | |
tree | 5202f5ec2b11290aa1d4a3a02dd29bc3d1c9e098 /libraries/SpacebrewYun/SpacebrewYun.h | |
parent | 36cc2c89e740a3a170bae02d1e48ea52625505a0 (diff) |
SpacebrewYun: added new example
Diffstat (limited to 'libraries/SpacebrewYun/SpacebrewYun.h')
-rw-r--r-- | libraries/SpacebrewYun/SpacebrewYun.h | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/libraries/SpacebrewYun/SpacebrewYun.h b/libraries/SpacebrewYun/SpacebrewYun.h new file mode 100644 index 0000000..8fd7bd2 --- /dev/null +++ b/libraries/SpacebrewYun/SpacebrewYun.h @@ -0,0 +1,122 @@ + +#ifndef YUNSPACEBREW_H +#define YUNSPACEBREW_H + +#include "Arduino.h" +#include <Bridge.h> +#include <Console.h> +#include <Process.h> + +enum SBmsg { + CONNECTION_START = char(28), + CONNECTION_END = char(27), + CONNECTION_ERROR = char(26), + MSG_START = char(29), + MSG_DIV = char(30), + MSG_END = char(31) +}; + +struct Publisher { + char *name; + char *type; + char *defaultValue; + Publisher * next; +}; + +struct Subscriber{ + char *name; + char *type; + Subscriber * next; +}; + +int const pidLength = 6; +int const sbPidsLen = 4; + +class SpacebrewYun { + + public: + + SpacebrewYun(const String&, const String&); + void addPublish(const String&, const String&); + void addSubscribe(const String&, const String&); + + void connect(String, int); + void connect() { connect(server, port); }; + void connect(String _server) { connect(String(_server), port); }; + + void monitor(); + void onMessage(); + + boolean connected(); + + void send(const String&, const String&); + void send(const String& name, char * value) { send(name, String(value)); } + void send(const String& name, bool value){ send(name, (value ? "true" : "false")); }; + void send(const String& name, int value) { send(name, String(value)); }; + void send(const String& name, long value) { send(name, String(value)); }; + void send(const String& name, float value) { send(name, String(value)); }; + + void verbose(boolean); + + typedef void (*OnBooleanMessage)(String name, boolean value); + typedef void (*OnRangeMessage)(String name, int value); + typedef void (*OnStringMessage)(String name, String value); + typedef void (*OnCustomMessage)(String name, String value, String type); + typedef void (*OnSBOpen)(); + typedef void (*OnSBClose)(); + typedef void (*OnSBError)(int code, String message); + + void onOpen(OnSBOpen function); + void onClose(OnSBClose function); + void onRangeMessage(OnRangeMessage function); + void onStringMessage(OnStringMessage function); + void onBooleanMessage(OnBooleanMessage function); + void onCustomMessage(OnCustomMessage function); + void onError(OnSBError function); + + private: + + Process brew; + String name; + String server; + String description; + boolean _connected; + boolean _error_msg; + boolean _verbose; + int port; + + /**Output should be at least 5 cells**/ + static OnBooleanMessage _onBooleanMessage; + static OnRangeMessage _onRangeMessage; + static OnStringMessage _onStringMessage; + static OnCustomMessage _onCustomMessage; + static OnSBOpen _onOpen; + static OnSBClose _onClose; + static OnSBError _onError; + + Subscriber * subscribers; + Publisher * publishers; + String sub_name; + String sub_msg; + String sub_type; + + boolean read_name; + boolean read_msg; + int sub_name_max; + int sub_msg_max; + + Process pids; + char pid [6]; + int sbPids [4]; + + void killPids(); + void getPids(); + + static char * createString(int len){ + char * out = ( char * )malloc( len + 1 ); + return out; + } + +}; + +#endif |