forked from opendroneid/transmitter-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
31 lines (27 loc) · 709 Bytes
/
utils.c
File metadata and controls
31 lines (27 loc) · 709 Bytes
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
/*
* Copyright (C) 2021, Soren Friis
*
* SPDX-License-Identifier: Apache-2.0
*
* Open Drone ID Linux transmitter example.
*
* Maintainer: Soren Friis
* friissoren2@gmail.com
*/
#include "utils.h"
// Convert a single uint8_t to two chars representing the value in ASCII format
// 0 - 9 => 0x30 - 0x39, A - F => 0x41 - 0x46
void uchar_to_ascii(char *out, uint8_t in) {
if (!out)
return;
unsigned char high = (in & 0xF0) >> 4;
if (high < 0xA)
*out++ = (char) (0x30 + high);
else
*out++ = (char) (0x41 + high - 0xA);
unsigned char low = in & 0x0F;
if (low < 0xA)
*out = (char) (0x30 + low);
else
*out = (char) (0x41 + low - 0xA);
}