Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LMqttsnClientApp.h Source File

LMqttsnClientApp.h

00001 /**************************************************************************************
00002  * Copyright (c) 2016-2018, Tomoaki Yamaguchi
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
00015  **************************************************************************************/
00016 
00017 #ifndef MQTTSNCLIENTAPP_H_
00018 #define MQTTSNCLIENTAPP_H_
00019 
00020 /*======================================
00021  *     Program mode Flag
00022  ======================================*/
00023 //#define CLIENT_MODE
00024 
00025 /*======================================
00026  *         Debug Flag
00027  ======================================*/
00028 //#define DEBUG_NW
00029 //#define DEBUG_MQTTSN
00030 
00031 /****************************************
00032       MQTT-SN Parameters
00033 *****************************************/
00034 #define MAX_INFLIGHT_MSG   10
00035 #define MQTTSN_MAX_MSG_LENGTH  1024
00036 #define MQTTSN_MAX_PACKET_SIZE 1024
00037 
00038 #define MQTTSN_DEFAULT_KEEPALIVE   900     // 1H
00039 #define MQTTSN_DEFAULT_DURATION    900     // 15min
00040 #define MQTTSN_TIME_SEARCHGW         3
00041 #define MQTTSN_TIME_RETRY           10
00042 #define MQTTSN_RETRY_COUNT           3
00043 
00044 /****************************************
00045       Application config structures
00046 *****************************************/
00047 typedef unsigned char  uint8_t;
00048 typedef unsigned short uint16_t;
00049 typedef unsigned int   uint32_t;
00050 typedef signed char    int8_t;
00051 typedef signed short   int16_t;
00052 typedef signed int     int32_t;
00053 
00054 /****************************************
00055       Application config structures
00056 *****************************************/
00057 
00058 struct LMqttsnConfig{
00059     uint16_t keepAlive;
00060     bool     cleanSession;
00061     uint32_t sleepDuration;
00062     const char* willTopic;
00063     const char* willMsg;
00064     uint8_t  willQos;
00065     bool     willRetain;
00066 };
00067 
00068 struct LUdpConfig{
00069     const char* clientId;
00070     uint8_t  ipAddress[4];
00071     uint16_t gPortNo;
00072     uint16_t uPortNo;
00073 };
00074 
00075 
00076 typedef enum
00077 {
00078     MQTTSN_TOPIC_TYPE_NORMAL,
00079     MQTTSN_TOPIC_TYPE_PREDEFINED,
00080     MQTTSN_TOPIC_TYPE_SHORT
00081 } MQTTSN_topicTypes;
00082 
00083 
00084 /*======================================
00085       MACROs for Application
00086 =======================================*/
00087 #define MQTTSN_CONFIG    MqttsnConfig  theMqttsnConfig
00088 #define NETWORK_CONFIG   UdpConfig theNetworkConfig
00089 
00090 #define CONNECT(...) theClient->getGwProxy()->connect(__VA_ARGS__)
00091 #define PUBLISH(...)     theClient->publish(__VA_ARGS__)
00092 #define SUBSCRIBE(...)   theClient->subscribe(__VA_ARGS__)
00093 #define UNSUBSCRIBE(...) theClient->unsubscribe(__VA_ARGS__)
00094 #define DISCONNECT(...)  theClient->disconnect(__VA_ARGS__)
00095 
00096 #define TASK_LIST         TaskList theTaskList[]
00097 #define TASK(...)         {__VA_ARGS__, 0, 0}
00098 #define END_OF_TASK_LIST  {0, 0, 0, 0}
00099 #define TEST_LIST         TestList theTestList[]
00100 #define TEST(...)         {__VA_ARGS__, 0}
00101 #define END_OF_TEST_LIST  {0, 0, 0}
00102 #define SUBSCRIBE_LIST    OnPublishList theOnPublishList[]
00103 #define SUB(...)          {__VA_ARGS__}
00104 #define END_OF_SUBSCRIBE_LIST {MQTTSN_TOPIC_TYPE_NORMAL,0,0,0, 0}
00105 #define UDPCONF  LUdpConfig theNetcon
00106 #define MQTTSNCONF LMqttsnConfig  theMqcon
00107 #define SetForwarderMode(...)  theClient->getGwProxy()->setForwarderMode(__VA_ARGS__)
00108 #define SetQoSMinus1Mode(...) theClient->getGwProxy()->setQoSMinus1Mode(__VA_ARGS__)
00109 
00110 #ifdef CLIENT_MODE
00111 #define DISPLAY(...)
00112 #define PROMPT(...)
00113 #define CHECKKEYIN(...) theScreen->checkKeyIn(__VA_ARGS__)
00114 #else
00115 #define DISPLAY(...) theScreen->display(__VA_ARGS__)
00116 #define PROMPT(...) theScreen->prompt(__VA_ARGS__)
00117 #define CHECKKEYIN(...) theScreen->checkKeyIn(__VA_ARGS__)
00118 #endif
00119 /*======================================
00120       MACROs for debugging
00121 ========================================*/
00122 #ifndef DEBUG_NW
00123     #define D_NWLOG(...)
00124 #else
00125     #define D_NWLOG(...)    printf(__VA_ARGS__)
00126 #endif
00127 
00128 #ifndef DEBUG_MQTTSN
00129     #define D_MQTTLOG(...)
00130 #else
00131     #define D_MQTTLOG(...)  printf(__VA_ARGS__)
00132 #endif
00133 
00134 #ifndef DEBUG_OTA
00135     #define D_OTALOG(...)
00136 #else
00137     #define D_OTALOG(...)   printf(__VA_ARGS__)
00138 #endif
00139 
00140 /*======================================
00141       MQTT-SN Defines
00142 ========================================*/
00143 #define QoS0  0
00144 #define QoS1  1
00145 #define QoS2  2
00146 #define Q0Sm1 3
00147 #define MQTTSN_TYPE_ADVERTISE     0x00
00148 #define MQTTSN_TYPE_SEARCHGW      0x01
00149 #define MQTTSN_TYPE_GWINFO        0x02
00150 #define MQTTSN_TYPE_CONNECT       0x04
00151 #define MQTTSN_TYPE_CONNACK       0x05
00152 #define MQTTSN_TYPE_WILLTOPICREQ  0x06
00153 #define MQTTSN_TYPE_WILLTOPIC     0x07
00154 #define MQTTSN_TYPE_WILLMSGREQ    0x08
00155 #define MQTTSN_TYPE_WILLMSG       0x09
00156 #define MQTTSN_TYPE_REGISTER      0x0A
00157 #define MQTTSN_TYPE_REGACK        0x0B
00158 #define MQTTSN_TYPE_PUBLISH       0x0C
00159 #define MQTTSN_TYPE_PUBACK        0x0D
00160 #define MQTTSN_TYPE_PUBCOMP       0x0E
00161 #define MQTTSN_TYPE_PUBREC        0x0F
00162 #define MQTTSN_TYPE_PUBREL        0x10
00163 #define MQTTSN_TYPE_SUBSCRIBE     0x12
00164 #define MQTTSN_TYPE_SUBACK        0x13
00165 #define MQTTSN_TYPE_UNSUBSCRIBE   0x14
00166 #define MQTTSN_TYPE_UNSUBACK      0x15
00167 #define MQTTSN_TYPE_PINGREQ       0x16
00168 #define MQTTSN_TYPE_PINGRESP      0x17
00169 #define MQTTSN_TYPE_DISCONNECT    0x18
00170 #define MQTTSN_TYPE_WILLTOPICUPD  0x1A
00171 #define MQTTSN_TYPE_WILLTOPICRESP 0x1B
00172 #define MQTTSN_TYPE_WILLMSGUPD    0x1C
00173 #define MQTTSN_TYPE_WILLMSGRESP   0x1D
00174 #define MQTTSN_TYPE_ENCAPSULATED  0xFE
00175 
00176 #define MQTTSN_TOPIC_TYPE           0x03
00177 
00178 #define MQTTSN_FLAG_DUP     0x80
00179 #define MQTTSN_FLAG_QOS_0   0x0
00180 #define MQTTSN_FLAG_QOS_1   0x20
00181 #define MQTTSN_FLAG_QOS_2   0x40
00182 #define MQTTSN_FLAG_QOS_M1  0x60
00183 #define MQTTSN_FLAG_RETAIN  0x10
00184 #define MQTTSN_FLAG_WILL    0x08
00185 #define MQTTSN_FLAG_CLEAN   0x04
00186 
00187 #define MQTTSN_PROTOCOL_ID  0x01
00188 #define MQTTSN_HEADER_SIZE  2
00189 
00190 #define MQTTSN_RC_ACCEPTED                  0x00
00191 #define MQTTSN_RC_REJECTED_CONGESTION       0x01
00192 #define MQTTSN_RC_REJECTED_INVALID_TOPIC_ID 0x02
00193 #define MQTTSN_RC_REJECTED_NOT_SUPPORTED    0x03
00194 
00195 /*=================================
00196  *    Starting prompt
00197  ==================================*/
00198 #define TESTER_VERSION " * Version: 2.0.0"
00199 
00200 #define PAHO_COPYRIGHT0 " * MQTT-SN Gateway Tester"
00201 #define PAHO_COPYRIGHT1 " * Part of Project Paho in Eclipse"
00202 #define PAHO_COPYRIGHT2 " * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)"
00203 #define PAHO_COPYRIGHT3 " * Author : Tomoaki YAMAGUCHI"
00204 #define PAHO_COPYRIGHT4 " ***************************************************************************"
00205 
00206 #endif /* MQTTSNCLIENTAPP_H_ */