Project

General

Profile

Revision 289

forgot files

View differences:

proj/libs/uart/include/hltp.h
1
#ifndef HLTP_H_INCLUDED
2
#define HLTP_H_INCLUDED
3

  
4
#include "uart.h"
5

  
6
typedef enum{
7
    hltp_type_invalid = 0x00,
8
    hltp_type_string  = 0x53
9
} hltp_type;
10

  
11
int hltp_send_string(const char *p);
12
hltp_type hltp_interpret(const uint8_t *p, const size_t sz, void **dest);
13

  
14
#endif //HLTP_H_INCLUDED
0 15

  
proj/libs/uart/src/hltp.c
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
}
0 28

  

Also available in: Unified diff