Skip to content

Commit bf08515

Browse files
committed
Readme fix 2.0
1 parent a45daac commit bf08515

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22

33
**Version 1.0.0**
44

5-
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.
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__.
66

77

88

99
## Installation
1010

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.
1212

1313
## Usage
1414

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.__
1616

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+
```
1820
// +---- Create instruction data for the API ----+
1921
// | |
2022
// | 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
2325
// +-----------------------------------------------+
2426
2527
create_instruction_data(stop, "basic stop command");
26-
'''
28+
```
29+
30+
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!__
2731

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.__
2933

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:
3135

32-
'''
36+
```
3337
// +---- Match instruction to it's function ----+
3438
// | |
3539
// | 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
3842
// | |
3943
// +-----------------------------------------------+
4044
add_instruction(stop, stop_func);
41-
'''
45+
```
4246

43-
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.__
4450

4551
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:
4652

47-
'''
53+
```
4854
// +---- Set the correct values ----+
4955
// | |
5056
// | 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
5359
// +----------------------------------+
5460
5561
#define NUM_OF_API_FUNCS 4
56-
'''
62+
```
5763

5864
Modify the __NUM_OF_API_FUNCS__ value to the right number unless __the program will crash!__
5965

66+
__4.__
67+
6068
The last thing you have to do is to actually create your functions. A simple example function can be like this:
6169

62-
'''
70+
```
6371
void stop_func(char *args, int(*resp_fn)(const char*, ...))
6472
{
6573
printf("STOP!\r\n");
@@ -74,12 +82,12 @@ void stop_func(char *args, int(*resp_fn)(const char*, ...))
7482
7583
}
7684
}
77-
'''
85+
```
7886

79-
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.
8088

8189
## 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 compile time 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.
8391

8492
## Contributing
8593
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.
8997

9098
## License & copyright
9199
© Daniel Hajnal
92-
Licensed under the [MIT License](https://choosealicense.com/licenses/mit/)
100+
Licensed under the [MIT License](https://choosealicense.com/licenses/mit/).

0 commit comments

Comments
 (0)