Skip to content

Commit 83ff146

Browse files
committed
Add hex encoding
1 parent 27d50c2 commit 83ff146

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/Arduino_HEX.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 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+
#pragma once
11+
12+
#include "./hex/hex.h"

src/hex/hex.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 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 "hex.h"
12+
13+
namespace arduino { namespace hex {
14+
15+
String encode(uint8_t* in, uint32_t size) {
16+
String out;
17+
out.reserve((size * 2) + 1);
18+
19+
char *ptr = out.begin();
20+
for (uint32_t i = 0; i < size; i++) {
21+
ptr += sprintf(ptr, "%02X", in[i]);
22+
}
23+
return String(out.c_str());
24+
}
25+
26+
}} // arduino::hex

src/hex/hex.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
This file is part of the Arduino_CloudUtils library.
3+
4+
Copyright (c) 2024 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+
#pragma once
12+
13+
#include <Arduino.h>
14+
15+
namespace arduino { namespace hex {
16+
/*
17+
* This library contains the methods to get board provisioning id
18+
*/
19+
20+
String encode(uint8_t* in, uint32_t size);
21+
22+
}} // arduino::hex

0 commit comments

Comments
 (0)