diff --git a/check_version.sh b/check_version.sh new file mode 100755 index 0000000..e640203 --- /dev/null +++ b/check_version.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# +# check_version.sh -- verify the library version is consistent and released. +# +# A read-only sanity check (it changes nothing). It confirms the version is the +# same in all three places it's declared: +# +# * library.properties version=X.Y.Z (Arduino Library Manager) +# * library.json "version": "X.Y.Z" (PlatformIO Registry) +# * src/meshcore_companion.h MESHCORE_COMPANION_VERSION "X.Y.Z" +# +# ...and that a matching git tag (vX.Y.Z or X.Y.Z) exists. Run it before tagging +# a release. Exit status is non-zero if anything is inconsistent or untagged. +# +# SPDX-License-Identifier: MIT + +set -u +cd "$(dirname "$0")" || exit 2 + +ok() { printf ' \033[32mok\033[0m %s\n' "$*"; } +bad() { printf ' \033[31mFAIL\033[0m %s\n' "$*"; } +note() { printf ' %s\n' "$*"; } + +prop_ver=$(sed -nE 's/^version=([^[:space:]]+).*/\1/p' library.properties | tr -d '\r' | head -1) +json_ver=$(sed -nE 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/p' library.json | head -1) +hdr_ver=$(sed -nE 's/.*MESHCORE_COMPANION_VERSION[[:space:]]+"([^"]+)".*/\1/p' src/meshcore_companion.h | head -1) + +printf 'Declared versions:\n' +printf ' library.properties : %s\n' "${prop_ver:-}" +printf ' library.json : %s\n' "${json_ver:-}" +printf ' meshcore_companion.h : %s\n' "${hdr_ver:-}" +printf '\nChecks:\n' + +fail=0 + +# 1) all three present and identical +if [ -z "$prop_ver" ] || [ -z "$json_ver" ] || [ -z "$hdr_ver" ]; then + bad "could not read a version from every source" + fail=1 +elif [ "$prop_ver" = "$json_ver" ] && [ "$json_ver" = "$hdr_ver" ]; then + ok "all three versions match ($prop_ver)" +else + bad "versions disagree (properties=$prop_ver json=$json_ver header=$hdr_ver)" + fail=1 +fi + +ver="$prop_ver" + +# 2) a matching git tag exists (vX.Y.Z or X.Y.Z) +if ! git rev-parse --git-dir >/dev/null 2>&1; then + bad "not a git repository -- cannot check for a release tag" + fail=1 +elif [ -z "$ver" ]; then + bad "no version to match a tag against" + fail=1 +else + tag="" + for cand in "v$ver" "$ver"; do + if git rev-parse -q --verify "refs/tags/$cand" >/dev/null 2>&1; then tag="$cand"; break; fi + done + if [ -n "$tag" ]; then + ok "git tag '$tag' exists" + if [ "$(git rev-list -n1 "$tag")" != "$(git rev-parse HEAD)" ]; then + note "(tag '$tag' is not on the current HEAD -- fine if you've moved on since the release)" + fi + else + bad "no git tag 'v$ver' or '$ver' -- create one to release: git tag v$ver" + fail=1 + fi +fi + +printf '\n' +if [ "$fail" -eq 0 ]; then + printf '\033[32mVersion %s is consistent and tagged.\033[0m\n' "$ver" +else + printf '\033[31mVersion check failed.\033[0m\n' +fi +exit "$fail" diff --git a/examples/AutoProvision/src/config.h b/examples/AutoProvision/src/config.h new file mode 100644 index 0000000..37688db --- /dev/null +++ b/examples/AutoProvision/src/config.h @@ -0,0 +1,52 @@ +/* + * config.h — user-tunable settings for the AutoProvision example. + * + * Pins and the radio region default here but are normally set per board in + * platformio.ini build_flags; the #ifndef guards let either win. The identity, + * channel and echo strings are plain constants — edit them for your setup. + * + * SPDX-License-Identifier: MIT + */ +#ifndef AUTOPROVISION_CONFIG_H +#define AUTOPROVISION_CONFIG_H + +#include + +// --- Host UART to the companion (override per board in platformio.ini) --- +#ifndef UART_RX_PIN +#define UART_RX_PIN 17 // host RX <- companion TX +#endif +#ifndef UART_TX_PIN +#define UART_TX_PIN 18 // host TX -> companion RX +#endif +#ifndef UART_BAUD +#define UART_BAUD 115200 +#endif + +// --- Radio region: AU narrow band (override in platformio.ini build_flags) --- +#ifndef LORA_FREQ +#define LORA_FREQ 916.575 // MHz +#endif +#ifndef LORA_BW +#define LORA_BW 62.5 // kHz +#endif +#ifndef LORA_SF +#define LORA_SF 7 +#endif +#ifndef LORA_CR +#define LORA_CR 8 +#endif +#ifndef LORA_TX_POWER +#define LORA_TX_POWER 20 // dBm +#endif + +// --- Identity + channel to provision --- +static const char* NODE_NAME = "auto-host"; +static const uint8_t CHANNEL_IDX = 2; +static const char* CHANNEL_NAME = "auto"; +static const char* CHANNEL_PSK_HEX = "000102030405060708090a0b0c0d0e0f"; // replace + +static const char* HELLO_TEXT = "hello"; +static const char* REPLY_TEXT = "hi there, auto-host here"; + +#endif // AUTOPROVISION_CONFIG_H diff --git a/examples/AutoProvision/src/main.cpp b/examples/AutoProvision/src/main.cpp index 5d960e6..97ae003 100644 --- a/examples/AutoProvision/src/main.cpp +++ b/examples/AutoProvision/src/main.cpp @@ -24,43 +24,7 @@ */ #include #include "MeshCoreCompanion.h" - -// --- Host UART to the companion (set in platformio.ini build_flags) --- -#ifndef UART_RX_PIN -#define UART_RX_PIN 17 // host RX <- companion TX -#endif -#ifndef UART_TX_PIN -#define UART_TX_PIN 18 // host TX -> companion RX -#endif -#ifndef UART_BAUD -#define UART_BAUD 115200 -#endif - -// --- Radio region: AU narrow band (normally set in platformio.ini build_flags) --- -#ifndef LORA_FREQ -#define LORA_FREQ 916.575 // MHz -#endif -#ifndef LORA_BW -#define LORA_BW 62.5 // kHz -#endif -#ifndef LORA_SF -#define LORA_SF 7 -#endif -#ifndef LORA_CR -#define LORA_CR 8 -#endif -#ifndef LORA_TX_POWER -#define LORA_TX_POWER 20 // dBm -#endif - -// --- Identity + channel to provision --- -static const char* NODE_NAME = "auto-host"; -static const uint8_t CHANNEL_IDX = 2; -static const char* CHANNEL_NAME = "auto"; -static const char* CHANNEL_PSK_HEX = "000102030405060708090a0b0c0d0e0f"; // replace - -static const char* HELLO_TEXT = "hello"; -static const char* REPLY_TEXT = "hi there, auto-host here"; +#include "config.h" // pins, region, identity/channel — edit there MeshCoreCompanion mc(Serial1); diff --git a/library.json b/library.json index a64b26a..4d83120 100644 --- a/library.json +++ b/library.json @@ -14,6 +14,7 @@ "srcFilter": ["+<*.c>", "+<*.cpp>"] }, "examples": [ + { "name": "AutoProvision", "base": "examples/AutoProvision", "files": ["platformio.ini", "src/main.cpp", "src/config.h"] }, { "name": "SensorChannelBridge", "base": "examples/SensorChannelBridge", "files": ["SensorChannelBridge.ino"] } ] } diff --git a/src/meshcore_companion.h b/src/meshcore_companion.h index 5c2e736..25dcd6d 100644 --- a/src/meshcore_companion.h +++ b/src/meshcore_companion.h @@ -28,6 +28,10 @@ extern "C" { #endif +/* Library version. Keep in sync with library.json and library.properties; + * check_version.sh verifies all three match and that a git tag exists. */ +#define MESHCORE_COMPANION_VERSION "0.2.0" + /* ---- Compile-time sizing (override before including if you need more) ---- */ #ifndef MC_MAX_PAYLOAD #define MC_MAX_PAYLOAD 255 /* largest companion payload we will buffer */