aqhome: use new type GWEN_ConnectableMsgEndpoint.
This allows for reconnect of endpoints if necessary.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "aqhome/msg/msg_recvstats.h"
|
||||
|
||||
#include <gwenhywfar/endpoint_tcpc.h>
|
||||
#include <gwenhywfar/endpoint_connectable.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
@@ -198,27 +199,17 @@ void _run(GWEN_MSG_ENDPOINT *ep)
|
||||
if (xep->previousRunFn)
|
||||
xep->previousRunFn(ep);
|
||||
|
||||
state=GWEN_TcpcEndpoint_GetState(ep);
|
||||
if (state==GWEN_MSG_ENDPOINT_TCPC_STATE_UNCONNECTED) {
|
||||
int rv;
|
||||
|
||||
rv=GWEN_TcpcEndpoint_StartConnect(ep);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Error starting to connect (%d)", rv);
|
||||
}
|
||||
}
|
||||
else if (state==GWEN_MSG_ENDPOINT_TCPC_STATE_CONNECTING) {
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Still connecting");
|
||||
}
|
||||
else if (state==GWEN_MSG_ENDPOINT_TCPC_STATE_CONNECTED)
|
||||
state=GWEN_ConnectableMsgEndpoint_GetState(ep);
|
||||
if (state==GWEN_MSG_ENDPOINT_CONN_STATE_CONNECTED)
|
||||
_sendConnectMsg(ep);
|
||||
else if (state==GWEN_ENDPOINT_MQTTC_STATE_WAITFORCONNACK)
|
||||
_checkForConnAckMsg(ep);
|
||||
else if (state==GWEN_ENDPOINT_MQTTC_STATE_ESTABLISHED){
|
||||
else if (state==GWEN_ENDPOINT_MQTTC_STATE_ESTABLISHED ||
|
||||
state<GWEN_MSG_ENDPOINT_CONN_STATE_CONNECTED){
|
||||
/* nothing to do */
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Unhandled connection status %d", state);
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Unhandled connection status %d", state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,7 +227,7 @@ void _sendConnectMsg(GWEN_MSG_ENDPOINT *ep)
|
||||
if (msg) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Sending MQTT CONNECT request.");
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, msg);
|
||||
GWEN_TcpcEndpoint_SetState(ep, GWEN_ENDPOINT_MQTTC_STATE_WAITFORCONNACK);
|
||||
GWEN_ConnectableMsgEndpoint_SetState(ep, GWEN_ENDPOINT_MQTTC_STATE_WAITFORCONNACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +244,7 @@ void _checkForConnAckMsg(GWEN_MSG_ENDPOINT *ep)
|
||||
msgType=AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0;
|
||||
if (msgType==AQH_MQTTMSG_MSGTYPE_CONNACK) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "MQTT CONNACK received, logical connection established.");
|
||||
GWEN_TcpcEndpoint_SetState(ep, GWEN_ENDPOINT_MQTTC_STATE_ESTABLISHED);
|
||||
GWEN_ConnectableMsgEndpoint_SetState(ep, GWEN_ENDPOINT_MQTTC_STATE_ESTABLISHED);
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Unexpected message received (%s)", AQH_MqttMsg_MsgTypeToString(msgType));
|
||||
@@ -266,7 +257,7 @@ void _checkForConnAckMsg(GWEN_MSG_ENDPOINT *ep)
|
||||
|
||||
void _processOutMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *nodeMsg)
|
||||
{
|
||||
if (GWEN_TcpcEndpoint_GetState(ep)==GWEN_ENDPOINT_MQTTC_STATE_ESTABLISHED) {
|
||||
if (GWEN_ConnectableMsgEndpoint_GetState(ep)==GWEN_ENDPOINT_MQTTC_STATE_ESTABLISHED) {
|
||||
DBG_DEBUG(AQH_LOGDOMAIN, "Processing output message");
|
||||
switch(AQH_NodeMsg_GetMsgType(nodeMsg)) {
|
||||
case AQH_MSG_TYPE_VALUE2:
|
||||
|
||||
Reference in New Issue
Block a user