From e60dfc121983138b3c0c7872ece5fff749e9bc9f Mon Sep 17 00:00:00 2001 From: XavierChanth Date: Fri, 6 Dec 2024 14:48:22 -0500 Subject: [PATCH] feat: Allow custom atlogger implementation --- generators/arduino/atsdk/generate.sh | 24 +++++++++++++++---- packages/atchops/include/atchops/platform.h | 4 ---- .../atchops/tests/test_rsaprivatepopulate.c | 2 +- packages/atclient/src/notify.c | 5 ---- packages/atcommons/include/atcommons/json.h | 10 -------- packages/atlogger/src/atlogger.c | 10 ++++---- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/generators/arduino/atsdk/generate.sh b/generators/arduino/atsdk/generate.sh index 78fbb1ae..fdb0b9f4 100755 --- a/generators/arduino/atsdk/generate.sh +++ b/generators/arduino/atsdk/generate.sh @@ -181,7 +181,6 @@ fix_rel_headers() { public_headers() { cp $script_dir/lib/* $src_base/ - # cat "$script_dir/atsdk.htemplate" >>$src_base/atsdk.h for d in ${packages[@]}; do local includes=$( cd "$src_base/$d" && @@ -191,9 +190,22 @@ public_headers() { echo "#include \"$d/$f\" // IWYU pragma: export" >>$src_base/atsdk.h done done - # cp "$script_dir/atsdk_cjson.htemplate" $src_base/atsdk_cjson.h - # cp "$script_dir/atsdk_cjson.ctemplate" $src_base/atsdk_cjson.c - # cp "$script_dir/atsdk_atsdk.cpptemplate" $src_base/atsdk_atsdk.cpp +} + +overrides() { + # logging + echo "#define ATLOGGER_OVERRIDE_LOG_FUNCTION" >>$src_base/atlogger/atlogger.h + # json + { + echo "#define ATCOMMONS_JSON_PROVIDER_CJSON" + echo "#include " + } >>$src_base/atcommons/json.h + # platform + { + echo '#define PRIu64 "llu"' + echo "#define ATCHOPS_TARGET_ARDUINO" + echo "#define ATCHOPS_MBEDTLS_VERSION_2" + } >>$src_base/atchops/platform.h } echo "Cleaning generated files and folders" @@ -228,6 +240,9 @@ public_headers echo "Fixing all includes to be relative" fix_rel_headers +echo "Applying Arduino specific overrides" +overrides + echo "Done generating Arduino library" # functions @@ -236,6 +251,7 @@ unset clean unset gen_src unset public_headers unset fix_rel_headers +unset overrides # global variables unset script_dir diff --git a/packages/atchops/include/atchops/platform.h b/packages/atchops/include/atchops/platform.h index 056416a4..b07faf10 100644 --- a/packages/atchops/include/atchops/platform.h +++ b/packages/atchops/include/atchops/platform.h @@ -18,9 +18,5 @@ #elif defined(CONFIG_IDF_TARGET_ESP32) #define ATCHOPS_TARGET_ESPIDF -#elif defined(TARGET_PORTENTA_H7) -#define ATCHOPS_TARGET_ARDUINO -#define ATCHOPS_MBEDTLS_VERSION_2 - #endif #endif diff --git a/packages/atchops/tests/test_rsaprivatepopulate.c b/packages/atchops/tests/test_rsaprivatepopulate.c index 0adcd5a1..81e5e92d 100644 --- a/packages/atchops/tests/test_rsaprivatepopulate.c +++ b/packages/atchops/tests/test_rsaprivatepopulate.c @@ -1,7 +1,7 @@ #include "atchops/rsa_key.h" +#include #include #include -#include #define PRIVATE_KEY_BASE64 \ "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCy64Pzy9ZDdm6e96z3DmjektD7sKUo40Ax+" \ diff --git a/packages/atclient/src/notify.c b/packages/atclient/src/notify.c index c8e3e9b3..5cd91ee3 100644 --- a/packages/atclient/src/notify.c +++ b/packages/atclient/src/notify.c @@ -335,12 +335,7 @@ static int generate_cmd(const atclient_notify_params *params, const char *cmdval } if (atclient_notify_params_is_notification_expiry_initialized(params) && params->notification_expiry > 0) { -#ifdef TARGET_PORTENTA_H7 - // PRIu64 not defined on portenta but we know it's 32 bit so we can hard code it to llu - snprintf(cmd + off, cmdsize - off, ":ttln:%llu", params->notification_expiry); -#else snprintf(cmd + off, cmdsize - off, ":ttln:%" PRIu64, params->notification_expiry); -#endif off += strlen(":ttln:") + atclient_string_utils_long_strlen(params->notification_expiry); } diff --git a/packages/atcommons/include/atcommons/json.h b/packages/atcommons/include/atcommons/json.h index 7c6e983c..584070bd 100644 --- a/packages/atcommons/include/atcommons/json.h +++ b/packages/atcommons/include/atcommons/json.h @@ -17,16 +17,6 @@ extern "C" { #define ATCOMMONS_JSON_PROVIDER_CJSON #include // IWYU pragma: export -#elif defined(TARGET_PORTENTA_H7) -#define ATCOMMONS_JSON_PROVIDER_CJSON -#define ATCOMMONS_JSON_PROVIDER_ARDUINO - -// This file will be injected into the Arduino build by the generator -// search for atsdk_cjson.h.template in the generators directory -#include - -#else -#error "unable to resolve json provider for platform" #endif #ifdef __cplusplus diff --git a/packages/atlogger/src/atlogger.c b/packages/atlogger/src/atlogger.c index 11cee62a..cf32b685 100644 --- a/packages/atlogger/src/atlogger.c +++ b/packages/atlogger/src/atlogger.c @@ -6,11 +6,7 @@ #include #include -#if defined(TARGET_PORTENTA_H7) -#define ATLOGGER_DISABLE_TIMESTAMPS -#endif - -#ifndef ATLOGGER_DISABLE_TIMESTAMPS +#if !defined(ATLOGGER_DISABLE_TIMESTAMPS) && !defined(ATLOGGER_OVERRIDE_LOG_FUNCTION) #include #endif @@ -35,6 +31,7 @@ static atlogger_ctx *atlogger_get_instance() { return &ctx; } +#ifndef ATLOGGER_OVERRIDE_LOG_FUNCTION static void atlogger_get_prefix(enum atlogger_logging_level logging_level, char *prefix, size_t prefixlen) { memset(prefix, 0, prefixlen); int off = 0; @@ -88,6 +85,7 @@ static void atlogger_get_prefix(enum atlogger_logging_level logging_level, char off += 2; prefix[off] = '\0'; } +#endif enum atlogger_logging_level atlogger_get_logging_level() { atlogger_ctx *ctx = atlogger_get_instance(); @@ -104,6 +102,7 @@ void atlogger_set_opts(int opts) { ctx->opts = opts; } +#ifndef ATLOGGER_OVERRIDE_LOG_FUNCTION void atlogger_log(const char *tag, const enum atlogger_logging_level level, const char *format, ...) { atlogger_ctx *ctx = atlogger_get_instance(); @@ -125,6 +124,7 @@ void atlogger_log(const char *tag, const enum atlogger_logging_level level, cons vprintf(format, args); va_end(args); } +#endif void atlogger_fix_stdout_buffer(char *str, const size_t strlen) { // if str == 'Jeremy\r\n', i want it to be 'Jeremy'