SingingCat 0
application
command-parser.h
1#ifndef COMMAND_PARSER_H
2#define COMMAND_PARSER_H 1
3#include <platform-header.h>
4#include "addressing.h"
5#include "command.h"
6
11#define MAX_SINGLE_ARG_SIZE 196
12
13#define PROTOCOL_VERSION_ASCII 1
14
15#define CLOUD_SERVER 0x00000001
16
17#define COMMAND_MAXARGS 17
18
19// if set, this will force sending out throgh th'sourcedev' wether or not the device is available or enabled. (useful to send initial handshakes)
20#define COM_LOCAL_FLAG_FORCE_DEVICE 1
21
22
23// this is an utility to parse commands from datastreams
24
25// returns a command or NULL if not a valid command
26struct command *command_parse(const byte *buf, int size);
27
28// returns a command if one is complete.
29struct command *command_add_byte(int b);
30
31// init a new command
32void command_start();
33
34void command_print(struct command *com);
35
36int command_encode_ascii(struct command *com, int bufsize, char *buf);
37void command_init(struct command *com);
38int command_add_binary_arg(struct command *com, const int len, const byte *srcbuf);
39void command_add_arg(struct command *com, const char *format, ...);
40void command_add_varg(struct command *com, const char *format, va_list args);
41int command_add_encoded_arg(struct command *com, byte *buf);
42byte command_calc_checksum(struct command *com);
43const char *namedarg(struct command *com, const char *name);
44int namedarg_uint16(struct command *com, const char *name, uint16_t *value);
45int namedarg_uint32(struct command *com, const char *name, uint32_t *value);
46const char *get_arg(const struct command *com, int index);
47const byte *get_arg_new(const struct command *com, int index);
48int get_arg_size(const struct command *com, int index);
49int get_arg_size_inmem(const struct command *com, int index);
50int get_arg_int_array(const struct command *com, const int index, int *result, const int arraysize);
51
53const char *command_get_name(int num);
54
55#endif
char * command_get_source_name(byte sourcedev)
returns a human readable text identifying a source device
int namedarg_uint16(struct command *com, const char *name, uint16_t *value)
get a named arg (key-value pair), parsed as integer. result in "value". if return value == 0 ,...
int command_encode_ascii(struct command *com, int bufsize, char *buf)
encode a command to an ascii blob properly surrounded by '{' and '}' and escaped returns length if ok...
int get_arg_size_inmem(const struct command *com, int index)
given an argument by index [0..n], will returns the number in bytes this argument takes up in memory....
void command_add_arg(struct command *com, const char *format,...)
adds an arg to a partially initialised command structure
const char * namedarg(struct command *com, const char *name)
get a named arg (key-value pair) or NULL
void command_add_varg(struct command *com, const char *format, va_list args)
adds a varg list of parameters to a command
int namedarg_uint32(struct command *com, const char *name, uint32_t *value)
get a named arg (key-value pair), parsed as integer. result in "value". if return value == 0 ,...
const char * command_get_name(int num)
given a command number returns its name
void command_init(struct command *com)
initialize a command structure with default values
const byte * get_arg_new(const struct command *com, int index)
given an argument by index[0..n], will returns a pointer to it. This will include the fieldnumber and...
int get_arg_int_array(const struct command *com, const int index, int *result, const int arraysize)
given a command and argument index, will attempt to parse the arg as array and return it array syntax...
void command_print(struct command *com)
prints a command in human readable format to serial console
int command_add_binary_arg(struct command *com, const int len, const byte *srcbuf)
adds a binary parameter to command returns 0 if ok otherwise errorcode
const char * get_arg(const struct command *com, int index)
given an argument by index[0..n], will return a pointer to the bytearray (excluding the fieldtype) th...
int get_arg_size(const struct command *com, int index)
given an argument by index [0..n], will returns the size of the value in bytes. for a string/array it...
void command_start()
initialization for command parser
int com
Definition: command.h:22
uint8_t sourcedev
Definition: command.h:17
int index
Definition: command.h:13