Skip to content

Commit ed7b70b

Browse files
committed
add example
1 parent 5faf031 commit ed7b70b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.github/workflows/compile-examples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- examples/customCborEncoder
3131
- examples/timedBlink
3232
- examples/flashFormatter
33+
- examples/versionCborEncoder
3334
SKETCHES_REPORTS_PATH: sketches-reports
3435

3536
strategy:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2025 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <Arduino_CBOR.h>
12+
#include <cbor/standards/StandardMessages.h>
13+
14+
void setup() {
15+
Serial.begin(9600);
16+
while(!Serial);
17+
18+
VersionMessage command;
19+
command.c.id = StandardMessageId::WiFiFWVersionMessageId;
20+
command.params.version = "1.6.0";
21+
uint8_t buffer[512];
22+
size_t buf_len = sizeof(buffer);
23+
24+
CBORMessageEncoder encoder;
25+
MessageEncoder::Status err = encoder.encode((Message*)&command, buffer, buf_len);
26+
27+
uint8_t expected_result[] = {
28+
0xda, 0x00, 0x01, 0x20, 0x14, 0x81, 0x65, 0x31, 0x2E, 0x36, 0x2E, 0x30
29+
};
30+
size_t res_len=buf_len;
31+
MessageEncoder::Status res = encoder.encode((Message*)&command, buffer, res_len);
32+
33+
if(res == MessageEncoder::Status::Complete &&
34+
memcmp(buffer, expected_result, res_len) == 0) {
35+
36+
Serial.println("Encode operation completed with success");
37+
} else {
38+
Serial.println("Encode operation failed");
39+
}
40+
}
41+
42+
void loop() {}

0 commit comments

Comments
 (0)