Add errno to a Exception property

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2021-05-05 15:29:59 +09:00
parent 29486503d1
commit f631f27c25
12 changed files with 57 additions and 39 deletions

View File

@@ -31,6 +31,9 @@ namespace MQTTSNGW
#define MQTTSNGW_RB_MUTEX_KEY "rbmutex.key"
#define MQTTSNGW_RB_SEMAPHOR_NAME "/rbsemaphor"
#define RED_HDR "\033[0m\033[0;31m"
#define CLR_HDR "\033[0m\033[0;37m"
/*=====================================
Class Mutex
====================================*/
@@ -129,9 +132,8 @@ public: void EXECRUN() \
} \
catch ( Exception &ex ) \
{ \
WRITELOG("\033[0m\033[0;31m"); \
ex.writeMessage(); \
WRITELOG("\033[0m\033[0;37m%s caught an exception and stopped.\n", getTaskName()); \
WRITELOG("%s%s caught an exception and stopped.%s\n", RED_HDR, getTaskName(), CLR_HDR); \
theMultiTaskProcess->abort(); \
} \
theMultiTaskProcess->threadStopped(); \

View File

@@ -119,7 +119,7 @@ int SensorNetwork::read(uint8_t* buf, uint16_t bufLen)
return LoRaLink::recv(buf, bufLen, &_clientAddr);
}
int SensorNetwork::initialize(void)
void SensorNetwork::initialize(void)
{
char param[MQTTSNGW_PARAM_MAX];
uint32_t baudrate = 115200;
@@ -135,15 +135,22 @@ int SensorNetwork::initialize(void)
theProcess->getParam("DeviceRxLoRaLink", param);
_description += ", SerialRx ";
_description += param;
errno = 0;
if ( LoRaLink::open(LORALINK_MODEM_RX, param, baudrate) < 0 )
{
return -1;
throw EXCEPTION("Can't open a LoRaLink", errno);
}
theProcess->getParam("DeviceTxLoRaLink", param);
_description += ", SerialTx ";
_description += param;
return LoRaLink::open(LORALINK_MODEM_TX, param, baudrate);
errno = 0;
if ( LoRaLink::open(LORALINK_MODEM_TX, param, baudrate) < 0 )
{
throw EXCEPTION("Can't open a LoRaLink", errno);
}
}
const char* SensorNetwork::getDescription(void)

View File

@@ -173,7 +173,7 @@ public:
int unicast(const uint8_t* payload, uint16_t payloadLength, SensorNetAddress* sendto);
int broadcast(const uint8_t* payload, uint16_t payloadLength);
int read(uint8_t* buf, uint16_t bufLen);
int initialize(void);
void initialize(void);
const char* getDescription(void);
SensorNetAddress* getSenderAddress(void);

View File

@@ -177,9 +177,8 @@ int SensorNetwork::read(uint8_t* buf, uint16_t bufLen)
* Prepare UDP sockets and description of SensorNetwork like
* "UDP Multicast 225.1.1.1:1883 Gateway Port 10000".
* The description is for a start up prompt.
* @return success = 0, error = -1
*/
int SensorNetwork::initialize(void)
void SensorNetwork::initialize(void)
{
char param[MQTTSNGW_PARAM_MAX];
uint16_t multicastPortNo = 0;
@@ -224,7 +223,11 @@ int SensorNetwork::initialize(void)
}
/* Prepare UDP sockets */
return UDPPort::open(ip.c_str(), multicastPortNo, unicastPortNo, ttl);
errno = 0;
if ( UDPPort::open(ip.c_str(), multicastPortNo, unicastPortNo, ttl) < 0 )
{
throw EXCEPTION("Can't open a UDP", errno);
}
}
const char* SensorNetwork::getDescription(void)

View File

@@ -91,7 +91,7 @@ public:
int unicast(const uint8_t* payload, uint16_t payloadLength, SensorNetAddress* sendto);
int broadcast(const uint8_t* payload, uint16_t payloadLength);
int read(uint8_t* buf, uint16_t bufLen);
int initialize(void);
void initialize(void);
const char* getDescription(void);
SensorNetAddress* getSenderAddress(void);

View File

@@ -169,7 +169,7 @@ int SensorNetwork::read(uint8_t* buf, uint16_t bufLen)
return UDPPort6::recv(buf, bufLen, &_clientAddr);
}
int SensorNetwork::initialize(void)
void SensorNetwork::initialize(void)
{
char param[MQTTSNGW_PARAM_MAX];
uint16_t unicastPortNo = 0;
@@ -209,7 +209,12 @@ int SensorNetwork::initialize(void)
_description += param;
}
return UDPPort6::open(ip.c_str(), unicastPortNo, broadcast.c_str(), interface.c_str(), hops);
errno = 0;
if ( UDPPort6::open(ip.c_str(), unicastPortNo, broadcast.c_str(), interface.c_str(), hops) < 0 )
{
throw EXCEPTION("Can't open a UDP6", errno);
}
}
const char* SensorNetwork::getDescription(void)

View File

@@ -99,7 +99,7 @@ public:
int unicast(const uint8_t* payload, uint16_t payloadLength, SensorNetAddress* sendto);
int broadcast(const uint8_t* payload, uint16_t payloadLength);
int read(uint8_t* buf, uint16_t bufLen);
int initialize(void);
void initialize(void);
const char* getDescription(void);
SensorNetAddress* getSenderAddress(void);

View File

@@ -118,7 +118,7 @@ int SensorNetwork::read(uint8_t* buf, uint16_t bufLen)
return XBee::recv(buf, bufLen, &_clientAddr);
}
int SensorNetwork::initialize(void)
void SensorNetwork::initialize(void)
{
char param[MQTTSNGW_PARAM_MAX];
uint32_t baudrate = 9600;
@@ -145,7 +145,12 @@ int SensorNetwork::initialize(void)
_description += ", SerialDevice ";
_description += param;
return XBee::open(param, baudrate);
errno =0;
if ( XBee::open(param, baudrate) < 0 )
{
throw EXCEPTION("Can't open a XBee", errno);
}
}
const char* SensorNetwork::getDescription(void)

View File

@@ -126,7 +126,7 @@ public:
int unicast(const uint8_t* payload, uint16_t payloadLength, SensorNetAddress* sendto);
int broadcast(const uint8_t* payload, uint16_t payloadLength);
int read(uint8_t* buf, uint16_t bufLen);
int initialize(void);
void initialize(void);
const char* getDescription(void);
SensorNetAddress* getSenderAddress(void);