blob: 224cc3bfe46d5fd3c4f6c52f4b8f4f7c6cc77539 (
plain) (
blame)
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
|
// simpleserial.h
// Generic module for interpreting SimpleSerial commands
#ifndef SIMPLESERIAL_H
#define SIMPLESERIAL_H
#include <stdint.h>
#define MAX_SS_CMDS 26
#define MAX_SS_LEN 512
// Set up the SimpleSerial module
// This prepares any internal commands
void simpleserial_init(void);
// Add a command to the SimpleSerial module
// Args:
// - c: The character designating this command
// - len: The number of bytes expected
// - fp: A pointer to a callback, which is called after receiving data
// Example: simpleserial_addcmd('p', 16, encrypt_text)
// - Calls encrypt_text() with a 16 byte array after receiving a line
// like p00112233445566778899AABBCCDDEEFF\n
// Notes:
// - Maximum of 26 active commands
// - Maximum length of 256 bytes
// - Returns 1 if either of these fail; otherwise 0
// - The callback function returns a number in [0x00, 0xFF] as a status code;
// in protocol v1.1, this status code is returned through a "z" message
int simpleserial_addcmd(char c, uint32_t len, uint8_t (*fp)(uint8_t*, uint16_t));
// Attempt to process a command
// If a full string is found, the relevant callback function is called
// Might return without calling a callback for several reasons:
// - First character didn't match any known commands
// - One of the characters wasn't in [0-9|A-F|a-f]
// - Data was too short or too long
int simpleserial_get(void);
// Write some data to the serial port
// Prepends the character c to the start of the line
// Example: simpleserial_put('r', 16, ciphertext)
void simpleserial_put(char c, uint32_t size, uint8_t* output);
#endif // SIMPLESERIAL_H
|