Skip to content

Commit 4a30fdb

Browse files
committed
Update README.md
1 parent 71bf286 commit 4a30fdb

File tree

1 file changed

+131
-11
lines changed

1 file changed

+131
-11
lines changed

README.md

Lines changed: 131 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# PiCode Library
22

3-
C++ class to manage OOK protocols supported by [**"pilight"**](https://github.com/pilight/pilight) project.
3+
C/C++ library to manage OOK protocols supported by [**"pilight"**](https://github.com/pilight/pilight) project.
4+
5+
Works on any libc/libc++ compatible system, like macOS, FreeBSD, Linux, even Windows.
46

57
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
68
[![Build tests](https://github.com/latchdevel/PiCode/actions/workflows/BuildTest.yml/badge.svg)](https://github.com/latchdevel/PiCode/actions/workflows/BuildTest.yml)
@@ -65,7 +67,7 @@ Example: `{"arctech_switch":{"id":92,"unit":0,"on":1}}`
6567

6668

6769
## BUILD
68-
No external depends, can run on any libc/libc++ compatible system, like MacOS, FreeBSD, Linux, even Windows.
70+
No external depends, can run on any libc/libc++ compatible system, like macOS, FreeBSD, Linux, even Windows.
6971
```
7072
$ git clone https://github.com/latchdevel/PiCode (or download .zip)
7173
$ cd PiCode
@@ -74,11 +76,12 @@ No external depends, can run on any libc/libc++ compatible system, like MacOS, F
7476
$ cmake .. (or "cmake -DCMAKE_BUILD_TYPE=debug .." for debug)
7577
$ make
7678
$ make install (optional)
77-
# make picode_example (optional)
79+
# make picode_example (optional C++ example)
80+
# make cpicode_example (optional C example)
7881
$ make uninstall (to uninstall)
7982
```
8083

81-
## Example
84+
## C++ example
8285
```cpp
8386
/*
8487
Example of using the PiCode Library
@@ -90,17 +93,44 @@ No external depends, can run on any libc/libc++ compatible system, like MacOS, F
9093
9194
*/
9295

93-
#include "src/PiCode.h"
94-
#include <stdio.h>
96+
#include <cstdio> /* printf() */
97+
#include <cstdlib> /* free() */
98+
#include <cinttypes> /* uint8_t */
99+
100+
#include "src/PiCode.h" /* PiCode object class */
95101

96102
int main(){
97103

104+
int result = 0;
105+
106+
printf("picode_example (%s)\n", STRINGIFY(BUILD_VERSION));
107+
printf("Compiled at " __DATE__ " " __TIME__ " %s (%s)\n",STRINGIFY(BUILD_COMPILER), BUILD_TYPE );
108+
109+
/* Get PiCode library version */
110+
111+
char* library_version = PiCode.getPiCodeVersion();
112+
113+
if (library_version){
114+
115+
printf("PiCode library version: %s\n", library_version);
116+
117+
free(library_version);
118+
119+
}else{
120+
printf("ERROR: Unable to get PiCode library version.\n");
121+
result--;
122+
}
123+
124+
printf("\n");
125+
98126
/* Decode from pilight string */
99127

100128
char* pilight_string = (char*) "c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@";
101129

102130
char* decoded_string = PiCode.decodeString(pilight_string);
103131

132+
printf("String to decode: \"%s\"\n",pilight_string);
133+
104134
if (decoded_string){
105135

106136
printf("Decode string successful:\n");
@@ -109,7 +139,8 @@ int main(){
109139
free(decoded_string);
110140

111141
}else{
112-
printf("Unable to decode string\n");
142+
printf("ERROR: Unable to decode string.\n");
143+
result--;
113144
}
114145

115146
/* Encode to pilight string from json */
@@ -119,6 +150,8 @@ int main(){
119150

120151
char* encoded_json_string = PiCode.encodeJson(json,repeats);
121152

153+
printf("\nJSON to encode: \"%s\"\n",json);
154+
122155
if (encoded_json_string){
123156

124157
printf("Encode successful:\n");
@@ -127,15 +160,100 @@ int main(){
127160
free(encoded_json_string);
128161

129162
}else{
130-
printf("Unable to encode\n");
163+
printf("ERROR: Unable to encode JSON.\n");
164+
result--;
165+
}
166+
printf("\n");
167+
return result;
168+
}
169+
```
170+
171+
## C example
172+
```c
173+
/*
174+
Example of using the pure C PiCode Library
175+
176+
https://github.com/latchdevel/PiCode
177+
178+
Copyright (c) 2021 Jorge Rivera. All right reserved.
179+
License GNU Lesser General Public License v3.0.
180+
181+
*/
182+
183+
#include <stdio.h> /* printf() */
184+
#include <stdlib.h> /* free(), uint8_t */
185+
186+
#include "src/cPiCode.h" /* Pure C PiCode library */
187+
188+
int main(){
189+
190+
int result = 0;
191+
192+
printf("cpicode_example (%s)\n", STRINGIFY(BUILD_VERSION));
193+
printf("Compiled at " __DATE__ " " __TIME__ " %s (%s)\n",STRINGIFY(BUILD_COMPILER), BUILD_TYPE );
194+
195+
/* Get PiCode library version */
196+
197+
char* library_version = getPiCodeVersion();
198+
199+
if (library_version){
200+
printf("PiCode library version: %s\n", library_version);
201+
free(library_version);
202+
}else{
203+
printf("ERROR: Unable to get PiCode library version.\n");
204+
result--;
205+
}
206+
207+
printf("\n");
208+
209+
/* Decode from pilight string */
210+
211+
char* pilight_string = (char*) "c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@";
212+
213+
char* decoded_string = decodeString(pilight_string);
214+
215+
printf("String to decode: \"%s\"\n",pilight_string);
216+
217+
if (decoded_string){
218+
219+
printf("Decode string successful:\n");
220+
printf("%s\n",decoded_string);
221+
222+
free(decoded_string);
223+
224+
}else{
225+
printf("ERROR: Unable to decode string.\n");
226+
result--;
131227
}
132228

133-
return 0;
229+
/* Encode to pilight string from json */
230+
231+
char* json = (char*) "{ 'arctech_switch' : { 'id': 92, 'unit': 0, 'on': 1 }}";
232+
uint8_t repeats = 5;
233+
234+
char* encoded_json_string = encodeJson(json,repeats);
235+
236+
printf("\nJSON to encode: \"%s\"\n",json);
237+
238+
if (encoded_json_string){
239+
240+
printf("Encode successful:\n");
241+
printf("%s\n",encoded_json_string);
242+
243+
free(encoded_json_string);
244+
245+
}else{
246+
printf("ERROR: Unable to encode JSON.\n");
247+
result--;
248+
}
249+
printf("\n");
250+
return result;
134251
}
135252
```
136253

137254
## Output
138255
```
256+
String to decode: "c:011010100101011010100110101001100110010101100110101010101010101012;p:1400,600,6800@"
139257
Decode string successful:
140258
[{
141259
"conrad_rsl_switch": {
@@ -144,12 +262,14 @@ Decode string successful:
144262
"state": "on"
145263
}
146264
}]
265+
266+
JSON to encode: "{ 'arctech_switch' : { 'id': 92, 'unit': 0, 'on': 1 }}"
147267
Encode successful:
148-
c:010002000200020002000200020002000200020002000200020002000200020002000200020002020000020200020002000002000200020200000200020002000203;p:315,2835,1260,10710;r:5
268+
c:010002000200020002000200020002000200020002000200020002000200020002000200020002020000020200020002000002000200020200000200020002000203;p:315,2835,1260,10710;r:5@
149269
```
150270

151271
# License
152-
Copyright (c) 2021 Jorge Rivera. All right reserved.
272+
Copyright (c) 2021-2022 Jorge Rivera. All right reserved.
153273

154274
License GNU Lesser General Public License v3.0.
155275

0 commit comments

Comments
 (0)