mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 23:46:51 +01:00
Update: Create param.conf and key files automatically.
BugFix: change parameter name BroadcastIp and BroadcastPortNo to MulticastIP and MulticastPortNo, respectively. Update: Makefile to copy param.conf and build Log monitor. Update: README Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -23,7 +23,7 @@ namespace MQTTSNGW
|
||||
/*=================================
|
||||
* Starting prompt
|
||||
==================================*/
|
||||
#define GATEWAY_VERSION "(Ver 0.1.1)"
|
||||
#define GATEWAY_VERSION "(Ver 0.2.0)"
|
||||
|
||||
/*=================================
|
||||
* Log controls
|
||||
@@ -37,8 +37,6 @@ namespace MQTTSNGW
|
||||
#define MQTTSNGW_MAX_PACKET_SIZE (1024) // Max Packet size
|
||||
#define SIZEOF_LOG_PACKET (128) // Length of the packet log in bytes
|
||||
|
||||
#define MQTTSNGW_CONFIG_FILE "/usr/local/etc/mqttsnGateway/config/param.conf"
|
||||
#define MQTTSNGW_CLIENT_LIST "/usr/local/etc/mqttsnGateway/config/clientList.conf"
|
||||
#define MQTTSNGW_TLS_CA_DIR "/etc/ssl/certs"
|
||||
|
||||
/*=================================
|
||||
|
||||
@@ -91,11 +91,14 @@ int Process::getParam(const char* parameter, char* value)
|
||||
char str[MQTTSNGW_PARAM_MAX];
|
||||
char param[MQTTSNGW_PARAM_MAX];
|
||||
FILE *fp;
|
||||
|
||||
string filename = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_CONFIG_FILE);
|
||||
|
||||
int i = 0, j = 0;
|
||||
|
||||
if ((fp = fopen(MQTTSNGW_CONFIG_FILE, "r")) == NULL)
|
||||
if ((fp = fopen(filename.c_str(), "r")) == NULL)
|
||||
{
|
||||
WRITELOG("No config file:[%s]\n", MQTTSNGW_CONFIG_FILE);
|
||||
WRITELOG("No config file:[%s]\n", filename.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@ namespace MQTTSNGW
|
||||
/*=================================
|
||||
* Parameters
|
||||
==================================*/
|
||||
#define MQTTSNGW_CONFIG_DIRECTORY "./"
|
||||
|
||||
#define MQTTSNGW_CONFIG_FILE "param.conf"
|
||||
#define MQTTSNGW_CLIENT_LIST "clientList.conf"
|
||||
|
||||
#define MQTTSNGW_MAX_TASK 10 // number of Tasks
|
||||
#define PROCESS_LOG_BUFFER_SIZE 16384 // Ring buffer size for Logs
|
||||
#define MQTTSNGW_PARAM_MAX 128 // Max length of config records.
|
||||
|
||||
@@ -62,6 +62,11 @@ void Gateway::initialize(int argc, char** argv)
|
||||
throw Exception( "Gateway::initialize: invalid Gateway Id");
|
||||
}
|
||||
|
||||
if (getParam("GatewayName", param) == 0)
|
||||
{
|
||||
_params.gatewayName = (uint8_t*) strdup(param);
|
||||
}
|
||||
|
||||
_params.mqttVersion = DEFAULT_MQTT_VERSION;
|
||||
if (getParam("MQTTVersion", param) == 0)
|
||||
{
|
||||
@@ -100,7 +105,9 @@ void Gateway::initialize(int argc, char** argv)
|
||||
{
|
||||
if (!strcasecmp(param, "YES"))
|
||||
{
|
||||
if (!_clientList.authorize(MQTTSNGW_CLIENT_LIST))
|
||||
string fileName = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_CLIENT_LIST);
|
||||
|
||||
if (!_clientList.authorize(fileName.c_str()))
|
||||
{
|
||||
throw Exception("Gateway::initialize: can't authorize clients.");
|
||||
}
|
||||
@@ -113,7 +120,7 @@ void Gateway::initialize(int argc, char** argv)
|
||||
void Gateway::run(void)
|
||||
{
|
||||
_lightIndicator.redLight(true);
|
||||
WRITELOG("%s MQTT-SN Gateway has been started. %s %s\n", currentDateTime(), _sensorNetwork.getType(), GATEWAY_VERSION);
|
||||
WRITELOG("%s %s has been started. %s %s\n", currentDateTime(), _params.gatewayName, _sensorNetwork.getType(), GATEWAY_VERSION);
|
||||
if ( getClientList()->isAuthorized() )
|
||||
{
|
||||
WRITELOG("\n Client authentication is required by the configuration settings.\n");
|
||||
|
||||
@@ -143,6 +143,7 @@ typedef struct
|
||||
uint8_t gatewayId;
|
||||
uint8_t mqttVersion;
|
||||
uint16_t maxInflightMsgs;
|
||||
uint8_t* gatewayName;
|
||||
}GatewayParams;
|
||||
|
||||
/*=====================================
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace MQTTSNGW;
|
||||
@@ -235,6 +236,15 @@ void Semaphore::timedwait(uint16_t millsec)
|
||||
=========================================*/
|
||||
RingBuffer::RingBuffer()
|
||||
{
|
||||
int fp = 0;
|
||||
string fileName = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_RINGBUFFER_KEY);
|
||||
fp = open(fileName.c_str(), O_CREAT, 0);
|
||||
close(fp);
|
||||
|
||||
fileName = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_RB_MUTEX_KEY);
|
||||
fp = open(fileName.c_str(), O_CREAT, 0);
|
||||
close(fp);
|
||||
|
||||
key_t key = ftok(MQTTSNGW_RINGBUFFER_KEY, 1);
|
||||
|
||||
if ((_shmid = shmget(key, PROCESS_LOG_BUFFER_SIZE,
|
||||
|
||||
@@ -19,13 +19,12 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include "MQTTSNGWDefines.h"
|
||||
|
||||
namespace MQTTSNGW
|
||||
{
|
||||
|
||||
#define MQTTSNGW_RINGBUFFER_KEY "/usr/local/etc/mqttsnGateway/config/ringbuffer.key"
|
||||
#define MQTTSNGW_RB_MUTEX_KEY "/usr/local/etc/mqttsnGateway/config/rbmutex.key"
|
||||
#define MQTTSNGW_RINGBUFFER_KEY "ringbuffer.key"
|
||||
#define MQTTSNGW_RB_MUTEX_KEY "rbmutex.key"
|
||||
#define MQTTSNGW_RB_SEMAPHOR_NAME "/rbsemaphor"
|
||||
|
||||
/*=====================================
|
||||
|
||||
Reference in New Issue
Block a user