root / proj / libs / uart / src / hltp.c @ 297
History | View | Annotate | Download (767 Bytes)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include "hltp.h" |
4 |
|
5 |
#include "uart.h" |
6 |
|
7 |
static void* hltp_interpret_string(const uint8_t *p, const size_t sz){ |
8 |
void *ret = malloc((sz+1)*sizeof(char)); |
9 |
for(size_t i = 0; i < sz; ++i) ((char*)ret)[i] = p[i]; |
10 |
((char*)ret)[sz] = '\0'; |
11 |
return ret;
|
12 |
} |
13 |
int hltp_send_string(const char *p){ |
14 |
uint8_t type = hltp_type_string; |
15 |
uint8_t* ptr[2]; ptr[0] = &type; ptr[1] = (uint8_t*)p; |
16 |
size_t sz[2]; sz [0] = 1; sz [1] = strlen(p); |
17 |
return nctp_send(2, ptr, sz); |
18 |
} |
19 |
|
20 |
hltp_type hltp_interpret(const uint8_t *p, const size_t sz, void **dest){ |
21 |
uint8_t ret = p[0];
|
22 |
switch(ret){
|
23 |
case hltp_type_string: *dest = hltp_interpret_string(p+1, sz-1); break; |
24 |
default: *dest = NULL; break; |
25 |
} |
26 |
return ret;
|
27 |
} |