boardcommands.h 2.21 KB
Newer Older
Nelso Jost's avatar
Nelso Jost committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*-----------------------------------------------------------------------------
 *  Author: Nelso G. Jost (nelsojost@gmail.com)
 *  License: GPLv2
 *  Purpose: Serial commands parsing and execution.
 *---------------------------------------------------------------------------*/

#ifndef BOARDCOMMANDS_H
#define BOARDCOMMANDS_H
#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

/*  Parse and execute the serial command on the given CSV string line expected
 *  to be on the format:
 *  
 *      commandName,arg1,arg2,...,argN
 *
 *  Returns a new string with the command output or "<invalid_command:...>"
 *  if the command name or its arguments are invalid.
 */
Nelso Jost's avatar
Nelso Jost committed
23
String execute_board_command(String csv_line);
Nelso Jost's avatar
Nelso Jost committed
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


/*  Given a CSV string line with sensor names or nicknames, returns a new CSV
 *  string with the output values of the reading function for each sensor.
 *
 *  For instance, given the CSV string
 *
 *      SENSOR_A,WRONG,sb
 *
 *  where, hipotetically, "SENSOR_A" is a valid sensor name, "WRONG" is an
 *  invalid one and "sb" is a valid sensor nickname (mapped to "SENSOR_B").
 *  This function will iterate over each one by calling call_read_sensor()
 *  on them. All results are joined on a new CSV string:
 *
 *      81.1,<invalid_sensor_name:WRONG>,23
 */
String read_sensors(String csv_line);


/*  Given a sensor name/nickname, call its corresponding read_SENSOR_NAME() 
 *  function defined at "mysensors.h" and returns its string response.
 *
 *  This function tries to match the given name with the ones on the global 
 *  vectors _sensor_names[] and _sensor_nicknames[]. If positive, the index
 *  is used to lookup at the function pointer vector _fp_array_sensor_read[],
 *  retrieve the correct function and call it.
 */
String call_read_sensor(String name);


/*  Returns a CSV string with all available sensor names and nicknames on the
 *  following format:
 *
 *      name1:nick1,name2:nick2,...,nameN:nickN
 */
String get_sensor_names(); 

/*   Function pointer type to be used at the vector with all read_SENSOR_NAME()
 *   functions. Those functions must expect no arguments and always return a
 *   String (with a number from the reading, presumably).
 */
typedef String (* ReadSensorFP)(void);

#endif