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)
{
_network.initialize(netconf);
if (_network.initialize(netconf) == false)
{
DISPLAY("Can't open SensorNetwork\n");
exit(-1);
}
_clientId = netconf->clientId;
_willTopic = mqconf->willTopic;
_willMsg = mqconf->willMsg;

View File

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