File tree 2 files changed +24
-9
lines changed
2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change 9
9
*/
10
10
11
11
#include " hex.h"
12
+ #include " chex.h"
12
13
13
14
namespace arduino { namespace hex {
14
15
15
- String encode (uint8_t * in, uint32_t size) {
16
- String out;
17
- out.reserve ((size * 2 ) + 1 );
16
+ String encode (const uint8_t * in, uint32_t size) {
17
+ char out[(size * 2 ) + 1 ];
18
+ unsigned int byteNumber;
19
+ byteNumber = chex_encode (out, sizeof (out), in, size);
20
+ out[byteNumber] = 0 ;
21
+ return String (out);
22
+ }
23
+
24
+ String encodeUpper (const uint8_t * in, uint32_t size) {
25
+ String out = encode (in, size);
26
+ out.toUpperCase ();
27
+ return out;
28
+ }
18
29
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 ());
30
+ bool decode (const String in, uint8_t * out, uint32_t size) {
31
+ unsigned int byteNumber;
32
+ byteNumber = chex_decode (out, size, in.begin (), in.length ());
33
+ Serial.println (byteNumber);
34
+ Serial.println (in.length ());
35
+ return byteNumber * 2 == in.length ();
24
36
}
25
37
26
38
}} // arduino::hex
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ namespace arduino { namespace hex {
17
17
* This library contains the methods to get board provisioning id
18
18
*/
19
19
20
- String encode (uint8_t * in, uint32_t size);
20
+ String encode (const uint8_t * in, uint32_t size);
21
+ String encodeUpper (const uint8_t * in, uint32_t size);
22
+
23
+ bool decode (const String in, uint8_t * out, uint32_t size);
21
24
22
25
}} // arduino::hex
You can’t perform that action at this time.
0 commit comments