|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 Martin Jäger / Libre Solar |
| 3 | + * Copyright (c) 2021 Bobby Noelte |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <stdio.h> |
| 8 | + |
| 9 | +#include <thingset.h> |
| 10 | + |
| 11 | +/* variables to be exposed via ThingSet */ |
| 12 | +extern char device_id[]; |
| 13 | +extern bool enable_switch; |
| 14 | +extern float ambient_temp; |
| 15 | + |
| 16 | +/* the ThingSet data objects database */ |
| 17 | +TS_OBJ_DATABASE_DECLARE(data_objects_db); |
| 18 | + |
| 19 | +/* The ports table */ |
| 20 | +TS_PORT_TABLE_DECLARE(ports_table); |
| 21 | + |
| 22 | +/* Create context and assign data objects and ports */ |
| 23 | +TS_CONTEXT_DEFINE(tsc, data_objects_db, ports_table); |
| 24 | + |
| 25 | +void main(void) |
| 26 | +{ |
| 27 | + uint8_t response[100]; |
| 28 | + |
| 29 | + /* initialize ThingSet context and assign data objects */ |
| 30 | + tsc_init(&tsc); |
| 31 | + |
| 32 | + /* |
| 33 | + * Below requests are for demonstration of the ThingSet process function only. They would |
| 34 | + * usually be received from a connected serial interface or other communication channels. |
| 35 | + */ |
| 36 | + |
| 37 | + /* TBD -------------- |
| 38 | + const char request1[] = "= {\"HeaterEnable\":true}"; |
| 39 | + printf("Request: %s\n", request1); |
| 40 | + ts_process(&ts, (uint8_t *)request1, strlen(request1), response, sizeof(response)); |
| 41 | + printf("Response: %s\n\n", (char *)response); |
| 42 | +
|
| 43 | + const char request2[] = "!x-reset"; |
| 44 | + printf("Request: %s\n", request2); |
| 45 | + ts_process(&ts, (uint8_t *)request2, strlen(request2), response, sizeof(response)); |
| 46 | + printf("Response: %s\n\n", (char *)response); |
| 47 | +
|
| 48 | + const char request3[] = "?"; |
| 49 | + printf("Request: %s\n", request3); |
| 50 | + ts_process(&ts, (uint8_t *)request3, strlen(request3), response, sizeof(response)); |
| 51 | + printf("Response: %s\n\n", (char *)response); |
| 52 | + */ |
| 53 | + |
| 54 | +} |
0 commit comments