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

+37 -65
View File
@@ -29,8 +29,8 @@
#ifdef Zgateway2G
#include <ArduinoJson.h>
#include <A6lib.h> // library for controling A6 or A7 module
# include <A6lib.h> // library for controling A6 or A7 module
# include <ArduinoJson.h>
// Instantiate the library with TxPin, RxPin.
A6lib A6l(_2G_TX_PIN, _2G_RX_PIN); //D6 to A6 RX, D7 to A6 TX
@@ -39,16 +39,14 @@ int unreadSMSLocs[50] = {0};
int unreadSMSNum = 0;
SMSmessage sms;
void setup2G()
{
void setup2G() {
Log.notice(F("_2G_TX_PIN: %d " CR), _2G_TX_PIN);
Log.notice(F("_2G_RX_PIN: %d " CR), _2G_RX_PIN);
setupGSM(false);
Log.trace(F("Zgateway2G setup done " CR));
}
void setupGSM(bool deleteSMS)
{
void setupGSM(bool deleteSMS) {
Log.trace(F("Init 2G module: %d" CR), _2G_PWR_PIN);
delay(1000);
// Power-cycle the module to reset it.
@@ -59,45 +57,37 @@ void setupGSM(bool deleteSMS)
signalStrengthAnalysis();
delay(1000);
// deleting all sms
if (deleteSMS)
{
if (A6l.deleteSMS(1, 4) == A6_OK)
{
if (deleteSMS) {
if (A6l.deleteSMS(1, 4) == A6_OK) {
Log.notice(F("delete SMS OK" CR));
}
else
{
} else {
Log.error(F("delete SMS KO" CR));
}
}
}
void signalStrengthAnalysis()
{
void signalStrengthAnalysis() {
int signalStrength = 0;
signalStrength = A6l.getSignalStrength();
Log.trace(F("Signal strength: %d" CR), signalStrength);
if (signalStrength < _2G_MIN_SIGNAL || signalStrength > _2G_MAX_SIGNAL)
{
if (signalStrength < _2G_MIN_SIGNAL || signalStrength > _2G_MAX_SIGNAL) {
Log.trace(F("Signal too low restart the module" CR));
setupGSM(false); // if we are below or above a threshold signal we relaunch the setup of GSM module
}
}
bool _2GtoMQTT()
{
bool _2GtoMQTT() {
// Get the memory locations of unread SMS messages.
unreadSMSNum = A6l.getUnreadSMSLocs(unreadSMSLocs, 512);
Log.trace(F("Creating SMS buffer" CR));
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject &SMSdata = jsonBuffer.createObject();
for (int i = 0; i < unreadSMSNum; i++)
{
JsonObject& SMSdata = jsonBuffer.createObject();
for (int i = 0; i < unreadSMSNum; i++) {
Log.notice(F("New message at index: %d" CR), unreadSMSNum);
sms = A6l.readSMS(unreadSMSLocs[i]);
SMSdata.set("message", (char *)sms.message.c_str());
SMSdata.set("date", (char *)sms.date.c_str());
SMSdata.set("phone", (char *)sms.number.c_str());
SMSdata.set("message", (char*)sms.message.c_str());
SMSdata.set("date", (char*)sms.date.c_str());
SMSdata.set("phone", (char*)sms.number.c_str());
A6l.deleteSMS(unreadSMSLocs[i]); // we delete the SMS received
Log.trace(F("Adv data 2GtoMQTT" CR));
pub(subject2GtoMQTT, SMSdata);
@@ -105,76 +95,58 @@ bool _2GtoMQTT()
}
return false;
}
#ifdef simpleReceiving
void MQTTto2G(char *topicOri, char *datacallback)
{
# ifdef simpleReceiving
void MQTTto2G(char* topicOri, char* datacallback) {
String data = datacallback;
String topic = topicOri;
if (cmpToMainTopic(topicOri, subjectMQTTto2G))
{
if (cmpToMainTopic(topicOri, subjectMQTTto2G)) {
Log.trace(F("MQTTto2G data analysis" CR));
// 2G DATA ANALYSIS
String phone_number = "";
int pos0 = topic.lastIndexOf(_2GPhoneKey);
if (pos0 != -1)
{
if (pos0 != -1) {
pos0 = pos0 + strlen(_2GPhoneKey);
phone_number = topic.substring(pos0);
Log.notice(F("MQTTto2G phone: %s" CR),(char *)phone_number.c_str());
Log.notice(F("MQTTto2G sms: %s" CR),(char *)data.c_str());
if (A6l.sendSMS(phone_number, data) == A6_OK)
{
Log.notice(F("MQTTto2G phone: %s" CR), (char*)phone_number.c_str());
Log.notice(F("MQTTto2G sms: %s" CR), (char*)data.c_str());
if (A6l.sendSMS(phone_number, data) == A6_OK) {
Log.notice(F("SMS OK" CR));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, "SMS OK"); // 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("SMS KO" CR));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, "SMS KO"); // 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("MQTTto2G Fail reading phone number" CR));
}
}
}
#endif
# endif
#ifdef jsonReceiving
void MQTTto2G(char *topicOri, JsonObject &SMSdata)
{
if (cmpToMainTopic(topicOri, subjectMQTTto2G))
{
const char *sms = SMSdata["message"];
const char *phone = SMSdata["phone"];
# ifdef jsonReceiving
void MQTTto2G(char* topicOri, JsonObject& SMSdata) {
if (cmpToMainTopic(topicOri, subjectMQTTto2G)) {
const char* sms = SMSdata["message"];
const char* phone = SMSdata["phone"];
Log.trace(F("MQTTto2G json data analysis" CR));
if (sms && phone)
{
Log.notice(F("MQTTto2G phone: %s" CR),phone);
Log.notice(F("MQTTto2G sms: %s" CR),sms);
if (A6l.sendSMS(String(phone), String(sms)) == A6_OK)
{
if (sms && phone) {
Log.notice(F("MQTTto2G phone: %s" CR), phone);
Log.notice(F("MQTTto2G sms: %s" CR), sms);
if (A6l.sendSMS(String(phone), String(sms)) == A6_OK) {
Log.notice(F("SMS OK" CR));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, "SMS OK"); // 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("SMS KO" CR));
pub(subjectGTW2GtoMQTT, "SMS KO"); // 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("MQTTto2G failed json read" CR));
}
}
}
#endif
# endif
#endif