Add support for serial gateway to Rpi
This commit is contained in:
@@ -30,12 +30,12 @@ static const size_t _length = 1024; // ATMega328 has 1024 bytes
|
||||
static uint8_t _config[_length];
|
||||
|
||||
bool CheckConfigFile() {
|
||||
struct stat fileInfo;
|
||||
struct stat fileInfo;
|
||||
|
||||
if (stat(CONFIG_FILE, &fileInfo) != 0) {
|
||||
//File does not exist. Create it.
|
||||
debug("Config file %s does not exist, creating new config file.\n", CONFIG_FILE);
|
||||
ofstream myFile(CONFIG_FILE, ios::out | ios::binary);
|
||||
std::ofstream myFile(CONFIG_FILE, std::ios::out | std::ios::binary);
|
||||
if (!myFile) {
|
||||
debug("Unable to create config file %s.\n", CONFIG_FILE);
|
||||
return false;
|
||||
@@ -47,7 +47,7 @@ bool CheckConfigFile() {
|
||||
return false;
|
||||
} else {
|
||||
//Read config into local memory.
|
||||
ifstream myFile(CONFIG_FILE, ios::in | ios::binary);
|
||||
std::ifstream myFile(CONFIG_FILE, std::ios::in | std::ios::binary);
|
||||
if (!myFile) {
|
||||
debug("Unable to open config to file %s for reading.\n", CONFIG_FILE);
|
||||
return false;
|
||||
@@ -68,6 +68,10 @@ void hwInit()
|
||||
if (!CheckConfigFile()) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef MY_GATEWAY_SERIAL
|
||||
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void hwReadConfigBlock(void* buf, void* addr, size_t length)
|
||||
@@ -86,7 +90,7 @@ void hwWriteConfigBlock(void* buf, void* addr, size_t length)
|
||||
if (length && offs + length <= _length) {
|
||||
memcpy(_config+offs, buf, length);
|
||||
|
||||
ofstream myFile(CONFIG_FILE, ios::out | ios::binary);
|
||||
std::ofstream myFile(CONFIG_FILE, std::ios::out | std::ios::binary);
|
||||
if (!myFile) {
|
||||
debug("Unable to write config to file %s.\n", CONFIG_FILE);
|
||||
return;
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
#ifndef MyHwLinuxGeneric_h
|
||||
#define MyHwLinuxGeneric_h
|
||||
|
||||
#include "MyHw.h"
|
||||
#include <cstdlib>
|
||||
#include <pthread.h>
|
||||
#include "MyHw.h"
|
||||
#include "SerialPort.h"
|
||||
|
||||
SerialPort Serial = SerialPort(MY_LINUX_SERIAL_PORT);
|
||||
#define MY_SERIALDEVICE Serial
|
||||
|
||||
// Define these as macros (do nothing)
|
||||
@@ -35,8 +37,8 @@
|
||||
void hwInit();
|
||||
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
||||
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
||||
void hwWriteConfig(int adr, uint8_t value);
|
||||
uint8_t hwReadConfig(int adr);
|
||||
void hwWriteConfig(int adr, uint8_t value);
|
||||
|
||||
#ifdef MY_RF24_IRQ_PIN
|
||||
static pthread_mutex_t hw_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -51,7 +51,7 @@ void _process() {
|
||||
transportProcess();
|
||||
#endif
|
||||
|
||||
#if defined(LINUX)
|
||||
#if defined(__linux__)
|
||||
// To avoid high cpu usage
|
||||
usleep(10000); // 10ms
|
||||
#endif
|
||||
@@ -65,7 +65,7 @@ void _infiniteLoop() {
|
||||
#if defined (MY_LEDS_BLINKING_FEATURE)
|
||||
ledsProcess();
|
||||
#endif
|
||||
#if defined(LINUX)
|
||||
#if defined(__linux__)
|
||||
exit(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
|
||||
#ifdef LINUX_ARCH_RASPBERRYPI
|
||||
#include "drivers/RF24/RF24_Linux.cpp"
|
||||
#ifdef __linux__
|
||||
#include "drivers/RF24/RF24_Linux.h"
|
||||
#else
|
||||
#include "drivers/RF24/RF24.h"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user