Skip to content

Commit

Permalink
Update cltool_main with missing changes from development
Browse files Browse the repository at this point in the history
  • Loading branch information
steezeman committed Jan 26, 2023
1 parent c8ee0b2 commit 0c7c8a3
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/cltool_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// Contains command line parsing and utility functions. Include this in your project to use these utility functions.
#include "cltool.h"

#include <signal.h>

using namespace std;

static bool g_killThreadsNow = false;

static void display_server_client_status(InertialSense* i, bool server=false, bool showMessageSummary=false, bool refreshDisplay=false)
{
Expand Down Expand Up @@ -384,18 +387,24 @@ void printProgress()

is_operation_result bootloadUpdateCallback(void* obj, float percent)
{
ISBootloader::cISBootloaderBase* ctx = (ISBootloader::cISBootloaderBase*)obj;
ctx->m_update_progress = percent;

return IS_OP_OK;
if(obj)
{
ISBootloader::cISBootloaderBase* ctx = (ISBootloader::cISBootloaderBase*)obj;
ctx->m_update_progress = percent;
}

return g_killThreadsNow ? IS_OP_CANCELLED : IS_OP_OK;
}

is_operation_result bootloadVerifyCallback(void* obj, float percent)
{
ISBootloader::cISBootloaderBase* ctx = (ISBootloader::cISBootloaderBase*)obj;
ctx->m_verify_progress = percent;
if(obj)
{
ISBootloader::cISBootloaderBase* ctx = (ISBootloader::cISBootloaderBase*)obj;
ctx->m_verify_progress = percent;
}

return IS_OP_OK;
return g_killThreadsNow ? IS_OP_CANCELLED : IS_OP_OK;
}

void cltool_bootloadUpdateInfo(void* obj, const char* str, ISBootloader::eLogLevel level)
Expand Down Expand Up @@ -487,6 +496,13 @@ static int cltool_createHost()
return 0;
}

static void sigint_cb(int sig)
{
g_killThreadsNow = true;
cltool_bootloadUpdateInfo(NULL, "Update cancelled, killing threads and exiting...", ISBootloader::eLogLevel::IS_LOG_LEVEL_ERROR);
signal(SIGINT, SIG_DFL);
}

static int inertialSenseMain()
{
// clear display
Expand All @@ -503,6 +519,7 @@ static int inertialSenseMain()
// if app firmware was specified on the command line, do that now and return
else if (g_commandLineOptions.updateAppFirmwareFilename.length() != 0)
{
signal(SIGINT, sigint_cb);
return cltool_updateFirmware();
}
else if (g_commandLineOptions.updateBootloaderFilename.length() != 0)
Expand Down

0 comments on commit 0c7c8a3

Please sign in to comment.