/*----------------------------------------------------------------------------- * 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 "" * if the command name or its arguments are invalid. */ String execute_board_command(String csv_line); /* 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,,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