Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: state_machine_modes_1_12_11_11h
cmd_io.h@6:ee6b303c2868, 2011-11-30 (annotated)
- Committer:
- Nurbol
- Date:
- Wed Nov 30 04:11:44 2011 +0000
- Revision:
- 6:ee6b303c2868
- Parent:
- 5:9aa646406402
- Child:
- 7:17fdd31d90cf
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Nurbol | 1:399a68bfe991 | 1 | // |
| Nurbol | 1:399a68bfe991 | 2 | // cmd_io.h : Common definitions |
| Nurbol | 1:399a68bfe991 | 3 | // ======== |
| Nurbol | 1:399a68bfe991 | 4 | // |
| Nurbol | 1:399a68bfe991 | 5 | #include "mbed.h" |
| Nurbol | 1:399a68bfe991 | 6 | |
| Nurbol | 1:399a68bfe991 | 7 | #ifndef CMD_IO_H // used to prevent 'cmd_io.h' being |
| Nurbol | 1:399a68bfe991 | 8 | #define CMD_IO_H // included multiple time during a compilation |
| Nurbol | 1:399a68bfe991 | 9 | // |
| Nurbol | 1:399a68bfe991 | 10 | // Constants |
| Nurbol | 1:399a68bfe991 | 11 | // |
| Nurbol | 1:399a68bfe991 | 12 | #define CMD_STR_BUFFER_SZ 100 |
| Nurbol | 1:399a68bfe991 | 13 | #define MAX_SERVO_NUMBER 5 |
| Nurbol | 1:399a68bfe991 | 14 | #define MIN_SERVO_ANGLE 0 |
| Nurbol | 5:9aa646406402 | 15 | #define MAX_SERVO_ANGLE 200 |
| Nurbol | 1:399a68bfe991 | 16 | // |
| Nurbol | 1:399a68bfe991 | 17 | // Use 'enum' construct to create list of return codes. |
| Nurbol | 1:399a68bfe991 | 18 | // Each entry will be defined as 1 more than the previous entry |
| Nurbol | 1:399a68bfe991 | 19 | // |
| Nurbol | 1:399a68bfe991 | 20 | enum { |
| Nurbol | 1:399a68bfe991 | 21 | OK = 0, // should start at 0 by default but set to 0 to be safe |
| Nurbol | 1:399a68bfe991 | 22 | CMD_BAD_CHARACTER, |
| Nurbol | 1:399a68bfe991 | 23 | CMD_BAD_NUMBER_OF_PARAMETERS, |
| Nurbol | 1:399a68bfe991 | 24 | CMD_BAD_SERVO_NUMBER, |
| Nurbol | 1:399a68bfe991 | 25 | CMD_BAD_SERVO_VALUE, |
| Nurbol | 1:399a68bfe991 | 26 | CMD_BAD_SERVO_SPEED_VALUE, |
| Nurbol | 1:399a68bfe991 | 27 | CMD_NO_TERMINATOR, |
| Nurbol | 1:399a68bfe991 | 28 | CMD_UNKNOWN_COMMAND |
| Nurbol | 1:399a68bfe991 | 29 | }; |
| Nurbol | 1:399a68bfe991 | 30 | |
| Nurbol | 1:399a68bfe991 | 31 | // |
| Nurbol | 1:399a68bfe991 | 32 | // command set |
| Nurbol | 1:399a68bfe991 | 33 | // |
| Nurbol | 1:399a68bfe991 | 34 | #define SERVO_CMD 's' |
| Nurbol | 1:399a68bfe991 | 35 | #define TEXT_CMD 'T' |
| Nurbol | 1:399a68bfe991 | 36 | #define READ_CMD 'r' |
| Nurbol | 1:399a68bfe991 | 37 | |
| Nurbol | 3:9f108fca5c3b | 38 | #define MAINT_MODE 'z' //add define to receive mode value |
| Nurbol | 3:9f108fca5c3b | 39 | #define SORT_MODE 'y' //add define to receive mode value |
| Nurbol | 4:c099ce00dd9a | 40 | #define URGENCY 'u' //add define to receive the urgency mode |
| Nurbol | 6:ee6b303c2868 | 41 | #define EXIT 'e' // add define to receive the exit mode |
| Nurbol | 2:04ce6f583f44 | 42 | |
| Nurbol | 1:399a68bfe991 | 43 | // |
| Nurbol | 1:399a68bfe991 | 44 | // Misc defines |
| Nurbol | 1:399a68bfe991 | 45 | // |
| Nurbol | 1:399a68bfe991 | 46 | #define SERVO_UNKNOWN 9999 |
| Nurbol | 1:399a68bfe991 | 47 | |
| Nurbol | 1:399a68bfe991 | 48 | //************************************************************************ |
| Nurbol | 1:399a68bfe991 | 49 | // definition of a structure to hold a PC command, its parameteres |
| Nurbol | 1:399a68bfe991 | 50 | // its results and status. |
| Nurbol | 1:399a68bfe991 | 51 | // |
| Nurbol | 1:399a68bfe991 | 52 | typedef struct { |
| Nurbol | 1:399a68bfe991 | 53 | char cmd_str[CMD_STR_BUFFER_SZ]; |
| Nurbol | 1:399a68bfe991 | 54 | uint32_t char_cnt; // number of characters in string |
| Nurbol | 1:399a68bfe991 | 55 | uint32_t cmd_code; // extracted command code |
| Nurbol | 1:399a68bfe991 | 56 | uint32_t param[4]; // command parameters |
| Nurbol | 1:399a68bfe991 | 57 | uint32_t nos_params; // number of parameters |
| Nurbol | 4:c099ce00dd9a | 58 | uint32_t result_data[7]; // data resulting from command execution |
| Nurbol | 1:399a68bfe991 | 59 | uint32_t nos_data; // number of data items |
| Nurbol | 1:399a68bfe991 | 60 | uint32_t result_status; // status |
| Nurbol | 1:399a68bfe991 | 61 | } CMD_STRUCT; |
| Nurbol | 1:399a68bfe991 | 62 | |
| Nurbol | 1:399a68bfe991 | 63 | //************************************************************************ |
| Nurbol | 1:399a68bfe991 | 64 | // definition of a structure to hold complete status return |
| Nurbol | 1:399a68bfe991 | 65 | // |
| Nurbol | 1:399a68bfe991 | 66 | typedef struct { |
| Nurbol | 1:399a68bfe991 | 67 | uint8_t status; |
| Nurbol | 1:399a68bfe991 | 68 | union { // union allows one data item to be viewed in different ways |
| Nurbol | 1:399a68bfe991 | 69 | uint8_t byte[4]; |
| Nurbol | 1:399a68bfe991 | 70 | int16_t value16[2]; |
| Nurbol | 1:399a68bfe991 | 71 | int32_t value32; |
| Nurbol | 1:399a68bfe991 | 72 | } parameter; |
| Nurbol | 1:399a68bfe991 | 73 | uint8_t result; |
| Nurbol | 1:399a68bfe991 | 74 | } STAT_STRUCT; |
| Nurbol | 1:399a68bfe991 | 75 | |
| Nurbol | 1:399a68bfe991 | 76 | //************************************************************************ |
| Nurbol | 1:399a68bfe991 | 77 | // function prototypes : list of functions in file 'cmd_io.cpp" |
| Nurbol | 1:399a68bfe991 | 78 | // |
| Nurbol | 1:399a68bfe991 | 79 | uint32_t get_cmd(CMD_STRUCT *command); |
| Nurbol | 1:399a68bfe991 | 80 | void init_sys(void); |
| Nurbol | 1:399a68bfe991 | 81 | uint32_t parse_cmd(CMD_STRUCT *command); |
| Nurbol | 1:399a68bfe991 | 82 | void reply_to_cmd(CMD_STRUCT *command); |
| Nurbol | 1:399a68bfe991 | 83 | void send_status(uint32_t value); |
| Nurbol | 1:399a68bfe991 | 84 | void send_data(CMD_STRUCT *command); |
| Nurbol | 1:399a68bfe991 | 85 | uint32_t process_cmd(CMD_STRUCT *command); |
| Nurbol | 1:399a68bfe991 | 86 | |
| Nurbol | 0:1722aea42640 | 87 | #endif // end of multiple include protection facility |