adapted to latest changes in gwen (msgio API v2 becomes v1).
This commit is contained in:
@@ -143,7 +143,7 @@ int main(int argc, char **argv)
|
||||
int _serve(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
const char *pidFile;
|
||||
GWEN_MSG_ENDPOINT2 *epTcp;
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
ITEM_LIST *itemList;
|
||||
int rv;
|
||||
int timeout;
|
||||
@@ -186,7 +186,7 @@ int _serve(GWEN_DB_NODE *dbArgs)
|
||||
rv=AqHomeMqttLog_MqttConnect(epTcp);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
Item_List_free(itemList);
|
||||
return rv;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ int _serve(GWEN_DB_NODE *dbArgs)
|
||||
rv=AqHomeMqttLog_Subscribe(epTcp, "#");
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
Item_List_free(itemList);
|
||||
return rv;
|
||||
}
|
||||
@@ -203,14 +203,14 @@ int _serve(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
while(!stopService) {
|
||||
DBG_DEBUG(NULL, "Next loop");
|
||||
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
if (GWEN_MsgEndpoint2_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
|
||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
if (GWEN_MsgEndpoint_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
|
||||
DBG_INFO(NULL, "Not connected...");
|
||||
}
|
||||
else {
|
||||
GWEN_MSG *msg;
|
||||
|
||||
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
|
||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
||||
if (msg) {
|
||||
#ifdef FULL_DEBUG
|
||||
DBG_ERROR(NULL, "Received this message:");
|
||||
@@ -267,7 +267,7 @@ int _serve(GWEN_DB_NODE *dbArgs)
|
||||
if (pidFile && *pidFile)
|
||||
remove(pidFile);
|
||||
|
||||
GWEN_MsgEndpoint2_free(epTcp);
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
Item_List_free(itemList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/aqhome.h>
|
||||
|
||||
#include "aqhome/mqtt/endpoint2_mqttc.h"
|
||||
#include "aqhome/mqtt/endpoint_mqttc.h"
|
||||
#include <aqhome/mqtt/msg_mqtt_connect.h>
|
||||
#include <aqhome/mqtt/msg_mqtt_connack.h>
|
||||
#include <aqhome/mqtt/msg_mqtt_publish.h>
|
||||
@@ -44,7 +44,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketType, int timeoutInSeconds);
|
||||
static GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT *epTcp, uint8_t expectedPacketType, int timeoutInSeconds);
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ static GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketT
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
GWEN_MSG_ENDPOINT *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
const char *mqttAddress;
|
||||
int mqttPort;
|
||||
@@ -68,17 +68,17 @@ GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
mqttKeepAlive=GWEN_DB_GetIntValue(dbArgs, "mqttKeepAlive", 0, 600);
|
||||
|
||||
if (mqttAddress && *mqttAddress && mqttPort) {
|
||||
GWEN_MSG_ENDPOINT2 *epMqtt;
|
||||
GWEN_MSG_ENDPOINT *epMqtt;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Connecting to %s (port %d)", mqttAddress, mqttPort);
|
||||
epMqtt=AQH_MqttClientEndpoint2_new(mqttClientId, mqttAddress, mqttPort, NULL, 0);
|
||||
epMqtt=AQH_MqttClientEndpoint_new(mqttClientId, mqttAddress, mqttPort, NULL, 0);
|
||||
if (epMqtt==NULL) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Error creating endpoint TCP");
|
||||
return NULL;
|
||||
}
|
||||
if (mqttTopicPrefix && *mqttTopicPrefix)
|
||||
AQH_MqttClientEndpoint2_SetTopicPrefix(epMqtt, mqttTopicPrefix);
|
||||
AQH_MqttClientEndpoint2_SetKeepAliveTime(epMqtt, mqttKeepAlive);
|
||||
AQH_MqttClientEndpoint_SetTopicPrefix(epMqtt, mqttTopicPrefix);
|
||||
AQH_MqttClientEndpoint_SetKeepAliveTime(epMqtt, mqttKeepAlive);
|
||||
|
||||
return epMqtt;
|
||||
}
|
||||
@@ -88,41 +88,41 @@ GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
|
||||
|
||||
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT2 *epTcp)
|
||||
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT *epTcp)
|
||||
{
|
||||
if (GWEN_MsgEndpoint2_GetState(epTcp)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
|
||||
if (GWEN_MsgEndpoint_GetState(epTcp)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) {
|
||||
int rv;
|
||||
|
||||
rv=AQH_MqttClientEndpoint2_StartConnect(epTcp);
|
||||
rv=AQH_MqttClientEndpoint_StartConnect(epTcp);
|
||||
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
|
||||
DBG_ERROR(NULL, "Error starting to connect (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
while(GWEN_MsgEndpoint2_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
|
||||
while(GWEN_MsgEndpoint_GetState(epTcp)!=GWEN_MSG_ENDPOINT_STATE_CONNECTED) {
|
||||
DBG_DEBUG(NULL, "Next loop");
|
||||
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT2 *epTcp, const char *topicFilter)
|
||||
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT *epTcp, const char *topicFilter)
|
||||
{
|
||||
uint16_t pckId;
|
||||
GWEN_MSG *msgOut;
|
||||
GWEN_MSG *msgIn;
|
||||
|
||||
DBG_INFO(NULL, "Sending SUBSCRIBE %s", topicFilter);
|
||||
pckId=AQH_MqttClientEndpoint2_GetNextPacketId(epTcp);
|
||||
pckId=AQH_MqttClientEndpoint_GetNextPacketId(epTcp);
|
||||
msgOut=GWEN_SubscribeMqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE, pckId, topicFilter, 0);
|
||||
if (msgOut==NULL) {
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_INTERNAL;
|
||||
}
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
|
||||
DBG_INFO(NULL, "Waiting for response");
|
||||
msgIn=_awaitPacket(epTcp, AQH_MQTTMSG_MSGTYPE_SUBACK, AQHOME_MQTTLOG_DEFAULT_CMDTIMEOUT);
|
||||
@@ -141,7 +141,7 @@ int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT2 *epTcp, const char *topicFilter)
|
||||
|
||||
|
||||
|
||||
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT2 *epTcp)
|
||||
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT *epTcp)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
@@ -151,14 +151,14 @@ int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT2 *epTcp)
|
||||
DBG_ERROR(NULL, "Error creating message");
|
||||
return GWEN_ERROR_INTERNAL;
|
||||
}
|
||||
GWEN_MsgEndpoint2_AddSendMessage(epTcp, msgOut);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketType, int timeoutInSeconds)
|
||||
GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT *epTcp, uint8_t expectedPacketType, int timeoutInSeconds)
|
||||
{
|
||||
time_t startTime;
|
||||
|
||||
@@ -168,8 +168,8 @@ GWEN_MSG *_awaitPacket(GWEN_MSG_ENDPOINT2 *epTcp, uint8_t expectedPacketType, in
|
||||
GWEN_MSG *msg;
|
||||
time_t now;
|
||||
|
||||
GWEN_MsgEndpoint2_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
msg=GWEN_MsgEndpoint2_TakeFirstReceivedMessage(epTcp);
|
||||
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
|
||||
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
|
||||
if (msg) {
|
||||
if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(expectedPacketType & 0xf0)) {
|
||||
return msg;
|
||||
|
||||
@@ -10,16 +10,16 @@
|
||||
#define AQHOME_TOOL_MQTT_H
|
||||
|
||||
|
||||
#include "aqhome/mqtt/endpoint2_mqttc.h"
|
||||
#include "aqhome/mqtt/endpoint_mqttc.h"
|
||||
|
||||
#include <gwenhywfar/db.h>
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT2 *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT2 *epTcp);
|
||||
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT2 *epTcp, const char *topicFilter);
|
||||
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT2 *epTcp);
|
||||
GWEN_MSG_ENDPOINT *AqHomeMqttLog_CreateMqttEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
int AqHomeMqttLog_MqttConnect(GWEN_MSG_ENDPOINT *epTcp);
|
||||
int AqHomeMqttLog_Subscribe(GWEN_MSG_ENDPOINT *epTcp, const char *topicFilter);
|
||||
int AqHomeMqttLog_Ping(GWEN_MSG_ENDPOINT *epTcp);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user