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