You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-17Lines changed: 25 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,21 @@
2
2
3
3
**Version 1.0.0**
4
4
5
-
Commander API is a C API to interpret characterbased commands and map them to their functions easily. It is designed mainly to work with low memory capacity devices for example small ARM devices or some embedded stuff.
5
+
The __Commander API__is a __C API__ to interpret character-based commands and map them to their functions easily. It is designed mainly to work with low memory capacity devices, for example, __small ARM devices or some embedded stuff__.
6
6
7
7
8
8
9
9
## Installation
10
10
11
-
Installation is easy. Jus add __interpreter.h__, and __interpreter.c__ files to your project.
11
+
Installation is easy. Just add __interpreter.h__, and __interpreter.c__ files to your project.
12
12
13
13
## Usage
14
14
15
-
First you have to add the two files to your project. Than you have to create the instruction data in __interpreter.c__ file under the following comment:
15
+
__1.__
16
16
17
-
'''
17
+
First, you have to add the two files to your project. Than you have to create the instruction data in the __interpreter.c__ file under the following comment:
18
+
19
+
```
18
20
// +---- Create instruction data for the API ----+
19
21
// | |
20
22
// | This is where you have to add |
@@ -23,13 +25,15 @@ First you have to add the two files to your project. Than you have to create the
Use the __create_instruction_data()__ macro to add your commands to the interpreter like above. You have to do this for every instruction that you want to add. The first argument is the exact command name( this will be the exact command name! ), and the second one is a short description. Note that the first argument __must not have any quotes before and after thet!__
27
31
28
-
Use the __create_instruction_data()__ macro to add your commands to the interpreter like above. You have to do this for every instruction that you want to add. The first argument is the exact command name( this will be the exact command name! ), and the second one is a short description. Note that the first argument __must not have any quotes before and after!__
32
+
__2.__
29
33
30
-
The next step is to match the functions to your commands. You have to do it in interpreter.c file, in the init_interpreter() function, under the following comment:
34
+
The next step is to match the functions to your commands. You have to do it in the interpreter.c file, in the init_interpreter() function, under the following comment:
31
35
32
-
'''
36
+
```
33
37
// +---- Match instruction to it's function ----+
34
38
// | |
35
39
// | This is where you have to match |
@@ -38,13 +42,15 @@ The next step is to match the functions to your commands. You have to do it in i
Use the __add_instruction()__ macro to match the name and the asociated function like above. You have to do this for every instruction that you have added previously. The first argument is the instruction name __exactly like the previous step__, the second argument is the function that you want to use when this command gets executed. This function has to be a __void__ return type with two arguments. The first argument is a __char*__ type and the second one is a __int(*resp_fn)(const char*, ...)__ type. I know that it looks scary but it can be very handy and you have to just copy the example function to create a new one.
47
+
Use the __add_instruction()__ macro to match the name and the associated function like above. You have to do this for every instruction that you have added previously. The first argument is the instruction name __exactly like the previous step__, the second argument is the function that you want to use when this command gets executed. This function has to be a __void__ return type with two arguments. The first argument is a __char*__ type and the second one is a very ugly __int(*resp_fn)(const char*, ...)__ type. I know that it looks scary, but it can be very handy, and you have to just copy the example function to create a new one.
48
+
49
+
__3.__
44
50
45
51
The next thing you have to do is to specify the number of commands you have been added. It can be done in the __interpreter.h__ file under the following comment:
46
52
47
-
'''
53
+
```
48
54
// +---- Set the correct values ----+
49
55
// | |
50
56
// | NUM_OF_API_FUNCS value has |
@@ -53,13 +59,15 @@ The next thing you have to do is to specify the number of commands you have been
53
59
// +----------------------------------+
54
60
55
61
#define NUM_OF_API_FUNCS 4
56
-
'''
62
+
```
57
63
58
64
Modify the __NUM_OF_API_FUNCS__ value to the right number unless __the program will crash!__
59
65
66
+
__4.__
67
+
60
68
The last thing you have to do is to actually create your functions. A simple example function can be like this:
The example function above shows the function of the response function. The interpreter can send messages back to the sender channel. If not used just pass a __null__ pointer to it.
87
+
The example function above shows the function of the response function. The interpreter can send messages back to the sender channel. If not used, just pass a __null__ pointer to it.
80
88
81
89
## How it works, why to use?
82
-
The library does not use any malloc or dynamic memory. The module creates a balanced binary tree by alphabetical order in initialization time. The memory requirement of this tree can be calculated at compiletime if we know how many instructions we have. This is why you must configure __NUM_OF_API_FUNCS__ symbol correctly! To create the balanced tree it is a bit more compute hungry than the old strcmp method, but the tree method will boost significantly the speed in search time, so I think it's worth it. In the worst case it finds a command in O*log2(N). That means it can find a command(if it exists) in a __1024__ element long command list under __10__ search steps.
90
+
The library does __not use any malloc or dynamic memory,__ so it is suitable for embedded platforms. The module creates a balanced binary tree by alphabetical order in initialization time. The memory requirement of this tree can be calculated by compile-time if we know how many instructions we have. This is why you must configure __NUM_OF_API_FUNCS__ symbol correctly! To save some RAM, the module uses __char**__ datatypes to reference the commands and the descriptions stored in program memory.To create the balanced tree it is a bit more compute hungry than the old strcmp method, but the tree method will boost significantly the speed in search time, so I think it's worth it. In the worst case it finds a command in O*log2(N). That means it can find a command(if it exists) in a __1024__ element long command list under __10__ search steps.
83
91
84
92
## Contributing
85
93
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
@@ -89,4 +97,4 @@ Please make sure to update tests as appropriate.
0 commit comments