mirror of
https://gitlab.com/fabinfra/fabhardware/fabreader3.git
synced 2025-03-12 14:41:43 +01:00
some formatting
This commit is contained in:
parent
d0eada7a40
commit
7006b39724
@ -16,42 +16,42 @@ Display::Display(int sda, int scl, int readerid)
|
||||
|
||||
void Display::clearReaderInfo()
|
||||
{
|
||||
char buffer [DISPLAY_BUFFER_SIZE];
|
||||
char buffer[DISPLAY_BUFFER_SIZE];
|
||||
sprintf(buffer, "%05d", readerid);
|
||||
writeReaderInfo(buffer);
|
||||
}
|
||||
|
||||
void Display::createReaderInfo(const char* state)
|
||||
void Display::createReaderInfo(const char *state)
|
||||
{
|
||||
if(strlen(state) < DISPLAY_BUFFER_SIZE - 1 - 6)
|
||||
if (strlen(state) < DISPLAY_BUFFER_SIZE - 1 - 6)
|
||||
{
|
||||
char buffer [DISPLAY_BUFFER_SIZE];
|
||||
char buffer[DISPLAY_BUFFER_SIZE];
|
||||
sprintf(buffer, "%s %05d", state, readerid);
|
||||
writeReaderInfo(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void Display::writeReaderInfo(const char* text)
|
||||
void Display::writeReaderInfo(const char *text)
|
||||
{
|
||||
if(strlen(text) < DISPLAY_BUFFER_SIZE - 1)
|
||||
if (strlen(text) < DISPLAY_BUFFER_SIZE - 1)
|
||||
{
|
||||
strcpy(ReaderInfo, text);
|
||||
}
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
void Display::writeTitle(const char* text)
|
||||
void Display::writeTitle(const char *text)
|
||||
{
|
||||
if(strlen(text) < DISPLAY_BUFFER_SIZE - 1)
|
||||
if (strlen(text) < DISPLAY_BUFFER_SIZE - 1)
|
||||
{
|
||||
strcpy(Title, text);
|
||||
}
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
void Display::writeInfo(const char* text)
|
||||
void Display::writeInfo(const char *text)
|
||||
{
|
||||
if(strlen(text) < DISPLAY_BUFFER_SIZE - 1)
|
||||
if (strlen(text) < DISPLAY_BUFFER_SIZE - 1)
|
||||
{
|
||||
strcpy(Info, text);
|
||||
}
|
||||
@ -75,7 +75,7 @@ void Display::updateDisplay()
|
||||
display->display();
|
||||
}
|
||||
|
||||
void Display::updateByMQTT(const char* topic, byte* payload, unsigned int length)
|
||||
void Display::updateByMQTT(const char *topic, byte *payload, unsigned int length)
|
||||
{
|
||||
char topic_displayTitle[] = "fabreader/00000/display/title";
|
||||
sprintf(topic_displayTitle, "fabreader/%05d/display/title", readerid);
|
||||
@ -86,18 +86,18 @@ void Display::updateByMQTT(const char* topic, byte* payload, unsigned int length
|
||||
char topic_stopOTA[] = "fabreader/00000/stopOTA";
|
||||
sprintf(topic_stopOTA, "fabreader/%05d/stopOTA", readerid);
|
||||
|
||||
char* buffer = new char[length + 1];
|
||||
char *buffer = new char[length + 1];
|
||||
memcpy(buffer, payload, length);
|
||||
|
||||
if(!strcmp(topic, topic_displayTitle))
|
||||
if (!strcmp(topic, topic_displayTitle))
|
||||
{
|
||||
writeTitle(buffer);
|
||||
}
|
||||
else if(!strcmp(topic, topic_displayInfo))
|
||||
else if (!strcmp(topic, topic_displayInfo))
|
||||
{
|
||||
writeInfo(buffer);
|
||||
}
|
||||
else if(!strcmp(topic, topic_stopOTA))
|
||||
else if (!strcmp(topic, topic_stopOTA))
|
||||
{
|
||||
clearReaderInfo();
|
||||
}
|
||||
|
@ -6,21 +6,21 @@
|
||||
|
||||
class Display
|
||||
{
|
||||
private:
|
||||
SSD1306Wire* display;
|
||||
private:
|
||||
SSD1306Wire *display;
|
||||
int readerid;
|
||||
char ReaderInfo[DISPLAY_BUFFER_SIZE];
|
||||
char Title[DISPLAY_BUFFER_SIZE];
|
||||
char Info[DISPLAY_BUFFER_SIZE];
|
||||
|
||||
public:
|
||||
public:
|
||||
Display(int sda, int scl, int readerid);
|
||||
void createReaderInfo(const char* state);
|
||||
void createReaderInfo(const char *state);
|
||||
void clearReaderInfo();
|
||||
void writeReaderInfo(const char* text);
|
||||
void writeTitle(const char* text);
|
||||
void writeInfo(const char* text);
|
||||
void writeReaderInfo(const char *text);
|
||||
void writeTitle(const char *text);
|
||||
void writeInfo(const char *text);
|
||||
void updateDisplay();
|
||||
void updateByMQTT(const char* topic, byte* payload, unsigned int length);
|
||||
void updateByMQTT(const char *topic, byte *payload, unsigned int length);
|
||||
};
|
||||
#endif
|
@ -31,13 +31,13 @@ bool NFC::testNFC()
|
||||
bool NFC::checkforCard()
|
||||
{
|
||||
// RequestA
|
||||
if ( ! rfid->PICC_IsNewCardPresent())
|
||||
if (!rfid->PICC_IsNewCardPresent())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// PICC_Select ???
|
||||
if ( ! rfid->PICC_ReadCardSerial())
|
||||
if (!rfid->PICC_ReadCardSerial())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -57,7 +57,8 @@ bool NFC::connecttoCard()
|
||||
byte ats[16];
|
||||
byte atsLength = 16;
|
||||
MFRC522::StatusCode state = rfid->PICC_RequestATS(ats, &atsLength);
|
||||
if (state != MFRC522::STATUS_OK) {
|
||||
if (state != MFRC522::STATUS_OK)
|
||||
{
|
||||
Serial.println(F("Failed ATS"));
|
||||
Serial.println(state);
|
||||
rfid->PICC_HaltA();
|
||||
@ -98,9 +99,9 @@ bool NFC::testCard()
|
||||
return true;
|
||||
}
|
||||
|
||||
MFRC522::StatusCode NFC::Transceive(byte* command, byte command_len, byte* response, byte* response_len)
|
||||
MFRC522::StatusCode NFC::Transceive(byte *command, byte command_len, byte *response, byte *response_len)
|
||||
{
|
||||
if(command_len >= 0xFF - 4)
|
||||
if (command_len >= 0xFF - 4)
|
||||
{
|
||||
return MFRC522::STATUS_NO_ROOM;
|
||||
}
|
||||
|
@ -7,15 +7,14 @@
|
||||
|
||||
class NFC
|
||||
{
|
||||
private:
|
||||
|
||||
private:
|
||||
MFRC522::Uid uid;
|
||||
byte pcb = 0x0A;
|
||||
byte cid = 0x00;
|
||||
bool cardSelected = false;
|
||||
|
||||
public:
|
||||
DESFire* rfid;
|
||||
public:
|
||||
DESFire *rfid;
|
||||
NFC(int pin_ss, int pin_rst);
|
||||
bool testNFC();
|
||||
bool checkforCard();
|
||||
@ -25,7 +24,7 @@ class NFC
|
||||
bool hasCardSelected();
|
||||
MFRC522::Uid getUID();
|
||||
|
||||
MFRC522::StatusCode Transceive(byte* command, byte command_len, byte* response, byte* response_len);
|
||||
MFRC522::StatusCode Transceive(byte *command, byte command_len, byte *response, byte *response_len);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "nfc.h"
|
||||
#include <PubSubClient.h>
|
||||
|
||||
OTAProxy::OTAProxy(PubSubClient* mqttClient, NFC* nfc, int id)
|
||||
OTAProxy::OTAProxy(PubSubClient *mqttClient, NFC *nfc, int id)
|
||||
{
|
||||
this->mqtt = mqttClient;
|
||||
this->nfc = nfc;
|
||||
@ -16,7 +16,7 @@ bool OTAProxy::hasActiveOTA()
|
||||
|
||||
void OTAProxy::startOTA()
|
||||
{
|
||||
if(!(nfc->hasCardSelected()))
|
||||
if (!(nfc->hasCardSelected()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -30,7 +30,7 @@ void OTAProxy::startOTA()
|
||||
Serial.println("Start OTA");
|
||||
}
|
||||
|
||||
void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
|
||||
void OTAProxy::continueOTA(char *topic, byte *payload, unsigned int length)
|
||||
{
|
||||
char topic_requestOTA[] = "fabreader/00000/requestOTA";
|
||||
sprintf(topic_requestOTA, "fabreader/%05d/requestOTA", id);
|
||||
@ -44,7 +44,7 @@ void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
|
||||
char topic_restartOTA[] = "fabreader/00000/restartOTA";
|
||||
sprintf(topic_restartOTA, "fabreader/%05d/restartOTA", id);
|
||||
|
||||
if(!strcmp(topic, topic_requestOTA))
|
||||
if (!strcmp(topic, topic_requestOTA))
|
||||
{
|
||||
Serial.println("Request OTA");
|
||||
byte response[APDU_BUFFER_SIZE] = {0};
|
||||
@ -56,7 +56,7 @@ void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
|
||||
status = nfc->Transceive(payload, length, response, &response_len);
|
||||
Serial.printf("PICC_Tranceive: 0x%02x\n", status);
|
||||
|
||||
if(status != MFRC522::STATUS_OK)
|
||||
if (status != MFRC522::STATUS_OK)
|
||||
{
|
||||
cancelOTA();
|
||||
return;
|
||||
@ -65,7 +65,7 @@ void OTAProxy::continueOTA(char* topic, byte* payload, unsigned int length)
|
||||
mqtt->publish(topic_responseOTA, response, response_len);
|
||||
Serial.println("Response OTA");
|
||||
}
|
||||
else if(!strcmp(topic, topic_stopOTA))
|
||||
else if (!strcmp(topic, topic_stopOTA))
|
||||
{
|
||||
Serial.println("Stop OTA");
|
||||
nfc->disconnectCard();
|
||||
@ -89,7 +89,8 @@ void OTAProxy::cancelOTA()
|
||||
MFRC522::Uid uid = nfc->getUID();
|
||||
mqtt->publish(topic_cancelOTA, uid.uidByte, uid.size);
|
||||
|
||||
while(!(nfc->disconnectCard()));
|
||||
while (!(nfc->disconnectCard()))
|
||||
;
|
||||
activeOTA = false;
|
||||
|
||||
Serial.println("Cancel OTA");
|
||||
|
@ -7,18 +7,19 @@
|
||||
|
||||
class OTAProxy
|
||||
{
|
||||
private:
|
||||
private:
|
||||
bool activeOTA = false;
|
||||
PubSubClient* mqtt;
|
||||
NFC* nfc;
|
||||
PubSubClient *mqtt;
|
||||
NFC *nfc;
|
||||
int id;
|
||||
char msg[MSG_BUFFER_SIZE];
|
||||
public:
|
||||
OTAProxy(PubSubClient* mqtt, NFC* nfc, int id);
|
||||
|
||||
public:
|
||||
OTAProxy(PubSubClient *mqtt, NFC *nfc, int id);
|
||||
bool hasActiveOTA();
|
||||
|
||||
void startOTA();
|
||||
void continueOTA(char* topic, byte* payload, unsigned int length);
|
||||
void continueOTA(char *topic, byte *payload, unsigned int length);
|
||||
void cancelOTA();
|
||||
};
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "helpers.h"
|
||||
|
||||
void char2byte(char* str, byte* array)
|
||||
void char2byte(char *str, byte *array)
|
||||
{
|
||||
for(int i=0; i <2 ; i++)
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
char c = *str;
|
||||
if (c >= '0' && c <= '9')
|
||||
@ -24,46 +24,46 @@ void char2byte(char* str, byte* array)
|
||||
}
|
||||
}
|
||||
|
||||
void chars2bytes(char* str, byte* array, bool msb)
|
||||
void chars2bytes(char *str, byte *array, bool msb)
|
||||
{
|
||||
int len = strlen(str);
|
||||
for(int i = 0; i < len; i += 2)
|
||||
for (int i = 0; i < len; i += 2)
|
||||
{
|
||||
if(msb)
|
||||
if (msb)
|
||||
{
|
||||
char2byte(&str[i], &array[i/2]);
|
||||
char2byte(&str[i], &array[i / 2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
char2byte(&str[i], &array[len-2 - i/2]);
|
||||
char2byte(&str[i], &array[len - 2 - i / 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void byte2char(byte* array, char* str)
|
||||
void byte2char(byte *array, char *str)
|
||||
{
|
||||
sprintf(str, "%02x", *array);
|
||||
}
|
||||
|
||||
void bytes2chars(byte* array, byte array_len, char* str, bool msb)
|
||||
void bytes2chars(byte *array, byte array_len, char *str, bool msb)
|
||||
{
|
||||
for(int i = 0; i < array_len; i++)
|
||||
for (int i = 0; i < array_len; i++)
|
||||
{
|
||||
if(msb)
|
||||
if (msb)
|
||||
{
|
||||
byte2char(&array[i], &str[i*2]);
|
||||
byte2char(&array[i], &str[i * 2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte2char(&array[array_len-2 - i], &str[i*2]);
|
||||
byte2char(&array[array_len - 2 - i], &str[i * 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printbytes(byte* array, byte array_len)
|
||||
void printbytes(byte *array, byte array_len)
|
||||
{
|
||||
Serial.print("0x");
|
||||
for(int i = 0; i < array_len; i++)
|
||||
for (int i = 0; i < array_len; i++)
|
||||
{
|
||||
Serial.printf("%02x", array[i]);
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
#define HELPERS_H
|
||||
|
||||
#include <Arduino.h>
|
||||
void char2byte(char* str, byte* array);
|
||||
void chars2bytes(char* str, byte* array, bool msb);
|
||||
void char2byte(char *str, byte *array);
|
||||
void chars2bytes(char *str, byte *array, bool msb);
|
||||
|
||||
void byte2char(byte* array, char* str);
|
||||
void bytes2chars(byte* array, byte array_len, char* str, bool msb);
|
||||
void byte2char(byte *array, char *str);
|
||||
void bytes2chars(byte *array, byte array_len, char *str, bool msb);
|
||||
|
||||
void printbytes(byte* array, byte array_len);
|
||||
void printbytes(byte *array, byte array_len);
|
||||
|
||||
#endif
|
@ -17,12 +17,12 @@
|
||||
#include <SPI.h>
|
||||
|
||||
WiFiClient espClient;
|
||||
//Config_Data config;
|
||||
// Config_Data config;
|
||||
|
||||
PubSubClient* mqtt;
|
||||
NFC* nfc;
|
||||
OTAProxy* ota;
|
||||
Display* display;
|
||||
PubSubClient *mqtt;
|
||||
NFC *nfc;
|
||||
OTAProxy *ota;
|
||||
Display *display;
|
||||
|
||||
unsigned long otatimeout = 3000;
|
||||
unsigned long lastotatime;
|
||||
@ -97,11 +97,11 @@ void reconnect()
|
||||
}
|
||||
}
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length)
|
||||
void callback(char *topic, byte *payload, unsigned int length)
|
||||
{
|
||||
Serial.println("Receive Message");
|
||||
Serial.println(topic);
|
||||
if(ota->hasActiveOTA())
|
||||
if (ota->hasActiveOTA())
|
||||
{
|
||||
ota->continueOTA(topic, payload, length);
|
||||
}
|
||||
@ -125,7 +125,7 @@ void setup()
|
||||
display->writeInfo("Start NFC ...");
|
||||
Serial.println("Connecting NFC ...");
|
||||
nfc = new NFC(PIN_RFID_SPI_SS, PIN_RFID_RST);
|
||||
if(!(nfc->rfid->PCD_PerformSelfTest()))
|
||||
if (!(nfc->rfid->PCD_PerformSelfTest()))
|
||||
{
|
||||
Serial.println("NFC Test failed");
|
||||
}
|
||||
@ -151,12 +151,12 @@ void loop()
|
||||
}
|
||||
mqtt->loop();
|
||||
|
||||
if(!ota->hasActiveOTA())
|
||||
if (!ota->hasActiveOTA())
|
||||
{
|
||||
if(nfc->checkforCard())
|
||||
if (nfc->checkforCard())
|
||||
{
|
||||
Serial.println("Card detected");
|
||||
if(nfc->connecttoCard())
|
||||
if (nfc->connecttoCard())
|
||||
{
|
||||
Serial.println("Card connected");
|
||||
lastotatime = millis();
|
||||
@ -170,9 +170,9 @@ void loop()
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ota->hasActiveOTA())
|
||||
if (ota->hasActiveOTA())
|
||||
{
|
||||
if(millis() - lastotatime > otatimeout)
|
||||
if (millis() - lastotatime > otatimeout)
|
||||
{
|
||||
ota->cancelOTA();
|
||||
display->clearReaderInfo();
|
||||
|
Loading…
x
Reference in New Issue
Block a user