Complete reanme Props to Prop

This commit is contained in:
fauresystems
2020-04-30 16:48:56 +02:00
parent 79bf402739
commit f3b78e3669
16 changed files with 58 additions and 73 deletions
-1
View File
@@ -224,7 +224,6 @@ However, this can help in special cases.
```csharp
/*
Name: BlinkOnBridgePubSub.ino
Created: 29/10/2019 16:51:55
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
+3 -3
View File
@@ -6,7 +6,7 @@
# Datatypes (KEYWORD1)
#######################################
Props KEYWORD1
Prop KEYWORD1
BridgeProp KEYWORD1
EthernetProp KEYWORD1
WifiProp KEYWORD1
@@ -16,8 +16,8 @@ PropDataDecimal KEYWORD1
PropDataInteger KEYWORD1
PropDataLogical KEYWORD1
PropDataText KEYWORD1
PropsCallback KEYWORD1
PropsMessageReceived KEYWORD1
PropCallback KEYWORD1
PropMessageReceived KEYWORD1
InboxMessage KEYWORD1
#######################################
-1
View File
@@ -1,6 +1,5 @@
/*
Name: ArduinoProps.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
-1
View File
@@ -1,6 +1,5 @@
/*
Name: ArduinoProps.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
+2 -3
View File
@@ -1,17 +1,16 @@
/*
Name: BridgeProp.cpp
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
Class Props for Arduino Yun and Dragino Yun shield.
Prop for Arduino Yun and Dragino Yun shield.
*/
#include "BridgeProp.h"
BridgeProp::BridgeProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
: Props(client_id, in_box, out_box, broker, port)
: Prop(client_id, in_box, out_box, broker, port)
{
_client.setClient(_bridgeClient);
}
+2 -3
View File
@@ -1,11 +1,10 @@
/*
Name: BridgeProp.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
Class Props for Arduino Yun and Dragino Yun shield.
Prop for Arduino Yun and Dragino Yun shield.
*/
#ifndef BRIDGEPROP_H
#define BRIDGEPROP_H
@@ -14,7 +13,7 @@
#include <IPAddress.h>
#include "Prop.h"
class BridgeProp : public Props
class BridgeProp : public Prop
{
public:
BridgeProp(const char*, const char*, const char*, const char*, const int);
+2 -3
View File
@@ -1,17 +1,16 @@
/*
Name: EthernetProp.cpp
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
Class Props for Arduino with Ethernet shield.
Prop for Arduino with Ethernet shield.
*/
#include "EthernetProp.h"
EthernetProp::EthernetProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
: Props(client_id, in_box, out_box, broker, port)
: Prop(client_id, in_box, out_box, broker, port)
{
_client.setClient(_ethernetClient);
}
+2 -3
View File
@@ -1,11 +1,10 @@
/*
Name: EthernetProp.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
Class Props for Arduino with Ethernet shield.
Prop for Arduino with Ethernet shield.
*/
#ifndef ETHERNETPROP_H
#define ETHERNETPROP_H
@@ -16,7 +15,7 @@
#include <EthernetClient.h>
#include "Prop.h"
class EthernetProp : public Props
class EthernetProp : public Prop
{
public:
EthernetProp(const char*, const char*, const char*, const char*, const int);
+33 -34
View File
@@ -1,6 +1,5 @@
/*
Name: Props.cpp
Created: 29/10/2019 09:20:31
Name: Prop.cpp
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
@@ -14,7 +13,7 @@
#include <avr/wdt.h>
#endif
void PropsCallback::run(char* topic, byte* payload, unsigned int len)
void PropCallback::run(char* topic, byte* payload, unsigned int len)
{
if (len)
{
@@ -24,17 +23,17 @@ void PropsCallback::run(char* topic, byte* payload, unsigned int len)
if (String(p) == "@PING")
client->publish(outbox, "PONG");
else
Props::onInboxMessageReceived(p);
Prop::onInboxMessageReceived(p);
free(p);
}
}
void PropsMessageReceived::run(String a)
void PropMessageReceived::run(String a)
{
client->publish(outbox, String("OMIT " + a).c_str());
}
Props::Props(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
Prop::Prop(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
{
clientId = client_id;
inbox = in_box;
@@ -43,27 +42,27 @@ Props::Props(const char* client_id, const char* in_box, const char* out_box, con
_nextReconAttempt = 0;
_dataSentCount = 0;
_maximumSilentPeriod = 30; // 30 seconds
_payloadMax = MQTT_MAX_PACKET_SIZE - (1 + 2 + strlen(Props::outbox));
_payloadMax = MQTT_MAX_PACKET_SIZE - (1 + 2 + strlen(Prop::outbox));
_brokerIpAddress.fromString(broker);
_client.setServer(_brokerIpAddress, port);
PropsCallback::client = &_client;
PropsCallback::outbox = outbox;
_client.setCallback(PropsCallback::run);
PropCallback::client = &_client;
PropCallback::outbox = outbox;
_client.setCallback(PropCallback::run);
PropsMessageReceived::client = &_client;
PropsMessageReceived::outbox = outbox;
PropMessageReceived::client = &_client;
PropMessageReceived::outbox = outbox;
_sendDataAction.reset(400); // check data changes every 400 milliseconds
}
void Props::addData(PropData* d)
void Prop::addData(PropData* d)
{
_dataTable.Add(d);
}
void Props::loop()
void Prop::loop()
{
if (_client.connected())
{
@@ -84,7 +83,7 @@ void Props::loop()
if (_sendDataAction.tick()) checkDataChanges(); // send data changes if any
}
void Props::checkDataChanges()
void Prop::checkDataChanges()
{
if (_dataSentCount) {
sendDataChanges();
@@ -98,7 +97,7 @@ void Props::checkDataChanges()
if (_dataSentCount > (_maximumSilentPeriod * 1000 / _sendDataAction.getInterval())) _dataSentCount = 0;
}
void Props::resetMcu()
void Prop::resetMcu()
{
#if defined(ARDUINO_ARCH_SAMD)
NVIC_SystemReset();
@@ -108,7 +107,7 @@ void Props::resetMcu()
#endif
}
void Props::sendAllData()
void Prop::sendAllData()
{
String data("DATA "), str;
for (int i = 0; i < _dataTable.Count(); i++) {
@@ -121,7 +120,7 @@ void Props::sendAllData()
}
}
void Props::sendDataChanges()
void Prop::sendDataChanges()
{
String data("DATA "), str;
for (int i = 0; i < _dataTable.Count(); i++) {
@@ -134,7 +133,7 @@ void Props::sendDataChanges()
}
}
void Props::send(String* d, String* s)
void Prop::send(String* d, String* s)
{
if (d->length() + s->length() <= _payloadMax) {
*d += *s;
@@ -146,49 +145,49 @@ void Props::send(String* d, String* s)
}
}
void Props::sendData(String data) {
void Prop::sendData(String data) {
if (data.length() > 5) {
_client.publish(outbox, String("DATA " + data).c_str());
}
}
void Props::sendDone(String action) {
void Prop::sendDone(String action) {
_client.publish(outbox, String("DONE " + action).c_str());
}
void Props::sendMesg(String mesg) {
void Prop::sendMesg(String mesg) {
if (mesg.length() > 5) {
_client.publish(outbox, String("MESG " + mesg).c_str());
}
}
void Props::sendMesg(String mesg, char *topic) {
void Prop::sendMesg(String mesg, char *topic) {
if (mesg.length() > 5) {
_client.publish(topic, String("MESG " + mesg).c_str());
}
}
void Props::sendOmit(String action) {
void Prop::sendOmit(String action) {
_client.publish(outbox, String("OMIT " + action).c_str());
}
void Props::sendOver(String challenge) {
void Prop::sendOver(String challenge) {
_client.publish(outbox, String("OVER " + challenge).c_str());
}
void Props::sendProg(String program) {
void Prop::sendProg(String program) {
_client.publish(outbox, String("PROG " + program).c_str());
}
void Props::sendRequ(String request) {
void Prop::sendRequ(String request) {
_client.publish(outbox, String("REQU " + request).c_str());
}
void Props::sendRequ(String action, char* topic) {
void Prop::sendRequ(String action, char* topic) {
_client.publish(topic, String("REQU " + action).c_str());
}
void Props::resetIntervals(const int changes, const int silent)
void Prop::resetIntervals(const int changes, const int silent)
{
_nextReconAttempt = 0;
_dataSentCount = 0;
@@ -197,8 +196,8 @@ void Props::resetIntervals(const int changes, const int silent)
}
PubSubClient *PropsCallback::client;
const char *PropsCallback::outbox;
PubSubClient *PropsMessageReceived::client;
const char *PropsMessageReceived::outbox;
void (*Props::onInboxMessageReceived)(String) = PropsMessageReceived::run;
PubSubClient *PropCallback::client;
const char *PropCallback::outbox;
PubSubClient *PropMessageReceived::client;
const char *PropMessageReceived::outbox;
void (*Prop::onInboxMessageReceived)(String) = PropMessageReceived::run;
+5 -6
View File
@@ -1,6 +1,5 @@
/*
Name: Prop.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
@@ -26,7 +25,7 @@
#define MQTT_MAX_PACKET_SIZE 128 // Bridge tranfer stuff (see PubSubClient)
#endif
class PropsCallback
class PropCallback
{
public:
static PubSubClient *client;
@@ -34,7 +33,7 @@ class PropsCallback
static void run(char* topic, byte* payload, unsigned int len);
};
class PropsMessageReceived
class PropMessageReceived
{
public:
static PubSubClient *client;
@@ -42,16 +41,16 @@ class PropsMessageReceived
static void run(String);
};
class InboxMessage : public PropsMessageReceived
class InboxMessage : public PropMessageReceived
{
public:
static void run(String); // to be implemented in .ino sketch
};
class Props
class Prop
{
public:
Props(const char*, const char*, const char*, const char*, const int=1883);
Prop(const char*, const char*, const char*, const char*, const int=1883);
virtual void begin(void(*)(String) = NULL) = 0;
void addData(PropData*);
void loop();
-1
View File
@@ -1,6 +1,5 @@
/*
Name: PropAction.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
+3 -4
View File
@@ -1,6 +1,5 @@
/*
Name: PropAction.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
@@ -8,8 +7,8 @@
Provide an easy way of triggering functions at a set interval.
*/
#ifndef PROPSACTION_H
#define PROPSACTION_H
#ifndef PROPACTION_H
#define PROPACTION_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
@@ -17,7 +16,7 @@
#include "WProgram.h"
#endif
class Props;
class Prop;
class PropAction {
-1
View File
@@ -1,6 +1,5 @@
/*
Name: PropData.cpp
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
+2 -3
View File
@@ -1,14 +1,13 @@
/*
Name: PropData.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
Variable wrapper for connected prop.
*/
#ifndef PROPSDATA_H
#define PROPSDATA_H
#ifndef PROPDATA_H
#define PROPDATA_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
+2 -3
View File
@@ -1,11 +1,10 @@
/*
Name: WifiProp.cpp
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
Class Props for Arduino with WiFiNINA.
Prop for Arduino with WiFiNINA.
*/
#include "WifiProp.h"
@@ -15,7 +14,7 @@
WifiProp::WifiProp(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
: Props(client_id, in_box, out_box, broker, port)
: Prop(client_id, in_box, out_box, broker, port)
{
_client.setClient(_wifiClient);
}
+2 -3
View File
@@ -1,11 +1,10 @@
/*
Name: WifiProp.h
Created: 29/10/2019 09:20:31
Author: Marie Faure <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Marie Faure <dev at faure dot systems>
Class Props for Arduino with WiFiNINA.
Prop for Arduino with WiFiNINA.
*/
#ifndef WIFIPROP_H
#define WIFIPROP_H
@@ -20,7 +19,7 @@
#include <WiFiClient.h>
#include "Prop.h"
class WifiProp : public Props
class WifiProp : public Prop
{
public:
WifiProp(const char*, const char*, const char*, const char*, const int);