Added clang-format (#623)

* added .clang-format
* added names to travis jobs
removed deprecated travis option
* check github action
* added .gitignore
This commit is contained in:
Leon Kiefer authored and GitHub committed 2020-06-09 16:09:23 -05:00
1 parent 661ef9c55e
commit 10a9d00aaf
59 files changed
+2892 -3640

No files matched your search

+47 -93
View File
@@ -35,19 +35,16 @@
unsigned char _uartbuf[RF_MESSAGE_SIZE + 3] = {0};
unsigned char _uartpos = 0;
void setupSRFB()
{
void setupSRFB() {
Log.trace(F("ZgatewaySRFB setup done " CR));
Log.trace(F("Serial Baud: %l" CR),SERIAL_BAUD);
Log.trace(F("Serial Baud: %l" CR), SERIAL_BAUD);
}
void _rfbSend(byte *message)
{
void _rfbSend(byte* message) {
Serial.println();
Serial.write(RF_CODE_START);
Serial.write(RF_CODE_RFOUT);
for (unsigned char j = 0; j < RF_MESSAGE_SIZE; j++)
{
for (unsigned char j = 0; j < RF_MESSAGE_SIZE; j++) {
Serial.write(message[j]);
}
Serial.write(RF_CODE_STOP);
@@ -55,17 +52,13 @@ void _rfbSend(byte *message)
Serial.println();
}
void _rfbSend(byte *message, int times)
{
void _rfbSend(byte* message, int times) {
char buffer[RF_MESSAGE_SIZE];
_rfbToChar(message, buffer);
Log.notice(F("[RFBRIDGE] Sending MESSAGE" CR));
for (int i = 0; i < times; i++)
{
if (i > 0)
{
for (int i = 0; i < times; i++) {
if (i > 0) {
unsigned long start = millis();
while (millis() - start < RF_SEND_DELAY)
delay(1);
@@ -74,30 +67,21 @@ void _rfbSend(byte *message, int times)
}
}
bool SRFBtoMQTT()
{
bool SRFBtoMQTT() {
static bool receiving = false;
while (Serial.available())
{
while (Serial.available()) {
yield();
byte c = Serial.read();
if (receiving)
{
if (c == RF_CODE_STOP)
{
if (receiving) {
if (c == RF_CODE_STOP) {
_rfbDecode();
receiving = false;
}
else
{
} else {
_uartbuf[_uartpos++] = c;
}
}
else if (c == RF_CODE_START)
{
} else if (c == RF_CODE_START) {
_uartpos = 0;
receiving = true;
}
@@ -105,9 +89,7 @@ bool SRFBtoMQTT()
return receiving;
}
void _rfbDecode()
{
void _rfbDecode() {
static unsigned long last = 0;
if (millis() - last < RF_RECEIVE_DELAY)
return;
@@ -116,14 +98,13 @@ void _rfbDecode()
byte action = _uartbuf[0];
char buffer[RF_MESSAGE_SIZE * 2 + 1] = {0};
if (action == RF_CODE_RFIN)
{
if (action == RF_CODE_RFIN) {
_rfbToChar(&_uartbuf[1], buffer);
Log.trace(F("Creating SRFB buffer" CR));
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject &SRFBdata = jsonBuffer.createObject();
SRFBdata.set("raw", (char *)buffer);
JsonObject& SRFBdata = jsonBuffer.createObject();
SRFBdata.set("raw", (char*)buffer);
char Tsyn[4] = {0};
extract_char(buffer, Tsyn, 0, 4, false, true);
@@ -145,14 +126,12 @@ void _rfbDecode()
unsigned long MQTTvalue = (unsigned long)strtoul(val, NULL, 10);
SRFBdata.set("value", (unsigned long)MQTTvalue);
if (!isAduplicate(MQTTvalue) && MQTTvalue != 0)
{ // conditions to avoid duplications of RF -->MQTT
if (!isAduplicate(MQTTvalue) && MQTTvalue != 0) { // conditions to avoid duplications of RF -->MQTT
Log.trace(F("Adv data SRFBtoMQTT" CR));
pub(subjectSRFBtoMQTT, SRFBdata);
Log.trace(F("Store val: %lu" CR), MQTTvalue);
storeValue(MQTTvalue);
if (repeatSRFBwMQTT)
{
if (repeatSRFBwMQTT) {
Log.trace(F("Publish SRFB for rpt" CR));
pub(subjectMQTTtoSRFB, SRFBdata);
}
@@ -161,8 +140,7 @@ void _rfbDecode()
}
}
void _rfbAck()
{
void _rfbAck() {
Log.trace(F("[RFBRIDGE] Sending ACK\n" CR));
Serial.println();
Serial.write(RF_CODE_START);
@@ -175,13 +153,11 @@ void _rfbAck()
/*
From an hexa char array ("A220EE...") to a byte array (half the size)
*/
bool _rfbToArray(const char *in, byte *out)
{
bool _rfbToArray(const char* in, byte* out) {
if (strlen(in) != RF_MESSAGE_SIZE * 2)
return false;
char tmp[3] = {0};
for (unsigned char p = 0; p < RF_MESSAGE_SIZE; p++)
{
for (unsigned char p = 0; p < RF_MESSAGE_SIZE; p++) {
memcpy(tmp, &in[p * 2], 2);
out[p] = strtol(tmp, NULL, 16);
}
@@ -191,57 +167,47 @@ bool _rfbToArray(const char *in, byte *out)
/*
From a byte array to an hexa char array ("A220EE...", double the size)
*/
bool _rfbToChar(byte *in, char *out)
{
for (unsigned char p = 0; p < RF_MESSAGE_SIZE; p++)
{
bool _rfbToChar(byte* in, char* out) {
for (unsigned char p = 0; p < RF_MESSAGE_SIZE; p++) {
sprintf_P(&out[p * 2], PSTR("%02X" CR), in[p]);
}
return true;
}
#ifdef simpleReceiving
void MQTTtoSRFB(char *topicOri, char *datacallback)
{
# ifdef simpleReceiving
void MQTTtoSRFB(char* topicOri, char* datacallback) {
// RF DATA ANALYSIS
String topic = topicOri;
int valueRPT = 0;
if (topic == subjectMQTTtoSRFB)
{
if (topic == subjectMQTTtoSRFB) {
int valueMiniPLSL = 0;
int valueMaxiPLSL = 0;
int valueSYNC = 0;
int pos = topic.lastIndexOf(SRFBRptKey);
if (pos != -1)
{
if (pos != -1) {
pos = pos + +strlen(SRFBRptKey);
valueRPT = (topic.substring(pos, pos + 1)).toInt();
Log.notice(F("SRFB Repeat: %d" CR),valueRPT);
Log.notice(F("SRFB Repeat: %d" CR), valueRPT);
}
int pos2 = topic.lastIndexOf(SRFBminipulselengthKey);
if (pos2 != -1)
{
if (pos2 != -1) {
pos2 = pos2 + strlen(SRFBminipulselengthKey);
valueMiniPLSL = (topic.substring(pos2, pos2 + 3)).toInt();
Log.notice(F("RF Mini Pulse Lgth: %d" CR),valueMiniPLSL);
Log.notice(F("RF Mini Pulse Lgth: %d" CR), valueMiniPLSL);
}
int pos3 = topic.lastIndexOf(SRFBmaxipulselengthKey);
if (pos3 != -1)
{
if (pos3 != -1) {
pos3 = pos3 + strlen(SRFBmaxipulselengthKey);
valueMaxiPLSL = (topic.substring(pos3, pos3 + 2)).toInt();
Log.notice(F("RF Maxi Pulse Lgth: %d" CR), valueMaxiPLSL);
}
int pos4 = topic.lastIndexOf(SRFBsyncKey);
if (pos4 != -1)
{
if (pos4 != -1) {
pos4 = pos4 + strlen(SRFBsyncKey);
valueSYNC = (topic.substring(pos4, pos4 + 2)).toInt();
Log.notice(F("RF sync: %d" CR), valueSYNC);
@@ -286,12 +252,9 @@ void MQTTtoSRFB(char *topicOri, char *datacallback)
// Acknowledgement to the GTWRF topic
pub(subjectGTWSRFBtoMQTT, datacallback); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
if (topic == subjectMQTTtoSRFBRaw)
{
if (topic == subjectMQTTtoSRFBRaw) {
int pos = topic.lastIndexOf(SRFBRptKey);
if (pos != -1)
{
if (pos != -1) {
pos = pos + +strlen(SRFBRptKey);
valueRPT = (topic.substring(pos, pos + 1)).toInt();
Log.notice(F("SRFB Repeat: %d" CR), valueRPT);
@@ -306,29 +269,22 @@ void MQTTtoSRFB(char *topicOri, char *datacallback)
pub(subjectGTWSRFBtoMQTT, datacallback); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
}
#endif
#ifdef jsonReceiving
void MQTTtoSRFB(char *topicOri, JsonObject &SRFBdata)
{
# endif
# ifdef jsonReceiving
void MQTTtoSRFB(char* topicOri, JsonObject& SRFBdata) {
// RF DATA ANALYSIS
const char *raw = SRFBdata["raw"];
const char* raw = SRFBdata["raw"];
int valueRPT = SRFBdata["repeat"] | 1;
if (cmpToMainTopic(topicOri, subjectMQTTtoSRFB))
{
if (cmpToMainTopic(topicOri, subjectMQTTtoSRFB)) {
Log.trace(F("MQTTtoSRFB json" CR));
if (raw)
{ // send raw in priority when defined in the json
if (raw) { // send raw in priority when defined in the json
Log.trace(F("MQTTtoSRFB raw ok" CR));
byte message_b[RF_MESSAGE_SIZE];
_rfbToArray(raw, message_b);
_rfbSend(message_b, valueRPT);
}
else
{
} else {
unsigned long data = SRFBdata["value"];
if (data != 0)
{
if (data != 0) {
Log.notice(F("MQTTtoSRFB data ok" CR));
int valueMiniPLSL = SRFBdata["val_Tlow"];
int valueMaxiPLSL = SRFBdata["val_Thigh"];
@@ -343,8 +299,8 @@ void MQTTtoSRFB(char *topicOri, JsonObject &SRFBdata)
if (valueSYNC == 0)
valueSYNC = 9500;
Log.notice(F("SRFB Repeat: %d" CR),valueRPT);
Log.notice(F("RF Mini Pulse Lgth: %d" CR),valueMiniPLSL);
Log.notice(F("SRFB Repeat: %d" CR), valueRPT);
Log.notice(F("RF Mini Pulse Lgth: %d" CR), valueMiniPLSL);
Log.notice(F("RF Maxi Pulse Lgth: %d" CR), valueMaxiPLSL);
Log.notice(F("RF sync: %d" CR), valueSYNC);
@@ -376,13 +332,11 @@ void MQTTtoSRFB(char *topicOri, JsonObject &SRFBdata)
_rfbSend(message_b, valueRPT);
// Acknowledgement to the GTWRF topic
pub(subjectGTWSRFBtoMQTT, SRFBdata); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
else
{
} else {
Log.error(F("MQTTtoSRFB error decoding value" CR));
}
}
}
}
#endif
# endif
#endif