Fix compilation errors for MQTT gateway
This commit is contained in:
+6
-10
@@ -616,7 +616,11 @@
|
|||||||
* @brief The Ethernet TCP/UDP port to open on controller or gateway.
|
* @brief The Ethernet TCP/UDP port to open on controller or gateway.
|
||||||
*/
|
*/
|
||||||
#ifndef MY_PORT
|
#ifndef MY_PORT
|
||||||
#define MY_PORT 5003
|
#ifdef MY_GATEWAY_MQTT_CLIENT
|
||||||
|
#define MY_PORT 1883
|
||||||
|
#else
|
||||||
|
#define MY_PORT 5003
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Static ip address of gateway (if this is disabled, DHCP will be used)
|
// Static ip address of gateway (if this is disabled, DHCP will be used)
|
||||||
@@ -718,15 +722,7 @@
|
|||||||
* @brief Set the name of predictable tty
|
* @brief Set the name of predictable tty
|
||||||
*/
|
*/
|
||||||
#ifndef MY_LINUX_TTY_NAME
|
#ifndef MY_LINUX_TTY_NAME
|
||||||
#define MY_LINUX_TTY_NAME "/dev/ttyMySensorsGateway"
|
#define MY_LINUX_TTY_NAME "/dev/ttyAMA0"
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @def MY_LINUX_TTY_GROUPNAME
|
|
||||||
* @brief Set the group name for the raw tty
|
|
||||||
*/
|
|
||||||
#ifndef MY_LINUX_TTY_GROUPNAME
|
|
||||||
#define MY_LINUX_TTY_GROUPNAME tty
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -267,13 +267,13 @@ for opt do
|
|||||||
CXXFLAGS="-DMY_PORT=${optarg} $CXXFLAGS"
|
CXXFLAGS="-DMY_PORT=${optarg} $CXXFLAGS"
|
||||||
;;
|
;;
|
||||||
--my-mqtt-client-id=*)
|
--my-mqtt-client-id=*)
|
||||||
CXXFLAGS="-DMY_MQTT_CLIENT_ID=${optarg} $CXXFLAGS"
|
CXXFLAGS="-DMY_MQTT_CLIENT_ID=\\\"${optarg}\\\" $CXXFLAGS"
|
||||||
;;
|
;;
|
||||||
--my-mqtt-publish-topic-prefix=*)
|
--my-mqtt-publish-topic-prefix=*)
|
||||||
CXXFLAGS="-DMY_MQTT_PUBLISH_TOPIC_PREFIX=${optarg} $CXXFLAGS"
|
CXXFLAGS="-DMY_MQTT_PUBLISH_TOPIC_PREFIX=\\\"${optarg}\\\" $CXXFLAGS"
|
||||||
;;
|
;;
|
||||||
--my-mqtt-subscribe-topic-prefix=*)
|
--my-mqtt-subscribe-topic-prefix=*)
|
||||||
CXXFLAGS="-DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=${optarg} $CXXFLAGS"
|
CXXFLAGS="-DMY_MQTT_SUBSCRIBE_TOPIC_PREFIX=\\\"${optarg}\\\" $CXXFLAGS"
|
||||||
;;
|
;;
|
||||||
--my-rf24-irq-pin=*)
|
--my-rf24-irq-pin=*)
|
||||||
CXXFLAGS="-DMY_RX_MESSAGE_BUFFER_FEATURE -DMY_RF24_IRQ_PIN=${optarg} $CXXFLAGS"
|
CXXFLAGS="-DMY_RX_MESSAGE_BUFFER_FEATURE -DMY_RF24_IRQ_PIN=${optarg} $CXXFLAGS"
|
||||||
@@ -319,7 +319,7 @@ if [[ ${gateway_type} == "ethernet" ]]; then
|
|||||||
CXXFLAGS="-DMY_GATEWAY_LINUX $CXXFLAGS"
|
CXXFLAGS="-DMY_GATEWAY_LINUX $CXXFLAGS"
|
||||||
elif [[ ${gateway_type} == "mqtt" ]]; then
|
elif [[ ${gateway_type} == "mqtt" ]]; then
|
||||||
LDFLAGS="-lmosquitto $LDFLAGS"
|
LDFLAGS="-lmosquitto $LDFLAGS"
|
||||||
CXXFLAGS="-DMY_GATEWAY_MQTT_CLIENT $CXXFLAGS"
|
CXXFLAGS="-DMY_GATEWAY_LINUX -DMY_GATEWAY_MQTT_CLIENT $CXXFLAGS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${radio_type} == "nrf24" ]]; then
|
if [[ ${radio_type} == "nrf24" ]]; then
|
||||||
|
|||||||
+16
-40
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "MyHwLinuxGeneric.h"
|
#include "MyHwLinuxGeneric.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -28,60 +27,47 @@
|
|||||||
|
|
||||||
static const char* CONFIG_FILE = MY_LINUX_CONFIG_FILE;
|
static const char* CONFIG_FILE = MY_LINUX_CONFIG_FILE;
|
||||||
static const size_t _length = 1024; // ATMega328 has 1024 bytes
|
static const size_t _length = 1024; // ATMega328 has 1024 bytes
|
||||||
static uint8_t _config[_length];
|
static uint8_t _config[_length];
|
||||||
static unsigned long millis_at_start;
|
|
||||||
|
|
||||||
bool CheckConfigFile() {
|
bool CheckConfigFile() {
|
||||||
struct stat fileInfo;
|
struct stat fileInfo;
|
||||||
|
|
||||||
if(stat(CONFIG_FILE, &fileInfo) != 0)
|
if (stat(CONFIG_FILE, &fileInfo) != 0) {
|
||||||
{
|
|
||||||
//File does not exist. Create it.
|
//File does not exist. Create it.
|
||||||
debug("Config file %s does not exist, creating new config file.\n", CONFIG_FILE);
|
debug("Config file %s does not exist, creating new config file.\n", CONFIG_FILE);
|
||||||
ofstream myFile(CONFIG_FILE, ios::out | ios::binary);
|
ofstream myFile(CONFIG_FILE, ios::out | ios::binary);
|
||||||
if(!myFile)
|
if (!myFile) {
|
||||||
{
|
|
||||||
debug("Unable to create config file %s.\n", CONFIG_FILE);
|
debug("Unable to create config file %s.\n", CONFIG_FILE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
myFile.write((const char*)_config, _length);
|
myFile.write((const char*)_config, _length);
|
||||||
myFile.close();
|
myFile.close();
|
||||||
}
|
} else if (fileInfo.st_size < 0 || (size_t)fileInfo.st_size != _length) {
|
||||||
else if(fileInfo.st_size < 0 || (size_t)fileInfo.st_size != _length)
|
|
||||||
{
|
|
||||||
debug("Config file %s is not the correct size of %i. Please remove the file and a new one will be created.\n", CONFIG_FILE, _length);
|
debug("Config file %s is not the correct size of %i. Please remove the file and a new one will be created.\n", CONFIG_FILE, _length);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
//Read config into local memory.
|
//Read config into local memory.
|
||||||
ifstream myFile(CONFIG_FILE, ios::in | ios::binary);
|
ifstream myFile(CONFIG_FILE, ios::in | ios::binary);
|
||||||
if(!myFile)
|
if (!myFile) {
|
||||||
{
|
|
||||||
debug("Unable to open config to file %s for reading.\n", CONFIG_FILE);
|
debug("Unable to open config to file %s for reading.\n", CONFIG_FILE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
myFile.read((char*)_config, _length);
|
myFile.read((char*)_config, _length);
|
||||||
myFile.close();
|
myFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwInit()
|
void hwInit()
|
||||||
{
|
{
|
||||||
timeval curTime;
|
for (size_t i = 0; i < _length; i++) {
|
||||||
|
|
||||||
for (size_t i = 0; i < _length; i++)
|
|
||||||
_config[i] = 0xFF;
|
_config[i] = 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
if (!CheckConfigFile())
|
if (!CheckConfigFile()) {
|
||||||
{
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday(&curTime, NULL);
|
|
||||||
millis_at_start = curTime.tv_sec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwReadConfigBlock(void* buf, void* addr, size_t length)
|
void hwReadConfigBlock(void* buf, void* addr, size_t length)
|
||||||
@@ -101,8 +87,7 @@ void hwWriteConfigBlock(void* buf, void* addr, size_t length)
|
|||||||
memcpy(_config+offs, buf, length);
|
memcpy(_config+offs, buf, length);
|
||||||
|
|
||||||
ofstream myFile(CONFIG_FILE, ios::out | ios::binary);
|
ofstream myFile(CONFIG_FILE, ios::out | ios::binary);
|
||||||
if(!myFile)
|
if (!myFile) {
|
||||||
{
|
|
||||||
debug("Unable to write config to file %s.\n", CONFIG_FILE);
|
debug("Unable to write config to file %s.\n", CONFIG_FILE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -121,21 +106,12 @@ uint8_t hwReadConfig(int adr)
|
|||||||
void hwWriteConfig(int adr, uint8_t value)
|
void hwWriteConfig(int adr, uint8_t value)
|
||||||
{
|
{
|
||||||
uint8_t curr = hwReadConfig(adr);
|
uint8_t curr = hwReadConfig(adr);
|
||||||
if (curr != value)
|
if (curr != value) {
|
||||||
{
|
|
||||||
hwWriteConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
hwWriteConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long hwMillis()
|
// Not supported!
|
||||||
{
|
|
||||||
timeval curTime;
|
|
||||||
|
|
||||||
gettimeofday(&curTime, NULL);
|
|
||||||
return ((curTime.tv_sec - millis_at_start) * 1000) + (curTime.tv_usec / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Not supported!
|
|
||||||
int8_t hwSleep(unsigned long ms)
|
int8_t hwSleep(unsigned long ms)
|
||||||
{
|
{
|
||||||
(void)ms;
|
(void)ms;
|
||||||
@@ -143,7 +119,7 @@ int8_t hwSleep(unsigned long ms)
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Not supported!
|
// Not supported!
|
||||||
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms)
|
int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms)
|
||||||
{
|
{
|
||||||
(void)interrupt;
|
(void)interrupt;
|
||||||
@@ -153,7 +129,7 @@ int8_t hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms)
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Not supported!
|
// Not supported!
|
||||||
int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms)
|
int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms)
|
||||||
{
|
{
|
||||||
(void)interrupt1;
|
(void)interrupt1;
|
||||||
|
|||||||
@@ -30,25 +30,25 @@
|
|||||||
#define hwDigitalWrite(__pin, __value)
|
#define hwDigitalWrite(__pin, __value)
|
||||||
#define hwWatchdogReset()
|
#define hwWatchdogReset()
|
||||||
#define hwReboot()
|
#define hwReboot()
|
||||||
|
#define hwMillis() millis()
|
||||||
|
|
||||||
void hwInit();
|
void hwInit();
|
||||||
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
||||||
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
||||||
void hwWriteConfig(int adr, uint8_t value);
|
void hwWriteConfig(int adr, uint8_t value);
|
||||||
uint8_t hwReadConfig(int adr);
|
uint8_t hwReadConfig(int adr);
|
||||||
unsigned long hwMillis();
|
|
||||||
|
|
||||||
#ifdef MY_RF24_IRQ_PIN
|
#ifdef MY_RF24_IRQ_PIN
|
||||||
static pthread_mutex_t hw_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t hw_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static __inline__ void __hwUnlock(const uint8_t *__s) {
|
static __inline__ void __hwUnlock(const uint8_t *__s) {
|
||||||
pthread_mutex_unlock(&hw_mutex);
|
pthread_mutex_unlock(&hw_mutex);
|
||||||
(void)__s;
|
(void)__s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline__ void __hwLock() {
|
static __inline__ void __hwLock() {
|
||||||
pthread_mutex_lock(&hw_mutex);
|
pthread_mutex_lock(&hw_mutex);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DOXYGEN)
|
#if defined(DOXYGEN)
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ char *ltoa(long value, char* result, int base);
|
|||||||
char *ultoa(long num, char *str, int radix);
|
char *ultoa(long num, char *str, int radix);
|
||||||
char *utoa(int num, char *str, int radix);
|
char *utoa(int num, char *str, int radix);
|
||||||
char *dtostrf(float f, int width, int decimals, char *result);
|
char *dtostrf(float f, int width, int decimals, char *result);
|
||||||
|
unsigned long millis(void);
|
||||||
void delay(unsigned int millis);
|
void delay(unsigned int millis);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
// For millis()
|
||||||
|
static unsigned long millis_at_start = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C++ version 0.4 char* style "itoa":
|
* C++ version 0.4 char* style "itoa":
|
||||||
* Written by Lukás Chmela
|
* Written by Lukás Chmela
|
||||||
@@ -177,6 +181,19 @@ char *dtostrf(float f, int width, int decimals, char *result)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long millis(void)
|
||||||
|
{
|
||||||
|
timeval curTime;
|
||||||
|
|
||||||
|
if (millis_at_start == 0) {
|
||||||
|
gettimeofday(&curTime, NULL);
|
||||||
|
millis_at_start = curTime.tv_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
gettimeofday(&curTime, NULL);
|
||||||
|
return ((curTime.tv_sec - millis_at_start) * 1000) + (curTime.tv_usec / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
void delay(unsigned int millis)
|
void delay(unsigned int millis)
|
||||||
{
|
{
|
||||||
struct timespec sleeper;
|
struct timespec sleeper;
|
||||||
|
|||||||
Reference in New Issue
Block a user