From 91fbf63bd8db3b4b4b24b34fb7347fa74db5455c Mon Sep 17 00:00:00 2001 From: Sreedev Kodichath Date: Sat, 22 Aug 2026 08:27:27 +0200 Subject: [PATCH] [ADD] app: read the platform delay and bike counts --- src/c/model.c | 8 ++++++++ src/c/model.h | 6 ++++++ src/c/msg.c | 16 +++++++++++++++ tests/c/pebble.h | 7 ++++++- tests/c/test_msg.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/c/model.c b/src/c/model.c index bb3ebfd..2c10d62 100644 --- a/src/c/model.c +++ b/src/c/model.c @@ -50,6 +50,14 @@ void model_deinit(void) { void model_begin(uint8_t stop_count) { s_count = stop_count > MAX_STOPS ? MAX_STOPS : stop_count; memset(s_stops, 0, sizeof(s_stops)); + for (uint8_t i = 0; i < MAX_STOPS; i++) { + s_stops[i].bikes_mechanical = -1; + s_stops[i].bikes_electrical = -1; + s_stops[i].docks = -1; + for (uint8_t j = 0; j < MAX_ROWS; j++) { + s_stops[i].rows[j].delay_seconds = -1; + } + } } Stop *model_stop_at(uint8_t index) { diff --git a/src/c/model.h b/src/c/model.h index 0d6f5cd..917783a 100644 --- a/src/c/model.h +++ b/src/c/model.h @@ -7,6 +7,7 @@ #define NAME_LEN 32 #define ID_LEN 8 #define LINE_LEN 8 +#define PLATFORM_LEN 8 #define MAX_STRIP 8 #define MAX_SHAPE_BYTES 48 #define MAX_DEPARTURES 64 @@ -26,6 +27,8 @@ typedef struct { int16_t stops_away; uint8_t flags; int16_t drift; + char platform[PLATFORM_LEN]; + int16_t delay_seconds; } Row; typedef struct { @@ -59,6 +62,9 @@ typedef struct { uint8_t nearby; uint16_t distance_m; uint8_t row_count; + int16_t bikes_mechanical; + int16_t bikes_electrical; + int16_t docks; Row rows[MAX_ROWS]; } Stop; diff --git a/src/c/msg.c b/src/c/msg.c index 7c081b2..2c97cdb 100644 --- a/src/c/msg.c +++ b/src/c/msg.c @@ -118,6 +118,22 @@ static void fill_row(DictionaryIterator *it) { if ((t = dict_find(it, MESSAGE_KEY_ROW_DRIFT))) { row->drift = (int16_t)t->value->int32; } + if ((t = dict_find(it, MESSAGE_KEY_ROW_PLATFORM))) { + strncpy(row->platform, t->value->cstring, PLATFORM_LEN - 1); + row->platform[PLATFORM_LEN - 1] = '\0'; + } + if ((t = dict_find(it, MESSAGE_KEY_ROW_DELAY))) { + row->delay_seconds = (int16_t)t->value->int32; + } + if ((t = dict_find(it, MESSAGE_KEY_VILLO_MECHANICAL))) { + stop->bikes_mechanical = (int16_t)t->value->int32; + } + if ((t = dict_find(it, MESSAGE_KEY_VILLO_ELECTRICAL))) { + stop->bikes_electrical = (int16_t)t->value->int32; + } + if ((t = dict_find(it, MESSAGE_KEY_VILLO_DOCKS))) { + stop->docks = (int16_t)t->value->int32; + } } static void fill_line_header(DictionaryIterator *it) { diff --git a/tests/c/pebble.h b/tests/c/pebble.h index 6b43515..dcfa812 100644 --- a/tests/c/pebble.h +++ b/tests/c/pebble.h @@ -91,7 +91,12 @@ enum { MESSAGE_KEY_LINE_STATUS, MESSAGE_KEY_LINE_SHAPE, MESSAGE_KEY_STOP_NEARBY, - MESSAGE_KEY_REQ_DEST + MESSAGE_KEY_REQ_DEST, + MESSAGE_KEY_ROW_PLATFORM, + MESSAGE_KEY_ROW_DELAY, + MESSAGE_KEY_VILLO_MECHANICAL, + MESSAGE_KEY_VILLO_ELECTRICAL, + MESSAGE_KEY_VILLO_DOCKS }; typedef union { diff --git a/tests/c/test_msg.c b/tests/c/test_msg.c index 16ec603..dcda694 100644 --- a/tests/c/test_msg.c +++ b/tests/c/test_msg.c @@ -83,11 +83,44 @@ static void test_stop_and_row_fill(void) { td_int(&d, MESSAGE_KEY_ROW_MIN1, 1); td_int(&d, MESSAGE_KEY_ROW_MIN2, 11); td_int(&d, MESSAGE_KEY_ROW_FLAGS, 3); + td_str(&d, MESSAGE_KEY_ROW_PLATFORM, "12B"); + td_int(&d, MESSAGE_KEY_ROW_DELAY, 120); + td_int(&d, MESSAGE_KEY_VILLO_MECHANICAL, 4); + td_int(&d, MESSAGE_KEY_VILLO_ELECTRICAL, 0); + td_int(&d, MESSAGE_KEY_VILLO_DOCKS, 9); td_send(&d); Row *row = &stop->rows[0]; assert(strcmp(row->line, "62") == 0); assert(strcmp(row->destination, "SAINT-LAMBERT") == 0); assert(row->min1 == 1 && row->min2 == 11 && row->flags == 3); + assert(strcmp(row->platform, "12B") == 0); + assert(row->delay_seconds == 120); + assert(stop->bikes_mechanical == 4); + assert(stop->bikes_electrical == 0); + assert(stop->docks == 9); +} + +static void test_platform_delay_villo_absent_defaults(void) { + send_stop(0, 1, "6419", "BOTANIQUE", 1); + TestDict d = {0}; + td_int(&d, MESSAGE_KEY_KIND, 2); + td_int(&d, MESSAGE_KEY_STOP_INDEX, 0); + td_int(&d, MESSAGE_KEY_ROW_INDEX, 0); + td_str(&d, MESSAGE_KEY_ROW_LINE, "62"); + td_send(&d); + Stop *stop = model_stop_at(0); + assert(stop->rows[0].platform[0] == '\0'); + assert(stop->rows[0].delay_seconds == -1); + assert(stop->bikes_mechanical == -1); + assert(stop->bikes_electrical == -1); + assert(stop->docks == -1); + d.count = 0; + td_int(&d, MESSAGE_KEY_KIND, 2); + td_int(&d, MESSAGE_KEY_STOP_INDEX, 0); + td_int(&d, MESSAGE_KEY_ROW_INDEX, 0); + td_int(&d, MESSAGE_KEY_ROW_DELAY, 0); + td_send(&d); + assert(stop->rows[0].delay_seconds == 0); } static void test_stop_nearby_fill(void) { @@ -184,9 +217,19 @@ static void test_int32_extremes(void) { td_int(&d, MESSAGE_KEY_ROW_KIND, x); td_int(&d, MESSAGE_KEY_ROW_COLOR, x); td_int(&d, MESSAGE_KEY_ROW_FLAGS, x); + td_int(&d, MESSAGE_KEY_ROW_DELAY, x); + td_int(&d, MESSAGE_KEY_VILLO_MECHANICAL, x); + td_int(&d, MESSAGE_KEY_VILLO_ELECTRICAL, x); + td_int(&d, MESSAGE_KEY_VILLO_DOCKS, x); + td_str(&d, MESSAGE_KEY_ROW_PLATFORM, g_long); td_send(&d); assert(stop->rows[0].min1 == (int16_t)x); assert(stop->rows[0].stops_away == (int16_t)x); + assert(stop->rows[0].delay_seconds == (int16_t)x); + assert(stop->bikes_mechanical == (int16_t)x); + assert(stop->bikes_electrical == (int16_t)x); + assert(stop->docks == (int16_t)x); + assert(strlen(stop->rows[0].platform) == PLATFORM_LEN - 1); d.count = 0; td_int(&d, MESSAGE_KEY_KIND, 6); td_int(&d, MESSAGE_KEY_ROW_MIN1, x); @@ -431,6 +474,7 @@ static void model_invariants(void) { for (uint8_t j = 0; j < MAX_ROWS; j++) { assert(strlen(stop->rows[j].line) < LINE_LEN); assert(strlen(stop->rows[j].destination) < NAME_LEN); + assert(strlen(stop->rows[j].platform) < PLATFORM_LEN); } } LineDetail *detail = model_line_detail(); @@ -453,12 +497,14 @@ static void test_stress_random_dicts(void) { MESSAGE_KEY_ROW_FLAGS, MESSAGE_KEY_ROW_DRIFT, MESSAGE_KEY_ERROR, MESSAGE_KEY_RAIN_MINUTES, MESSAGE_KEY_CFG_VIBRATE, MESSAGE_KEY_CFG_LANG, MESSAGE_KEY_LINE_STRIP_INDEX, MESSAGE_KEY_LINE_STRIP_COUNT, - MESSAGE_KEY_LINE_STRIP_MARKER, MESSAGE_KEY_LINE_STATUS, MESSAGE_KEY_STOP_NEARBY + MESSAGE_KEY_LINE_STRIP_MARKER, MESSAGE_KEY_LINE_STATUS, MESSAGE_KEY_STOP_NEARBY, + MESSAGE_KEY_ROW_DELAY, MESSAGE_KEY_VILLO_MECHANICAL, MESSAGE_KEY_VILLO_ELECTRICAL, + MESSAGE_KEY_VILLO_DOCKS }; static const uint32_t str_keys[] = { MESSAGE_KEY_STOP_ID, MESSAGE_KEY_STOP_NAME, MESSAGE_KEY_STOP_DIRECTION, MESSAGE_KEY_ROW_LINE, MESSAGE_KEY_ROW_DEST, MESSAGE_KEY_LINE_STRIP_NAME, - MESSAGE_KEY_LINE_DISRUPTION + MESSAGE_KEY_LINE_DISRUPTION, MESSAGE_KEY_ROW_PLATFORM }; char buf[300]; uint8_t data[256]; @@ -495,6 +541,7 @@ int main(void) { msg_init(on_update); assert(pebble_stub_inbox != NULL); test_stop_and_row_fill(); + test_platform_delay_villo_absent_defaults(); test_stop_nearby_fill(); test_string_termination(); test_int32_extremes(); -- knotmirror 0.0.1