mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 23:46:51 +01:00
Add comment to the GatewayTester
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -1,162 +0,0 @@
|
|||||||
/**************************************************************************************
|
|
||||||
* Copyright (c) 2016, Tomoaki Yamaguchi
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
|
||||||
*
|
|
||||||
* The Eclipse Public License is available at
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
* and the Eclipse Distribution License is available at
|
|
||||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Tomoaki Yamaguchi - initial API and implementation
|
|
||||||
**************************************************************************************/
|
|
||||||
|
|
||||||
#include "LMqttsnClientApp.h"
|
|
||||||
#include "LMqttsnClient.h"
|
|
||||||
#include "LScreen.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace linuxAsyncClient;
|
|
||||||
extern LMqttsnClient* theClient;
|
|
||||||
extern LScreen* theScreen;
|
|
||||||
extern int run(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* MQTT-SN Functions supported :
|
|
||||||
*
|
|
||||||
* void PUBLISH ( const char* topicName, uint8_t* payload,
|
|
||||||
* uint16_t len, uint8_t qos, bool retain = false );
|
|
||||||
*
|
|
||||||
* void PUBLISH ( uint16_t topicId, uint8_t* payload,
|
|
||||||
* uint16_t len, uint8_t qos, bool retain = false );
|
|
||||||
*
|
|
||||||
* void SUBSCRIBE ( const char* topicName, TopicCallback onPublish,
|
|
||||||
* uint8_t qos );
|
|
||||||
*
|
|
||||||
* void UNSUBSCRIBE( const char* topicName );
|
|
||||||
*
|
|
||||||
* void DISCONNECT ( uint16_t sleepInSecs );
|
|
||||||
*
|
|
||||||
* void DISPLAY( format, valiables, .....); <== instead of printf()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* UDP Configuration
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
UDPCONF = {
|
|
||||||
"GatewayTester", // ClientId
|
|
||||||
{225,1,1,1}, // Multicast group IP
|
|
||||||
1883, // Multicast group Port
|
|
||||||
20000, // Local PortNo
|
|
||||||
};
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* Client Configuration
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
MQTTSNCONF = {
|
|
||||||
60, //KeepAlive (seconds)
|
|
||||||
true, //Clean session
|
|
||||||
0, //Sleep duration in msecs
|
|
||||||
"willTopic", //WillTopic
|
|
||||||
"willMessage", //WillMessage
|
|
||||||
0, //WillQos
|
|
||||||
false //WillRetain
|
|
||||||
};
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* Define Topics
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
const char* topic1 = "ty4tw/clientId";
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* Callback routines for Subscribed Topics
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
int on_publish01(uint8_t* pload, uint16_t ploadlen)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* A Link list of Callback routines and Topics
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
|
|
||||||
SUBSCRIBE_LIST = {// e.g. SUB(topic, callback, QoS),
|
|
||||||
//SUB(topic1, on_publish01, 1),
|
|
||||||
END_OF_SUBSCRIBE_LIST
|
|
||||||
};
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* Test functions
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
void test1(void)
|
|
||||||
{
|
|
||||||
char payload[300];
|
|
||||||
sprintf(payload, "Client-01 ");
|
|
||||||
uint8_t qos = 0;
|
|
||||||
PUBLISH(topic1,(uint8_t*)payload, strlen(payload), qos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test2(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void test3(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void test4(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void test5(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* A List of Test functions
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
|
|
||||||
TEST_LIST = {// e.g. TEST( Label, Test),
|
|
||||||
TEST("Publish topic1", test1),
|
|
||||||
END_OF_TEST_LIST
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* unused for Test
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
TASK_LIST = {// e.g. TASK( task, executing duration in second),
|
|
||||||
TASK(test1, 4),
|
|
||||||
END_OF_TASK_LIST
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* Initialize function
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
void setup(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*======================================================
|
|
||||||
* main
|
|
||||||
*======================================================*/
|
|
||||||
|
|
||||||
/* uncomment this
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
return run();
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/**************************************************************************************
|
/****************************************************************************
|
||||||
* Copyright (c) 2016, Tomoaki Yamaguchi
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
@@ -10,22 +10,11 @@
|
|||||||
* and the Eclipse Distribution License is available at
|
* and the Eclipse Distribution License is available at
|
||||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
*
|
*
|
||||||
* Contributors:
|
*---------------------------------------------------------------------------
|
||||||
* Tomoaki Yamaguchi - initial API and implementation
|
*
|
||||||
**************************************************************************************/
|
* MQTT-SN GATEWAY TEST CLIENT
|
||||||
|
*
|
||||||
#include "LMqttsnClientApp.h"
|
* Supported functions.
|
||||||
#include "LMqttsnClient.h"
|
|
||||||
#include "LScreen.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace linuxAsyncClient;
|
|
||||||
extern LMqttsnClient* theClient;
|
|
||||||
extern LScreen* theScreen;
|
|
||||||
extern int run(void);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Functions supported.
|
|
||||||
*
|
*
|
||||||
* void PUBLISH ( const char* topicName, uint8_t* payload,
|
* void PUBLISH ( const char* topicName, uint8_t* payload,
|
||||||
* uint16_t len, uint8_t qos, bool retain = false );
|
* uint16_t len, uint8_t qos, bool retain = false );
|
||||||
@@ -42,7 +31,20 @@ extern int run(void);
|
|||||||
*
|
*
|
||||||
* void DISPLAY( format, .....); <== instead of printf()
|
* void DISPLAY( format, .....); <== instead of printf()
|
||||||
*
|
*
|
||||||
*/
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "LMqttsnClientApp.h"
|
||||||
|
#include "LMqttsnClient.h"
|
||||||
|
#include "LScreen.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace linuxAsyncClient;
|
||||||
|
extern LMqttsnClient* theClient;
|
||||||
|
extern LScreen* theScreen;
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* UDP Configuration (theNetcon)
|
* UDP Configuration (theNetcon)
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
@@ -168,7 +170,9 @@ void asleep(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* A List of Test functions
|
* A List of Test functions is valid in case of
|
||||||
|
* line 23 of LMqttsnClientApp.h is commented out.
|
||||||
|
* //#define CLIENT_MODE
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
TEST_LIST = {// e.g. TEST( Label, Test),
|
TEST_LIST = {// e.g. TEST( Label, Test),
|
||||||
@@ -188,13 +192,17 @@ TEST_LIST = {// e.g. TEST( Label, Test),
|
|||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* unused for Test
|
* List of tasks is valid in case of line23 of
|
||||||
|
* LMqttsnClientApp.h is uncommented.
|
||||||
|
* #define CLIENT_MODE
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
TASK_LIST = {// e.g. TASK( task, executing duration in second),
|
TASK_LIST = {// e.g. TASK( task, executing duration in second),
|
||||||
//TASK(test1, 4);
|
TASK(publishTopic1, 4), // publishTopic1() is executed every 4 seconds
|
||||||
|
TASK(publishTopic2, 7), // publishTopic2() is executed every 7 seconds
|
||||||
END_OF_TASK_LIST
|
END_OF_TASK_LIST
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------
|
/*------------------------------------------------------
|
||||||
* Initialize function
|
* Initialize function
|
||||||
*------------------------------------------------------*/
|
*------------------------------------------------------*/
|
||||||
@@ -203,11 +211,5 @@ void setup(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------
|
|
||||||
* main
|
|
||||||
*------------------------------------------------------*/
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
/***************** END OF PROGRAM ********************/
|
||||||
{
|
|
||||||
return run();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ extern OnPublishList theOnPublishList[];
|
|||||||
extern MQTTSNCONF;
|
extern MQTTSNCONF;
|
||||||
extern UDPCONF;
|
extern UDPCONF;
|
||||||
extern void setup(void);
|
extern void setup(void);
|
||||||
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
LMqttsnClient
|
LMqttsnClient
|
||||||
======================================*/
|
======================================*/
|
||||||
@@ -39,10 +40,15 @@ LScreen* theScreen = new LScreen();
|
|||||||
bool theOTAflag = false;
|
bool theOTAflag = false;
|
||||||
bool theClientMode = true;
|
bool theClientMode = true;
|
||||||
|
|
||||||
int run(void)
|
|
||||||
|
/*-------------------------------------
|
||||||
|
* main
|
||||||
|
*------------------------------------*/
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
#ifndef CLIENT_MODE
|
||||||
char c = 0;
|
char c = 0;
|
||||||
setup();
|
|
||||||
printf("\n%s", PAHO_COPYRIGHT4);
|
printf("\n%s", PAHO_COPYRIGHT4);
|
||||||
printf("\n%s\n", PAHO_COPYRIGHT0);
|
printf("\n%s\n", PAHO_COPYRIGHT0);
|
||||||
printf("%s\n", PAHO_COPYRIGHT1);
|
printf("%s\n", PAHO_COPYRIGHT1);
|
||||||
@@ -51,31 +57,29 @@ int run(void)
|
|||||||
printf("%s\n", TESTER_VERSION);
|
printf("%s\n", TESTER_VERSION);
|
||||||
printf("%s\n", PAHO_COPYRIGHT4);
|
printf("%s\n", PAHO_COPYRIGHT4);
|
||||||
|
|
||||||
#ifndef CLIENT_MODE
|
theClientMode = false;
|
||||||
|
PROMPT(" Do you like Tomoaki ? ( y/n ) : ");
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
theClientMode = false;
|
if (CHECKKEYIN(&c))
|
||||||
PROMPT(" Do you like Tomoaki ? ( y/n ) : ");
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
if (CHECKKEYIN(&c))
|
if ( toupper(c) == 'N' )
|
||||||
{
|
{
|
||||||
if ( toupper(c) == 'N' )
|
DISPLAY("\033[0;31m\n**** Sorry ****\033[0;37m\n\n");
|
||||||
{
|
|
||||||
DISPLAY("\033[0;31m\n**** Sorry ****\033[0;37m\n\n");
|
|
||||||
PROMPT("");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( toupper(c) == 'Y' )
|
|
||||||
{
|
|
||||||
DISPLAY("\033[0m\033[0;32mAttempting to Connect the Broker.....\033[0m\033[0;37m\n");
|
|
||||||
PROMPT("");
|
PROMPT("");
|
||||||
break;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( toupper(c) == 'Y' )
|
||||||
|
{
|
||||||
|
DISPLAY("\033[0m\033[0;32mAttempting to Connect the Broker.....\033[0m\033[0;37m\n");
|
||||||
|
PROMPT("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
setup();
|
||||||
theClient->addTask(theClientMode);
|
theClient->addTask(theClientMode);
|
||||||
theClient->initialize( theNetcon, theMqcon);
|
theClient->initialize( theNetcon, theMqcon);
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user