25 #ifndef VirtualShield_h
26 #define VirtualShield_h
30 #include <ArduinoJson.h>
44 #define REFRESH_HASH 0xC5BF
45 #define CONNECT_HASH 0xA91A
46 #define PING_HASH 0x2CFE
47 #define SUSPEND_HASH 0xC15E
48 #define RESUME_HASH 0x3549
64 bool checkSensors(
int watchForId = 0,
long timeout = 0,
int waitForResultId = -1);
76 void write(
const char* text);
77 int writeAll(
const char* serviceName,
EPtr values[],
int count,
Attr extraAttributes[] = 0,
int extraAttributeCount = 0,
const char sensorType =
'\0');
79 int writeAll(
const char* serviceName);
117 this->allowAutoBlocking = enable;
120 int parseToHash(
const char* text,
unsigned int *
hash,
int hashCount,
char separator =
' ',
unsigned int length = -1);
121 static unsigned int hash(
const char* s,
unsigned int len = -1,
unsigned int seed = 0);
135 bool allowAutoBlocking =
true;
139 int writeValue(
EPtr eptr,
int start = 0)
const;
void setPort(int port)
Sets the port for bluetooth (this only works for AVR_ATmega32U4 where there are more than one port)...
Definition: VirtualShield.cpp:118
void(* onConnect)(ShieldEvent *)=0
Definition: VirtualShield.h:54
Definition: VirtualShield.h:50
const long DEFAULT_BAUDRATE
Definition: VirtualShield.h:41
void onStringReceived(char *buffer, int length, ShieldEvent *shieldEvent)
Event callback for when a full string is received.
Definition: VirtualShield.cpp:360
Stream * _VShieldSerial
Definition: VirtualShield.h:131
bool addSensor(Sensor *sensor)
Adds a sensor to the list of known sensors in order to match and dispatch for incoming events...
Definition: VirtualShield.cpp:104
bool getEvent(ShieldEvent *shieldEvent)
Gets zero or one available events for processing.
Definition: VirtualShield.cpp:172
void setOnSuspend(void(*onSuspend)(ShieldEvent *))
Definition: VirtualShield.h:103
const long WAITFOR_TIMEOUT
Definition: VirtualShield.h:42
virtual void onJsonReceived(JsonObject &root, ShieldEvent *shieldEvent)
Event called when a valid json message was received. Dispatches to added sensors that match the incom...
Definition: VirtualShield.cpp:251
bool hasError(ShieldEvent *shieldEvent=0)
Returns true
Definition: VirtualShield.cpp:438
bool checkSensors(int watchForId=0, long timeout=0, int waitForResultId=-1)
Receives events as long as they exist, or until an optional timeout occurs.
Definition: VirtualShield.cpp:374
int endWrite()
Ends the write operation.
Definition: VirtualShield.cpp:695
void setOnEvent(void(*onEvent)(ShieldEvent *))
Definition: VirtualShield.h:88
VirtualShield()
Initializes a new instance of the VirtualShield class.
Definition: VirtualShield.cpp:94
void setOnResume(void(*onResume)(ShieldEvent *))
Definition: VirtualShield.h:108
void(* onSuspend)(ShieldEvent *)=0
Definition: VirtualShield.h:56
int waitFor(int id, long timeout=WAITFOR_TIMEOUT, bool asSuccess=true, int resultId=-1)
Blocks and awaits an event with an id.
Definition: VirtualShield.cpp:415
int writeAll(const char *serviceName, EPtr values[], int count, Attr extraAttributes[]=0, int extraAttributeCount=0, const char sensorType= '\0')
Writes all EPtr values to the communication channel.
Definition: VirtualShield.cpp:474
void setOnConnect(void(*onConnect)(ShieldEvent *))
Definition: VirtualShield.h:93
static unsigned int hash(const char *s, unsigned int len=-1, unsigned int seed=0)
Definition: VirtualShield.cpp:680
int beginWrite(const char *serviceName)
Begins a service write operation to the communication channel. Increments a message id...
Definition: VirtualShield.cpp:447
Definition: SensorModels.h:101
void(* onRefresh)(ShieldEvent *)=0
Definition: VirtualShield.h:55
void begin(long bitRate=DEFAULT_BAUDRATE)
Begins the specified bit rate.
Definition: VirtualShield.cpp:132
int sendFlashStringOnSerial(const char *flashStringAdr, int start=-1, bool encode=false) const
Sends the flash (PROGMEM) string on the communication channel.
Definition: VirtualShield.cpp:713
void(* onEvent)(ShieldEvent *)=0
Definition: VirtualShield.h:53
void enableAutoBlocking(bool enable)
Enables or disables block() to block for specific id-based responses.
Definition: VirtualShield.h:116
unsigned int UINT
Definition: VirtualShield.h:36
Definition: ShieldEvent.h:35
int directToSerial(const char *cmd)
Definition: VirtualShield.cpp:702
void flush()
Flushes this instance onto the serial port.
Definition: VirtualShield.cpp:161
int parseToHash(const char *text, unsigned int *hash, int hashCount, char separator= ' ', unsigned int length=-1)
Definition: VirtualShield.cpp:652
void(* onResume)(ShieldEvent *)=0
Definition: VirtualShield.h:57
void setOnRefresh(void(*onRefresh)(ShieldEvent *))
Definition: VirtualShield.h:98
void write(const char *text)
Writes the specified text to the communication channel.
Definition: VirtualShield.cpp:392
int block(int id, bool blocking, long timeout=WAITFOR_TIMEOUT, int waitForResultId=-1)
Blocks while waiting for a specific id-based response (only when blocking is true and allowAutoBlocki...
Definition: VirtualShield.cpp:153
void onJsonStringReceived(char *json, ShieldEvent *shieldEvent)
Event callback for when a full json string is received.
Definition: VirtualShield.cpp:342