This repository has been archived by the owner on Apr 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
com.h
70 lines (51 loc) · 1.87 KB
/
com.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef DEFINE_COM_HEADER
#define DEFINE_COM_HEADER
#include "HALMsg.h"
/*!
* Connection to the arduino. Manage requests and responses,
*/
typedef struct HALConnection HALConnection;
typedef enum HALErr {
OK = 0, //!< No error
TIMEOUT = 1, //!< Command timeouted
SEQERR = 2, //!< No more seq no avialableat the moment
LOCKERR = 3, //!< Cannot acquire lock on connection
CHKERR = 4, //!< Checksum error
READERR = 5, //!< Cannot read
WRITEERR = 6, //!< Cannot write
OUTOFSYNC = 7, //!< Encountered unexpected SYNC byte; must resync
UNKNERR = 8 //!< Unknown error
} HALErr;
HALConnection *HALConn_open(const char *path, const char *sock_path);
/*!
* Close connection to Arduino
*/
void HALConn_close(HALConnection *conn);
/*!
* Read a message from Arduino
* @param conn The HAL connection to use
* @param msg Message received
*/
HALErr HALConn_read_message(HALConnection *conn, HALMsg *msg);
HALErr HALConn_write_message(HALConnection *conn, const HALMsg *msg);
/*!
* Send request to HAL and wait for response
* @param conn The HAL connection to use
* @param msg [in+out] Message to send. Contains the response if return value
is OK
* @return One of HALErr
*/
HALErr HALConn_request(HALConnection *conn, HALMsg *msg);
/*!
* Start the read thread, and call reader for each correctly received message
* @param conn The HAL connection to use
* @param reader Function to call on each correctly received message
*/
int HALConn_run_reader(HALConnection *conn, const char **trigger_names, size_t n_triggers);
void HALConn_stop_reader(HALConnection *conn);
int HALConn_is_running(HALConnection *conn);
int HALConn_uptime(HALConnection *conn);
size_t HALConn_rx_bytes(HALConnection *conn);
size_t HALConn_tx_bytes(HALConnection *conn);
const char *HALConn_sock_path(HALConnection *conn);
#endif