Bugfix check network status after initialization.

future branch is merged into develop. #69
Change Tab to 4 spaces

Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
tomoaki
2021-06-07 18:49:51 +09:00
parent 85ae4e3596
commit 83c30d662f
2 changed files with 130 additions and 122 deletions

View File

@@ -68,7 +68,11 @@ LGwProxy::~LGwProxy()
void LGwProxy::initialize(SENSORNET_CONFIG_t* netconf, LMqttsnConfig* mqconf) void LGwProxy::initialize(SENSORNET_CONFIG_t* netconf, LMqttsnConfig* mqconf)
{ {
_network.initialize(netconf); if (_network.initialize(netconf) == false)
{
DISPLAY("Can't open SensorNetwork\n");
exit(-1);
}
_clientId = netconf->clientId; _clientId = netconf->clientId;
_willTopic = mqconf->willTopic; _willTopic = mqconf->willTopic;
_willMsg = mqconf->willMsg; _willMsg = mqconf->willMsg;

View File

@@ -14,7 +14,6 @@
* Tomoaki Yamaguchi - initial API and implementation and/or initial documentation * Tomoaki Yamaguchi - initial API and implementation and/or initial documentation
**************************************************************************************/ **************************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -32,148 +31,153 @@ extern LMqttsnClient* theClient;
extern LScreen* theScreen; extern LScreen* theScreen;
extern bool theClientMode; extern bool theClientMode;
/*===================================== /*=====================================
TaskManager TaskManager
======================================*/ ======================================*/
LTaskManager::LTaskManager(void){ LTaskManager::LTaskManager(void)
_tasks = 0; {
_tests = 0; _tasks = 0;
_index = 0; _tests = 0;
_index = 0;
} }
LTaskManager::~LTaskManager(void){ LTaskManager::~LTaskManager(void)
{
} }
void LTaskManager::add(TaskList* task){ void LTaskManager::add(TaskList* task)
{
_tasks = task; _tasks = task;
} }
void LTaskManager::add(TestList* test){ void LTaskManager::add(TestList* test)
{
_tests = test; _tests = test;
} }
void LTaskManager::run(void){ void LTaskManager::run(void)
int i = 0; {
char c = 0; int i = 0;
bool cancelFlg = false; char c = 0;
TestList test = {0}; bool cancelFlg = false;
TaskList task = {0}; TestList test = { 0 };
TaskList task = { 0 };
if ( !theClientMode ) if (!theClientMode)
{ {
theClient->getGwProxy()->getMessage(); theClient->getGwProxy()->getMessage();
for (i = 0; _tests[i].testTask > test.testTask; i++) for (i = 0; _tests[i].testTask > test.testTask; i++)
{ {
PROMPT("Execute \"%s\" ? ( y/n ) : ", _tests[i].testLabel); PROMPT("Execute \"%s\" ? ( y/n ) : ", _tests[i].testLabel);
while (true) while (true)
{ {
if (CHECKKEYIN(&c)) if (CHECKKEYIN(&c))
{ {
if ( toupper(c) == 'N' ) if (toupper(c) == 'N')
{ {
DISPLAY("\033[0m\033[0;32m\n**** %s is canceled ****\033[0m\033[0;37m\n\n", _tests[i].testLabel); DISPLAY("\033[0m\033[0;32m\n**** %s is canceled ****\033[0m\033[0;37m\n\n", _tests[i].testLabel);
theScreen->prompt(""); theScreen->prompt("");
cancelFlg = true; cancelFlg = true;
break; break;
} }
else if ( toupper(c) == 'Y' ) else if (toupper(c) == 'Y')
{ {
DISPLAY("\033[0m\033[0;32m\n\n**** %s start ****\033[0m\033[0;37m\n", _tests[i].testLabel); DISPLAY("\033[0m\033[0;32m\n\n**** %s start ****\033[0m\033[0;37m\n", _tests[i].testLabel);
theScreen->prompt(""); theScreen->prompt("");
(_tests[i].testTask)(); (_tests[i].testTask)();
cancelFlg = false; cancelFlg = false;
break; break;
} }
} }
else else
{ {
theClient->getGwProxy()->getMessage(); theClient->getGwProxy()->getMessage();
} }
} }
while ( true ) while (true)
{ {
do do
{ {
theClient->getGwProxy()->getMessage(); theClient->getGwProxy()->getMessage();
} }
while(theClient->getPublishManager()->isMaxFlight() || while (theClient->getPublishManager()->isMaxFlight() || !theClient->getSubscribeManager()->isDone()
!theClient->getSubscribeManager()->isDone() || || !theClient->getRegisterManager()->isDone());
!theClient->getRegisterManager()->isDone());
if (theClient->getPublishManager()->isDone()) if (theClient->getPublishManager()->isDone())
{ {
break; break;
} }
} }
if ( !cancelFlg ) if (!cancelFlg)
{ {
DISPLAY("\033[0m\033[0;32m\n**** %s complete ****\033[0m\033[0;37m\n\n", _tests[i].testLabel); DISPLAY("\033[0m\033[0;32m\n**** %s complete ****\033[0m\033[0;37m\n\n", _tests[i].testLabel);
} }
} }
DISPLAY("\033[0m\033[0;32m\n\n######### All tests complete! ###########\033[0m\033[0;37m\n\n"); DISPLAY("\033[0m\033[0;32m\n\n######### All tests complete! ###########\033[0m\033[0;37m\n\n");
} }
else else
{ {
while (true) while (true)
{ {
theClient->getGwProxy()->getMessage(); theClient->getGwProxy()->getMessage();
for (_index = 0; _tasks[_index].callback > task.callback; _index++) for (_index = 0; _tasks[_index].callback > task.callback; _index++)
{ {
if ((_tasks[_index].prevTime + _tasks[_index].interval <= time(NULL)) && if ((_tasks[_index].prevTime + _tasks[_index].interval <= time(NULL)) && _tasks[_index].count == 0)
_tasks[_index].count == 0) {
{ _tasks[_index].prevTime = time(NULL);
_tasks[_index].prevTime = time(NULL); (_tasks[_index].callback)();
(_tasks[_index].callback)(); }
} }
}
do do
{ {
theClient->getGwProxy()->getMessage(); theClient->getGwProxy()->getMessage();
} }
while(theClient->getPublishManager()->isMaxFlight() || while (theClient->getPublishManager()->isMaxFlight() || !theClient->getSubscribeManager()->isDone()
!theClient->getSubscribeManager()->isDone() || || !theClient->getRegisterManager()->isDone());
!theClient->getRegisterManager()->isDone());
if (theClient->getPublishManager()->isDone()) if (theClient->getPublishManager()->isDone())
{ {
break; break;
} }
} }
} }
} }
uint8_t LTaskManager::getIndex(void){ uint8_t LTaskManager::getIndex(void)
return _index; {
return _index;
} }
void LTaskManager::done(uint8_t index){ void LTaskManager::done(uint8_t index)
if (_tasks ) {
{ if (_tasks)
if (_tasks[index].count > 0) {
{ if (_tasks[index].count > 0)
_tasks[index].count--; {
} _tasks[index].count--;
} }
if (_tests ) }
{ if (_tests)
if (_tests[index].count > 0) {
{ if (_tests[index].count > 0)
_tests[index].count--; {
} _tests[index].count--;
} }
}
} }
void LTaskManager::suspend(uint8_t index){ void LTaskManager::suspend(uint8_t index)
if ( _tasks ) {
{ if (_tasks)
_tasks[index].count++; {
} _tasks[index].count++;
if ( _tests ) }
{ if (_tests)
_tests[index].count++; {
} _tests[index].count++;
}
} }