mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-14 07:56:52 +01:00
Update & BugFix Add GatewayTester
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -235,13 +235,18 @@ void Semaphore::timedwait(uint16_t millsec)
|
||||
Class RingBuffer
|
||||
=========================================*/
|
||||
RingBuffer::RingBuffer()
|
||||
{
|
||||
RingBuffer(MQTTSNGW_CONFIG_DIRECTORY);
|
||||
}
|
||||
|
||||
RingBuffer::RingBuffer(const char* keyDirectory)
|
||||
{
|
||||
int fp = 0;
|
||||
string fileName = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_RINGBUFFER_KEY);
|
||||
string fileName = keyDirectory + string(MQTTSNGW_RINGBUFFER_KEY);
|
||||
fp = open(fileName.c_str(), O_CREAT, 0);
|
||||
close(fp);
|
||||
|
||||
fileName = string(MQTTSNGW_CONFIG_DIRECTORY) + string(MQTTSNGW_RB_MUTEX_KEY);
|
||||
fileName = keyDirectory + string(MQTTSNGW_RB_MUTEX_KEY);
|
||||
fp = open(fileName.c_str(), O_CREAT, 0);
|
||||
close(fp);
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ class RingBuffer
|
||||
{
|
||||
public:
|
||||
RingBuffer();
|
||||
RingBuffer(const char* keyDirctory);
|
||||
~RingBuffer();
|
||||
void put(char* buffer);
|
||||
int get(char* buffer, int bufferLength);
|
||||
|
||||
@@ -31,14 +31,14 @@ using namespace MQTTSNGW;
|
||||
=====================================*/
|
||||
char theCurrentTime[32];
|
||||
|
||||
char* currentDateTime()
|
||||
const char* currentDateTime()
|
||||
{
|
||||
struct timeval now;
|
||||
struct tm tstruct;
|
||||
gettimeofday(&now, 0);
|
||||
tstruct = *localtime(&now.tv_sec);
|
||||
strftime(theCurrentTime, sizeof(theCurrentTime), "%Y%m%d %H%M%S", &tstruct);
|
||||
sprintf(theCurrentTime + 15, " %03d", (int)now.tv_usec / 1000 );
|
||||
sprintf(theCurrentTime + 15, ".%03d", (int)now.tv_usec / 1000 );
|
||||
return theCurrentTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,12 +53,12 @@ void SensorNetAddress::setAddress(uint32_t IpAddr, uint16_t port)
|
||||
|
||||
/**
|
||||
* convert Text data to SensorNetAddress
|
||||
* @param buf is pointer of PortNo@IP_Address format text
|
||||
* @param buf is pointer of IP_Address:PortNo format text
|
||||
* @return success = 0, Invalid format = -1
|
||||
*/
|
||||
int SensorNetAddress::setAddress(string* data)
|
||||
{
|
||||
size_t pos = data->find_first_of("@");
|
||||
size_t pos = data->find_first_of(":");
|
||||
|
||||
if ( pos == string::npos )
|
||||
{
|
||||
@@ -67,8 +67,8 @@ int SensorNetAddress::setAddress(string* data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
string port = data->substr(0, pos);
|
||||
string ip = data->substr(pos + 1);
|
||||
string ip = data->substr(0, pos);
|
||||
string port = data->substr(pos + 1);
|
||||
int portNo = 0;
|
||||
|
||||
if ((portNo = atoi(port.c_str())) == 0 || (_IpAddr = inet_addr(ip.c_str())) == INADDR_NONE)
|
||||
@@ -124,23 +124,33 @@ int SensorNetwork::initialize(void)
|
||||
char param[MQTTSNGW_PARAM_MAX];
|
||||
uint16_t multicastPortNo = 0;
|
||||
uint16_t unicastPortNo = 0;
|
||||
string ip;
|
||||
|
||||
if (theProcess->getParam("MulticastIP", param) == 0)
|
||||
{
|
||||
ip = param;
|
||||
_description = "UDP Multicast ";
|
||||
_description += param;
|
||||
}
|
||||
if (theProcess->getParam("MulticastPortNo", param) == 0)
|
||||
{
|
||||
multicastPortNo = atoi(param);
|
||||
_description += ":";
|
||||
_description += param;
|
||||
}
|
||||
if (theProcess->getParam("GatewayPortNo", param) == 0)
|
||||
{
|
||||
unicastPortNo = atoi(param);
|
||||
_description += " and Gateway Port ";
|
||||
_description += param;
|
||||
}
|
||||
|
||||
theProcess->getParam("MulticastIP", param);
|
||||
return UDPPort::open(param, multicastPortNo, unicastPortNo);
|
||||
return UDPPort::open(ip.c_str(), multicastPortNo, unicastPortNo);
|
||||
}
|
||||
|
||||
const char* SensorNetwork::getType(void)
|
||||
const char* SensorNetwork::getDescription(void)
|
||||
{
|
||||
return "UDP";
|
||||
return _description.c_str();
|
||||
}
|
||||
|
||||
/*=========================================
|
||||
@@ -173,7 +183,7 @@ void UDPPort::close(void)
|
||||
}
|
||||
}
|
||||
|
||||
int UDPPort::open(char* ipAddress, uint16_t multiPortNo, uint16_t uniPortNo)
|
||||
int UDPPort::open(const char* ipAddress, uint16_t multiPortNo, uint16_t uniPortNo)
|
||||
{
|
||||
char loopch = 0;
|
||||
const int reuse = 1;
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace MQTTSNGW
|
||||
#define D_NWSTACK(...)
|
||||
#endif
|
||||
|
||||
#define SENSORNETWORK_TYPE "UDP"
|
||||
/*===========================================
|
||||
Class SensorNetAddreess
|
||||
============================================*/
|
||||
@@ -67,7 +66,7 @@ public:
|
||||
UDPPort();
|
||||
virtual ~UDPPort();
|
||||
|
||||
int open(char* ipAddress, uint16_t multiPortNo, uint16_t uniPortNo);
|
||||
int open(const char* ipAddress, uint16_t multiPortNo, uint16_t uniPortNo);
|
||||
void close(void);
|
||||
int unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* sendToAddr);
|
||||
int broadcast(const uint8_t* buf, uint32_t length);
|
||||
@@ -99,7 +98,7 @@ public:
|
||||
int broadcast(const uint8_t* payload, uint16_t payloadLength);
|
||||
int read(uint8_t* buf, uint16_t bufLen);
|
||||
int initialize(void);
|
||||
const char* getType(void);
|
||||
const char* getDescription(void);
|
||||
SensorNetAddress* getSenderAddress(void)
|
||||
{
|
||||
return &_clientAddr;
|
||||
@@ -108,6 +107,7 @@ public:
|
||||
|
||||
private:
|
||||
SensorNetAddress _clientAddr; // Sender's address. not gateway's one.
|
||||
string _description;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user