#ifndef _FRAMEX_H_ #define _FRAMEX_H_ /***********************/ /* Constant values */ /***********************/ /* Define logging levels - log written to stdout */ #define LOGNONE 0x00000000 /* No log output is produced */ #define LOGNORMAL 0x00000001 /* Log significant events */ #define LOGERROR 0x00000002 /* Log error conditions only */ #define LOGIPC 0x00000004 /* Log inter thread communication */ #define LOGTCPIP 0x00000008 /* Log TCP/IP i/o events */ #define LOGSCADA 0x00000010 /* Log WMQTT i/o events */ #define LOGDEBUG 0x00000020 /* Produce detailed debugging output */ /* Return codes for the client API */ #define MQISDP_OK 0 #define MQISDP_PROTOCOL_VERSION_ERROR 1001 #define MQISDP_HOSTNAME_NOT_FOUND 1002 #define MQISDP_Q_FULL 1003 #define MQISDP_FAILED 1004 #define MQISDP_PUBS_AVAILABLE 1005 #define MQISDP_NO_PUBS_AVAILABLE 1006 #define MQISDP_PERSISTENCE_FAILED 1007 #define MQISDP_CONN_HANDLE_ERROR 1008 #define MQISDP_NO_WILL_TOPIC 1010 #define MQISDP_INVALID_STRUC_LENGTH 1011 #define MQISDP_DATA_LENGTH_ERROR 1012 #define MQISDP_DATA_TOO_BIG 1013 #define MQISDP_ALREADY_CONNECTED 1014 #define MQISDP_CONNECTION_BROKEN 1017 #define MQISDP_DATA_TRUNCATED 1018 #define MQISDP_CLIENT_ID_ERROR 1019 #define MQISDP_BROKER_UNAVAILABLE 1020 #define MQISDP_SOCKET_CLOSED 1021 #define MQISDP_OUT_OF_MEMORY 1022 /* Message status */ #define MQISDP_DELIVERED 1 #define MQISDP_RETRYING 2 #define MQISDP_IN_PROGRESS 3 #define MQISDP_MSG_HANDLE_ERROR 4 /* Connection states */ #define MQISDP_CONNECTING 6 #define MQISDP_CONNECTED 7 #define MQISDP_DISCONNECTED 8 /* Flags */ #define MQISDP_NONE 0x0000 #define MQISDP_WILL 0x0001 #define MQISDP_RETAIN 0x0002 #define MQISDP_QOS_0 0x0004 #define MQISDP_QOS_1 0x0008 #define MQISDP_QOS_2 0x0010 #define MQISDP_CLEAN_START 0x0020 #define MQISDP_WILL_RETAIN 0x0040 #define MQISDP_DUPLICATE 0x0080 /* Disconnect options */ #define MQISDP_IMMEDIATE 0x00000001 #define MQISDP_QUIESCE 0x00000002 /* lengths */ #define MQISDP_CLIENT_ID_LENGTH 23L #define MQISDP_MAX_MSGS 65535L #define MQISDP_INET_ADDR_LENGTH 16L #define MQISDP_INFO_STRING_LENGTH 32L #define MQISDP_RC_STRING_LENGTH 32L /* Invalid handle */ #define MQISDP_INV_MSG_HANDLE (-1L) #define MQISDP_INV_CONN_HANDLE NULL /* ---- Flags used by the persistence interface */ /* Define flags to indicate if a publication has been released or not */ /* The last bytes of a the buffer passed into the persistence contains */ /* the bit. */ #define MQISDP_RELEASED 0x01 /* OR flag */ #define MSP_SINGLE_THREAD #define NO_Msg #define MSP_NO_LOCALTIME /* ---- End persistence interface flags */ /* type definitions */ typedef void* MQISDPCH; /* Connection Handle */ typedef unsigned long MQISDPMH; /* Message handle */ /* These are default values */ typedef int MBH; /* Mailbox handle */ typedef int MTH; /* Mutex handle */ typedef int MSH; /* Semaphore handle */ /***********************/ /* Structures */ /***********************/ /* Task info required for starting the send and receive tasks */ typedef struct struct_mti { MBH apiMailbox; MBH sendMailbox; MBH receiveMailbox; MTH sendMutex; MSH receiveSemaphore; long logLevel; } MQISDPTI; /* Persistence structure which holds function entry points and user data */ typedef struct struct_PSISTMSG { unsigned long key; int length; char *pWmqttMsg; } MQISDP_PMSG; typedef struct struct_PSIST { void *pUserData; int (*open)( void *pUserData, char *pClientId, char *pBroker, int port ); int (*close)( void *pUserData ); int (*reset)( void *pUserData ); int (*getAllReceivedMessages)( void *pUserData, int *numMsgs, MQISDP_PMSG** ); int (*getAllSentMessages)( void *pUserData, int *numMsgs, MQISDP_PMSG** ); int (*addSentMessage)( void *pUserData, unsigned long key, int msgLength, char *pWmqttMsg ); int (*updSentMessage)( void *pUserData, unsigned long key, int msgLength, char *pWmqttMsg ); int (*delSentMessage)( void *pUserData, unsigned long key ); int (*addReceivedMessage)( void *pUserData, unsigned long key, int msgLength, char *pWmqttMsg ); int (*updReceivedMessage)( void *pUserData, unsigned long key ); int (*delReceivedMessage)( void *pUserData, unsigned long key ); } MQISDP_PERSIST; /* Connect parameters - fixed length portion*/ typedef struct struct_CP { long strucLength; /* Fixed length plus variable portion length */ char clientId[MQISDP_CLIENT_ID_LENGTH + 1]; long retryCount; long retryInterval; /* seconds */ unsigned short options; /* WILL flag, WILL retain, WILL QoS and Clean Start */ unsigned short keepAliveTime; /* seconds */ MQISDP_PERSIST *pPersistFuncs; char *brokerHostname; long brokerPort; } CONN_PARMS; /* Connect parameters - variable length portion long willTopicLength; char willTopic[n]; - Must be 4 byte aligned and padded with space long willMessageLength; char willMessage[n]; - Must be 4 byte aligned and padded with space */ /* Publish parameters - fixed length portion */ typedef struct struct_PP { long strucLength; long options; long topicLength; char *topic; long dataLength; char *data; } PUB_PARMS; /* Subscribe parameters - fixed length portion */ typedef struct struct_SP { long strucLength; /* Fixed length plus variable portion length */ } SUB_PARMS; /* Subscribe parameters - variable length portion long topicLength; char topic[n]; - Must be 4 byte aligned and padded with space long options; - currently only the QoS NOTE: topicLength, topic and options must be adjacent, and may repeat as a triplet */ /* Unsubscribe parameters */ typedef struct struct_UP { long strucLength; /* Fixed length plus variable portion length */ } UNSUB_PARMS; /* Unsubscribe parameters - variable length portion long topicLength; char topic[n]; - Must be 4 byte aligned and padded with space NOTE: topicLength and topic must be adjacent, and may repeat as a pair */ /* ReceivePublication parameters */ typedef struct struct_RP { long strucLength; long options; /* Retain and QoS flags */ } RCVPUB_PARMS; typedef struct _MQISDPCMD { char clientId[MQISDP_CLIENT_ID_LENGTH + 1]; char pBroker[32]; //*pBroker; int port; char topic[100];//*topic; int qos; int retain; char lwtTopic[32];//*lwtTopic; int lwtQos; int lwtRetain; char lwtData[32];//*lwtData; int debug; int dataArg; MQISDPCH hConn; MQISDPMH lastSentMsg; } PUBPARMS; typedef struct _MQISDPCMD_S { char clientId[MQISDP_CLIENT_ID_LENGTH + 1]; char pBroker[32];//*pBroker; int port; char topic[100];//*topic; int qos; int timeout; char lwtTopic[32];//*lwtTopic; int lwtQos; int lwtRetain; char lwtData[32];//*lwtData; int debug; int dataArg; MQISDPCH hConn; MQISDPMH lastSentMsg; } SUBPARMS; #ifdef __cplusplus extern "C" { #endif /////////////////////////////////////////////////////////////////////////////// #define MAX_RESENT_BUF 20 #define MAX_PORT 8 #define MQ_MAX 4 //=========================================================== //Ethernet initial for 7186 int Ethernet_Init(void); /* Return: 0: ok. -1: function "llip" error -2: function "Ninit" error -3: function "Portinit" error */ //=========================================================== // MQtt_X API int MQtt_Init(int Broker_ID); /* MQtt_Init Inputs : Broker_ID = 0 ~ 3 */ int MQtt_Close(int Broker_ID); /* MQtt_Close Inputs : Broker_ID = 0 ~ 3 */ int MQtt_MQIsdpConnect(int Broker_ID, PUBPARMS *ppp, MQISDPTI *pApiTaskInfo, int RetryInt, int KeepAlive, int CleanStart); /* MQtt_MQIsdpConnect Inputs : Broker_ID = 0 ~ 3 PUBPARMS RetryInt(Retry counts) KeepAlive(Keep alive time) CleanStart(whether clean start) Returns: MQISDPTI(Task Information) int return code */ int MQtt_MQIsdpDisconnect(int Broker_ID, PUBPARMS *ppp ); /* MQtt_MQIsdpDisconnect Inputs : Broker_ID = 0 ~ 3 PUBPARMS Returns: int return code */ int MQtt_MQIsdpPublish(int Broker_ID, PUBPARMS *ppp, char *pData, int dataLength ); /* MQtt_MQIsdpPublish Inputs : Broker_ID = 0 ~ 3 PUBPARMS data to publish dataLength Returns: int return code */ int MQtt_MQIsdpSubscribe(int Broker_ID, SUBPARMS *ppp ); /* MQtt_MQIsdpSubscribe Inputs : Broker_ID = 0 ~ 3 SUBPARMS Returns: int return code */ int MQtt_MQIsdpUnsubscribe(int Broker_ID, SUBPARMS *ppp ); /* MQtt_MQIsdpUnsubscribe Inputs : Broker_ID = 0 ~ 3 SUBPARMS Returns: int return code */ int MQtt_MQIsdpRcvPub(int Broker_ID, SUBPARMS *ppp, char *pMatchData, long *topicLength, long *dataLength); /* MQtt_MQIsdpRcvPub Inputs : Broker_ID = 0 ~ 3 SUBPARMS Returns: pMatchData(match data buffer) topicLength - actual length dataLength - actual length int return code */ int MQtt_MQIsdp_getMsgStatus(int Broker_ID, MQISDPCH hConn, MQISDPMH hMsg); /* MQtt_MQIsdp_getMsgStatus Inputs : Broker_ID = 0 ~ 3 MQISDPCH (connection handle) MQISDPMH (message handle) Returns: int return code */ int MQtt_MQIsdp_version( int Broker_ID ); /* Version information Inputs : none Returns: version number */ /////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus } #endif #endif //_FRAMEX_H_