mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Run new astyle formatter against libs Bridge, SpacebrewYun and Temboo
This commit is contained in:
parent
b4c68b3dff
commit
00bdd3df03
@ -33,12 +33,12 @@ void BridgeClass::begin() {
|
||||
do {
|
||||
dropAll();
|
||||
delay(1000);
|
||||
} while (stream.available()>0);
|
||||
} while (stream.available() > 0);
|
||||
|
||||
while (true) {
|
||||
// Bridge interrupt:
|
||||
// - Ask the bridge to close itself
|
||||
uint8_t quit_cmd[] = {'X','X','X','X','X'};
|
||||
uint8_t quit_cmd[] = {'X', 'X', 'X', 'X', 'X'};
|
||||
max_retries = 1;
|
||||
transfer(quit_cmd, 5);
|
||||
|
||||
@ -57,7 +57,7 @@ void BridgeClass::begin() {
|
||||
dropAll();
|
||||
|
||||
// Reset the brigde to check if it is running
|
||||
uint8_t cmd[] = {'X','X', '1','0','0'};
|
||||
uint8_t cmd[] = {'X', 'X', '1', '0', '0'};
|
||||
uint8_t res[1];
|
||||
max_retries = 50;
|
||||
uint16_t l = transfer(cmd, 5, res, 1);
|
||||
@ -121,7 +121,7 @@ uint16_t BridgeClass::transfer(const uint8_t *buff1, uint16_t len1,
|
||||
{
|
||||
uint16_t len = len1 + len2 + len3;
|
||||
uint8_t retries = 0;
|
||||
for ( ; retries<max_retries; retries++, delay(100), dropAll() /* Delay for retransmission */) {
|
||||
for ( ; retries < max_retries; retries++, delay(100), dropAll() /* Delay for retransmission */) {
|
||||
// Send packet
|
||||
crcReset();
|
||||
stream.write((char)0xFF); // Start of packet (0xFF)
|
||||
@ -132,15 +132,15 @@ uint16_t BridgeClass::transfer(const uint8_t *buff1, uint16_t len1,
|
||||
crcUpdate((len >> 8) & 0xFF);
|
||||
stream.write((char)(len & 0xFF)); // Message length (lo)
|
||||
crcUpdate(len & 0xFF);
|
||||
for (uint16_t i=0; i<len1; i++) { // Payload
|
||||
for (uint16_t i = 0; i < len1; i++) { // Payload
|
||||
stream.write((char)buff1[i]);
|
||||
crcUpdate(buff1[i]);
|
||||
}
|
||||
for (uint16_t i=0; i<len2; i++) { // Payload
|
||||
for (uint16_t i = 0; i < len2; i++) { // Payload
|
||||
stream.write((char)buff2[i]);
|
||||
crcUpdate(buff2[i]);
|
||||
}
|
||||
for (uint16_t i=0; i<len3; i++) { // Payload
|
||||
for (uint16_t i = 0; i < len3; i++) { // Payload
|
||||
stream.write((char)buff3[i]);
|
||||
crcUpdate(buff3[i]);
|
||||
}
|
||||
@ -171,7 +171,7 @@ uint16_t BridgeClass::transfer(const uint8_t *buff1, uint16_t len1,
|
||||
l += ll;
|
||||
|
||||
// Recv data
|
||||
for (uint16_t i=0; i<l; i++) {
|
||||
for (uint16_t i = 0; i < l; i++) {
|
||||
int c = timedRead(5);
|
||||
if (c < 0)
|
||||
continue;
|
||||
@ -188,7 +188,7 @@ uint16_t BridgeClass::transfer(const uint8_t *buff1, uint16_t len1,
|
||||
int crc_lo = timedRead(5);
|
||||
if (crc_lo < 0)
|
||||
continue;
|
||||
if (!crcCheck((crc_hi<<8)+crc_lo))
|
||||
if (!crcCheck((crc_hi << 8) + crc_lo))
|
||||
continue;
|
||||
|
||||
// Increase index
|
||||
@ -210,7 +210,7 @@ int BridgeClass::timedRead(unsigned int timeout) {
|
||||
do {
|
||||
c = stream.read();
|
||||
if (c >= 0) return c;
|
||||
} while(millis() - _startMillis < timeout);
|
||||
} while (millis() - _startMillis < timeout);
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
@ -222,8 +222,8 @@ void BridgeClass::dropAll() {
|
||||
|
||||
// Bridge instance
|
||||
#ifdef __AVR_ATmega32U4__
|
||||
// Leonardo variants (where HardwareSerial is Serial1)
|
||||
SerialBridgeClass Bridge(Serial1);
|
||||
// Leonardo variants (where HardwareSerial is Serial1)
|
||||
SerialBridgeClass Bridge(Serial1);
|
||||
#else
|
||||
SerialBridgeClass Bridge(Serial);
|
||||
SerialBridgeClass Bridge(Serial);
|
||||
#endif
|
||||
|
@ -23,17 +23,21 @@
|
||||
#include <Stream.h>
|
||||
|
||||
class BridgeClass {
|
||||
public:
|
||||
public:
|
||||
BridgeClass(Stream &_stream);
|
||||
void begin();
|
||||
|
||||
// Methods to handle key/value datastore
|
||||
void put(const char *key, const char *value);
|
||||
void put(const String &key, const String &value)
|
||||
{ put(key.c_str(), value.c_str()); }
|
||||
{
|
||||
put(key.c_str(), value.c_str());
|
||||
}
|
||||
unsigned int get(const char *key, uint8_t *buff, unsigned int size);
|
||||
unsigned int get(const char *key, char *value, unsigned int maxlen)
|
||||
{ get(key, reinterpret_cast<uint8_t *>(value), maxlen); }
|
||||
{
|
||||
get(key, reinterpret_cast<uint8_t *>(value), maxlen);
|
||||
}
|
||||
|
||||
// Trasnfer a frame (with error correction and response)
|
||||
uint16_t transfer(const uint8_t *buff1, uint16_t len1,
|
||||
@ -42,30 +46,36 @@ public:
|
||||
uint8_t *rxbuff, uint16_t rxlen);
|
||||
// multiple inline versions of the same function to allow efficient frame concatenation
|
||||
uint16_t transfer(const uint8_t *buff1, uint16_t len1)
|
||||
{ return transfer(buff1, len1, NULL, 0); }
|
||||
{
|
||||
return transfer(buff1, len1, NULL, 0);
|
||||
}
|
||||
uint16_t transfer(const uint8_t *buff1, uint16_t len1,
|
||||
uint8_t *rxbuff, uint16_t rxlen)
|
||||
{ return transfer(buff1, len1, NULL, 0, rxbuff, rxlen); }
|
||||
{
|
||||
return transfer(buff1, len1, NULL, 0, rxbuff, rxlen);
|
||||
}
|
||||
uint16_t transfer(const uint8_t *buff1, uint16_t len1,
|
||||
const uint8_t *buff2, uint16_t len2,
|
||||
uint8_t *rxbuff, uint16_t rxlen)
|
||||
{ return transfer(buff1, len1, buff2, len2, NULL, 0, rxbuff, rxlen); }
|
||||
{
|
||||
return transfer(buff1, len1, buff2, len2, NULL, 0, rxbuff, rxlen);
|
||||
}
|
||||
|
||||
static const int TRANSFER_TIMEOUT = 0xFFFF;
|
||||
|
||||
private:
|
||||
private:
|
||||
uint8_t index;
|
||||
int timedRead(unsigned int timeout);
|
||||
void dropAll();
|
||||
|
||||
private:
|
||||
private:
|
||||
void crcUpdate(uint8_t c);
|
||||
void crcReset();
|
||||
void crcWrite();
|
||||
bool crcCheck(uint16_t _CRC);
|
||||
uint16_t CRC;
|
||||
|
||||
private:
|
||||
private:
|
||||
static const char CTRL_C = 3;
|
||||
Stream &stream;
|
||||
bool started;
|
||||
@ -74,7 +84,7 @@ private:
|
||||
|
||||
// This subclass uses a serial port Stream
|
||||
class SerialBridgeClass : public BridgeClass {
|
||||
public:
|
||||
public:
|
||||
SerialBridgeClass(HardwareSerial &_serial)
|
||||
: BridgeClass(_serial), serial(_serial) {
|
||||
// Empty
|
||||
@ -85,7 +95,7 @@ public:
|
||||
BridgeClass::begin();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
HardwareSerial &serial;
|
||||
};
|
||||
|
||||
|
@ -53,10 +53,10 @@ size_t ConsoleClass::write(uint8_t c) {
|
||||
size_t ConsoleClass::write(const uint8_t *buff, size_t size) {
|
||||
if (autoFlush) {
|
||||
// TODO: do it in a more efficient way
|
||||
uint8_t *tmp = new uint8_t[size+1];
|
||||
uint8_t *tmp = new uint8_t[size + 1];
|
||||
tmp[0] = 'P';
|
||||
memcpy(tmp+1, buff, size);
|
||||
bridge.transfer(tmp, size+1);
|
||||
memcpy(tmp + 1, buff, size);
|
||||
bridge.transfer(tmp, size + 1);
|
||||
delete[] tmp;
|
||||
return size;
|
||||
} else {
|
||||
@ -86,11 +86,11 @@ void ConsoleClass::noBuffer() {
|
||||
|
||||
void ConsoleClass::buffer(uint8_t size) {
|
||||
noBuffer();
|
||||
if (size==0)
|
||||
if (size == 0)
|
||||
return;
|
||||
outBuffer = new uint8_t[size+1];
|
||||
outBuffer = new uint8_t[size + 1];
|
||||
outBuffer[0] = 'P'; // WRITE tag
|
||||
outBufferSize = size+1;
|
||||
outBufferSize = size + 1;
|
||||
outBuffered = 1;
|
||||
autoFlush = false;
|
||||
}
|
||||
@ -98,7 +98,7 @@ void ConsoleClass::buffer(uint8_t size) {
|
||||
bool ConsoleClass::connected() {
|
||||
uint8_t tmp = 'a';
|
||||
bridge.transfer(&tmp, 1, &tmp, 1);
|
||||
return tmp==1;
|
||||
return tmp == 1;
|
||||
}
|
||||
|
||||
int ConsoleClass::available() {
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <Bridge.h>
|
||||
|
||||
class ConsoleClass : public Stream {
|
||||
public:
|
||||
public:
|
||||
// Default constructor uses global Bridge instance
|
||||
ConsoleClass();
|
||||
// Constructor with a user provided BridgeClass instance
|
||||
@ -47,9 +47,11 @@ public:
|
||||
size_t write(const uint8_t *buffer, size_t size);
|
||||
void flush();
|
||||
|
||||
operator bool () { return connected(); }
|
||||
operator bool () {
|
||||
return connected();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
BridgeClass &bridge;
|
||||
|
||||
void doBuffer();
|
||||
|
@ -26,7 +26,7 @@ File::File(BridgeClass &b) : mode(255), bridge(b) {
|
||||
|
||||
File::File(const char *_filename, uint8_t _mode, BridgeClass &b) : mode(_mode), bridge(b) {
|
||||
filename = _filename;
|
||||
char modes[] = {'r','w','a'};
|
||||
char modes[] = {'r', 'w', 'a'};
|
||||
uint8_t cmd[] = {'F', modes[mode]};
|
||||
uint8_t res[2];
|
||||
dirPosition = 1;
|
||||
@ -91,7 +91,7 @@ boolean File::seek(uint32_t position) {
|
||||
};
|
||||
uint8_t res[1];
|
||||
bridge.transfer(cmd, 6, res, 1);
|
||||
if (res[0]==0) {
|
||||
if (res[0] == 0) {
|
||||
// If seek succeed then flush buffers
|
||||
buffered = 0;
|
||||
return true;
|
||||
@ -121,10 +121,10 @@ void File::doBuffer() {
|
||||
uint8_t cmd[] = {'G', handle, BUFFER_SIZE - 1};
|
||||
buffered = bridge.transfer(cmd, 3, buffer, BUFFER_SIZE) - 1;
|
||||
//err = buff[0]; // First byte is error code
|
||||
if (buffered>0) {
|
||||
if (buffered > 0) {
|
||||
// Shift the reminder of buffer
|
||||
for (uint8_t i=0; i<buffered; i++)
|
||||
buffer[i] = buffer[i+1];
|
||||
for (uint8_t i = 0; i < buffered; i++)
|
||||
buffer[i] = buffer[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ boolean File::isDirectory() {
|
||||
}
|
||||
|
||||
|
||||
File File::openNextFile(uint8_t mode){
|
||||
File File::openNextFile(uint8_t mode) {
|
||||
Process awk;
|
||||
char tmp;
|
||||
String command;
|
||||
@ -181,23 +181,23 @@ File File::openNextFile(uint8_t mode){
|
||||
|
||||
awk.runShellCommand(command);
|
||||
|
||||
while(awk.running());
|
||||
while (awk.running());
|
||||
|
||||
command = "";
|
||||
|
||||
while (awk.available()){
|
||||
while (awk.available()) {
|
||||
tmp = awk.read();
|
||||
if (tmp!='\n') command += tmp;
|
||||
if (tmp != '\n') command += tmp;
|
||||
}
|
||||
if (command.length() == 0)
|
||||
return File();
|
||||
dirPosition++;
|
||||
filepath = filename + "/" + command;
|
||||
return File(filepath.c_str(),mode);
|
||||
return File(filepath.c_str(), mode);
|
||||
|
||||
}
|
||||
|
||||
void File::rewindDirectory(void){
|
||||
void File::rewindDirectory(void) {
|
||||
dirPosition = 1;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
class File : public Stream {
|
||||
|
||||
public:
|
||||
public:
|
||||
File(BridgeClass &b = Bridge);
|
||||
File(const char *_filename, uint8_t _mode, BridgeClass &b = Bridge);
|
||||
~File();
|
||||
@ -51,7 +51,7 @@ public:
|
||||
|
||||
//using Print::write;
|
||||
|
||||
private:
|
||||
private:
|
||||
void doBuffer();
|
||||
uint8_t buffered;
|
||||
uint8_t readPos;
|
||||
@ -60,7 +60,7 @@ private:
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
BridgeClass &bridge;
|
||||
String filename;
|
||||
uint8_t mode;
|
||||
@ -69,7 +69,7 @@ private:
|
||||
};
|
||||
|
||||
class FileSystemClass {
|
||||
public:
|
||||
public:
|
||||
FileSystemClass() : bridge(Bridge) { }
|
||||
FileSystemClass(BridgeClass &_b) : bridge(_b) { }
|
||||
|
||||
@ -92,7 +92,7 @@ public:
|
||||
|
||||
boolean rmdir(const char *filepath);
|
||||
|
||||
private:
|
||||
private:
|
||||
friend class File;
|
||||
|
||||
BridgeClass &bridge;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <Process.h>
|
||||
|
||||
class HttpClient : public Process {
|
||||
public:
|
||||
public:
|
||||
|
||||
unsigned int get(String &url);
|
||||
unsigned int get(const char * url);
|
||||
|
@ -26,7 +26,7 @@ unsigned int MailboxClass::readMessage(uint8_t *buff, unsigned int size) {
|
||||
void MailboxClass::readMessage(String &str, unsigned int maxLength) {
|
||||
uint8_t tmp[] = { 'm' };
|
||||
// XXX: Is there a better way to create the string?
|
||||
uint8_t buff[maxLength+1];
|
||||
uint8_t buff[maxLength + 1];
|
||||
int l = bridge.transfer(tmp, 1, buff, maxLength);
|
||||
buff[l] = 0;
|
||||
str = (const char *)buff;
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <Bridge.h>
|
||||
|
||||
class MailboxClass {
|
||||
public:
|
||||
public:
|
||||
MailboxClass(BridgeClass &b = Bridge) : bridge(b) { }
|
||||
|
||||
void begin() { }
|
||||
@ -31,7 +31,7 @@ public:
|
||||
// Receive a message and store it inside a buffer
|
||||
unsigned int readMessage(uint8_t *buffer, unsigned int size);
|
||||
// Receive a message and store it inside a String
|
||||
void readMessage(String &str, unsigned int maxLength=128);
|
||||
void readMessage(String &str, unsigned int maxLength = 128);
|
||||
|
||||
// Send a message
|
||||
void writeMessage(const uint8_t *buffer, unsigned int size);
|
||||
@ -44,7 +44,7 @@ public:
|
||||
// no messages in queue.
|
||||
unsigned int messageAvailable();
|
||||
|
||||
private:
|
||||
private:
|
||||
BridgeClass &bridge;
|
||||
};
|
||||
|
||||
|
@ -85,7 +85,7 @@ void Process::runAsynchronously() {
|
||||
delete cmdline;
|
||||
cmdline = NULL;
|
||||
|
||||
if (res[0]==0) // res[0] contains error code
|
||||
if (res[0] == 0) // res[0] contains error code
|
||||
started = true;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <Bridge.h>
|
||||
|
||||
class Process : public Stream {
|
||||
public:
|
||||
public:
|
||||
// Constructor with a user provided BridgeClass instance
|
||||
Process(BridgeClass &_b = Bridge) :
|
||||
bridge(_b), started(false), buffered(0), readPos(0) { }
|
||||
@ -39,7 +39,9 @@ public:
|
||||
unsigned int runShellCommand(const String &command);
|
||||
void runShellCommandAsynchronously(const String &command);
|
||||
|
||||
operator bool () { return started; }
|
||||
operator bool () {
|
||||
return started;
|
||||
}
|
||||
|
||||
// Stream methods
|
||||
// (read from process stdout)
|
||||
@ -51,13 +53,13 @@ public:
|
||||
void flush();
|
||||
// TODO: add optimized function for block write
|
||||
|
||||
private:
|
||||
private:
|
||||
BridgeClass &bridge;
|
||||
unsigned int handle;
|
||||
String *cmdline;
|
||||
boolean started;
|
||||
|
||||
private:
|
||||
private:
|
||||
void doBuffer();
|
||||
uint8_t buffered;
|
||||
uint8_t readPos;
|
||||
|
@ -141,7 +141,7 @@ int YunClient::connect(const char *host, uint16_t port) {
|
||||
};
|
||||
uint8_t res[1];
|
||||
int l = bridge.transfer(tmp, 3, (const uint8_t *)host, strlen(host), res, 1);
|
||||
if (l==0)
|
||||
if (l == 0)
|
||||
return 0;
|
||||
handle = res[0];
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <Client.h>
|
||||
|
||||
class YunClient : public Client {
|
||||
public:
|
||||
public:
|
||||
// Constructor with a user provided BridgeClass instance
|
||||
YunClient(int _h, BridgeClass &_b = Bridge);
|
||||
YunClient(BridgeClass &_b = Bridge);
|
||||
@ -41,7 +41,9 @@ public:
|
||||
virtual void flush();
|
||||
// TODO: add optimized function for block write
|
||||
|
||||
virtual operator bool () { return opened; }
|
||||
virtual operator bool () {
|
||||
return opened;
|
||||
}
|
||||
|
||||
YunClient& operator=(const YunClient &_x);
|
||||
|
||||
@ -51,12 +53,12 @@ public:
|
||||
virtual int connect(IPAddress ip, uint16_t port);
|
||||
virtual int connect(const char *host, uint16_t port);
|
||||
|
||||
private:
|
||||
private:
|
||||
BridgeClass &bridge;
|
||||
unsigned int handle;
|
||||
boolean opened;
|
||||
|
||||
private:
|
||||
private:
|
||||
void doBuffer();
|
||||
uint8_t buffered;
|
||||
uint8_t readPos;
|
||||
|
@ -41,7 +41,7 @@ YunClient YunServer::accept() {
|
||||
uint8_t cmd[] = {'k'};
|
||||
uint8_t res[1];
|
||||
unsigned int l = bridge.transfer(cmd, 1, res, 1);
|
||||
if (l==0)
|
||||
if (l == 0)
|
||||
return YunClient();
|
||||
return YunClient(res[0]);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
class YunClient;
|
||||
|
||||
class YunServer : public Server {
|
||||
public:
|
||||
public:
|
||||
// Constructor with a user provided BridgeClass instance
|
||||
YunServer(uint16_t port = 5555, BridgeClass &_b = Bridge);
|
||||
|
||||
@ -34,10 +34,14 @@ public:
|
||||
|
||||
virtual size_t write(uint8_t c);
|
||||
|
||||
void listenOnLocalhost() { useLocalhost = true; }
|
||||
void noListenOnLocalhost() { useLocalhost = false; }
|
||||
void listenOnLocalhost() {
|
||||
useLocalhost = true;
|
||||
}
|
||||
void noListenOnLocalhost() {
|
||||
useLocalhost = false;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
uint16_t port;
|
||||
bool listening;
|
||||
bool useLocalhost;
|
||||
|
@ -45,25 +45,25 @@ SpacebrewYun::OnSBOpen SpacebrewYun::_onOpen = NULL;
|
||||
SpacebrewYun::OnSBClose SpacebrewYun::_onClose = NULL;
|
||||
SpacebrewYun::OnSBError SpacebrewYun::_onError = NULL;
|
||||
|
||||
void SpacebrewYun::onOpen(OnSBOpen function){
|
||||
void SpacebrewYun::onOpen(OnSBOpen function) {
|
||||
_onOpen = function;
|
||||
}
|
||||
void SpacebrewYun::onClose(OnSBClose function){
|
||||
void SpacebrewYun::onClose(OnSBClose function) {
|
||||
_onClose = function;
|
||||
}
|
||||
void SpacebrewYun::onRangeMessage(OnRangeMessage function){
|
||||
void SpacebrewYun::onRangeMessage(OnRangeMessage function) {
|
||||
_onRangeMessage = function;
|
||||
}
|
||||
void SpacebrewYun::onStringMessage(OnStringMessage function){
|
||||
void SpacebrewYun::onStringMessage(OnStringMessage function) {
|
||||
_onStringMessage = function;
|
||||
}
|
||||
void SpacebrewYun::onBooleanMessage(OnBooleanMessage function){
|
||||
void SpacebrewYun::onBooleanMessage(OnBooleanMessage function) {
|
||||
_onBooleanMessage = function;
|
||||
}
|
||||
void SpacebrewYun::onCustomMessage(OnCustomMessage function){
|
||||
void SpacebrewYun::onCustomMessage(OnCustomMessage function) {
|
||||
_onCustomMessage = function;
|
||||
}
|
||||
void SpacebrewYun::onError(OnSBError function){
|
||||
void SpacebrewYun::onError(OnSBError function) {
|
||||
_onError = function;
|
||||
}
|
||||
|
||||
@ -88,13 +88,13 @@ void SpacebrewYun::addPublish(const String& name, const String& type) {
|
||||
name.toCharArray(p->name, name.length() + 1);
|
||||
type.toCharArray(p->type, type.length() + 1);
|
||||
|
||||
if (publishers == NULL){
|
||||
if (publishers == NULL) {
|
||||
publishers = p;
|
||||
}
|
||||
else {
|
||||
struct Publisher *curr = publishers;
|
||||
int counter = 1;
|
||||
while(curr->next != NULL){
|
||||
while (curr->next != NULL) {
|
||||
curr = curr->next;
|
||||
counter++;
|
||||
}
|
||||
@ -110,12 +110,12 @@ void SpacebrewYun::addSubscribe(const String& name, const String& type) {
|
||||
name.toCharArray(s->name, name.length() + 1);
|
||||
type.toCharArray(s->type, type.length() + 1);
|
||||
|
||||
if (subscribers == NULL){
|
||||
if (subscribers == NULL) {
|
||||
subscribers = s;
|
||||
}
|
||||
else {
|
||||
struct Subscriber *curr = subscribers;
|
||||
while(curr->next != NULL){
|
||||
while (curr->next != NULL) {
|
||||
curr = curr->next;
|
||||
}
|
||||
curr->next = s;
|
||||
@ -142,7 +142,7 @@ void SpacebrewYun::connect(String _server, int _port) {
|
||||
|
||||
if (subscribers != NULL) {
|
||||
struct Subscriber *curr = subscribers;
|
||||
while(curr != NULL){
|
||||
while (curr != NULL) {
|
||||
if (_verbose) {
|
||||
Serial.print(F("Creating subscribers: "));
|
||||
Serial.print(curr->name);
|
||||
@ -163,7 +163,7 @@ void SpacebrewYun::connect(String _server, int _port) {
|
||||
}
|
||||
if (publishers != NULL) {
|
||||
struct Publisher *curr = publishers;
|
||||
while(curr != NULL){
|
||||
while (curr != NULL) {
|
||||
if (_verbose) {
|
||||
Serial.print(F("Creating publishers: "));
|
||||
Serial.print(curr->name);
|
||||
@ -189,7 +189,9 @@ void SpacebrewYun::connect(String _server, int _port) {
|
||||
if (_verbose) {
|
||||
Serial.println(F("Brew started "));
|
||||
}
|
||||
while (!Console) { ; }
|
||||
while (!Console) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void SpacebrewYun::monitor() {
|
||||
@ -203,7 +205,7 @@ void SpacebrewYun::monitor() {
|
||||
Serial.print(F("Application name set to: "));
|
||||
Serial.println(name);
|
||||
}
|
||||
if (_onOpen != NULL){
|
||||
if (_onOpen != NULL) {
|
||||
_onOpen();
|
||||
}
|
||||
_connected = true;
|
||||
@ -214,7 +216,7 @@ void SpacebrewYun::monitor() {
|
||||
Serial.print(F("Disconnected from spacebrew server at: "));
|
||||
Serial.println(server);
|
||||
}
|
||||
if (_onClose != NULL){
|
||||
if (_onClose != NULL) {
|
||||
_onClose();
|
||||
}
|
||||
}
|
||||
@ -269,7 +271,7 @@ void SpacebrewYun::monitor() {
|
||||
|
||||
if (publishers != NULL) {
|
||||
struct Publisher *curr = publishers;
|
||||
while((curr != NULL)){
|
||||
while ((curr != NULL)) {
|
||||
|
||||
if ( (curr->confirmed == 0) && ((millis() - curr->time) > 50) ) {
|
||||
if (_verbose) {
|
||||
@ -287,7 +289,7 @@ void SpacebrewYun::monitor() {
|
||||
void SpacebrewYun::onConfirm() {
|
||||
if (publishers != NULL) {
|
||||
struct Publisher *curr = publishers;
|
||||
while((curr != NULL)){
|
||||
while ((curr != NULL)) {
|
||||
if (sub_name.equals(curr->name) == true) {
|
||||
curr->confirmed = true;
|
||||
// if (_verbose) {
|
||||
@ -316,7 +318,7 @@ void SpacebrewYun::verbose(boolean verbose = true) {
|
||||
void SpacebrewYun::onMessage() {
|
||||
if (subscribers != NULL) {
|
||||
struct Subscriber *curr = subscribers;
|
||||
while((curr != NULL) && (sub_type == "")){
|
||||
while ((curr != NULL) && (sub_type == "")) {
|
||||
if (sub_name.equals(curr->name) == true) {
|
||||
sub_type = curr->type;
|
||||
}
|
||||
@ -356,7 +358,7 @@ void SpacebrewYun::onMessage() {
|
||||
}
|
||||
|
||||
|
||||
void SpacebrewYun::send(const String& name, const String& value){
|
||||
void SpacebrewYun::send(const String& name, const String& value) {
|
||||
if (publishers != NULL) {
|
||||
|
||||
Console.print(char(29));
|
||||
@ -367,7 +369,7 @@ void SpacebrewYun::send(const String& name, const String& value){
|
||||
Console.flush();
|
||||
|
||||
struct Publisher *curr = publishers;
|
||||
while(curr != NULL){
|
||||
while (curr != NULL) {
|
||||
if (name.equals(curr->name) == true) {
|
||||
int msg_len = 0;
|
||||
|
||||
@ -420,7 +422,7 @@ void SpacebrewYun::getPids() {
|
||||
sbPids[sbPidsIndex] = atoi(pid);
|
||||
if ( sbPidsIndex < (sbPidsLen - 1) ) sbPidsIndex = (sbPidsIndex + 1);
|
||||
|
||||
for( int i = 0; i < pidLength; i++ ){
|
||||
for ( int i = 0; i < pidLength; i++ ) {
|
||||
pid[i] = '\0';
|
||||
pidCharIndex = 0;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ struct Publisher {
|
||||
long time;
|
||||
};
|
||||
|
||||
struct Subscriber{
|
||||
struct Subscriber {
|
||||
char *name;
|
||||
char *type;
|
||||
Subscriber *next;
|
||||
@ -44,8 +44,12 @@ class SpacebrewYun {
|
||||
void addSubscribe(const String&, const String&);
|
||||
|
||||
void connect(String, int);
|
||||
void connect() { connect(server, port); };
|
||||
void connect(String _server) { connect(String(_server), port); };
|
||||
void connect() {
|
||||
connect(server, port);
|
||||
};
|
||||
void connect(String _server) {
|
||||
connect(String(_server), port);
|
||||
};
|
||||
|
||||
void monitor();
|
||||
void onMessage();
|
||||
@ -54,11 +58,21 @@ class SpacebrewYun {
|
||||
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 ? String("true") : String("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 send(const String& name, char * value) {
|
||||
send(name, String(value));
|
||||
}
|
||||
void send(const String& name, bool value) {
|
||||
send(name, (value ? String("true") : String("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);
|
||||
|
||||
@ -121,12 +135,12 @@ class SpacebrewYun {
|
||||
void killPids();
|
||||
void getPids();
|
||||
|
||||
static char * createString(int len){
|
||||
static char * createString(int len) {
|
||||
char * out = ( char * ) malloc ( len + 1 );
|
||||
return out;
|
||||
}
|
||||
|
||||
static void emptyString(char * str, int len){
|
||||
static void emptyString(char * str, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
str[i] = '\0';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user