mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-15 16:36:52 +01:00
Add a new sensor network Bluetooth RFCOMM
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -20,7 +20,7 @@ CPPSRCS := \
|
||||
$(SUBDIR)/LGwProxy.cpp \
|
||||
$(SUBDIR)/LMqttsnClient.cpp \
|
||||
$(SUBDIR)/LNetworkUdp.cpp \
|
||||
$(SUBDIR)/LNetworkBle.cpp \
|
||||
$(SUBDIR)/LNetworkRfcomm.cpp \
|
||||
$(SUBDIR)/LPublishManager.cpp \
|
||||
$(SUBDIR)/LRegisterManager.cpp \
|
||||
$(SUBDIR)/LSubscribeManager.cpp \
|
||||
|
||||
@@ -59,10 +59,10 @@ UDPCONF = {
|
||||
};
|
||||
|
||||
/*------------------------------------------------------
|
||||
* BLE Configuration (theNetcon)
|
||||
* RFCOMM Configuration (theNetcon)
|
||||
*------------------------------------------------------*/
|
||||
BLECONF = { "GatewayTestClient", // ClientId
|
||||
{ 0x60, 0x57, 0x18, 0x06, 0x8b, 0x72 }, // GW Address
|
||||
RFCOMMCONF = { "GatewayTestClient", // ClientId
|
||||
"60:57:18:06:8B:72", // GW Address
|
||||
1, // Rfcomm channel
|
||||
};
|
||||
|
||||
|
||||
@@ -59,10 +59,10 @@ UDPCONF = {
|
||||
};
|
||||
|
||||
/*------------------------------------------------------
|
||||
* BLE Configuration (theNetcon)
|
||||
* RFCOMM Configuration (theNetcon)
|
||||
*------------------------------------------------------*/
|
||||
BLECONF = { "GatewayTestClient", // ClientId
|
||||
{ 0x60, 0x57, 0x18, 0x06, 0x8b, 0x72 }, // GW Address
|
||||
RFCOMMCONF = { "GatewayTestClient", // ClientId
|
||||
"60:57:18:06:8B:72", // GW Address
|
||||
1, // Rfcomm channel
|
||||
};
|
||||
|
||||
|
||||
@@ -59,10 +59,10 @@ UDPCONF = {
|
||||
};
|
||||
|
||||
/*------------------------------------------------------
|
||||
* BLE Configuration (theNetcon)
|
||||
* RFCOMM Configuration (theNetcon)
|
||||
*------------------------------------------------------*/
|
||||
BLECONF = { "GatewayTestClient", // ClientId
|
||||
{ 0x44, 0x1C, 0xA8, 0x16, 0x94, 0x94 }, // GW Address
|
||||
RFCOMMCONF = { "GatewayTestClient", // ClientId
|
||||
"60:57:18:06:8B:72", // GW Address
|
||||
1, // Rfcomm channel
|
||||
};
|
||||
|
||||
|
||||
@@ -58,10 +58,10 @@ UDPCONF = { "GatewayTestClient", // ClientId
|
||||
};
|
||||
|
||||
/*------------------------------------------------------
|
||||
* BLE Configuration (theNetcon)
|
||||
* RFCOMM Configuration (theNetcon)
|
||||
*------------------------------------------------------*/
|
||||
BLECONF = { "GatewayTestClient", // ClientId
|
||||
{ 0x60, 0x57, 0x18, 0x06, 0x8b, 0x72 }, // GW Address
|
||||
RFCOMMCONF = { "GatewayTestClient", // ClientId
|
||||
"60:57:18:06:8B:72", // GW Address
|
||||
1, // Rfcomm channel
|
||||
};
|
||||
|
||||
|
||||
@@ -66,16 +66,16 @@ LGwProxy::~LGwProxy()
|
||||
_topicTbl.clearTopic();
|
||||
}
|
||||
|
||||
void LGwProxy::initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf)
|
||||
void LGwProxy::initialize(SENSORNET_CONFIG_t* netconf, LMqttsnConfig* mqconf)
|
||||
{
|
||||
_network.initialize(netconf);
|
||||
_clientId = netconf.clientId;
|
||||
_willTopic = mqconf.willTopic;
|
||||
_willMsg = mqconf.willMsg;
|
||||
_qosWill = mqconf.willQos;
|
||||
_retainWill = mqconf.willRetain;
|
||||
_cleanSession = mqconf.cleanSession;
|
||||
_tkeepAlive = mqconf.keepAlive;
|
||||
_clientId = netconf->clientId;
|
||||
_willTopic = mqconf->willTopic;
|
||||
_willMsg = mqconf->willMsg;
|
||||
_qosWill = mqconf->willQos;
|
||||
_retainWill = mqconf->willRetain;
|
||||
_cleanSession = mqconf->cleanSession;
|
||||
_tkeepAlive = mqconf->keepAlive;
|
||||
_initialized = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include "LMqttsnClientApp.h"
|
||||
#include "LNetworkUdp.h"
|
||||
#include "LNetworkBle.h"
|
||||
#include "LNetworkRfcomm.h"
|
||||
#include "LRegisterManager.h"
|
||||
#include "LTimer.h"
|
||||
#include "LTopicTable.h"
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
LGwProxy();
|
||||
~LGwProxy();
|
||||
|
||||
void initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf);
|
||||
void initialize(SENSORNET_CONFIG_t* netconf, LMqttsnConfig* mqconf);
|
||||
void connect(void);
|
||||
void disconnect(uint16_t sec = 0);
|
||||
int getMessage(void);
|
||||
|
||||
@@ -53,8 +53,8 @@ int main(int argc, char** argv)
|
||||
printf("\n%s", PAHO_COPYRIGHT0);
|
||||
#if defined(UDP)
|
||||
printf(" UDP\n");
|
||||
#elif defined(BLE)
|
||||
printf(" BLE\n");
|
||||
#elif defined(RFCOMM)
|
||||
printf(" RFCOMM\n");
|
||||
#else
|
||||
printf("\n");
|
||||
#endif
|
||||
@@ -90,7 +90,7 @@ int main(int argc, char** argv)
|
||||
|
||||
setup();
|
||||
theClient->addTask(theClientMode);
|
||||
theClient->initialize( theNetcon, theMqcon);
|
||||
theClient->initialize( &theNetcon, &theMqcon);
|
||||
do
|
||||
{
|
||||
theClient->run();
|
||||
@@ -115,10 +115,10 @@ LMqttsnClient::~LMqttsnClient()
|
||||
|
||||
}
|
||||
|
||||
void LMqttsnClient::initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf)
|
||||
void LMqttsnClient::initialize(SENSORNET_CONFIG_t* netconf, LMqttsnConfig* mqconf)
|
||||
{
|
||||
_gwProxy.initialize(netconf, mqconf);
|
||||
setSleepDuration(mqconf.sleepDuration);
|
||||
setSleepDuration(mqconf->sleepDuration);
|
||||
}
|
||||
|
||||
void LMqttsnClient::addTask(bool clientMode)
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
void unsubscribe(const char* topicName);
|
||||
void unsubscribe(const uint16_t topicId);
|
||||
void disconnect(uint16_t sleepInSecs);
|
||||
void initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf);
|
||||
void initialize(SENSORNET_CONFIG_t* netconf, LMqttsnConfig* mqconf);
|
||||
void run(void);
|
||||
void addTask(bool test);
|
||||
void setSleepDuration(uint32_t duration);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
======================================*/
|
||||
//#define CLIENT_MODE
|
||||
#define UDP
|
||||
//#define BLE
|
||||
//#define RFCOMM
|
||||
/*======================================
|
||||
* Debug Flag
|
||||
======================================*/
|
||||
@@ -75,10 +75,10 @@ struct LUdpConfig
|
||||
uint16_t uPortNo;
|
||||
};
|
||||
|
||||
struct LBleConfig
|
||||
struct LRfcommConfig
|
||||
{
|
||||
const char* clientId;
|
||||
uint8_t gwAddress[6];
|
||||
const char* gwAddress;
|
||||
uint8_t channel;
|
||||
};
|
||||
|
||||
@@ -100,13 +100,16 @@ typedef enum
|
||||
#ifdef UDP
|
||||
#define NETWORK_CONFIG UdpConfig theNetworkConfig
|
||||
#define UDPCONF LUdpConfig theNetcon
|
||||
#define BLECONF LBleConfig theConf
|
||||
#define RFCOMMCONF LRfcommConfig theConf
|
||||
#define SENSORNET_CONFIG_t LUdpConfig
|
||||
#else
|
||||
#ifdef RFCOMM
|
||||
#define NETWORK_CONFIG BleConfig theNetworkConfig
|
||||
#define BLECONF LBleConfig theNetcon
|
||||
#define RFCOMMCONF LRfcommConfig theNetcon
|
||||
#define UDPCONF LUdpConfig theConf
|
||||
#define SENSORNET_CONFIG_t LBleConfig
|
||||
#define SENSORNET_CONFIG_t LRfcommConfig
|
||||
#endif
|
||||
#error "UDP and RFCOMM are not defined in LMqttsnClientApp.h"
|
||||
#endif
|
||||
|
||||
#define CONNECT(...) theClient->getGwProxy()->connect(__VA_ARGS__)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
|
||||
**************************************************************************************/
|
||||
#include "LMqttsnClientApp.h"
|
||||
#ifdef BLE
|
||||
#ifdef RFCOMM
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/rfcomm.h>
|
||||
|
||||
#include "LNetworkBle.h"
|
||||
#include "LNetworkRfcomm.h"
|
||||
#include "LTimer.h"
|
||||
#include "LScreen.h"
|
||||
|
||||
@@ -40,7 +40,7 @@ extern uint16_t getUint16(const uint8_t* pos);
|
||||
extern uint32_t getUint32(const uint8_t* pos);
|
||||
extern LScreen* theScreen;
|
||||
extern bool theClientMode;
|
||||
extern LBleConfig theNetcon;
|
||||
extern LRfcommConfig theNetcon;
|
||||
/*=========================================
|
||||
Class LNetwork
|
||||
=========================================*/
|
||||
@@ -57,12 +57,12 @@ LNetwork::~LNetwork()
|
||||
|
||||
int LNetwork::broadcast(const uint8_t* xmitData, uint16_t dataLen)
|
||||
{
|
||||
return LBlePort::unicast(xmitData, dataLen);
|
||||
return LRfcommPort::unicast(xmitData, dataLen);
|
||||
}
|
||||
|
||||
int LNetwork::unicast(const uint8_t* xmitData, uint16_t dataLen)
|
||||
{
|
||||
return LBlePort::unicast(xmitData, dataLen);
|
||||
return LRfcommPort::unicast(xmitData, dataLen);
|
||||
}
|
||||
|
||||
uint8_t* LNetwork::getMessage(int* len)
|
||||
@@ -70,7 +70,7 @@ uint8_t* LNetwork::getMessage(int* len)
|
||||
*len = 0;
|
||||
if (checkRecvBuf())
|
||||
{
|
||||
uint16_t recvLen = LBlePort::recv(_rxDataBuf, MQTTSN_MAX_PACKET_SIZE, false);
|
||||
uint16_t recvLen = LRfcommPort::recv(_rxDataBuf, MQTTSN_MAX_PACKET_SIZE, false);
|
||||
|
||||
if (recvLen < 0)
|
||||
{
|
||||
@@ -87,12 +87,7 @@ uint8_t* LNetwork::getMessage(int* len)
|
||||
{
|
||||
*len = _rxDataBuf[0];
|
||||
}
|
||||
//if(recvLen != *len){
|
||||
// *len = 0;
|
||||
// return 0;
|
||||
//}else{
|
||||
return _rxDataBuf;
|
||||
//}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -104,13 +99,13 @@ void LNetwork::setGwAddress(void)
|
||||
|
||||
void LNetwork::setFixedGwAddress(void)
|
||||
{
|
||||
_channel = LBlePort::_channel;
|
||||
memcpy(_gwAddress, theNetcon.gwAddress, 6);
|
||||
_channel = LRfcommPort::_channel;
|
||||
str2ba( theNetcon.gwAddress, (bdaddr_t*)_gwAddress);
|
||||
}
|
||||
|
||||
bool LNetwork::initialize(LBleConfig config)
|
||||
bool LNetwork::initialize(LRfcommConfig* config)
|
||||
{
|
||||
return LBlePort::open(config);
|
||||
return LRfcommPort::open(config);
|
||||
}
|
||||
|
||||
void LNetwork::setSleep()
|
||||
@@ -124,55 +119,51 @@ bool LNetwork::isBroadcastable()
|
||||
}
|
||||
|
||||
/*=========================================
|
||||
Class BleStack
|
||||
Class RFCOMM Stack
|
||||
=========================================*/
|
||||
LBlePort::LBlePort()
|
||||
LRfcommPort::LRfcommPort()
|
||||
{
|
||||
_disconReq = false;
|
||||
_sockBle = 0;
|
||||
_sockRfcomm = 0;
|
||||
_channel = 0;
|
||||
}
|
||||
|
||||
LBlePort::~LBlePort()
|
||||
LRfcommPort::~LRfcommPort()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void LBlePort::close()
|
||||
void LRfcommPort::close()
|
||||
{
|
||||
if (_sockBle > 0)
|
||||
if (_sockRfcomm > 0)
|
||||
{
|
||||
::close(_sockBle);
|
||||
_sockBle = 0;
|
||||
::close(_sockRfcomm);
|
||||
_sockRfcomm = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool LBlePort::open(LBleConfig config)
|
||||
bool LRfcommPort::open(LRfcommConfig* config)
|
||||
{
|
||||
const int reuse = 1;
|
||||
uint8_t* gw = config.gwAddress + 5;
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
*(_gwAddress + i) = *gw--;
|
||||
}
|
||||
_channel = config.channel;
|
||||
str2ba(config->gwAddress, (bdaddr_t*)_gwAddress);
|
||||
_channel = config->channel;
|
||||
|
||||
if (_channel == 0 || _gwAddress == 0 || _devAddress == 0)
|
||||
if (_channel == 0 || _gwAddress == 0 )
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror BLE Address in BlePort::open\033[0m\033[0;37m\n");
|
||||
DISPLAY("\033[0m\033[0;31m\nerror BLE Address in BlePort::open\033[0m\033[0;37m\n");
|
||||
D_NWLOG("\033[0m\033[0;31merror Bluetooth Address in LRfcommPort::open\033[0m\033[0;37m\n");
|
||||
DISPLAY("\033[0m\033[0;31m\nerror Bluetooth Address in LRfcommPort::open\033[0m\033[0;37m\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
_sockBle = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
|
||||
if (_sockBle < 0)
|
||||
_sockRfcomm = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
|
||||
if (_sockRfcomm < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror Can't create socket in BlePort::open\033[0m\033[0;37m\n");
|
||||
DISPLAY("\033[0m\033[0;31m\nerror Can't create socket in BlePort::open\033[0m\033[0;37m\n");
|
||||
D_NWLOG("\033[0m\033[0;31merror Can't create socket in LRfcommPort::open\033[0m\033[0;37m\n");
|
||||
DISPLAY("\033[0m\033[0;31m\nerror Can't create socket in LRfcommPort::open\033[0m\033[0;37m\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
setsockopt(_sockBle, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
|
||||
setsockopt(_sockRfcomm, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
|
||||
|
||||
struct sockaddr_rc addru = { 0 };
|
||||
addru.rc_family = AF_BLUETOOTH;
|
||||
@@ -185,24 +176,24 @@ bool LBlePort::open(LBleConfig config)
|
||||
|
||||
// connect to server
|
||||
errno = 0;
|
||||
int status = connect(_sockBle, (struct sockaddr *) &addru, sizeof(addru));
|
||||
int status = connect(_sockRfcomm, (struct sockaddr *) &addru, sizeof(addru));
|
||||
if (status < 0)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merror = %d Can't connect to GW in BlePort::open\033[0m\033[0;37m\n", errno);
|
||||
DISPLAY("\033[0m\033[0;31mCan't connect to GW Ble socket in BlePort::open\033[0m\033[0;37m\n");
|
||||
D_NWLOG("\033[0m\033[0;31merror = %d Can't connect to GW in LRfcommPort::open\033[0m\033[0;37m\n", errno);
|
||||
DISPLAY("\033[0m\033[0;31merror = %d Can't connect to GW Ble socket in LRfcommPort::open\033[0m\033[0;37m\n",errno);
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int LBlePort::unicast(const uint8_t* buf, uint32_t length)
|
||||
int LRfcommPort::unicast(const uint8_t* buf, uint32_t length)
|
||||
{
|
||||
int status = ::write(_sockBle, buf, length);
|
||||
int status = ::write(_sockRfcomm, buf, length);
|
||||
if (status < 0)
|
||||
{
|
||||
D_NWLOG("errno == %d in LBlePort::unicast\n", errno);
|
||||
DISPLAY("errno == %d in LBlePort::unicast\n", errno);
|
||||
D_NWLOG("errno == %d in LRfcommPort::unicast\n", errno);
|
||||
DISPLAY("errno == %d in LRfcommPort::unicast\n", errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -235,25 +226,25 @@ int LBlePort::unicast(const uint8_t* buf, uint32_t length)
|
||||
return status;
|
||||
}
|
||||
|
||||
bool LBlePort::checkRecvBuf()
|
||||
bool LRfcommPort::checkRecvBuf()
|
||||
{
|
||||
uint8_t buf[2];
|
||||
if (::recv(_sockBle, buf, 1, MSG_DONTWAIT | MSG_PEEK) > 0)
|
||||
if (::recv(_sockRfcomm, buf, 1, MSG_DONTWAIT | MSG_PEEK) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int LBlePort::recv(uint8_t* buf, uint16_t length, bool flg)
|
||||
int LRfcommPort::recv(uint8_t* buf, uint16_t length, bool flg)
|
||||
{
|
||||
int flags = flg ? MSG_DONTWAIT : 0;
|
||||
int status = ::recv(_sockBle, buf, length, flags);
|
||||
int status = ::recv(_sockRfcomm, buf, length, flags);
|
||||
|
||||
if (status < 0 && errno != EAGAIN)
|
||||
{
|
||||
D_NWLOG("\033[0m\033[0;31merrno == %d in BlePort::recv \033[0m\033[0;37m\n", errno);
|
||||
DISPLAY("\033[0m\033[0;31merrno == %d in BlePort::recv \033[0m\033[0;37m\n", errno);
|
||||
D_NWLOG("\033[0m\033[0;31merrno = %d in LRfcommPort::recv \033[0m\033[0;37m\n", errno);
|
||||
DISPLAY("\033[0m\033[0;31merrno = %d in LRfcommPort::recv \033[0m\033[0;37m\n", errno);
|
||||
}
|
||||
else if (status > 0)
|
||||
{
|
||||
@@ -14,11 +14,11 @@
|
||||
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
|
||||
**************************************************************************************/
|
||||
|
||||
#ifndef NETWORKBLE_H_
|
||||
#define NETWORKBLE_H_
|
||||
#ifndef NETWORKRFCOMM_H_
|
||||
#define NETWORKRFCOMM_H_
|
||||
|
||||
#include "LMqttsnClientApp.h"
|
||||
#ifdef BLE
|
||||
#ifdef RFCOMM
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <iostream>
|
||||
@@ -44,17 +44,15 @@ using namespace std;
|
||||
namespace linuxAsyncClient
|
||||
{
|
||||
/*========================================
|
||||
Class LBlePort
|
||||
Class LRfcommPort
|
||||
=======================================*/
|
||||
class LBlePort
|
||||
class LRfcommPort
|
||||
{
|
||||
friend class LNetwork;
|
||||
public:
|
||||
LBlePort();
|
||||
virtual ~LBlePort();
|
||||
|
||||
bool open(LBleConfig config);
|
||||
|
||||
LRfcommPort();
|
||||
virtual ~LRfcommPort();
|
||||
bool open(LRfcommConfig* config);
|
||||
int unicast(const uint8_t* buf, uint32_t length);
|
||||
int recv(uint8_t* buf, uint16_t len, bool nonblock);
|
||||
bool checkRecvBuf();
|
||||
@@ -63,8 +61,7 @@ public:
|
||||
private:
|
||||
void close();
|
||||
|
||||
int _sockBle;
|
||||
uint8_t _devAddress[6];
|
||||
int _sockRfcomm;
|
||||
uint8_t _gwAddress[6];
|
||||
uint8_t _channel;
|
||||
bool _disconReq;
|
||||
@@ -76,7 +73,7 @@ private:
|
||||
/*===========================================
|
||||
Class Network
|
||||
============================================*/
|
||||
class LNetwork: public LBlePort
|
||||
class LNetwork: public LRfcommPort
|
||||
{
|
||||
public:
|
||||
LNetwork();
|
||||
@@ -87,7 +84,7 @@ public:
|
||||
void setGwAddress(void);
|
||||
void resetGwAddress(void);
|
||||
void setFixedGwAddress(void);
|
||||
bool initialize(LBleConfig config);
|
||||
bool initialize(LRfcommConfig* config);
|
||||
uint8_t* getMessage(int* len);
|
||||
bool isBroadcastable();
|
||||
|
||||
@@ -102,5 +99,5 @@ private:
|
||||
};
|
||||
|
||||
} /* end of namespace */
|
||||
#endif /* BLE */
|
||||
#endif /* NETWORKBLE_H_ */
|
||||
#endif /* RFCOMM */
|
||||
#endif /* NETWORKRFCOM_H_ */
|
||||
@@ -104,7 +104,7 @@ void LNetwork::resetGwAddress(void){
|
||||
}
|
||||
|
||||
|
||||
bool LNetwork::initialize(LUdpConfig config){
|
||||
bool LNetwork::initialize(LUdpConfig* config){
|
||||
return LUdpPort::open(config);
|
||||
}
|
||||
|
||||
@@ -119,43 +119,48 @@ bool LNetwork::isBroadcastable()
|
||||
/*=========================================
|
||||
Class udpStack
|
||||
=========================================*/
|
||||
LUdpPort::LUdpPort(){
|
||||
LUdpPort::LUdpPort()
|
||||
{
|
||||
_disconReq = false;
|
||||
_sockfdUcast = -1;
|
||||
_sockfdMcast = -1;
|
||||
_castStat = 0;
|
||||
}
|
||||
|
||||
LUdpPort::~LUdpPort(){
|
||||
LUdpPort::~LUdpPort()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void LUdpPort::close(){
|
||||
if(_sockfdMcast > 0){
|
||||
if(_sockfdMcast > 0)
|
||||
{
|
||||
::close( _sockfdMcast);
|
||||
_sockfdMcast = -1;
|
||||
if(_sockfdUcast > 0){
|
||||
if(_sockfdUcast > 0)
|
||||
{
|
||||
::close( _sockfdUcast);
|
||||
_sockfdUcast = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LUdpPort::open(LUdpConfig config){
|
||||
bool LUdpPort::open(LUdpConfig* config)
|
||||
{
|
||||
const int reuse = 1;
|
||||
char loopch = 1;
|
||||
|
||||
uint8_t sav = config.ipAddress[3];
|
||||
config.ipAddress[3] = config.ipAddress[0];
|
||||
config.ipAddress[0] = sav;
|
||||
sav = config.ipAddress[2];
|
||||
config.ipAddress[2] = config.ipAddress[1];
|
||||
config.ipAddress[1] = sav;
|
||||
uint8_t sav = config->ipAddress[3];
|
||||
config->ipAddress[3] = config->ipAddress[0];
|
||||
config->ipAddress[0] = sav;
|
||||
sav = config->ipAddress[2];
|
||||
config->ipAddress[2] = config->ipAddress[1];
|
||||
config->ipAddress[1] = sav;
|
||||
|
||||
_gPortNo = htons(config.gPortNo);
|
||||
_gIpAddr = getUint32((const uint8_t*)config.ipAddress);
|
||||
_uPortNo = htons(config.uPortNo);
|
||||
_gPortNo = htons(config->gPortNo);
|
||||
_gIpAddr = getUint32((const uint8_t*)config->ipAddress);
|
||||
_uPortNo = htons(config->uPortNo);
|
||||
|
||||
if( _gPortNo == 0 || _gIpAddr == 0 || _uPortNo == 0){
|
||||
return false;
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
LUdpPort();
|
||||
virtual ~LUdpPort();
|
||||
|
||||
bool open(LUdpConfig config);
|
||||
bool open(LUdpConfig* config);
|
||||
|
||||
int unicast(const uint8_t* buf, uint32_t length, uint32_t ipaddress, uint16_t port );
|
||||
int multicast( const uint8_t* buf, uint32_t length );
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
void setGwAddress(void);
|
||||
void resetGwAddress(void);
|
||||
void setFixedGwAddress(void);
|
||||
bool initialize(LUdpConfig config);
|
||||
bool initialize(LUdpConfig* config);
|
||||
uint8_t* getMessage(int* len);
|
||||
bool isBroadcastable();
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user