mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 23:46:51 +01:00
BugFix: PINGREQ & PINGRESP can't be received and sent.
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -13,7 +13,7 @@ KeepAlive=900
|
|||||||
#Password=
|
#Password=
|
||||||
|
|
||||||
# UDP
|
# UDP
|
||||||
GatewayPortNo=2000
|
GatewayPortNo=10000
|
||||||
MulticastIP=225.1.1.1
|
MulticastIP=225.1.1.1
|
||||||
MulticastPortNo=1883
|
MulticastPortNo=1883
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ int BrokerRecvTask::log(Client* client, MQTTGWPacket* packet)
|
|||||||
break;
|
break;
|
||||||
case SUBACK:
|
case SUBACK:
|
||||||
case UNSUBACK:
|
case UNSUBACK:
|
||||||
WRITELOG(FORMAT_YE_GR_MSGID, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROW, client->getClientId(), packet->print(pbuf));
|
WRITELOG(FORMAT_GR_MSGID, currentDateTime(), packet->getName(), packet->getMsgId(msgId), LEFTARROW, client->getClientId(), packet->print(pbuf));
|
||||||
break;
|
break;
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
WRITELOG(FORMAT_GR_NL, currentDateTime(), packet->getName(), LEFTARROW, client->getClientId(), packet->print(pbuf));
|
WRITELOG(FORMAT_GR_NL, currentDateTime(), packet->getName(), LEFTARROW, client->getClientId(), packet->print(pbuf));
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void ClientRecvTask::run()
|
|||||||
MQTTSNPacket* packet = new MQTTSNPacket();
|
MQTTSNPacket* packet = new MQTTSNPacket();
|
||||||
int packetLen = packet->recv(_sensorNetwork);
|
int packetLen = packet->recv(_sensorNetwork);
|
||||||
|
|
||||||
if (packetLen < 3 )
|
if (packetLen < 2 )
|
||||||
{
|
{
|
||||||
delete packet;
|
delete packet;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -246,6 +246,7 @@ void MQTTSNConnectionHandler::handlePingreq(Client* client, MQTTSNPacket* packet
|
|||||||
/* send PINGREQ to the broker */
|
/* send PINGREQ to the broker */
|
||||||
MQTTGWPacket* pingreq = new MQTTGWPacket();
|
MQTTGWPacket* pingreq = new MQTTGWPacket();
|
||||||
pingreq->setHeader(PINGREQ);
|
pingreq->setHeader(PINGREQ);
|
||||||
Event* ev1 = new Event();
|
Event* evt = new Event();
|
||||||
ev1->setBrokerSendEvent(client, pingreq);
|
evt->setBrokerSendEvent(client, pingreq);
|
||||||
|
_gateway->getBrokerSendQue()->post(evt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ namespace MQTTSNGW
|
|||||||
/*=================================
|
/*=================================
|
||||||
* Starting prompt
|
* Starting prompt
|
||||||
==================================*/
|
==================================*/
|
||||||
#define GATEWAY_VERSION "(Ver 0.2.0)"
|
#define GATEWAY_VERSION "(Ver 0.2.1)"
|
||||||
|
|
||||||
/*=================================
|
/*=================================
|
||||||
* Log controls
|
* Log controls
|
||||||
==================================*/
|
==================================*/
|
||||||
//#define DEBUG // print out log for debug
|
//#define DEBUG // print out log for debug
|
||||||
//#define RINGBUFFER // print out Packets log into shared memory
|
//#define RINGBUFFER // print out Packets log into shared memory
|
||||||
|
//#define DEBUG_NWSTACK // print out SensorNetwork log
|
||||||
/*=================================
|
/*=================================
|
||||||
* Parametrs
|
* Parametrs
|
||||||
==================================*/
|
==================================*/
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ int MQTTSNPacket::recv(SensorNetwork* network)
|
|||||||
{
|
{
|
||||||
uint8_t buf[MQTTSNGW_MAX_PACKET_SIZE];
|
uint8_t buf[MQTTSNGW_MAX_PACKET_SIZE];
|
||||||
int len = network->read((uint8_t*) buf, MQTTSNGW_MAX_PACKET_SIZE);
|
int len = network->read((uint8_t*) buf, MQTTSNGW_MAX_PACKET_SIZE);
|
||||||
if (len >= 3)
|
if (len > 1)
|
||||||
{
|
{
|
||||||
len = desirialize(buf, len);
|
len = desirialize(buf, len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ int UDPPort::unicast(const uint8_t* buf, uint32_t length, SensorNetAddress* addr
|
|||||||
{
|
{
|
||||||
D_NWSTACK("errno == %d in UDPPort::sendto\n", errno);
|
D_NWSTACK("errno == %d in UDPPort::sendto\n", errno);
|
||||||
}
|
}
|
||||||
D_NWSTACK("sendto %s:%u length = %d\n", inet_ntoa(dest.sin_addr), htons(addr->getPortNo()), status);
|
D_NWSTACK("sendto %s:%u length = %d\n", inet_ntoa(dest.sin_addr), ntohs(dest.sin_port), status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +289,7 @@ int UDPPort::recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr)
|
|||||||
{
|
{
|
||||||
fd_set recvfds;
|
fd_set recvfds;
|
||||||
int maxSock = 0;
|
int maxSock = 0;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
FD_ZERO(&recvfds);
|
FD_ZERO(&recvfds);
|
||||||
FD_SET(_sockfdUnicast, &recvfds);
|
FD_SET(_sockfdUnicast, &recvfds);
|
||||||
@@ -307,13 +308,13 @@ int UDPPort::recv(uint8_t* buf, uint16_t len, SensorNetAddress* addr)
|
|||||||
|
|
||||||
if (FD_ISSET(_sockfdUnicast, &recvfds))
|
if (FD_ISSET(_sockfdUnicast, &recvfds))
|
||||||
{
|
{
|
||||||
return recvfrom(_sockfdUnicast, buf, len, 0, addr);
|
rc = recvfrom(_sockfdUnicast, buf, len, 0, addr);
|
||||||
}
|
}
|
||||||
else if (FD_ISSET(_sockfdMulticast, &recvfds))
|
else if (FD_ISSET(_sockfdMulticast, &recvfds))
|
||||||
{
|
{
|
||||||
return recvfrom(_sockfdMulticast, buf, len, 0, &_grpAddr);
|
rc = recvfrom(_sockfdMulticast, buf, len, 0, &_grpAddr);
|
||||||
}
|
}
|
||||||
return 0;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UDPPort::recvfrom(int sockfd, uint8_t* buf, uint16_t len, uint8_t flags, SensorNetAddress* addr)
|
int UDPPort::recvfrom(int sockfd, uint8_t* buf, uint16_t len, uint8_t flags, SensorNetAddress* addr)
|
||||||
@@ -330,7 +331,7 @@ int UDPPort::recvfrom(int sockfd, uint8_t* buf, uint16_t len, uint8_t flags, Sen
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
addr->setAddress(sender.sin_addr.s_addr, sender.sin_port);
|
addr->setAddress(sender.sin_addr.s_addr, sender.sin_port);
|
||||||
D_NWSTACK("recved from %s:%d length = %d\n", inet_ntoa(sender.sin_addr), htons(addr->getPortNo()), status);
|
D_NWSTACK("recved from %s:%d length = %d\n", inet_ntoa(sender.sin_addr),ntohs(sender.sin_port), status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user