mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-14 07:56:52 +01:00
BugFix: Termination by ctl + C
Update: API mode is configurable Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -511,7 +511,7 @@ void Thread::stopProcess(void)
|
||||
_stopProcessEvent->post();
|
||||
}
|
||||
|
||||
void Thread::testThreadCancel(void)
|
||||
void Thread::cancel(void)
|
||||
{
|
||||
pthread_testcancel();
|
||||
pthread_cancel(_threadID);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
static bool equals(pthread_t*, pthread_t*);
|
||||
virtual void initialize(int argc, char** argv);
|
||||
void stopProcess(void);
|
||||
void testThreadCancel(void);
|
||||
void cancel(void);
|
||||
private:
|
||||
pthread_t _threadID;
|
||||
Semaphore* _stopProcessEvent;
|
||||
|
||||
@@ -153,6 +153,11 @@ const char* SensorNetwork::getDescription(void)
|
||||
return _description.c_str();
|
||||
}
|
||||
|
||||
SensorNetAddress* SensorNetwork::getSenderAddress(void)
|
||||
{
|
||||
return &_clientAddr;
|
||||
}
|
||||
|
||||
/*=========================================
|
||||
Class udpStack
|
||||
=========================================*/
|
||||
|
||||
@@ -99,11 +99,7 @@ public:
|
||||
int read(uint8_t* buf, uint16_t bufLen);
|
||||
int initialize(void);
|
||||
const char* getDescription(void);
|
||||
SensorNetAddress* getSenderAddress(void)
|
||||
{
|
||||
return &_clientAddr;
|
||||
}
|
||||
|
||||
SensorNetAddress* getSenderAddress(void);
|
||||
|
||||
private:
|
||||
SensorNetAddress _clientAddr; // Sender's address. not gateway's one.
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "SensorNetwork.h"
|
||||
#include "MQTTSNGWProcess.h"
|
||||
#include "Threading.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace MQTTSNGW;
|
||||
@@ -111,17 +110,27 @@ int SensorNetwork::initialize(void)
|
||||
{
|
||||
char param[MQTTSNGW_PARAM_MAX];
|
||||
uint16_t baudrate = 9600;
|
||||
uint8_t apimode = 2;
|
||||
|
||||
if (theProcess->getParam("XBee Baudrate", param) == 0)
|
||||
if (theProcess->getParam("ApiMode", param) == 0)
|
||||
{
|
||||
apimode = (uint8_t)atoi(param);
|
||||
}
|
||||
setApiMode(apimode);
|
||||
_description = "API mode ";
|
||||
sprintf(param, "%d", apimode);
|
||||
_description += param;
|
||||
|
||||
if (theProcess->getParam("Baudrate", param) == 0)
|
||||
{
|
||||
baudrate = (uint16_t)atoi(param);
|
||||
}
|
||||
_description = "Baudrate ";
|
||||
_description += ", Baudrate ";
|
||||
sprintf(param ,"%d", baudrate);
|
||||
_description += param;
|
||||
|
||||
theProcess->getParam("SerialDevice", param);
|
||||
_description = "SerialDevice ";
|
||||
_description += ", SerialDevice ";
|
||||
_description += param;
|
||||
|
||||
return XBee::open(param, baudrate);
|
||||
@@ -132,6 +141,11 @@ const char* SensorNetwork::getDescription(void)
|
||||
return _description.c_str();
|
||||
}
|
||||
|
||||
SensorNetAddress* SensorNetwork::getSenderAddress(void)
|
||||
{
|
||||
return &_clientAddr;
|
||||
}
|
||||
|
||||
/*===========================================
|
||||
Class XBee
|
||||
============================================*/
|
||||
@@ -140,6 +154,7 @@ XBee::XBee(){
|
||||
_respCd = 0;
|
||||
_dataLen = 0;
|
||||
_frameId = 0;
|
||||
_apiMode = 2;
|
||||
}
|
||||
|
||||
XBee::~XBee(){
|
||||
@@ -340,7 +355,7 @@ int XBee::send(const uint8_t* payload, uint8_t pLen, SensorNetAddress* addr){
|
||||
|
||||
void XBee::send(uint8_t c)
|
||||
{
|
||||
if(c == START_BYTE || c == ESCAPE || c == XON || c == XOFF){
|
||||
if(_apiMode == 2 && (c == START_BYTE || c == ESCAPE || c == XON || c == XOFF)){
|
||||
_serialPort->send(ESCAPE);
|
||||
_serialPort->send(c ^ 0x20);
|
||||
}else{
|
||||
@@ -352,7 +367,7 @@ int XBee::recv(uint8_t* buf)
|
||||
{
|
||||
if (_serialPort->recv(buf) )
|
||||
{
|
||||
if ( *buf == ESCAPE)
|
||||
if ( *buf == ESCAPE && _apiMode == 2 )
|
||||
{
|
||||
_serialPort->recv(buf);
|
||||
*buf = 0x20 ^ *buf;
|
||||
@@ -362,6 +377,11 @@ int XBee::recv(uint8_t* buf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void XBee::setApiMode(uint8_t mode)
|
||||
{
|
||||
_apiMode = mode;
|
||||
}
|
||||
|
||||
/*=========================================
|
||||
Class SerialPort
|
||||
=========================================*/
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
int unicast(const uint8_t* buf, uint16_t length, SensorNetAddress* sendToAddr);
|
||||
int broadcast(const uint8_t* buf, uint16_t length);
|
||||
int recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr);
|
||||
void setApiMode(uint8_t mode);
|
||||
|
||||
private:
|
||||
int readApiFrame(uint8_t* recvData);
|
||||
@@ -105,10 +106,10 @@ private:
|
||||
Mutex _meutex;
|
||||
SerialPort* _serialPort;
|
||||
uint8_t _frameId;
|
||||
|
||||
uint8_t _respCd;
|
||||
uint8_t _respId;
|
||||
uint8_t _dataLen;
|
||||
uint8_t _apiMode;
|
||||
};
|
||||
|
||||
/*===========================================
|
||||
@@ -125,11 +126,7 @@ public:
|
||||
int read(uint8_t* buf, uint16_t bufLen);
|
||||
int initialize(void);
|
||||
const char* getDescription(void);
|
||||
SensorNetAddress* getSenderAddress(void)
|
||||
{
|
||||
return &_clientAddr;
|
||||
}
|
||||
|
||||
SensorNetAddress* getSenderAddress(void);
|
||||
|
||||
private:
|
||||
SensorNetAddress _clientAddr; // Sender's address. not gateway's one.
|
||||
|
||||
Reference in New Issue
Block a user