From: Urban Wallasch Date: Sun, 11 Aug 2019 15:07:47 +0000 (+0200) Subject: * Improved SDK version checking and logging. X-Git-Tag: v0.1.0~31 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=6d6972ab96e35b914594c2201bc245ff0f4a9610;p=ets2_tele.git * Improved SDK version checking and logging. --- diff --git a/teleshmem.cpp b/teleshmem.cpp index 2e23dc6..dac73ce 100644 --- a/teleshmem.cpp +++ b/teleshmem.cpp @@ -92,6 +92,7 @@ static int log_open( void ) { static void log_close( void ) { if ( logfp ) { + fprintf( logfp, "\nclosing log\n" ); fclose( logfp ); logfp = NULL; } @@ -204,7 +205,7 @@ static void log_named_value( const scs_named_value_t *nv ) { } } #else -#define log_open() +#define log_open() 0 #define log_close() #define log_print(...) #define log_named_value(...) @@ -491,15 +492,28 @@ SCSAPI_VOID telemetry_store_bool(const scs_string_t name, const scs_u32_t index, */ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_init_params_t *const params) { - log_open(); - - // We currently support only one version. - - if (version != SCS_TELEMETRY_VERSION_1_01) { + const scs_telemetry_init_params_v100_t *const v100p = static_cast(params); + const unsigned version_req = SCS_TELEMETRY_VERSION_1_01; // we currently require version 1.01 + char vstr[20]; + char rvstr[20]; + char vlogstr[100]; + + if ( 0 != log_open() ) + v100p->common.log( SCS_LOG_TYPE_warning, "[teleshmem] unable to open log file" ); + + sprintf( vstr, "%u.%02u", (unsigned)SCS_GET_MAJOR_VERSION(version), (unsigned)SCS_GET_MINOR_VERSION(version) ); + sprintf( rvstr, "%u.%02u", (unsigned)SCS_GET_MAJOR_VERSION(version_req), (unsigned)SCS_GET_MINOR_VERSION(version_req) ); + sprintf( vlogstr, "[teleshmem] got telemetry version %s", vstr ); + log_print( "Got telemetry version %s.\n", vstr ); + v100p->common.log( SCS_LOG_TYPE_message, vlogstr ); + if ( version != version_req ) { + log_print( "Error: Want telemetry version %s, got %s\n", rvstr, vstr ); + v100p->common.log( SCS_LOG_TYPE_warning, "[teleshmem] telemetry version not supported" ); return SCS_RESULT_unsupported; } - const scs_telemetry_init_params_v100_t *const version_params = static_cast(params); + const scs_telemetry_init_params_v101_t *const version_params = static_cast(params); + if ( !init_shm() ) { log_print( "FATAL: Unable to initialize shared memory\n" ); version_params->common.log(SCS_LOG_TYPE_error, "[teleshmem] Unable to initialize shared memory");