Skip to content

Commit ecfe318

Browse files
author
Memfault Inc
committed
Memfault Firmware SDK 0.28.0 (Build 370105)
1 parent 8585f81 commit ecfe318

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1433
-318
lines changed

CHANGES.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
### Changes between Memfault SDK 0.28.0 and SDK 0.27.3 - Jan 4, 2022
2+
3+
#### :rocket: New Features
4+
5+
- Add support for setting string metrics, see
6+
`memfault_metrics_heartbeat_set_string()` in
7+
[`components/include/memfault/metrics/metrics.h`](components/include/memfault/metrics/metrics.h)
8+
for the new API. See the [Memfault Docs](https://mflt.io/embedded-metrics) for
9+
general information on using the metrics API.
10+
- Updated `memfault_metrics_heartbeat_debug_print()` to also print current timer
11+
values, instead of showing `0`. See
12+
[`components/include/memfault/metrics/metrics.h`](components/include/memfault/metrics/metrics.h)
13+
for details
14+
15+
#### :chart_with_upwards_trend: Improvements
16+
17+
- Update the STM32 QP/C example ([`examples/qp`](examples/qp)) to compile and
18+
run correctly now
19+
- Add intructions for exercising Memfault OTA in the ESP32 example, see the
20+
"Testing OTA" section in
21+
[`examples/esp32/README.md`](examples/esp32/README.md)
22+
- Update the Memfault HTTP client to URL-encode query params when checking for
23+
OTA updates (in the case of Device properties containing reserved characters,
24+
eg `+`). Update the ESP port to check for reserved characters in query params
25+
and emit an error
26+
- Fix an outdated comment in `cmake/Memfault.cmake`, as reported in
27+
[issue #21](https://github.com/memfault/memfault-firmware-sdk/issues/21)
28+
(thank you @C47D !)
29+
30+
#### :house: Internal
31+
32+
- Update Python tests to use a mocked-out gdb instance
33+
134
### Changes between Memfault SDK 0.27.3 and SDK 0.27.2 - Nov 22, 2021
235

336
#### :chart_with_upwards_trend: Improvements

VERSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
BUILD ID: 347225
2-
GIT COMMIT: 3f66c9c5e
1+
BUILD ID: 370105
2+
GIT COMMIT: 4641213bd

cmake/Memfault.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
# set(MEMFAULT_SDK_ROOT <The path to the root of the memfault-firmware-sdk repo>)
99
# list(APPEND MEMFAULT_COMPONENTS <The SDK components to be used, i.e "core util">)
10-
# include(${MEMFAULT_SDK_ROOT}/cmake/MemfaultWorker.cmake)
10+
# include(${MEMFAULT_SDK_ROOT}/cmake/Memfault.cmake)
1111
# memfault_library(${MEMFAULT_SDK_ROOT} MEMFAULT_COMPONENTS
1212
# MEMFAULT_COMPONENTS_SRCS MEMFAULT_COMPONENTS_INC_FOLDERS)
1313
#

components/http/src/memfault_http_utils.c

Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,25 @@
88

99
#include "memfault/http/utils.h"
1010

11+
#include <ctype.h>
1112
#include <limits.h>
1213
#include <stdio.h>
1314
#include <string.h>
15+
#include <stdint.h>
1416

1517
#include "memfault/core/compiler.h"
18+
#include "memfault/core/debug_log.h"
19+
#include "memfault/core/math.h"
1620
#include "memfault/core/platform/device_info.h"
1721
#include "memfault/http/http_client.h"
1822

23+
//! Default buffer size for the URL-encoded device info parameters. This may
24+
//! need to be set higher by the user if there are particularly long device info
25+
//! strings
26+
#ifndef MEMFAULT_DEVICE_INFO_URL_ENCODED_MAX_LEN
27+
#define MEMFAULT_DEVICE_INFO_URL_ENCODED_MAX_LEN (48)
28+
#endif
29+
1930
static bool prv_write_msg(MfltHttpClientSendCb write_callback, void *ctx,
2031
const char *msg, size_t msg_len, size_t max_len) {
2132
if (msg_len >= max_len) {
@@ -153,19 +164,49 @@ bool memfault_http_get_latest_ota_payload_url(MfltHttpClientSendCb write_callbac
153164

154165
#define MEMFAULT_STATIC_STRLEN(s) (sizeof(s) - 1)
155166

156-
if (!prv_write_qparam(write_callback, ctx,
157-
DEVICE_SERIAL_QPARAM, MEMFAULT_STATIC_STRLEN(DEVICE_SERIAL_QPARAM),
158-
device_info.device_serial) ||
159-
!prv_write_qparam(write_callback, ctx,
160-
HARDWARE_VERSION_QPARAM, MEMFAULT_STATIC_STRLEN(HARDWARE_VERSION_QPARAM),
161-
device_info.hardware_version) ||
162-
!prv_write_qparam(write_callback, ctx,
163-
SOFTWARE_TYPE_QPARAM, MEMFAULT_STATIC_STRLEN(SOFTWARE_TYPE_QPARAM),
164-
device_info.software_type) ||
165-
!prv_write_qparam(write_callback, ctx,
166-
CURRENT_VERSION_QPARAM, MEMFAULT_STATIC_STRLEN(CURRENT_VERSION_QPARAM),
167-
device_info.software_version)) {
168-
return false;
167+
const struct qparam_values_s {
168+
const char *name;
169+
size_t name_strlen;
170+
const char *value;
171+
} qparam_values[] = {
172+
{
173+
DEVICE_SERIAL_QPARAM,
174+
MEMFAULT_STATIC_STRLEN(DEVICE_SERIAL_QPARAM),
175+
device_info.device_serial,
176+
},
177+
{
178+
HARDWARE_VERSION_QPARAM,
179+
MEMFAULT_STATIC_STRLEN(HARDWARE_VERSION_QPARAM),
180+
device_info.hardware_version,
181+
},
182+
{
183+
SOFTWARE_TYPE_QPARAM,
184+
MEMFAULT_STATIC_STRLEN(SOFTWARE_TYPE_QPARAM),
185+
device_info.software_type,
186+
},
187+
{
188+
CURRENT_VERSION_QPARAM,
189+
MEMFAULT_STATIC_STRLEN(CURRENT_VERSION_QPARAM),
190+
device_info.software_version,
191+
},
192+
};
193+
194+
// URL encode the qparam values before writing them
195+
for (size_t i = 0; i < MEMFAULT_ARRAY_SIZE(qparam_values); i++) {
196+
const struct qparam_values_s *qparam_value = &qparam_values[i];
197+
198+
char qparam_encoded_buffer[MEMFAULT_DEVICE_INFO_URL_ENCODED_MAX_LEN];
199+
int rv = memfault_http_urlencode(qparam_value->value, strlen(qparam_value->value),
200+
qparam_encoded_buffer, sizeof(qparam_encoded_buffer));
201+
if (rv != 0) {
202+
MEMFAULT_LOG_ERROR("Failed to URL encode qparam value: %s", qparam_value->value);
203+
return false;
204+
}
205+
206+
if (!prv_write_qparam(write_callback, ctx, qparam_value->name, qparam_value->name_strlen,
207+
qparam_encoded_buffer)) {
208+
return false;
209+
}
169210
}
170211

171212
#define LATEST_REQUEST_LINE_END " HTTP/1.1\r\n"
@@ -619,3 +660,50 @@ bool memfault_http_get_ota_payload(MfltHttpClientSendCb write_callback, void *ct
619660

620661
return prv_write_crlf(write_callback, ctx);
621662
}
663+
664+
static bool prv_is_unreserved(char c) {
665+
return isalnum((uint8_t)c) || c == '-' || c == '_' || c == '.' || c == '~';
666+
}
667+
668+
bool memfault_http_needs_escape(const char *str, size_t len) {
669+
for (size_t i = 0; i < len; i++) {
670+
if (!prv_is_unreserved(str[i])) {
671+
return true;
672+
}
673+
}
674+
return false;
675+
}
676+
677+
int memfault_http_urlencode(const char *inbuf, size_t inbuf_len, char *outbuf, size_t outbuf_len) {
678+
// null check
679+
if (!inbuf || !outbuf || !inbuf_len || !outbuf_len) {
680+
return -1;
681+
}
682+
683+
while (inbuf_len--) {
684+
if (outbuf_len < 2) {
685+
// ran out of room before encoding the full input, error. there needs to
686+
// be 1 spare character for null term
687+
return -1;
688+
}
689+
char c = *inbuf++;
690+
if (prv_is_unreserved(c)) {
691+
*outbuf++ = c;
692+
outbuf_len--;
693+
} else {
694+
if (outbuf_len < 4) {
695+
// not enough room for encoded character and null term
696+
return -1;
697+
}
698+
// paste encoding (+ null term)
699+
snprintf(outbuf, 4, "%%%02X", (uint8_t)c);
700+
outbuf += 3;
701+
outbuf_len -= 3;
702+
}
703+
}
704+
705+
// null terminate
706+
*outbuf = '\0';
707+
708+
return 0;
709+
}

components/include/memfault/core/compiler_armcc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extern "C" {
3737
#define MEMFAULT_STATIC_ASSERT(expr, msg) \
3838
enum {MEMFAULT_CONCAT(MEMFAULT_ASSERTION_AT_, __LINE__) = sizeof(char[(expr) ? 1 : -1])}
3939

40+
#define MEMFAULT_DISABLE_WARNING(warning)
41+
4042
#ifdef __cplusplus
4143
}
4244
#endif

components/include/memfault/core/compiler_gcc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ extern "C" {
7979
# define MEMFAULT_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
8080
#endif
8181

82+
// Macro for disabling specific warnings. There must be quotes in the argument
83+
// to expand correctly to eg _Pragma("GCC diagnostic ignored \"warning-name\"")
84+
// Example:
85+
// MEMFAULT_DISABLE_WARNING("-Wunused-macros")
86+
#if defined(__clang__)
87+
#define MEMFAULT_PRAGMA_PREFIX clang
88+
#else
89+
#define MEMFAULT_PRAGMA_PREFIX GCC
90+
#endif
91+
#define MEMFAULT_DISABLE_WARNING(warning) \
92+
_Pragma(MEMFAULT_EXPAND_AND_QUOTE(MEMFAULT_PRAGMA_PREFIX diagnostic ignored warning))
93+
8294
#ifdef __cplusplus
8395
}
8496
#endif

components/include/memfault/core/compiler_iar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ extern "C" {
3636

3737
#define MEMFAULT_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
3838

39+
#define MEMFAULT_DISABLE_WARNING(warning)
40+
3941
#ifdef __cplusplus
4042
}
4143
#endif

components/include/memfault/core/compiler_ti_arm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ static uint32_t __get_PSP(void) {
7272
# define MEMFAULT_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
7373
#endif
7474

75+
#define MEMFAULT_DISABLE_WARNING(warning)
76+
7577
#ifdef __cplusplus
7678
}
7779
#endif

components/include/memfault/http/utils.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ typedef struct {
188188
//! @return true if parse was successful and uri_info_out is populated, false otherwise
189189
bool memfault_http_parse_uri(const char *uri, size_t uri_len, sMemfaultUriInfo *uri_info_out);
190190

191+
//! Check if a string contains any characters that require URL escaping
192+
//!
193+
//! @param str the string to check
194+
//! @param len length of str
195+
//!
196+
//! @return true if any characters in str require URL escaping, false otherwise
197+
bool memfault_http_needs_escape(const char *str, size_t len);
198+
199+
//! URL encode a string. See https://www.ietf.org/rfc/rfc3986.html#section-2.1
200+
//!
201+
//! @param inbuf String to encode; must be null-terminated
202+
//! @param[out] outbuf Endcoded string. Should be sized to fit possible encoding
203+
//! overhead, eg 3 * strlen(inbuf)
204+
//! @param outbuf_len Size of outbuf
205+
//!
206+
//! @return 0 if encoding was successful, non zero otherwise
207+
int memfault_http_urlencode(const char *inbuf, size_t inbuf_len, char *outbuf, size_t outbuf_len);
208+
191209
#ifdef __cplusplus
192210
}
193211
#endif

components/include/memfault/metrics/ids_impl.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@ extern "C" {
1818
#define MEMFAULT_METRICS_KEY_DEFINE_WITH_RANGE(key_name, value_type, _min, _max) \
1919
MEMFAULT_METRICS_KEY_DEFINE(key_name, value_type)
2020

21+
#define MEMFAULT_METRICS_STRING_KEY_DEFINE(key_name, max_length) \
22+
MEMFAULT_METRICS_KEY_DEFINE(key_name, _)
23+
2124
#define MEMFAULT_METRICS_KEY_DEFINE(key_name, value_type) \
2225
extern const char * const g_memfault_metrics_id_##key_name;
2326
#include "memfault/metrics/heartbeat_config.def"
2427
#include MEMFAULT_METRICS_USER_HEARTBEAT_DEFS_FILE
2528
#undef MEMFAULT_METRICS_KEY_DEFINE
2629
#undef MEMFAULT_METRICS_KEY_DEFINE_WITH_RANGE
30+
#undef MEMFAULT_METRICS_STRING_KEY_DEFINE
2731

2832
//! Generate an enum for all IDs (used for indexing into values)
2933
#define MEMFAULT_METRICS_KEY_DEFINE_WITH_RANGE(key_name, value_type, min_value, max_value) \
3034
MEMFAULT_METRICS_KEY_DEFINE(key_name, value_type)
3135

36+
#define MEMFAULT_METRICS_STRING_KEY_DEFINE(key_name, max_length) \
37+
MEMFAULT_METRICS_KEY_DEFINE(key_name, _)
38+
3239
#define MEMFAULT_METRICS_KEY_DEFINE(key_name, value_type) \
3340
kMfltMetricsIndex_##key_name,
3441

@@ -37,11 +44,13 @@ typedef enum MfltMetricsIndex {
3744
#include MEMFAULT_METRICS_USER_HEARTBEAT_DEFS_FILE
3845
#undef MEMFAULT_METRICS_KEY_DEFINE
3946
#undef MEMFAULT_METRICS_KEY_DEFINE_WITH_RANGE
47+
#undef MEMFAULT_METRICS_STRING_KEY_DEFINE
4048
} eMfltMetricsIndex;
4149

42-
#define _MEMFAULT_METRICS_KEY_DEFINE(key_name, value_type) \
50+
//! Stub define to detect accidental usage outside of the heartbeat config files
51+
#define MEMFAULT_METRICS_KEY_DEFINE_TRAP_() \
4352
MEMFAULT_STATIC_ASSERT(false, \
44-
"MEMFAULT_METRICS_KEY_DEFINE should only be used in " MEMFAULT_METRICS_USER_HEARTBEAT_DEFS_FILE)
53+
"MEMFAULT_METRICS_KEY_DEFINE should only be used in " MEMFAULT_METRICS_USER_HEARTBEAT_DEFS_FILE);
4554

4655
//! NOTE: Access to a key should _always_ be made via the MEMFAULT_METRICS_KEY() macro to ensure source
4756
//! code compatibility with future APIs updates

0 commit comments

Comments
 (0)