-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
35 lines (32 loc) · 1.02 KB
/
example.c
File metadata and controls
35 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
const char *hexdigits = "0123456789ABCDEF";
/*
* Each ASCII byte is encoded as two hexadecimal digits.
* The resulting buffer is suitable for use as "datahex" in
* function rk_sendData(type, port, datahex) seen here:
* https://github.com/RAKWireless/RAK811/blob/master/Arduino%20Library/RAK811/RAK811.cpp
*/
char* makeRak (uint8_t* inputBuffer, int inputSize) {
int i, j;
char* compositionBuffer = (char*) malloc(inputSize*2 + 1);
for (i = j = 0; i < inputSize; i++) {
unsigned char c;
c = (inputBuffer[i] >> 4) & 0xf;
compositionBuffer[j++] = hexdigits[c];
c = inputBuffer[i] & 0xf;
compositionBuffer[j++] = hexdigits[c];
}
return compositionBuffer;
}
int main(void) {
// uint8_t* inputBuffer = lpp.getBuffer();
// int inputSize = lpp.getSize();
char a[] = "ABCD";
uint8_t* inputBuffer = (uint8_t*) a;
int inputSize = sizeof(inputBuffer);
char* p = makeRak(inputBuffer, inputSize);
puts(p);
free(p);
}