├── .clang-format ├── .github └── workflows │ └── native.yml ├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── examples ├── arduino │ ├── .gitignore │ ├── README.md │ ├── platformio.ini │ └── src │ │ ├── ehz_bin.h │ │ └── main.cpp ├── arduino_serial │ ├── .clang-format │ ├── .gitignore │ ├── .vscode │ │ ├── extensions.json │ │ └── settings.json │ ├── README.md │ ├── main.cpp │ └── platformio.ini ├── esp32_lora │ ├── .gitignore │ ├── README.md │ ├── platformio.ini │ └── src │ │ ├── keys.h.example │ │ └── main.cpp ├── esp32_m5stack_sender │ ├── .gitignore │ ├── README.md │ ├── platformio.ini │ └── src │ │ ├── ehz_bin.h │ │ └── main.cpp ├── esp32_receiver │ ├── .gitignore │ ├── README.md │ ├── image.jpg │ ├── platformio.ini │ └── src │ │ └── main.cpp └── native │ ├── .gitignore │ ├── README.md │ ├── ehz_bin.h │ ├── main.cpp │ ├── platformio.ini │ └── run.sh ├── library.json ├── library.properties ├── src ├── sml.cpp ├── sml.h └── smlCrcTable.h └── test ├── README.md ├── platformio.ini └── test ├── test_56bit ├── ehz_bin.h └── test.cpp ├── test_EMH ├── ehz_bin.h └── test.cpp ├── test_ESY ├── data_bin.h └── test.cpp ├── test_efr_sgm_c2 ├── ehz_bin.h └── test.cpp └── test_negative ├── ehz_bin.h └── test.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | BreakBeforeBraces: Stroustrup 2 | -------------------------------------------------------------------------------- /.github/workflows/native.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-latest 8 | name: Test library 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Cache pip 12 | uses: actions/cache@v2 13 | with: 14 | path: ~/.cache/pip 15 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} 16 | restore-keys: ${{ runner.os }}-pip- 17 | - name: Cache PlatformIO 18 | uses: actions/cache@v2 19 | with: 20 | path: ~/.platformio 21 | key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} 22 | - name: Set up Python 23 | uses: actions/setup-python@v2 24 | - name: Install PlatformIO 25 | run: | 26 | python -m pip install --upgrade pip 27 | pip install platformio 28 | - name: Run tests on the native platform 29 | run: | 30 | cd test 31 | platformio test -e native 32 | publish: 33 | needs: test 34 | if: github.ref == 'refs/heads/main' && github.repository_owner == 'olliiiver' 35 | name: Publish Package 36 | runs-on: ubuntu-latest 37 | steps: 38 | - uses: actions/checkout@v2 39 | - name: Cache pip 40 | uses: actions/cache@v2 41 | with: 42 | path: ~/.cache/pip 43 | key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} 44 | restore-keys: ${{ runner.os }}-pip- 45 | - name: Cache PlatformIO 46 | uses: actions/cache@v2 47 | with: 48 | path: ~/.platformio 49 | key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} 50 | - name: Set up Python 51 | uses: actions/setup-python@v2 52 | - name: Install PlatformIO 53 | run: | 54 | python -m pip install --upgrade pip 55 | pip install --upgrade platformio 56 | - name: Publish package 57 | env: 58 | PLATFORMIO_AUTH_TOKEN: ${{ secrets.PIO_TOKEN }} 59 | run: pio package publish --non-interactive 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .pio/ 2 | lib/ 3 | .vscode/.browse.c_cpp.db* 4 | .vscode/c_cpp_properties.json 5 | .vscode/launch.json 6 | .vscode/ipch 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![PlatformIO Registry](https://badges.registry.platformio.org/packages/olliiiver/library/SML%20Parser.svg)](https://registry.platformio.org/libraries/olliiiver/SML%20Parser) [![Test](https://github.com/olliiiver/sml_parser/workflows/Test/badge.svg)](https://github.com/olliiiver/sml_parser/actions) 2 | 3 | # Smart Message Language (SML) parser 4 | 5 | Easy to use C library with a low memory footprint to parse SML messages (based on BSI TR-03109-1) byte by byte from smart meters. It's designed to be lightweight and efficient and has a small memory footprint, making it suitable for use on embedded systems or other devices with limited memory resources. 6 | 7 | The library will control the last CRC value to check if the received data is correct. On any error, the parser will reset and wait for valid data. This allows to start parsing at any time. For example, a half received message is discarded. The library allows you to register handlers to process the received information. This feature allows you to easily process the data in your application without having to handle the low-level details of parsing the SML messages. 8 | 9 | It's actively maintained and has already been used in various projects with meters from EMH, EFR, EasyMeter, etc. 10 | 11 | The API is described in [`sml.h`](src/sml.h) via doxygen comments. 12 | 13 | ## Examples 14 | 15 | | Directory | Description | 16 | | ------------------------------------------------------ | -------------------------------------------------------------- | 17 | | [arduino](examples/arduino/) | Loops through static data and outputs debug messages to serial | 18 | | [arduino_serial](examples/arduino_serial/) | Reads data from Arduino Pin 8 and outputs debug to serial | 19 | | [esp32_lora](examples/esp32_lora/) | Forward energy usage to LoraWAN (The Things Network) | 20 | | [esp32_m5stack_sender](examples/esp32_m5stack_sender/) | Use m5stack to produce a message for testing | 21 | | [esp32_receiver](examples/esp32_receiver/) | Receive messages and show infos on a display | 22 | | [native](examples/native/) | Test library locally | 23 | 24 | The easiest way to test the library would be over the [native](examples/native/) example. 25 | 26 | ## Example usage 27 | 28 | ```cpp 29 | void Manufacturer() { 30 | smlOBISManufacturer(manuf, MAX_STR_MANUF); 31 | } 32 | 33 | void PowerT1() { 34 | smlOBISWh(T1Wh); 35 | } 36 | 37 | void PowerSum() { 38 | smlOBISWh(SumWh); 39 | } 40 | 41 | SMLHandler SMLHandlers[] = { 42 | {{ 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff }, &Manufacturer}, /* 129-129:199.130.3*255 */ 43 | {{ 0x01, 0x00, 0x01, 0x08, 0x01, 0xff }, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 44 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 45 | {{ 0, 0 }} 46 | }; 47 | 48 | int main () { 49 | int i = 0, iHandler = 0; 50 | unsigned char c; 51 | sml_states_t s; 52 | for (i = 0; i < ehz_bin_len; ++i) { 53 | c = ehz_bin[i]; 54 | s = smlState(c); 55 | if (s == SML_START) { 56 | /* reset local vars */ 57 | manuf[0] = 0; T1Wh = -3; SumWh = -3; 58 | } 59 | if (s == SML_LISTEND) { 60 | /* check handlers on last received list */ 61 | for (iHandler=0; SMLHandlers[iHandler].Handler != 0 && 62 | !(smlOBISCheck(SMLHandlers[iHandler].OBIS)); iHandler++); 63 | if (SMLHandlers[iHandler].Handler != 0) { 64 | SMLHandlers[iHandler].Handler(); 65 | } 66 | } 67 | if (s == SML_UNEXPECTED) { 68 | printf(">>> Unexpected byte! <<<\n"); 69 | } 70 | if (s == SML_FINAL) { 71 | printf(">>> FINAL! Checksum OK\n"); 72 | printf(">>> Manufacturer.............: %s\n", manuf); 73 | printf(">>> Power T1 (1-0:1.8.1)..: %.3f kWh\n", T1Wh); 74 | printf(">>> Power T1+T2 (1-0:1.8.0)..: %.3f kWh\n\n", SumWh); 75 | } 76 | } 77 | } 78 | ``` 79 | 80 | ## Debug mode 81 | 82 | If debug mode via `SML_DEBUG` (see examples/native/platformio.ini) is enabled, the SML data is displayed in a tree like structure. 83 | 84 | ``` 85 | START 86 | LISTSTART on level 1 with 6 nodes 87 | Data 6 (length = 6, octet string): 00 0C 04 08 87 2D 88 | Data 5 (length = 1, unsigned int): 00 89 | Data 4 (length = 1, unsigned int): 00 90 | LISTSTART on level 2 with 2 nodes 91 | Data 2 (length = 2, unsigned int): 01 01 92 | LISTSTART on level 3 with 6 nodes 93 | Data 6 (empty) 94 | Data 5 (empty) 95 | Data 4 (length = 6, octet string): 00 0C 06 9E 2D 0F 96 | Data 3 (length = 10, octet string): 06 45 4D 48 01 00 1D 46 15 CA 97 | Data 2 (empty) 98 | Data 1 (empty) 99 | LISTEND 100 | back to previous list 101 | back to previous list 102 | Data 2 (length = 2, unsigned int): 2B 8E 103 | End of block at level 1 104 | back to previous list 105 | LISTSTART on level 1 with 6 nodes 106 | Data 6 (length = 6, octet string): 00 0C 04 08 87 2E 107 | Data 5 (length = 1, unsigned int): 00 108 | Data 4 (length = 1, unsigned int): 00 109 | LISTSTART on level 2 with 2 nodes 110 | Data 2 (length = 2, unsigned int): 07 01 111 | LISTSTART on level 3 with 7 nodes 112 | Data 7 (empty) 113 | Data 6 (length = 10, octet string): 06 45 4D 48 01 00 1D 46 15 CA 114 | Data 5 (empty) 115 | LISTSTART on level 4 with 2 nodes 116 | Data 2 (length = 1, unsigned int): 01 117 | Data 1 (length = 4, unsigned int): 06 9E FA 83 118 | LISTEND on level 4 119 | back to previous list 120 | LISTSTART on level 4 with 7 nodes 121 | LISTSTART on level 5 with 7 nodes 122 | Data 7 (length = 6, octet string): 81 81 C7 82 03 FF 123 | Data 6 (empty) 124 | Data 5 (empty) 125 | Data 4 (empty) 126 | Data 3 (empty) 127 | Data 2 (length = 3, octet string): 45 4D 48 128 | Data 1 (empty) 129 | LISTEND 130 | back to previous list 131 | LISTSTART on level 5 with 7 nodes 132 | Data 7 (length = 6, octet string): 01 00 00 00 09 FF 133 | Data 6 (empty) 134 | Data 5 (empty) 135 | Data 4 (empty) 136 | Data 3 (empty) 137 | Data 2 (length = 10, octet string): 06 45 4D 48 01 00 1D 46 15 CA 138 | Data 1 (empty) 139 | LISTEND 140 | back to previous list 141 | LISTSTART on level 5 with 7 nodes 142 | Data 7 (length = 6, octet string): 01 00 01 08 00 FF 143 | Data 6 (length = 2, unsigned int): 01 82 144 | Data 5 (empty) 145 | Data 4 (length = 1, unsigned int): 1E 146 | Data 3 (length = 1, signed int): 03 147 | Data 2 (length = 5, signed int): 00 00 00 1C 46 148 | Data 1 (empty) 149 | LISTEND 150 | back to previous list 151 | LISTSTART on level 5 with 7 nodes 152 | Data 7 (length = 6, octet string): 01 00 01 08 01 FF 153 | Data 6 (empty) 154 | Data 5 (empty) 155 | Data 4 (length = 1, unsigned int): 1E 156 | Data 3 (length = 1, signed int): FF 157 | Data 2 (length = 8, signed int): 00 00 00 00 07 5B CD 15 158 | Data 1 (empty) 159 | LISTEND 160 | back to previous list 161 | LISTSTART on level 5 with 7 nodes 162 | Data 7 (length = 6, octet string): 01 00 01 08 02 FF 163 | Data 6 (empty) 164 | Data 5 (empty) 165 | Data 4 (length = 1, unsigned int): 1E 166 | Data 3 (length = 1, signed int): 03 167 | Data 2 (length = 5, signed int): 00 00 00 1C 46 168 | Data 1 (empty) 169 | LISTEND 170 | back to previous list 171 | LISTSTART on level 5 with 7 nodes 172 | Data 7 (length = 6, octet string): 01 00 0F 07 00 FF 173 | Data 6 (empty) 174 | Data 5 (empty) 175 | Data 4 (length = 1, unsigned int): 1B 176 | Data 3 (length = 1, signed int): FF 177 | Data 2 (length = 4, signed int): 00 00 2F 65 178 | Data 1 (empty) 179 | LISTEND 180 | back to previous list 181 | LISTSTART on level 5 with 7 nodes 182 | Data 7 (length = 6, octet string): 81 81 C7 82 05 FF 183 | Data 6 (empty) 184 | Data 5 (empty) 185 | Data 4 (empty) 186 | Data 3 (empty) 187 | Data (length = 48): FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 188 | Data 2 (empty) 189 | Data 1 (empty) 190 | LISTEND 191 | back to previous list 192 | back to previous list 193 | Data 2 (empty) 194 | Data 1 (length = 2, unsigned int): B9 3F 195 | LISTEND on level 3 196 | back to previous list 197 | back to previous list 198 | End of block at level 1 199 | LISTSTART on level 2 with 6 nodes 200 | Data 6 (length = 6, octet string): 00 0C 04 08 87 31 201 | Data 5 (length = 1, unsigned int): 00 202 | Data 4 (length = 1, unsigned int): 00 203 | LISTSTART on level 3 with 2 nodes 204 | Data 2 (length = 2, unsigned int): 02 01 205 | LISTSTART on level 4 with 1 nodes 206 | Data 1 (empty) 207 | LISTEND 208 | back to previous list 209 | back to previous list 210 | Data 2 (length = 2, unsigned int): 6A 53 211 | End of block at level 2 212 | back to previous list 213 | back to previous list 214 | End of block at level 0 215 | Received checksum: C6E8 216 | Calculated checksum: C6E8 217 | >>> FINAL! Checksum OK 218 | >>> Manufacturer.............: EMH 219 | >>> Power T1 (1-0:1.8.1)..: 12345678.900 Wh 220 | >>> Power T1+T2 (1-0:1.8.0)..: 7238000.000 Wh 221 | ``` 222 | 223 | ## Links 224 | 225 | The following sites provided a lot of helpful information to me. 226 | 227 | - https://wiki.volkszaehler.org/software/obis 228 | - https://wiki.volkszaehler.org/software/sml 229 | - https://www.stefan-weigert.de/php_loader/sml.php 230 | - https://github.com/devZer0/libsml-testing 231 | 232 | ## License 233 | 234 | GNU LGPL v2.1 235 | -------------------------------------------------------------------------------- /examples/arduino/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode 3 | -------------------------------------------------------------------------------- /examples/arduino/README.md: -------------------------------------------------------------------------------- 1 | # Continuously loops through a static message from RAM and outputs information to serial 2 | -------------------------------------------------------------------------------- /examples/arduino/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:uno] 12 | platform = atmelavr 13 | board = uno 14 | framework = arduino 15 | board_build.mcu = atmega328p 16 | board_build.f_cpu = 16000000L 17 | build_flags = -D SML_DEBUG 18 | lib_deps = ../../src 19 | -------------------------------------------------------------------------------- /examples/arduino/src/ehz_bin.h: -------------------------------------------------------------------------------- 1 | // clang-format off 2 | 3 | // Formatted example data from https://github.com/devZer0/libsml-testing 4 | 5 | const unsigned char ehz_bin[] = { 6 | /* Start */ 0x1b, 0x1b, 0x1b, 0x1b, 7 | /* Version */ 0x01, 0x01, 0x01, 0x01, 8 | 9 | /* List (6 entries) */ 0x76, 10 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2d, 11 | /* 2. Group No */ 0x62, 0x00, 12 | /* 3. Abort On Error */ 0x62, 0x00, 13 | /* 4. List (2 entries) */ 0x72, 14 | /* 1. getOpenResponse */ 0x63, 0x01, 0x01, 15 | /* 2. List (6 entries) */ 0x76, 16 | /* 1. code page */ 0x01, 17 | /* 2. clientid */ 0x01, 18 | /* 3. Transaction ID */ 0x07, 0x00, 0x0c, 0x06, 0x9e, 0x2d, 0x0f, 19 | /* 4. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 20 | /* 5. List name */ 0x01, 21 | /* 6. Time */ 0x01, 22 | /* 5. CRC */ 0x63, 0x2b, 0x8e, 23 | /* 6. END */ 0x00, 24 | 25 | /* List (6 entries) */ 0x76, 26 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2e, 27 | /* 2. Group No */ 0x62, 0x00, 28 | /* 3. Abort On Error */ 0x62, 0x00, 29 | /* 4. Message Body (2) */ 0x72, 30 | /* 1. getListResponse */ 0x63, 0x07, 0x01, 31 | /* 2. List (7) */ 0x77, 32 | /* 1. ClientId */ 0x01, 33 | /* 2. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 34 | /* 3. ?? */ 0x01, 35 | /* 4. List (2) */ 0x72, 36 | /* 1. ?? */ 0x62, 0x01, 37 | /* 2. ?? */ 0x65, 0x06, 0x9e, 0xfa, 0x83, 38 | /* 5. List (7) */ 0x77, 39 | /* 1. List (7) */ 0x77, 40 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 41 | /* 2. */ 0x01, 42 | /* 3. */ 0x01, 43 | /* 4. */ 0x01, 44 | /* 5. */ 0x01, 45 | /* 6. */ 0x04, 0x45, 0x4d, 0x48, 46 | /* 7. */ 0x01, 47 | /* 2. List (7) */ 0x77, 48 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 49 | /* 2. */ 0x01, 50 | /* 3. */ 0x01, 51 | /* 4. */ 0x01, 52 | /* 5. */ 0x01, 53 | /* 6. */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 54 | /* 7. */ 0x01, 55 | /* 3. List (7) */ 0x77, 56 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 57 | /* 2. */ 0x63, 0x01, 0x82, 58 | /* 3. */ 0x01, 59 | /* 4. */ 0x62, 0x1e, 60 | /* 5. */ 0x52, 0xff, 61 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x74, 0xea, 62 | /* 7. */ 0x01, 63 | /* 4. List (7) */ 0x77, 64 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x01, 0xff, 65 | /* 2. */ 0x01, 66 | /* 3. */ 0x01, 67 | /* 4. Unit */ 0x62, 0x1e, 68 | /* 5. Scaler */ 0x52, 0xff, 69 | /* 6 Value */ 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xd6, 0x87, 70 | /* 7 */ 0x01, 71 | /* 5. List (7) */ 0x77, 72 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x02, 0xff, 73 | /* 2. */ 0x01, 74 | /* 3. */ 0x01, 75 | /* 4. */ 0x62, 0x1e, 76 | /* 5. */ 0x52, 0xff, 77 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 78 | /* 7. */ 0x01, 79 | /* 6. List (7) */ 0x77, 80 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x0f, 0x07, 0x00, 0xff, 81 | /* 2. */ 0x01, 82 | /* 3. */ 0x01, 83 | /* 4. */ 0x62, 0x1b, 84 | /* 5. */ 0x52, 0xff, 85 | /* 6. */ 0x55, 0x00, 0x00, 0x2f, 0x65, 86 | /* 7. */ 0x01, 87 | /* 7. List (7) */ 0x77, 88 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 89 | /* 2. */ 0x01, 90 | /* 3. */ 0x01, 91 | /* 4. */ 0x01, 92 | /* 5. */ 0x01, 93 | /* 6. Public Key */ 0x83, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 94 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 95 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 96 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 97 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 98 | /* 7. */ 0x01, 99 | 0x01, 100 | 0x01, 101 | 0x63, 0xb9, 0x3f, 102 | 0x00, 103 | /* List (6) */ 0x76, 104 | /* 1. */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x31, 105 | /* 2. */ 0x62, 0x00, 106 | /* 3. */ 0x62, 0x00, 107 | /* 4. List (2) */ 0x72, 108 | /* 1. */ 0x63, 0x02, 0x01, 109 | /* List (1) */ 0x71, 110 | /* 1. */ 0x01, 111 | /* 5. CRC */ 0x63, 0x6a, 0x53, 112 | /* 6. */ 0x00, 113 | 114 | 0x00, 115 | 0x1b, 0x1b, 0x1b, 0x1b, 116 | 0x1a, 0x01, 0xb6, 0x9d 117 | }; 118 | const unsigned int ehz_bin_len = 319; 119 | 120 | -------------------------------------------------------------------------------- /examples/arduino/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ehz_bin.h" 2 | #include "sml.h" 3 | #include 4 | #include 5 | 6 | // Continuously loops through a static message from RAM and outputs information 7 | // to serial 8 | 9 | double T1Wh = -2, SumWh = -2; 10 | 11 | typedef struct { 12 | const unsigned char OBIS[6]; 13 | void (*Handler)(); 14 | } OBISHandler; 15 | 16 | void PowerT1() { smlOBISWh(T1Wh); } 17 | 18 | void PowerSum() { smlOBISWh(SumWh); } 19 | 20 | // clang-format off 21 | OBISHandler OBISHandlers[] = { 22 | {{ 0x01, 0x00, 0x01, 0x08, 0x01, 0xff }, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 23 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 24 | {{ 0, 0 }} 25 | }; 26 | // clang-format on 27 | 28 | void setup() 29 | { 30 | Serial.begin(9600); 31 | Serial.println(F("Starting")); 32 | } 33 | 34 | void loop() 35 | { 36 | char floatBuffer[20]; 37 | unsigned int i = 0, iHandler = 0; 38 | unsigned char c; 39 | sml_states_t s; 40 | while (true) { 41 | for (i = 0; i < ehz_bin_len; ++i) { 42 | c = ehz_bin[i]; 43 | s = smlState(c); 44 | if (s == SML_START) { 45 | /* reset local vars */ 46 | T1Wh = -3; 47 | SumWh = -3; 48 | } 49 | if (s == SML_LISTEND) { 50 | /* check handlers on last received list */ 51 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 52 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 53 | iHandler++) 54 | ; 55 | if (OBISHandlers[iHandler].Handler != 0) { 56 | OBISHandlers[iHandler].Handler(); 57 | } 58 | } 59 | if (s == SML_UNEXPECTED) { 60 | Serial.print(F(">>> Unexpected byte! <<<\n")); 61 | } 62 | if (s == SML_FINAL) { 63 | Serial.print(F("Power T1 (1-0:1.8.1)..: ")); 64 | dtostrf(T1Wh, 10, 3, floatBuffer); 65 | Serial.print(floatBuffer); 66 | Serial.print(F("\n")); 67 | 68 | Serial.print(F("Power T1+T2 (1-0:1.8.0)..: ")); 69 | dtostrf(SumWh, 10, 3, floatBuffer); 70 | Serial.print(floatBuffer); 71 | Serial.print(F("\n\n\n\n")); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /examples/arduino_serial/.clang-format: -------------------------------------------------------------------------------- 1 | BreakBeforeBraces: Stroustrup 2 | -------------------------------------------------------------------------------- /examples/arduino_serial/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | lib 7 | -------------------------------------------------------------------------------- /examples/arduino_serial/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ], 7 | "unwantedRecommendations": [ 8 | "ms-vscode.cpptools-extension-pack" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /examples/arduino_serial/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } 4 | -------------------------------------------------------------------------------- /examples/arduino_serial/README.md: -------------------------------------------------------------------------------- 1 | # Arduino Serial 2 | 3 | Reads data from Arduino Pin 8. 4 | 5 | Outputs some more information from the message if `SML_DEBUG` is enabled (see platformio.ini). 6 | 7 | Dumps a successfully received message as hex values which can be inserted into a .h file for testing. 8 | 9 | # Example output 10 | 11 | ``` 12 | START 13 | LISTSTART on level 1 with 6 nodes 14 | Data 6 (length = 6, octet string): 00 0C 04 08 87 2D 15 | Data 5 (length = 1, unsigned int): 00 16 | Data 4 (length = 1, unsigned int): 00 17 | LISTSTART on level 2 with 2 nodes 18 | Data 2 (length = 2, unsigned int): 01 01 19 | LISTSTART on level 3 with 6 nodes 20 | Data 6 (empty) 21 | Data 5 (empty) 22 | Data 4 (length = 6, octet string): 00 0C 06 9E 2D 0F 23 | Data 3 (length = 10, octet string): 06 45 4D 48 01 00 1D 46 15 CA 24 | Data 2 (empty) 25 | Data 1 (empty) 26 | LISTEND 27 | back to previous list 28 | back to previous list 29 | Data 2 (length = 2, unsigned int): 2B 8E 30 | End of block at level 1 31 | back to previous list 32 | LISTSTART on level 1 with 6 nodes 33 | Data 6 (length = 6, octet string): 00 0C 04 08 87 2E 34 | Data 5 (length = 1, unsigned int): 00 35 | Data 4 (length = 1, unsigned int): 00 36 | LISTSTART on level 2 with 2 nodes 37 | Data 2 (length = 2, unsigned int): 07 01 38 | LISTSTART on level 3 with 7 nodes 39 | Data 7 (empty) 40 | Data 6 (length = 10, octet string): 06 45 4D 48 01 00 1D 46 15 CA 41 | Data 5 (empty) 42 | LISTSTART on level 4 with 2 nodes 43 | Data 2 (length = 1, unsigned int): 01 44 | Data 1 (length = 4, unsigned int): 06 9E FA 83 45 | LISTEND on level 4 46 | back to previous list 47 | LISTSTART on level 4 with 7 nodes 48 | LISTSTART on level 5 with 7 nodes 49 | Data 7 (length = 6, octet string): 81 81 C7 82 03 FF 50 | Data 6 (empty) 51 | Data 5 (empty) 52 | Data 4 (empty) 53 | Data 3 (empty) 54 | Data 2 (length = 3, octet string): 45 4D 48 55 | Data 1 (empty) 56 | LISTEND 57 | back to previous list 58 | LISTSTART on level 5 with 7 nodes 59 | Data 7 (length = 6, octet string): 01 00 00 00 09 FF 60 | Data 6 (empty) 61 | Data 5 (empty) 62 | Data 4 (empty) 63 | Data 3 (empty) 64 | Data 2 (length = 10, octet string): 06 45 4D 48 01 00 1D 46 15 CA 65 | Data 1 (empty) 66 | LISTEND 67 | back to previous list 68 | LISTSTART on level 5 with 7 nodes 69 | Data 7 (length = 6, octet string): 01 00 01 08 00 FF 70 | Data 6 (length = 2, unsigned int): 01 82 71 | Data 5 (empty) 72 | Data 4 (length = 1, unsigned int): 1E 73 | Data 3 (length = 1, signed int): FF 74 | Data 2 (length = 5, signed int): 00 09 06 74 EA 75 | Data 1 (empty) 76 | LISTEND 77 | back to previous list 78 | LISTSTART on level 5 with 7 nodes 79 | Data 7 (length = 6, octet string): 01 00 01 08 01 FF 80 | Data 6 (empty) 81 | Data 5 (empty) 82 | Data 4 (length = 1, unsigned int): 1E 83 | Data 3 (length = 1, signed int): FF 84 | Data 2 (length = 8, signed int): 00 00 00 00 07 5B CD 15 85 | Data 1 (empty) 86 | LISTEND 87 | back to previous list 88 | LISTSTART on level 5 with 7 nodes 89 | Data 7 (length = 6, octet string): 01 00 01 08 02 FF 90 | Data 6 (empty) 91 | Data 5 (empty) 92 | Data 4 (length = 1, unsigned int): 1E 93 | Data 3 (length = 1, signed int): FF 94 | Data 2 (length = 5, signed int): 00 00 00 00 00 95 | Data 1 (empty) 96 | LISTEND 97 | back to previous list 98 | LISTSTART on level 5 with 7 nodes 99 | Data 7 (length = 6, octet string): 01 00 0F 07 00 FF 100 | Data 6 (empty) 101 | Data 5 (empty) 102 | Data 4 (length = 1, unsigned int): 1B 103 | Data 3 (length = 1, signed int): FF 104 | Data 2 (length = 4, signed int): 00 00 2F 65 105 | Data 1 (empty) 106 | LISTEND 107 | back to previous list 108 | LISTSTART on level 5 with 7 nodes 109 | Data 7 (length = 6, octet string): 81 81 C7 82 05 FF 110 | Data 6 (empty) 111 | Data 5 (empty) 112 | Data 4 (empty) 113 | Data 3 (empty) 114 | Data (length = 48): FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 115 | Data 2 (empty) 116 | Data 1 (empty) 117 | LISTEND 118 | back to previous list 119 | back to previous list 120 | Data 2 (empty) 121 | Data 1 (length = 2, unsigned int): B9 3F 122 | LISTEND on level 3 123 | back to previous list 124 | back to previous list 125 | End of block at level 1 126 | LISTSTART on level 2 with 6 nodes 127 | Data 6 (length = 6, octet string): 00 0C 04 08 87 31 128 | Data 5 (length = 1, unsigned int): 00 129 | Data 4 (length = 1, unsigned int): 00 130 | LISTSTART on level 3 with 2 nodes 131 | Data 2 (length = 2, unsigned int): 02 01 132 | LISTSTART on level 4 with 1 nodes 133 | Data 1 (empty) 134 | LISTEND 135 | back to previous list 136 | back to previous list 137 | Data 2 (length = 2, unsigned int): 6A 53 138 | End of block at level 2 139 | back to previous list 140 | back to previous list 141 | End of block at level 0 142 | Received checksum: 1B70 143 | Calculated checksum: 1B70 144 | >>> Successfully received a complete message! 145 | Size: 319 146 | --- 147 | 0x1B, 0x1B, 0x1B, 0x1B, 0x01, 0x01, 0x01, 0x01, 0x76, 0x07, 0x00, 0x0C, 0x04, 0x08, 0x87, 148 | 0x2D, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x01, 0x01, 0x76, 0x01, 0x01, 0x07, 0x00, 0x0C, 149 | 0x06, 0x9E, 0x2D, 0x0F, 0x0B, 0x06, 0x45, 0x4D, 0x48, 0x01, 0x00, 0x1D, 0x46, 0x15, 0xCA, 150 | 0x01, 0x01, 0x63, 0x2B, 0x8E, 0x00, 0x76, 0x07, 0x00, 0x0C, 0x04, 0x08, 0x87, 0x2E, 0x62, 151 | 0x00, 0x62, 0x00, 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0B, 0x06, 0x45, 0x4D, 0x48, 0x01, 152 | 0x00, 0x1D, 0x46, 0x15, 0xCA, 0x01, 0x72, 0x62, 0x01, 0x65, 0x06, 0x9E, 0xFA, 0x83, 0x77, 153 | 0x77, 0x07, 0x81, 0x81, 0xC7, 0x82, 0x03, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x04, 0x45, 0x4D, 154 | 0x48, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x0B, 155 | 0x06, 0x45, 0x4D, 0x48, 0x01, 0x00, 0x1D, 0x46, 0x15, 0xCA, 0x01, 0x77, 0x07, 0x01, 0x00, 156 | 0x01, 0x08, 0x00, 0xFF, 0x63, 0x01, 0x82, 0x01, 0x62, 0x1E, 0x52, 0xFF, 0x56, 0x00, 0x09, 157 | 0x06, 0x74, 0xEA, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 0x08, 0x01, 0xFF, 0x01, 0x01, 0x62, 158 | 0x1E, 0x52, 0xFF, 0x59, 0x00, 0x00, 0x00, 0x00, 0x07, 0x5B, 0xCD, 0x15, 0x01, 0x77, 0x07, 159 | 0x01, 0x00, 0x01, 0x08, 0x02, 0xFF, 0x01, 0x01, 0x62, 0x1E, 0x52, 0xFF, 0x56, 0x00, 0x00, 160 | 0x00, 0x00, 0x00, 0x01, 0x77, 0x07, 0x01, 0x00, 0x0F, 0x07, 0x00, 0xFF, 0x01, 0x01, 0x62, 161 | 0x1B, 0x52, 0xFF, 0x55, 0x00, 0x00, 0x2F, 0x65, 0x01, 0x77, 0x07, 0x81, 0x81, 0xC7, 0x82, 162 | 0x05, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x83, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 163 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 164 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 165 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x01, 0x01, 0x63, 166 | 0xB9, 0x3F, 0x00, 0x76, 0x07, 0x00, 0x0C, 0x04, 0x08, 0x87, 0x31, 0x62, 0x00, 0x62, 0x00, 167 | 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 0x6A, 0x53, 0x00, 0x00, 0x1B, 0x1B, 0x1B, 0x1B, 168 | 0x1A, 0x01, 0x70, 0x1B 169 | --- 170 | ``` -------------------------------------------------------------------------------- /examples/arduino_serial/main.cpp: -------------------------------------------------------------------------------- 1 | #include "sml.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // Reads data from Arduino Pin 8 (only this pin is possible, see AltSoftSerial) 8 | // SoftwareSerial will be too slow to read data even on 9600 baud. 9 | // Dump successfully received message as hex values which 10 | // can be inserted into a .h file. 11 | 12 | #define MAX_BUF_SIZE 700 13 | 14 | AltSoftSerial inputSerial; 15 | 16 | sml_states_t currentState; 17 | 18 | RingBuf myBuffer; 19 | 20 | void print_buffer() 21 | { 22 | unsigned int i = 0; 23 | unsigned int j = 0; 24 | char b[5]; 25 | Serial.print(F("Size: ")); 26 | Serial.print(myBuffer.size()); 27 | Serial.println(""); 28 | Serial.println(F("--- ")); 29 | for (j = 0; j < myBuffer.size(); j++) { 30 | i++; 31 | sprintf(b, "0x%02X", myBuffer[j]); 32 | Serial.print(b); 33 | if (j < myBuffer.size() - 1) { 34 | Serial.print(", "); 35 | } 36 | else { 37 | Serial.println(""); 38 | Serial.println(F("--- ")); 39 | } 40 | if ((i % 15) == 0) { 41 | Serial.println(""); 42 | i = 0; 43 | } 44 | } 45 | } 46 | 47 | void readByte(unsigned char currentChar) 48 | { 49 | currentState = smlState(currentChar); 50 | if (currentState == SML_START) { 51 | myBuffer.clear(); 52 | myBuffer.push(0x1B); 53 | myBuffer.push(0x1B); 54 | myBuffer.push(0x1B); 55 | } 56 | else { 57 | if (myBuffer.size() < MAX_BUF_SIZE) { 58 | myBuffer.push(currentChar); 59 | } 60 | else { 61 | Serial.print(F(">>> Message larger than MAX_BUF_SIZE\n")); 62 | } 63 | } 64 | if (currentState == SML_UNEXPECTED) { 65 | Serial.print(F(">>> Unexpected byte\n")); 66 | } 67 | if (currentState == SML_FINAL) { 68 | Serial.print(F(">>> Successfully received a complete message!\n")); 69 | print_buffer(); 70 | } 71 | if (currentState == SML_CHECKSUM_ERROR) { 72 | Serial.print(F(">>> Checksum error.\n")); 73 | } 74 | } 75 | 76 | void setup() 77 | { 78 | inputSerial.begin(9600); 79 | Serial.begin(115200); 80 | Serial.println(F("Starting")); 81 | } 82 | 83 | void loop() 84 | { 85 | while (inputSerial.available() > 0) { 86 | readByte(inputSerial.read()); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /examples/arduino_serial/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | src_dir = ./ 13 | 14 | [env:uno] 15 | platform = atmelavr 16 | board = uno 17 | framework = arduino 18 | board_build.mcu = atmega328p 19 | board_build.f_cpu = 16000000L 20 | build_flags = -D SML_DEBUG 21 | lib_deps = 22 | ../../src 23 | paulstoffregen/AltSoftSerial@^1.4 24 | locoduino/RingBuffer@^1.0.3 25 | monitor_speed = 115200 26 | -------------------------------------------------------------------------------- /examples/esp32_lora/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | src/keys.h 3 | 4 | -------------------------------------------------------------------------------- /examples/esp32_lora/README.md: -------------------------------------------------------------------------------- 1 | # Forward energy usage to LoraWAN (The Things Network) 2 | 3 | - Rename keys.h.example to keys.h and insert your own DEVEUI and APPKEY 4 | - Use the following uplink payload formatter: 5 | 6 | ```JavaScript 7 | function decodeUplink(input) { 8 | var data = {}; 9 | var str = String.fromCharCode.apply(null, input.bytes).trim(); 10 | data.raw = str; 11 | if (str > 0) { 12 | data.kwh = str; 13 | } 14 | return { 15 | data: data, 16 | warnings: [], 17 | errors: [] 18 | }; 19 | } 20 | ``` 21 | -------------------------------------------------------------------------------- /examples/esp32_lora/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp32] 12 | platform = espressif32 13 | board = heltec_wifi_lora_32_V2 14 | framework = arduino 15 | monitor_speed = 115200 16 | build_flags = 17 | -D SML_DEBUG 18 | -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS 19 | -D CFG_eu868=1 20 | -D CFG_sx1276_radio=1 21 | -D LMIC_ENABLE_arbitrary_clock_error=1 22 | lib_deps = 23 | mcci-catena/MCCI LoRaWAN LMIC library@^4.1.1 24 | olikraus/U8g2@^2.32.10 25 | plerup/EspSoftwareSerial@^6.15.2 26 | ../../src 27 | -------------------------------------------------------------------------------- /examples/esp32_lora/src/keys.h.example: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include 3 | 4 | // This EUI must be in little-endian format, so least-significant-byte 5 | // first. When copying an EUI from ttnctl output, this means to reverse 6 | // the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, 7 | // 0x70. 8 | static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 9 | 10 | // This should also be in little endian format, see above. 11 | static const u1_t PROGMEM DEVEUI[8]={ 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0xD5, 0xB3, 0x70 }; 12 | 13 | // This key should be in big endian format (or, since it is not really a 14 | // number but a block of memory, endianness does not really apply). In 15 | // practice, a key taken from ttnctl can be copied as-is. 16 | static const u1_t PROGMEM APPKEY[16] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 17 | -------------------------------------------------------------------------------- /examples/esp32_lora/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "keys.h" 8 | #include "sml.h" 9 | #include 10 | #include 11 | 12 | #define rxPin 36 13 | 14 | SoftwareSerial inputSerial; 15 | U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/15, /* data=*/4, 16 | /* reset=*/16); 17 | 18 | sml_states_t currentState; 19 | unsigned char currentChar = 0; 20 | unsigned long counter = 0, transmitted = 0; 21 | char buffer[50]; 22 | char statusMsg[30] = "Unknown"; 23 | char floatBuffer[20]; 24 | double T1Wh = -2, SumWh = -2, T1WhSend = -2, SumWhSend = -2; 25 | 26 | static osjob_t sendjob; 27 | 28 | // Schedule TX every this many seconds 29 | const unsigned TX_INTERVAL = 500; 30 | 31 | void os_getArtEui(u1_t *buf) { memcpy_P(buf, APPEUI, 8); } 32 | void os_getDevEui(u1_t *buf) { memcpy_P(buf, DEVEUI, 8); } 33 | void os_getDevKey(u1_t *buf) { memcpy_P(buf, APPKEY, 16); } 34 | 35 | // Pin mapping 36 | const lmic_pinmap lmic_pins = { 37 | .nss = 18, 38 | .rxtx = LMIC_UNUSED_PIN, 39 | .rst = 14, 40 | .dio = {26, 34, 35}, 41 | }; 42 | 43 | typedef struct { 44 | const unsigned char OBIS[6]; 45 | void (*Handler)(); 46 | } OBISHandler; 47 | 48 | void PowerT1() { smlOBISWh(T1Wh); } 49 | 50 | void PowerSum() { smlOBISWh(SumWh); } 51 | 52 | // clang-format off 53 | OBISHandler OBISHandlers[] = { 54 | {{0x01, 0x00, 0x01, 0x08, 0x01, 0xff}, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 55 | {{0x01, 0x00, 0x01, 0x08, 0x00, 0xff}, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 56 | {{0}, 0} 57 | }; 58 | // clang-format on 59 | 60 | void printHex2(unsigned v) 61 | { 62 | v &= 0xff; 63 | if (v < 16) 64 | Serial.print('0'); 65 | Serial.print(v, HEX); 66 | } 67 | 68 | void updateDisplay() 69 | { 70 | u8x8.drawString(0, 2, statusMsg); 71 | 72 | sprintf(buffer, "Msg: %lu", counter); 73 | u8x8.drawString(0, 3, buffer); 74 | 75 | dtostrf(T1WhSend, 10, 1, floatBuffer); 76 | sprintf(buffer, "T1.: %s", floatBuffer); 77 | u8x8.drawString(0, 4, buffer); 78 | 79 | dtostrf(SumWhSend, 10, 1, floatBuffer); 80 | sprintf(buffer, "Sum: %s", floatBuffer); 81 | u8x8.drawString(0, 5, buffer); 82 | 83 | sprintf(buffer, "Tns: %lu", transmitted); 84 | u8x8.drawString(0, 6, buffer); 85 | } 86 | 87 | void do_send(osjob_t *j) 88 | { 89 | unsigned char floatBuffer[20]; 90 | // Check if there is not a current TX/RX job running 91 | if (LMIC.opmode & OP_TXRXPEND) { 92 | Serial.println(F("OP_TXRXPEND, not sending")); 93 | } 94 | else { 95 | // @todo should be optimized 96 | dtostrf(SumWhSend, 10, 1, (char *)floatBuffer); 97 | LMIC_setTxData2(1, floatBuffer, strlen((char *)floatBuffer), 0); 98 | Serial.printf("---> Packet queued %s", floatBuffer); 99 | Serial.println(""); 100 | } 101 | // Next TX is scheduled after TX_COMPLETE event. 102 | } 103 | 104 | void onEvent(ev_t ev) 105 | { 106 | Serial.print(os_getTime()); 107 | Serial.print(": "); 108 | switch (ev) { 109 | case EV_SCAN_TIMEOUT: 110 | Serial.println(F("EV_SCAN_TIMEOUT")); 111 | break; 112 | case EV_BEACON_FOUND: 113 | Serial.println(F("EV_BEACON_FOUND")); 114 | break; 115 | case EV_BEACON_MISSED: 116 | Serial.println(F("EV_BEACON_MISSED")); 117 | break; 118 | case EV_BEACON_TRACKED: 119 | Serial.println(F("EV_BEACON_TRACKED")); 120 | break; 121 | case EV_JOINING: 122 | Serial.println(F("EV_JOINING")); 123 | break; 124 | case EV_JOINED: 125 | Serial.println(F("EV_JOINED")); 126 | { 127 | u4_t netid = 0; 128 | devaddr_t devaddr = 0; 129 | u1_t nwkKey[16]; 130 | u1_t artKey[16]; 131 | LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey); 132 | Serial.print("netid: "); 133 | Serial.println(netid, DEC); 134 | Serial.print("devaddr: "); 135 | Serial.println(devaddr, HEX); 136 | Serial.print("AppSKey: "); 137 | for (size_t i = 0; i < sizeof(artKey); ++i) { 138 | if (i != 0) 139 | Serial.print("-"); 140 | printHex2(artKey[i]); 141 | } 142 | Serial.println(""); 143 | Serial.print("NwkSKey: "); 144 | for (size_t i = 0; i < sizeof(nwkKey); ++i) { 145 | if (i != 0) 146 | Serial.print("-"); 147 | printHex2(nwkKey[i]); 148 | } 149 | Serial.println(); 150 | sprintf(statusMsg, "Joined"); 151 | updateDisplay(); 152 | } 153 | // Disable link check validation (automatically enabled 154 | // during join, but because slow data rates change max TX 155 | // size, we don't use it in this example. 156 | LMIC_setLinkCheckMode(0); 157 | break; 158 | /* 159 | || This event is defined but not used in the code. No 160 | || point in wasting codespace on it. 161 | || 162 | || case EV_RFU1: 163 | || Serial.println(F("EV_RFU1")); 164 | || break; 165 | */ 166 | case EV_JOIN_FAILED: 167 | Serial.println(F("EV_JOIN_FAILED")); 168 | sprintf(statusMsg, "Join failed"); 169 | break; 170 | case EV_REJOIN_FAILED: 171 | Serial.println(F("EV_REJOIN_FAILED")); 172 | sprintf(statusMsg, "rejoin failed"); 173 | break; 174 | case EV_TXCOMPLETE: 175 | Serial.println(F("---> EV_TXCOMPLETE (includes waiting for RX windows)")); 176 | if (LMIC.txrxFlags & TXRX_ACK) 177 | Serial.println(F("Received ack")); 178 | if (LMIC.dataLen) { 179 | Serial.print(F("Received ")); 180 | Serial.print(LMIC.dataLen); 181 | Serial.println(F(" bytes of payload")); 182 | } 183 | // Schedule next transmission 184 | os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), 185 | do_send); 186 | transmitted++; 187 | sprintf(statusMsg, "TX Compl"); 188 | updateDisplay(); 189 | break; 190 | case EV_LOST_TSYNC: 191 | sprintf(statusMsg, "Lost sync"); 192 | updateDisplay(); 193 | Serial.println(F("EV_LOST_TSYNC")); 194 | break; 195 | case EV_RESET: 196 | sprintf(statusMsg, "Reset sync"); 197 | updateDisplay(); 198 | Serial.println(F("EV_RESET")); 199 | break; 200 | case EV_RXCOMPLETE: 201 | // data received in ping slot 202 | Serial.println(F("EV_RXCOMPLETE")); 203 | break; 204 | case EV_LINK_DEAD: 205 | sprintf(statusMsg, "Link dead"); 206 | updateDisplay(); 207 | Serial.println(F("EV_LINK_DEAD")); 208 | break; 209 | case EV_LINK_ALIVE: 210 | sprintf(statusMsg, "Link alive"); 211 | updateDisplay(); 212 | Serial.println(F("EV_LINK_ALIVE")); 213 | break; 214 | /* 215 | || This event is defined but not used in the code. No 216 | || point in wasting codespace on it. 217 | || 218 | || case EV_SCAN_FOUND: 219 | || Serial.println(F("EV_SCAN_FOUND")); 220 | || break; 221 | */ 222 | case EV_TXSTART: 223 | sprintf(statusMsg, "tx start"); 224 | updateDisplay(); 225 | Serial.println(F("EV_TXSTART")); 226 | break; 227 | case EV_TXCANCELED: 228 | Serial.println(F("EV_TXCANCELED")); 229 | break; 230 | case EV_RXSTART: 231 | /* do not print anything -- it wrecks timing */ 232 | break; 233 | case EV_JOIN_TXCOMPLETE: 234 | Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept")); 235 | break; 236 | 237 | default: 238 | Serial.print(F("Unknown event: ")); 239 | Serial.println((unsigned)ev); 240 | break; 241 | } 242 | } 243 | 244 | void setup() 245 | { 246 | Serial.begin(115200); 247 | Serial.println("Starting"); 248 | 249 | u8x8.begin(); 250 | u8x8.setFont(u8x8_font_chroma48medium8_r); 251 | u8x8.drawString(0, 1, "SML to LoraWAN"); 252 | u8x8.drawString(0, 2, "Waiting"); 253 | 254 | // LMIC init 255 | os_init(); 256 | 257 | // Reset the MAC state. Session and pending data transfers will be discarded. 258 | LMIC_reset(); 259 | 260 | pinMode(rxPin, INPUT); 261 | 262 | inputSerial.begin(9600, SWSERIAL_8N1, rxPin, -1, false, 0, 95); 263 | inputSerial.enableRx(true); 264 | inputSerial.enableTx(false); 265 | 266 | do_send(&sendjob); 267 | } 268 | 269 | void readByte() 270 | { 271 | unsigned int iHandler = 0; 272 | currentState = smlState(currentChar); 273 | if (currentState == SML_START) { 274 | /* reset local vars */ 275 | T1Wh = -3; 276 | SumWh = -3; 277 | } 278 | if (currentState == SML_LISTEND) { 279 | /* check handlers on last received list */ 280 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 281 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 282 | iHandler++) 283 | ; 284 | if (OBISHandlers[iHandler].Handler != 0) { 285 | OBISHandlers[iHandler].Handler(); 286 | } 287 | } 288 | if (currentState == SML_UNEXPECTED) { 289 | Serial.print(F(">>> Unexpected byte!\n")); 290 | } 291 | if (currentState == SML_FINAL) { 292 | SumWhSend = SumWh; 293 | T1WhSend = T1Wh; 294 | updateDisplay(); 295 | counter++; 296 | Serial.print(F(">>> Successfully received a complete message!\n")); 297 | } 298 | } 299 | 300 | void loop() 301 | { 302 | os_runloop_once(); 303 | if (inputSerial.available()) { 304 | currentChar = inputSerial.read(); 305 | readByte(); 306 | } 307 | } 308 | -------------------------------------------------------------------------------- /examples/esp32_m5stack_sender/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode 3 | .pioenvs 4 | .piolibdeps 5 | -------------------------------------------------------------------------------- /examples/esp32_m5stack_sender/README.md: -------------------------------------------------------------------------------- 1 | # M5Stack sender 2 | 3 | M5Stack example to produce some test data on TXD2 pin 4 | 5 | ## Usage 6 | 7 | ```bash 8 | pio run 9 | ``` 10 | -------------------------------------------------------------------------------- /examples/esp32_m5stack_sender/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:m5stack-core-esp32] 12 | platform = espressif32 13 | board = m5stack-core-esp32 14 | framework = arduino 15 | upload_speed = 921600 16 | targets = upload 17 | ; build_flags = -D DEBUG_ARDUINO 18 | lib_deps = 19 | M5Stack 20 | plerup/EspSoftwareSerial@^7.0.0 21 | ../../src 22 | monitor_speed = 115200 23 | 24 | -------------------------------------------------------------------------------- /examples/esp32_m5stack_sender/src/ehz_bin.h: -------------------------------------------------------------------------------- 1 | // clang-format off 2 | // Formatted example data from https://github.com/devZer0/libsml-testing 3 | 4 | const unsigned char ehz_bin[] = { 5 | /* Start */ 0x1b, 0x1b, 0x1b, 0x1b, 6 | /* Version */ 0x01, 0x01, 0x01, 0x01, 7 | 8 | /* List (6 entries) */ 0x76, 9 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2d, 10 | /* 2. Group No */ 0x62, 0x00, 11 | /* 3. Abort On Error */ 0x62, 0x00, 12 | /* 4. List (2 entries) */ 0x72, 13 | /* 1. getOpenResponse */ 0x63, 0x01, 0x01, 14 | /* 2. List (6 entries) */ 0x76, 15 | /* 1. code page */ 0x01, 16 | /* 2. clientid */ 0x01, 17 | /* 3. Transaction ID */ 0x07, 0x00, 0x0c, 0x06, 0x9e, 0x2d, 0x0f, 18 | /* 4. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 19 | /* 5. List name */ 0x01, 20 | /* 6. Time */ 0x01, 21 | /* 5. CRC */ 0x63, 0x2b, 0x8e, 22 | /* 6. END */ 0x00, 23 | 24 | /* List (6 entries) */ 0x76, 25 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2e, 26 | /* 2. Group No */ 0x62, 0x00, 27 | /* 3. Abort On Error */ 0x62, 0x00, 28 | /* 4. Message Body (2) */ 0x72, 29 | /* 1. getListResponse */ 0x63, 0x07, 0x01, 30 | /* 2. List (7) */ 0x77, 31 | /* 1. ClientId */ 0x01, 32 | /* 2. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 33 | /* 3. ?? */ 0x01, 34 | /* 4. List (2) */ 0x72, 35 | /* 1. ?? */ 0x62, 0x01, 36 | /* 2. ?? */ 0x65, 0x06, 0x9e, 0xfa, 0x83, 37 | /* 5. List (7) */ 0x77, 38 | /* 1. List (7) */ 0x77, 39 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 40 | /* 2. */ 0x01, 41 | /* 3. */ 0x01, 42 | /* 4. */ 0x01, 43 | /* 5. */ 0x01, 44 | /* 6. Value=Manuf */ 0x04, 0x45, 0x4d, 0x48, 45 | /* 7. */ 0x01, 46 | /* 2. List (7) */ 0x77, 47 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 48 | /* 2. */ 0x01, 49 | /* 3. */ 0x01, 50 | /* 4. */ 0x01, 51 | /* 5. */ 0x01, 52 | /* 6. Value */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 53 | /* 7. */ 0x01, 54 | /* 3. List (7) */ 0x77, 55 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 56 | /* 2. */ 0x63, 0x01, 0x82, 57 | /* 3. */ 0x01, 58 | /* 4. Unit=wh */ 0x62, 0x1e, 59 | /* 5. Scaler */ 0x52, 0xff, 60 | /* 6. Value */ 0x56, 0x00, 0x09, 0x06, 0x74, 0xea, 61 | /* 7. */ 0x01, 62 | /* 4. List (7) */ 0x77, 63 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x01, 0xff, 64 | /* 2. */ 0x01, 65 | /* 3. */ 0x01, 66 | /* 4. Unit=wh */ 0x62, 0x1e, 67 | /* 5. Scaler */ 0x52, 0xff, 68 | /* 6 Value */ 0x59, 0x00, 0x00, 0x00, 0x00, 0x07, 0x5b, 0xcd, 0x15, 69 | /* 7 */ 0x01, 70 | /* 5. List (7) */ 0x77, 71 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x02, 0xff, 72 | /* 2. */ 0x01, 73 | /* 3. */ 0x01, 74 | /* 4. */ 0x62, 0x1e, 75 | /* 5. */ 0x52, 0xff, 76 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 77 | /* 7. */ 0x01, 78 | /* 6. List (7) */ 0x77, 79 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x0f, 0x07, 0x00, 0xff, 80 | /* 2. */ 0x01, 81 | /* 3. */ 0x01, 82 | /* 4. */ 0x62, 0x1b, 83 | /* 5. */ 0x52, 0xff, 84 | /* 6. */ 0x55, 0x00, 0x00, 0x2f, 0x65, 85 | /* 7. */ 0x01, 86 | /* 7. List (7) */ 0x77, 87 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 88 | /* 2. */ 0x01, 89 | /* 3. */ 0x01, 90 | /* 4. */ 0x01, 91 | /* 5. */ 0x01, 92 | /* 6. Public Key */ 0x83, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 93 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 94 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 95 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 96 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 97 | /* 7. */ 0x01, 98 | 0x01, 99 | 0x01, 100 | 0x63, 0xb9, 0x3f, 101 | 0x00, 102 | /* List (6) */ 0x76, 103 | /* 1. */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x31, 104 | /* 2. */ 0x62, 0x00, 105 | /* 3. */ 0x62, 0x00, 106 | /* 4. List (2) */ 0x72, 107 | /* 1. */ 0x63, 0x02, 0x01, 108 | /* List (1) */ 0x71, 109 | /* 1. */ 0x01, 110 | /* 5. CRC */ 0x63, 0x6a, 0x53, 111 | /* 6. */ 0x00, 112 | 113 | 0x00, 114 | 0x1b, 0x1b, 0x1b, 0x1b, 115 | 0x1a, 0x01, 0x70, 0x1b 116 | }; 117 | const unsigned int ehz_bin_len = 319; 118 | 119 | -------------------------------------------------------------------------------- /examples/esp32_m5stack_sender/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ehz_bin.h" 2 | #include "sml.h" 3 | #include 4 | #include 5 | 6 | // M5Stack to produce some example data on TXD2 pin (blue grove connector) 7 | // Press button A to toggle between inverted/uninverted signal 8 | 9 | SoftwareSerial outSerial; 10 | 11 | int i = 0, counter = 0; 12 | unsigned char c; 13 | sml_states_t s; 14 | bool invert = true; 15 | 16 | unsigned long previousMillis = 0; 17 | const long interval = 2000; 18 | 19 | void setup() 20 | { 21 | outSerial.begin(9600, SWSERIAL_8N1, -1, TXD2, invert, 0, 95); 22 | outSerial.enableRx(false); 23 | Serial.begin(115200); 24 | M5.begin(); 25 | 26 | M5.Lcd.setCursor(1, 10); 27 | M5.Lcd.fillScreen(WHITE); 28 | M5.Lcd.setTextColor(BLACK); 29 | M5.Lcd.setTextSize(5); 30 | M5.Lcd.print("SML Sender"); 31 | } 32 | 33 | void updateDisplay() 34 | { 35 | M5.Lcd.fillRect(0, 50, M5.Lcd.width(), 50, WHITE); 36 | M5.Lcd.setCursor(1, 50); 37 | M5.Lcd.setTextSize(2); 38 | M5.Lcd.printf("Send: %i", counter); 39 | M5.Lcd.setCursor(1, 70); 40 | M5.Lcd.printf("Invert: %s", (invert) ? "Yes" : "No"); 41 | Serial.print("Message sent\n"); 42 | } 43 | 44 | void loop() 45 | { 46 | unsigned long currentMillis = millis(); 47 | M5.update(); 48 | if (M5.BtnA.wasReleased()) { 49 | invert = (invert) ? false : true; 50 | outSerial.begin(9600, SWSERIAL_8N1, -1, TXD2, invert, 0, 95); 51 | Serial.print("Button pressed.\n"); 52 | updateDisplay(); 53 | } 54 | if (currentMillis - previousMillis >= interval) { 55 | previousMillis = currentMillis; 56 | for (i = 0; i < ehz_bin_len; ++i) { 57 | c = ehz_bin[i]; 58 | s = smlState(c); 59 | outSerial.write(c); 60 | outSerial.flush(); 61 | if (s == SML_FINAL) { 62 | counter++; 63 | updateDisplay(); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /examples/esp32_receiver/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode 3 | 4 | -------------------------------------------------------------------------------- /examples/esp32_receiver/README.md: -------------------------------------------------------------------------------- 1 | # Receive messages and show infos on a display 2 | 3 | Receive messages on ESP32 pin 36. 4 | 5 | ![Example](image.jpg) 6 | 7 | # Upload 8 | 9 | ```bash 10 | pio run --target upload 11 | ``` 12 | -------------------------------------------------------------------------------- /examples/esp32_receiver/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olliiiver/sml_parser/365fd4cfb2b5d15d87b361661401c4ae7550bb9f/examples/esp32_receiver/image.jpg -------------------------------------------------------------------------------- /examples/esp32_receiver/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:esp32] 12 | platform = espressif32 13 | board = heltec_wifi_lora_32_V2 14 | framework = arduino 15 | monitor_speed = 115200 16 | build_flags = -D SML_DEBUG 17 | lib_deps = 18 | olikraus/U8g2@^2.32.10 19 | plerup/EspSoftwareSerial@^6.15.2 20 | olliiiver/SML Parser 21 | 22 | -------------------------------------------------------------------------------- /examples/esp32_receiver/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include 3 | #include 4 | 5 | #include "sml.h" 6 | #include 7 | 8 | #define rxPin 36 9 | 10 | #define MAX_STR_MANUF 5 11 | unsigned char manuf[MAX_STR_MANUF]; 12 | double T1Wh = -2, SumWh = -2; 13 | 14 | typedef struct { 15 | const unsigned char OBIS[6]; 16 | void (*Handler)(); 17 | } OBISHandler; 18 | 19 | void Manufacturer() { smlOBISManufacturer(manuf, MAX_STR_MANUF); } 20 | 21 | void PowerT1() { smlOBISWh(T1Wh); } 22 | 23 | void PowerSum() { smlOBISWh(SumWh); } 24 | 25 | // clang-format off 26 | OBISHandler OBISHandlers[] = { 27 | {{0x81, 0x81, 0xc7, 0x82, 0x03, 0xff}, &Manufacturer}, /* 129-129:199.130.3*255 */ 28 | {{0x01, 0x00, 0x01, 0x08, 0x01, 0xff}, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 29 | {{0x01, 0x00, 0x01, 0x08, 0x00, 0xff}, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 30 | {{0}, 0} 31 | }; 32 | // clang-format on 33 | 34 | SoftwareSerial inputSerial; 35 | 36 | U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/15, /* data=*/4, 37 | /* reset=*/16); 38 | 39 | sml_states_t currentState; 40 | unsigned char currentChar = 0; 41 | unsigned long counter = 0; 42 | char buffer[50]; 43 | char floatBuffer[20]; 44 | 45 | void updateDisplay() 46 | { 47 | sprintf(buffer, "Msg..: %lu", counter); 48 | u8x8.drawString(0, 2, buffer); 49 | sprintf(buffer, "Manuf: %s", manuf); 50 | u8x8.drawString(0, 3, buffer); 51 | 52 | dtostrf(T1Wh, 10, 1, floatBuffer); 53 | sprintf(buffer, "T1.: %s", floatBuffer); 54 | u8x8.drawString(0, 4, buffer); 55 | 56 | dtostrf(SumWh, 10, 1, floatBuffer); 57 | sprintf(buffer, "Sum: %s", floatBuffer); 58 | u8x8.drawString(0, 5, buffer); 59 | } 60 | 61 | void setup() 62 | { 63 | Serial.begin(115200); 64 | Serial.println("Starting"); 65 | 66 | u8x8.begin(); 67 | u8x8.setFont(u8x8_font_chroma48medium8_r); 68 | u8x8.drawString(0, 1, "SML Receiver"); 69 | 70 | pinMode(rxPin, INPUT); 71 | inputSerial.begin(9600, SWSERIAL_8N1, rxPin, -1, false, 0, 95); 72 | inputSerial.enableRx(true); 73 | inputSerial.enableTx(false); 74 | updateDisplay(); 75 | } 76 | 77 | void readByte() 78 | { 79 | unsigned int iHandler = 0; 80 | currentState = smlState(currentChar); 81 | if (currentState == SML_START) { 82 | /* reset local vars */ 83 | manuf[0] = 0; 84 | T1Wh = -3; 85 | SumWh = -3; 86 | } 87 | if (currentState == SML_LISTEND) { 88 | /* check handlers on last received list */ 89 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 90 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 91 | iHandler++) 92 | ; 93 | if (OBISHandlers[iHandler].Handler != 0) { 94 | OBISHandlers[iHandler].Handler(); 95 | } 96 | } 97 | if (currentState == SML_UNEXPECTED) { 98 | Serial.print(F(">>> Unexpected byte!\n")); 99 | } 100 | if (currentState == SML_FINAL) { 101 | updateDisplay(); 102 | counter++; 103 | Serial.print(F(">>> Successfully received a complete message!\n")); 104 | } 105 | } 106 | 107 | void loop() 108 | { 109 | if (inputSerial.available()) { 110 | currentChar = inputSerial.read(); 111 | readByte(); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /examples/native/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode 3 | -------------------------------------------------------------------------------- /examples/native/README.md: -------------------------------------------------------------------------------- 1 | # Native example 2 | 3 | Test the library on our local machine. 4 | 5 | Should simply work on OS X and Linux via `run.sh` 6 | 7 | ## Convert binary file 8 | 9 | If you have a binary output from a meter available, you can convert it by using `xxd`: 10 | 11 | ``` 12 | xxd --include ehz_bin.bin >ehz_bin.h 13 | ``` 14 | -------------------------------------------------------------------------------- /examples/native/ehz_bin.h: -------------------------------------------------------------------------------- 1 | // clang-format off 2 | // Formatted example data from https://github.com/devZer0/libsml-testing 3 | 4 | const unsigned char ehz_bin[] = { 5 | /* Start */ 0x1b, 0x1b, 0x1b, 0x1b, 6 | /* Version */ 0x01, 0x01, 0x01, 0x01, 7 | 8 | /* List (6 entries) */ 0x76, 9 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2d, 10 | /* 2. Group No */ 0x62, 0x00, 11 | /* 3. Abort On Error */ 0x62, 0x00, 12 | /* 4. List (2 entries) */ 0x72, 13 | /* 1. getOpenResponse */ 0x63, 0x01, 0x01, 14 | /* 2. List (6 entries) */ 0x76, 15 | /* 1. code page */ 0x01, 16 | /* 2. clientid */ 0x01, 17 | /* 3. Transaction ID */ 0x07, 0x00, 0x0c, 0x06, 0x9e, 0x2d, 0x0f, 18 | /* 4. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 19 | /* 5. List name */ 0x01, 20 | /* 6. Time */ 0x01, 21 | /* 5. CRC */ 0x63, 0x2b, 0x8e, 22 | /* 6. END */ 0x00, 23 | 24 | /* List (6 entries) */ 0x76, 25 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2e, 26 | /* 2. Group No */ 0x62, 0x00, 27 | /* 3. Abort On Error */ 0x62, 0x00, 28 | /* 4. Message Body (2) */ 0x72, 29 | /* 1. getListResponse */ 0x63, 0x07, 0x01, 30 | /* 2. List (7) */ 0x77, 31 | /* 1. ClientId */ 0x01, 32 | /* 2. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 33 | /* 3. ?? */ 0x01, 34 | /* 4. List (2) */ 0x72, 35 | /* 1. ?? */ 0x62, 0x01, 36 | /* 2. ?? */ 0x65, 0x06, 0x9e, 0xfa, 0x83, 37 | /* 5. List (7) */ 0x77, 38 | /* 1. List (7) */ 0x77, 39 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 40 | /* 2. */ 0x01, 41 | /* 3. */ 0x01, 42 | /* 4. */ 0x01, 43 | /* 5. */ 0x01, 44 | /* 6. */ 0x04, 0x45, 0x4d, 0x48, 45 | /* 7. */ 0x01, 46 | /* 2. List (7) */ 0x77, 47 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 48 | /* 2. */ 0x01, 49 | /* 3. */ 0x01, 50 | /* 4. */ 0x01, 51 | /* 5. */ 0x01, 52 | /* 6. */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 53 | /* 7. */ 0x01, 54 | /* 3. List (7) */ 0x77, 55 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 56 | /* 2. */ 0x63, 0x01, 0x82, 57 | /* 3. */ 0x01, 58 | /* 4. */ 0x62, 0x1e, 59 | /* 5. */ 0x52, 0x03, 60 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x1C, 0x46, 61 | /* 7. */ 0x01, 62 | /* 4. List (7) */ 0x77, 63 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x01, 0xff, 64 | /* 2. */ 0x01, 65 | /* 3. */ 0x01, 66 | /* 4. Unit */ 0x62, 0x1e, 67 | /* 5. Scaler */ 0x52, 0xff, 68 | /* 6 Value */ 0x59, 0x00, 0x00, 0x00, 0x00, 0x07, 0x5b, 0xcd, 0x15, 69 | /* 7 */ 0x01, 70 | /* 5. List (7) */ 0x77, 71 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x02, 0xff, 72 | /* 2. */ 0x01, 73 | /* 3. */ 0x01, 74 | /* 4. */ 0x62, 0x1e, 75 | /* 5. */ 0x52, 0x03, 76 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x1C, 0x46, 77 | /* 7. */ 0x01, 78 | /* 6. List (7) */ 0x77, 79 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x0f, 0x07, 0x00, 0xff, 80 | /* 2. */ 0x01, 81 | /* 3. */ 0x01, 82 | /* 4. */ 0x62, 0x1b, 83 | /* 5. */ 0x52, 0xff, 84 | /* 6. */ 0x55, 0x00, 0x00, 0x2f, 0x65, 85 | /* 7. */ 0x01, 86 | /* 7. List (7) */ 0x77, 87 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 88 | /* 2. */ 0x01, 89 | /* 3. */ 0x01, 90 | /* 4. */ 0x01, 91 | /* 5. */ 0x01, 92 | /* 6. Public Key */ 0x83, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 93 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 94 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 95 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 96 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 97 | /* 7. */ 0x01, 98 | 0x01, 99 | 0x01, 100 | 0x63, 0xb9, 0x3f, 101 | 0x00, 102 | /* List (6) */ 0x76, 103 | /* 1. */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x31, 104 | /* 2. */ 0x62, 0x00, 105 | /* 3. */ 0x62, 0x00, 106 | /* 4. List (2) */ 0x72, 107 | /* 1. */ 0x63, 0x02, 0x01, 108 | /* List (1) */ 0x71, 109 | /* 1. */ 0x01, 110 | /* 5. CRC */ 0x63, 0x6a, 0x53, 111 | /* 6. */ 0x00, 112 | 113 | 0x00, 114 | 0x1b, 0x1b, 0x1b, 0x1b, 115 | 0x1a, 0x01, 0xe8, 0xc6 116 | }; 117 | const unsigned int ehz_bin_len = 319; 118 | 119 | -------------------------------------------------------------------------------- /examples/native/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ehz_bin.h" 2 | #include "sml.h" 3 | #include 4 | 5 | #define MAX_STR_MANUF 5 6 | unsigned char manuf[MAX_STR_MANUF]; 7 | double T1Wh = -2, SumWh = -2, Watt = -2; 8 | 9 | typedef struct { 10 | const unsigned char OBIS[6]; 11 | void (*Handler)(); 12 | } OBISHandler; 13 | 14 | void Manufacturer() { smlOBISManufacturer(manuf, MAX_STR_MANUF); } 15 | 16 | void PowerT1() { smlOBISWh(T1Wh); } 17 | 18 | void PowerSum() { smlOBISWh(SumWh); } 19 | 20 | void PowerW() { smlOBISW(Watt); } 21 | 22 | // clang-format off 23 | OBISHandler OBISHandlers[] = { 24 | {{ 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff }, &Manufacturer}, /* 129-129:199.130.3*255 */ 25 | {{ 0x01, 0x00, 0x01, 0x08, 0x01, 0xff }, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 26 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 27 | {{ 0x01, 0x00, 0x0F, 0x07, 0x00, 0xff }, &PowerW}, /* 1- 0: 15. 7.0*255 (Watt) */ 28 | {{ 0, 0 }} 29 | }; 30 | // clang-format on 31 | 32 | int main() 33 | { 34 | int i = 0, iHandler = 0; 35 | unsigned char c; 36 | sml_states_t s; 37 | for (i = 0; i < ehz_bin_len; ++i) { 38 | c = ehz_bin[i]; 39 | s = smlState(c); 40 | if (s == SML_START) { 41 | /* reset local vars */ 42 | manuf[0] = 0; 43 | T1Wh = -3; 44 | SumWh = -3; 45 | } 46 | if (s == SML_LISTEND) { 47 | /* check handlers on last received list */ 48 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 49 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 50 | iHandler++) 51 | ; 52 | if (OBISHandlers[iHandler].Handler != 0) { 53 | OBISHandlers[iHandler].Handler(); 54 | } 55 | } 56 | if (s == SML_UNEXPECTED) { 57 | printf(">>> Unexpected byte >%02X>> FINAL! Checksum OK\n"); 61 | printf(">>> Manufacturer.............: %s\n", manuf); 62 | printf(">>> Power T1 (1-0:1.8.1)..: %.3f Wh\n", T1Wh); 63 | printf(">>> Power T1+T2 (1-0:1.8.0)..: %.3f Wh\n", SumWh); 64 | printf(">>> Watt (1-0:15.7.0).: %.3f W\n\n", Watt); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /examples/native/platformio.ini: -------------------------------------------------------------------------------- 1 | [platformio] 2 | src_dir = ./ 3 | 4 | [env:native] 5 | platform = native 6 | lib_deps = ../../src 7 | build_flags = -D SML_DEBUG -D SML_NATIVE -Wall 8 | -------------------------------------------------------------------------------- /examples/native/run.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | rm -rf .pio/libdeps/native/src 4 | pio run 5 | ./.pio/build/native/program -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SML Parser", 3 | "keywords": "SML, Smart Message Language, Parser, Smart Meter, OBIS", 4 | "description": "Universal library that can parse SML (Smart Message Language) messages from smart meters. It's designed to be lightweight and efficient and has a small memory footprint, making it suitable for use on embedded systems or other devices with limited memory resources.", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/olliiiver/sml_parser.git" 8 | }, 9 | "authors": [ 10 | { 11 | "name": "Olliiiver", 12 | "url": "https://github.com/olliiiver/", 13 | "maintainer": true 14 | } 15 | ], 16 | "license": "LGPL-2.1-only", 17 | "version": "0.28", 18 | "frameworks": "*", 19 | "platforms": "*" 20 | } 21 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=SML-Parser 2 | version=0.28 3 | author=Olliiiver 4 | maintainer=Olliiiver 5 | sentence=C++ library to parse Smart Message Language (SML) data from smart meters. 6 | paragraph=SML smart meter parser 7 | category=Data Processing 8 | url=https://github.com/olliiiver/sml_parser 9 | architectures=* 10 | repository=https://github.com/olliiiver/sml_parser.git 11 | license=LGPL-2.1-only 12 | -------------------------------------------------------------------------------- /src/sml.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "sml.h" 5 | #include "smlCrcTable.h" 6 | 7 | #ifdef SML_DEBUG 8 | char logBuff[200]; 9 | 10 | #ifdef SML_NATIVE 11 | #define SML_LOG(...) \ 12 | do { \ 13 | printf(__VA_ARGS__); \ 14 | } while (0) 15 | #define SML_TREELOG(level, ...) \ 16 | do { \ 17 | printf("%.*s", level, " "); \ 18 | printf(__VA_ARGS__); \ 19 | } while (0) 20 | #elif ARDUINO 21 | #include 22 | #define SML_LOG(...) \ 23 | do { \ 24 | sprintf(logBuff, __VA_ARGS__); \ 25 | Serial.print(logBuff); \ 26 | } while (0) 27 | #define SML_TREELOG(level, ...) \ 28 | do { \ 29 | sprintf(logBuff, __VA_ARGS__); \ 30 | Serial.print(logBuff); \ 31 | } while (0) 32 | #endif 33 | 34 | #else 35 | #define SML_LOG(...) \ 36 | do { \ 37 | } while (0) 38 | #define SML_TREELOG(level, ...) \ 39 | do { \ 40 | } while (0) 41 | #endif 42 | 43 | #define MAX_LIST_SIZE 80 44 | #define MAX_TREE_SIZE 10 45 | 46 | static sml_states_t currentState = SML_START; 47 | static char nodes[MAX_TREE_SIZE]; 48 | static unsigned char currentLevel = 0; 49 | static unsigned short crc = 0xFFFF; 50 | static signed char sc; 51 | static unsigned short crcMine = 0xFFFF; 52 | static unsigned short crcReceived = 0x0000; 53 | static unsigned char len = 4; 54 | static unsigned char listBuffer[MAX_LIST_SIZE]; /* keeps a list 55 | as length + state + data */ 56 | static unsigned char listPos = 0; 57 | 58 | void crc16(unsigned char &byte) 59 | { 60 | #ifdef ARDUINO 61 | crc = 62 | pgm_read_word_near(&smlCrcTable[(byte ^ crc) & 0xff]) ^ (crc >> 8 & 0xff); 63 | #else 64 | crc = smlCrcTable[(byte ^ crc) & 0xff] ^ (crc >> 8 & 0xff); 65 | #endif 66 | } 67 | 68 | void setState(sml_states_t state, int byteLen) 69 | { 70 | currentState = state; 71 | len = byteLen; 72 | } 73 | 74 | void pushListBuffer(unsigned char byte) 75 | { 76 | if (listPos < MAX_LIST_SIZE) { 77 | listBuffer[listPos++] = byte; 78 | } 79 | } 80 | 81 | void reduceList() 82 | { 83 | if (currentLevel >= 0 && nodes[currentLevel] > 0) 84 | nodes[currentLevel]--; 85 | } 86 | 87 | void smlNewList(unsigned char size) 88 | { 89 | reduceList(); 90 | if (currentLevel < MAX_TREE_SIZE) 91 | currentLevel++; 92 | nodes[currentLevel] = size; 93 | SML_TREELOG(currentLevel, "LISTSTART on level %i with %i nodes\n", 94 | currentLevel, size); 95 | setState(SML_LISTSTART, size); 96 | // @todo workaround for lists inside obis lists 97 | if (size > 5) { 98 | listPos = 0; 99 | memset(listBuffer, '\0', MAX_LIST_SIZE); 100 | } 101 | else { 102 | pushListBuffer(size); 103 | pushListBuffer(currentState); 104 | } 105 | } 106 | 107 | void checkMagicByte(unsigned char &byte) 108 | { 109 | unsigned int size = 0; 110 | while (currentLevel > 0 && nodes[currentLevel] == 0) { 111 | /* go back in tree if no nodes remaining */ 112 | SML_TREELOG(currentLevel, "back to previous list\n"); 113 | currentLevel--; 114 | } 115 | if (byte > 0x70 && byte <= 0x7F) { 116 | /* new list */ 117 | size = byte & 0x0F; 118 | smlNewList(size); 119 | } 120 | else if (byte >= 0x01 && byte <= 0x6F && nodes[currentLevel] > 0) { 121 | if (byte == 0x01) { 122 | /* no data, get next */ 123 | SML_TREELOG(currentLevel, " Data %i (empty)\n", nodes[currentLevel]); 124 | pushListBuffer(0); 125 | pushListBuffer(currentState); 126 | if (nodes[currentLevel] == 1) { 127 | setState(SML_LISTEND, 1); 128 | SML_TREELOG(currentLevel, "LISTEND\n"); 129 | } 130 | else { 131 | setState(SML_NEXT, 1); 132 | } 133 | } 134 | else { 135 | size = (byte & 0x0F) - 1; 136 | setState(SML_DATA, size); 137 | if ((byte & 0xF0) == 0x50) { 138 | setState(SML_DATA_SIGNED_INT, size); 139 | } 140 | else if ((byte & 0xF0) == 0x60) { 141 | setState(SML_DATA_UNSIGNED_INT, size); 142 | } 143 | else if ((byte & 0xF0) == 0x00) { 144 | setState(SML_DATA_OCTET_STRING, size); 145 | } 146 | SML_TREELOG(currentLevel, 147 | " Data %i (length = %i%s): ", nodes[currentLevel], size, 148 | (currentState == SML_DATA_SIGNED_INT) ? ", signed int" 149 | : (currentState == SML_DATA_UNSIGNED_INT) ? ", unsigned int" 150 | : (currentState == SML_DATA_OCTET_STRING) ? ", octet string" 151 | : ""); 152 | pushListBuffer(size); 153 | pushListBuffer(currentState); 154 | } 155 | reduceList(); 156 | } 157 | else if (byte == 0x00) { 158 | /* end of block */ 159 | reduceList(); 160 | SML_TREELOG(currentLevel, "End of block at level %i\n", currentLevel); 161 | if (currentLevel == 0) { 162 | setState(SML_NEXT, 1); 163 | } 164 | else { 165 | setState(SML_BLOCKEND, 1); 166 | } 167 | } 168 | else if (byte & 0x80) { 169 | // MSB bit is set, another TL byte will follow 170 | if (byte >= 0x80 && byte <= 0x8F) { 171 | // Datatype Octet String 172 | setState(SML_HDATA, (byte & 0x0F) << 4); 173 | } 174 | else if (byte >= 0xF0 && byte <= 0xFF) { 175 | /* Datatype List of ...*/ 176 | setState(SML_LISTEXTENDED, (byte & 0x0F) << 4); 177 | } 178 | } 179 | else if (byte == 0x1B && currentLevel == 0) { 180 | /* end sequence */ 181 | setState(SML_END, 3); 182 | } 183 | else { 184 | /* Unexpected Byte */ 185 | SML_TREELOG(currentLevel, 186 | "UNEXPECTED magicbyte >%02X< at currentLevel %i\n", byte, 187 | currentLevel); 188 | setState(SML_UNEXPECTED, 4); 189 | } 190 | } 191 | 192 | sml_states_t smlState(unsigned char ¤tByte) 193 | { 194 | unsigned char size; 195 | if (len > 0) 196 | len--; 197 | crc16(currentByte); 198 | switch (currentState) { 199 | case SML_UNEXPECTED: 200 | case SML_CHECKSUM_ERROR: 201 | case SML_FINAL: 202 | case SML_START: 203 | currentState = SML_START; 204 | currentLevel = 0; // Reset current level at the begin of a new transmission 205 | // to prevent problems 206 | if (currentByte != 0x1b) 207 | setState(SML_UNEXPECTED, 4); 208 | if (len == 0) { 209 | SML_TREELOG(0, "START\n"); 210 | /* completely clean any garbage from crc checksum */ 211 | crc = 0xFFFF; 212 | currentByte = 0x1b; 213 | crc16(currentByte); 214 | crc16(currentByte); 215 | crc16(currentByte); 216 | crc16(currentByte); 217 | setState(SML_VERSION, 4); 218 | } 219 | break; 220 | case SML_VERSION: 221 | if (currentByte != 0x01) 222 | setState(SML_UNEXPECTED, 4); 223 | if (len == 0) { 224 | setState(SML_BLOCKSTART, 1); 225 | } 226 | break; 227 | case SML_END: 228 | if (currentByte != 0x1b) { 229 | SML_LOG("UNEXPECTED char >%02X< at SML_END\n", currentByte); 230 | setState(SML_UNEXPECTED, 4); 231 | } 232 | if (len == 0) { 233 | setState(SML_CHECKSUM, 4); 234 | } 235 | break; 236 | case SML_CHECKSUM: 237 | // SML_LOG("CHECK: %02X\n", currentByte); 238 | if (len == 2) { 239 | crcMine = crc ^ 0xFFFF; 240 | } 241 | if (len == 1) { 242 | crcReceived += currentByte; 243 | } 244 | if (len == 0) { 245 | crcReceived = crcReceived | (currentByte << 8); 246 | SML_LOG("Received checksum: %02X\n", crcReceived); 247 | SML_LOG("Calculated checksum: %02X\n", crcMine); 248 | if (crcMine == crcReceived) { 249 | setState(SML_FINAL, 4); 250 | } 251 | else { 252 | setState(SML_CHECKSUM_ERROR, 4); 253 | } 254 | crc = 0xFFFF; 255 | crcReceived = 0x000; /* reset CRC */ 256 | } 257 | break; 258 | case SML_HDATA: 259 | size = len + currentByte - 1; 260 | setState(SML_DATA, size); 261 | pushListBuffer(size); 262 | pushListBuffer(currentState); 263 | SML_TREELOG(currentLevel, " Data (length = %i): ", size); 264 | break; 265 | case SML_LISTEXTENDED: 266 | size = len + (currentByte & 0x0F); 267 | SML_TREELOG(currentLevel, "Extended List with Size=%i\n", size); 268 | smlNewList(size); 269 | break; 270 | case SML_DATA: 271 | case SML_DATA_SIGNED_INT: 272 | case SML_DATA_UNSIGNED_INT: 273 | case SML_DATA_OCTET_STRING: 274 | SML_LOG("%02X ", currentByte); 275 | pushListBuffer(currentByte); 276 | if (nodes[currentLevel] == 0 && len == 0) { 277 | SML_LOG("\n"); 278 | SML_TREELOG(currentLevel, "LISTEND on level %i\n", currentLevel); 279 | currentState = SML_LISTEND; 280 | } 281 | else if (len == 0) { 282 | currentState = SML_DATAEND; 283 | SML_LOG("\n"); 284 | } 285 | break; 286 | case SML_DATAEND: 287 | case SML_NEXT: 288 | case SML_LISTSTART: 289 | case SML_LISTEND: 290 | case SML_BLOCKSTART: 291 | case SML_BLOCKEND: 292 | checkMagicByte(currentByte); 293 | break; 294 | } 295 | return currentState; 296 | } 297 | 298 | bool smlOBISCheck(const unsigned char *obis) 299 | { 300 | return (memcmp(obis, &listBuffer[2], 6) == 0); 301 | } 302 | 303 | void smlOBISManufacturer(unsigned char *str, int maxSize) 304 | { 305 | int i = 0, pos = 0, size = 0; 306 | while (i < listPos) { 307 | size = (int)listBuffer[i]; 308 | i++; 309 | pos++; 310 | if (pos == 6) { 311 | /* get manufacturer at position 6 in list */ 312 | size = (size > maxSize - 1) ? maxSize : size; 313 | memcpy(str, &listBuffer[i + 1], size); 314 | str[size + 1] = 0; 315 | } 316 | i += size + 1; 317 | } 318 | } 319 | 320 | void smlPow(double &val, signed char &scaler) 321 | { 322 | if (scaler < 0) { 323 | while (scaler++) { 324 | val /= 10; 325 | } 326 | } 327 | else { 328 | while (scaler--) { 329 | val *= 10; 330 | } 331 | } 332 | } 333 | 334 | void smlOBISByUnit(long long int &val, signed char &scaler, sml_units_t unit) 335 | { 336 | unsigned char i = 0, pos = 0, size = 0, y = 0, skip = 0; 337 | sml_states_t type; 338 | val = -1; /* unknown or error */ 339 | while (i < listPos) { 340 | pos++; 341 | size = (int)listBuffer[i++]; 342 | type = (sml_states_t)listBuffer[i++]; 343 | if (type == SML_LISTSTART && size > 0) { 344 | // skip a list inside an obis list 345 | skip = size; 346 | while (skip > 0) { 347 | size = (int)listBuffer[i++]; 348 | type = (sml_states_t)listBuffer[i++]; 349 | i += size; 350 | skip--; 351 | } 352 | size = 0; 353 | } 354 | if (pos == 4 && listBuffer[i] != unit) { 355 | /* return unknown (-1) if unit does not match */ 356 | return; 357 | } 358 | if (pos == 5) { 359 | scaler = listBuffer[i]; 360 | } 361 | if (pos == 6) { 362 | y = size; 363 | // initialize 64bit signed integer based on MSB from received value 364 | val = 365 | (type == SML_DATA_SIGNED_INT && (listBuffer[i] & (1 << 7))) ? ~0 : 0; 366 | for (y = 0; y < size; y++) { 367 | // left shift received bytes to 64 bit signed integer 368 | val = (val << 8) | listBuffer[i + y]; 369 | } 370 | } 371 | i += size; 372 | } 373 | } 374 | 375 | void smlOBISWh(double &wh) 376 | { 377 | long long int val; 378 | smlOBISByUnit(val, sc, SML_WATT_HOUR); 379 | wh = val; 380 | smlPow(wh, sc); 381 | } 382 | 383 | void smlOBISW(double &w) 384 | { 385 | long long int val; 386 | smlOBISByUnit(val, sc, SML_WATT); 387 | w = val; 388 | smlPow(w, sc); 389 | } 390 | 391 | void smlOBISVolt(double &v) 392 | { 393 | long long int val; 394 | smlOBISByUnit(val, sc, SML_VOLT); 395 | v = val; 396 | smlPow(v, sc); 397 | } 398 | 399 | void smlOBISAmpere(double &a) 400 | { 401 | long long int val; 402 | smlOBISByUnit(val, sc, SML_AMPERE); 403 | a = val; 404 | smlPow(a, sc); 405 | } 406 | 407 | void smlOBISHertz(double &h) 408 | { 409 | long long int val; 410 | smlOBISByUnit(val, sc, SML_HERTZ); 411 | h = val; 412 | smlPow(h, sc); 413 | } 414 | 415 | void smlOBISDegree(double &d) 416 | { 417 | long long int val; 418 | smlOBISByUnit(val, sc, SML_DEGREE); 419 | d = val; 420 | smlPow(d, sc); 421 | } 422 | -------------------------------------------------------------------------------- /src/sml.h: -------------------------------------------------------------------------------- 1 | #ifndef SML_H 2 | #define SML_H 3 | 4 | /*! 5 | * \file Parse and interpret an SML (Smart Message Language) message. 6 | * 7 | * The library uses shared static memory to store the parsed SML message. 8 | * Use \ref smlState to parse the message byte by byte. 9 | * This will store the parsed data in static memory. 10 | * To access values, check whether the OBIS code you are interested in has just 11 | * been parsed via \ref smlOBISCheck and if so, parse that value using \ref 12 | * smlOBISByUnit to get the data in full precision or one of the convenience 13 | * functions like \ref smlOBISW to get the data directly as double in the 14 | * specified unit. 15 | */ 16 | 17 | #include 18 | 19 | typedef enum { 20 | SML_START, 21 | SML_END, 22 | SML_VERSION, 23 | SML_NEXT, 24 | SML_LISTSTART, 25 | SML_LISTEND, 26 | SML_LISTEXTENDED, 27 | SML_DATA, 28 | SML_HDATA, 29 | SML_DATAEND, 30 | SML_BLOCKSTART, 31 | SML_BLOCKEND, 32 | SML_CHECKSUM, 33 | SML_CHECKSUM_ERROR, /* calculated checksum does not match */ 34 | SML_UNEXPECTED, /* unexpected byte received */ 35 | SML_FINAL, /* final state, checksum OK */ 36 | SML_DATA_SIGNED_INT, 37 | SML_DATA_UNSIGNED_INT, 38 | SML_DATA_OCTET_STRING, 39 | } sml_states_t; 40 | 41 | typedef enum { 42 | SML_YEAR = 1, 43 | SML_MONTH = 2, 44 | SML_WEEK = 3, 45 | SML_DAY = 4, 46 | SML_HOUR = 5, 47 | SML_MIN = 6, 48 | SML_SECOND = 7, 49 | SML_DEGREE = 8, 50 | SML_DEGREE_CELSIUS = 9, 51 | SML_CURRENCY = 10, 52 | SML_METRE = 11, 53 | SML_METRE_PER_SECOND = 12, 54 | SML_CUBIC_METRE = 13, 55 | SML_CUBIC_METRE_CORRECTED = 14, 56 | SML_CUBIC_METRE_PER_HOUR = 15, 57 | SML_CUBIC_METRE_PER_HOUR_CORRECTED = 16, 58 | SML_CUBIC_METRE_PER_DAY = 17, 59 | SML_CUBIC_METRE_PER_DAY_CORRECTED = 18, 60 | SML_LITRE = 19, 61 | SML_KILOGRAM = 20, 62 | SML_NEWTON = 21, 63 | SML_NEWTONMETER = 22, 64 | SML_PASCAL = 23, 65 | SML_BAR = 24, 66 | SML_JOULE = 25, 67 | SML_JOULE_PER_HOUR = 26, 68 | SML_WATT = 27, 69 | SML_VOLT_AMPERE = 28, 70 | SML_VAR = 29, 71 | SML_WATT_HOUR = 30, 72 | SML_VOLT_AMPERE_HOUR = 31, 73 | SML_VAR_HOUR = 32, 74 | SML_AMPERE = 33, 75 | SML_COULOMB = 34, 76 | SML_VOLT = 35, 77 | SML_VOLT_PER_METRE = 36, 78 | SML_FARAD = 37, 79 | SML_OHM = 38, 80 | SML_OHM_METRE = 39, 81 | SML_WEBER = 40, 82 | SML_TESLA = 41, 83 | SML_AMPERE_PER_METRE = 42, 84 | SML_HENRY = 43, 85 | SML_HERTZ = 44, 86 | SML_ACTIVE_ENERGY_METER_CONSTANT_OR_PULSE_VALUE = 45, 87 | SML_REACTIVE_ENERGY_METER_CONSTANT_OR_PULSE_VALUE = 46, 88 | SML_APPARENT_ENERGY_METER_CONSTANT_OR_PULSE_VALUE = 47, 89 | SML_VOLT_SQUARED_HOURS = 48, 90 | SML_AMPERE_SQUARED_HOURS = 49, 91 | SML_KILOGRAM_PER_SECOND = 50, 92 | SML_KELVIN = 52, 93 | SML_VOLT_SQUARED_HOUR_METER_CONSTANT_OR_PULSE_VALUE = 53, 94 | SML_AMPERE_SQUARED_HOUR_METER_CONSTANT_OR_PULSE_VALUE = 54, 95 | SML_METER_CONSTANT_OR_PULSE_VALUE = 55, 96 | SML_PERCENTAGE = 56, 97 | SML_AMPERE_HOUR = 57, 98 | SML_ENERGY_PER_VOLUME = 60, 99 | SML_CALORIFIC_VALUE = 61, 100 | SML_MOLE_PERCENT = 62, 101 | SML_MASS_DENSITY = 63, 102 | SML_PASCAL_SECOND = 64, 103 | SML_RESERVED = 253, 104 | SML_OTHER_UNIT = 254, 105 | SML_COUNT = 255 106 | } sml_units_t; 107 | 108 | /*! Parse a single byte of an SML message and return the status after parsing 109 | * that. */ 110 | sml_states_t smlState(unsigned char &byte); 111 | 112 | /* ! Return whether the 6-character OBIS identifier (binary encoded) matches to 113 | * the last received message. 114 | * If it does, use one of the specific functions to retrieve the value. 115 | * 116 | * Calling this function makes sense after a list was received and parsed, i.e. 117 | * after the state was \ref SML_LISTEND . 118 | * 119 | * OBIS (Object Identification System) identifies the kind of message that was 120 | * received in the format `A-B:C.D.E*F`, the encoding in \p obis is 121 | * an array `{A, B, C, D, E, F}`. 122 | * For example `{0x01, 0x00, 0x01, 0x08, 0x01, 0xff}` encodes `1-0:1.8.1*255`, 123 | which is the electric meter reading. 124 | * If the message matches this particular OBIS identifier, we know that a meter 125 | reading in Wh (Watt hours) was received and we can then read it using \ref 126 | smlOBISWh. 127 | */ 128 | bool smlOBISCheck(const unsigned char *obis); 129 | 130 | /*! Copy the first \p maxSize bytes of the name/identifier of the manufacturer 131 | * into buffer \p str. Use this after reading OBIS code `{0x81, 0x81, 0xc7, 132 | * 0x82, 0x03, 0xff}` i.e. 129-129:199.130.3*255. 133 | */ 134 | void smlOBISManufacturer(unsigned char *str, int maxSize); 135 | 136 | /*! Copy the value last read into \p val and the read scaler into \p scaler and 137 | * ensure that it has unit \p unit . If the unit was assumed wrongly, set \p val 138 | * to -1. 139 | * The final value is `val x 10^scaler`. 140 | * 141 | * There are 'convenience' functions that wrap this function to return the 142 | * actual value as double, see below. 143 | * 144 | * \return nothing, but set \p val to -1 in case of an error. 145 | */ 146 | void smlOBISByUnit(long long int &val, signed char &scaler, sml_units_t unit); 147 | 148 | // Be aware that double on Arduino UNO is just 32 bit 149 | 150 | /*! Convenience function to get a reading in Watt hours.*/ 151 | void smlOBISWh(double &wh); 152 | /*! Convenience function to get a reading in Watts.*/ 153 | void smlOBISW(double &w); 154 | /*! Convenience function to get a reading in Volts.*/ 155 | void smlOBISVolt(double &v); 156 | /*! Convenience function to get a reading in Amperes.*/ 157 | void smlOBISAmpere(double &a); 158 | /*! Convenience function to get a reading in Hertz.*/ 159 | void smlOBISHertz(double &h); 160 | /*! Convenience function to get a reading in Degrees.*/ 161 | void smlOBISDegree(double &d); 162 | 163 | #endif 164 | -------------------------------------------------------------------------------- /src/smlCrcTable.h: -------------------------------------------------------------------------------- 1 | #ifndef SML_CRC_TABLE_H 2 | #define SML_CRC_TABLE_H 3 | 4 | #include 5 | 6 | #ifdef ARDUINO 7 | #include 8 | static const uint16_t smlCrcTable[256] PROGMEM = 9 | #else 10 | static const uint16_t smlCrcTable[256] = 11 | #endif 12 | {0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 13 | 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7, 0x1081, 0x0108, 14 | 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 15 | 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876, 0x2102, 0x308B, 0x0210, 0x1399, 16 | 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 17 | 0xFAE7, 0xC87C, 0xD9F5, 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 18 | 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 19 | 0xC974, 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB, 20 | 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3, 0x5285, 21 | 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 22 | 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72, 0x6306, 0x728F, 0x4014, 23 | 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 24 | 0xA96A, 0xB8E3, 0x8A78, 0x9BF1, 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 25 | 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 26 | 0x9AF9, 0x8B70, 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 27 | 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF, 28 | 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 29 | 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E, 0xA50A, 0xB483, 30 | 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5, 0x2942, 0x38CB, 0x0A50, 31 | 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD, 0xB58B, 0xA402, 0x9699, 0x8710, 32 | 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 33 | 0x6E6E, 0x5CF5, 0x4D7C, 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 34 | 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 35 | 0x3EFB, 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 36 | 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A, 0xE70E, 37 | 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 38 | 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9, 0xF78F, 0xE606, 0xD49D, 39 | 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 40 | 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78}; 41 | 42 | #endif -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Unity tests 2 | 3 | Test the library on our local machine (native) or on MCUs. 4 | 5 | Execute only local tests: 6 | 7 | ``` 8 | pio test -e native 9 | ``` 10 | -------------------------------------------------------------------------------- /test/platformio.ini: -------------------------------------------------------------------------------- 1 | [platformio] 2 | src_dir = ./ 3 | 4 | [env:native] 5 | platform = native 6 | lib_deps = ../src 7 | build_flags = -D SML_DEBUG -D SML_NATIVE -Wall -D UNITY_INCLUDE_DOUBLE 8 | 9 | [env:uno] 10 | platform = atmelavr 11 | board = uno 12 | framework = arduino 13 | ;board_build.mcu = atmega328p 14 | ;board_build.f_cpu = 16000000L 15 | build_flags = -D SML_DEBUG -D UNITY_INCLUDE_DOUBLE 16 | lib_deps = ../src 17 | -------------------------------------------------------------------------------- /test/test/test_56bit/ehz_bin.h: -------------------------------------------------------------------------------- 1 | // clang-format off 2 | // Formatted example data from https://github.com/devZer0/libsml-testing 3 | 4 | const unsigned char ehz_bin[] = { 5 | /* Start */ 0x1b, 0x1b, 0x1b, 0x1b, 6 | /* Version */ 0x01, 0x01, 0x01, 0x01, 7 | 8 | /* List (6 entries) */ 0x76, 9 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2d, 10 | /* 2. Group No */ 0x62, 0x00, 11 | /* 3. Abort On Error */ 0x62, 0x00, 12 | /* 4. List (2 entries) */ 0x72, 13 | /* 1. getOpenResponse */ 0x63, 0x01, 0x01, 14 | /* 2. List (6 entries) */ 0x76, 15 | /* 1. code page */ 0x01, 16 | /* 2. clientid */ 0x01, 17 | /* 3. Transaction ID */ 0x07, 0x00, 0x0c, 0x06, 0x9e, 0x2d, 0x0f, 18 | /* 4. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 19 | /* 5. List name */ 0x01, 20 | /* 6. Time */ 0x01, 21 | /* 5. CRC */ 0x63, 0x2b, 0x8e, 22 | /* 6. END */ 0x00, 23 | 24 | /* List (6 entries) */ 0x76, 25 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2e, 26 | /* 2. Group No */ 0x62, 0x00, 27 | /* 3. Abort On Error */ 0x62, 0x00, 28 | /* 4. Message Body (2) */ 0x72, 29 | /* 1. getListResponse */ 0x63, 0x07, 0x01, 30 | /* 2. List (7) */ 0x77, 31 | /* 1. ClientId */ 0x01, 32 | /* 2. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 33 | /* 3. ?? */ 0x01, 34 | /* 4. List (2) */ 0x72, 35 | /* 1. ?? */ 0x62, 0x01, 36 | /* 2. ?? */ 0x65, 0x06, 0x9e, 0xfa, 0x83, 37 | /* 5. List (7) */ 0x77, 38 | /* 1. List (7) */ 0x77, 39 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 40 | /* 2. */ 0x01, 41 | /* 3. */ 0x01, 42 | /* 4. */ 0x01, 43 | /* 5. */ 0x01, 44 | /* 6. */ 0x04, 0x45, 0x4d, 0x48, 45 | /* 7. */ 0x01, 46 | /* 2. List (7) */ 0x77, 47 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 48 | /* 2. */ 0x01, 49 | /* 3. */ 0x01, 50 | /* 4. */ 0x01, 51 | /* 5. */ 0x01, 52 | /* 6. */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 53 | /* 7. */ 0x01, 54 | /* 3. List (7) */ 0x77, 55 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 56 | /* 2. */ 0x63, 0x01, 0x82, 57 | /* 3. */ 0x01, 58 | /* 4. */ 0x62, 0x1e, 59 | /* 5. */ 0x52, 0x03, 60 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x1C, 0x46, 61 | /* 7. */ 0x01, 62 | /* 4. List (7) */ 0x77, 63 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x01, 0xff, 64 | /* 2. */ 0x01, 65 | /* 3. */ 0x01, 66 | /* 4. Unit */ 0x62, 0x1e, 67 | /* 5. Scaler */ 0x52, 0xff, 68 | /* 6 Value */ 0x59, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 69 | /* 7 */ 0x01, 70 | /* 5. List (7) */ 0x77, 71 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x02, 0xff, 72 | /* 2. */ 0x01, 73 | /* 3. */ 0x01, 74 | /* 4. */ 0x62, 0x1e, 75 | /* 5. */ 0x52, 0x03, 76 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x1C, 0x46, 77 | /* 7. */ 0x01, 78 | /* 6. List (7) */ 0x77, 79 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x0f, 0x07, 0x00, 0xff, 80 | /* 2. */ 0x01, 81 | /* 3. */ 0x01, 82 | /* 4. */ 0x62, 0x1b, 83 | /* 5. */ 0x52, 0xff, 84 | /* 6. */ 0x55, 0x00, 0x00, 0x2f, 0x65, 85 | /* 7. */ 0x01, 86 | /* 7. List (7) */ 0x77, 87 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 88 | /* 2. */ 0x01, 89 | /* 3. */ 0x01, 90 | /* 4. */ 0x01, 91 | /* 5. */ 0x01, 92 | /* 6. Public Key */ 0x83, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 93 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 94 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 95 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 96 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 97 | /* 7. */ 0x01, 98 | 0x01, 99 | 0x01, 100 | 0x63, 0xb9, 0x3f, 101 | 0x00, 102 | /* List (6) */ 0x76, 103 | /* 1. */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x31, 104 | /* 2. */ 0x62, 0x00, 105 | /* 3. */ 0x62, 0x00, 106 | /* 4. List (2) */ 0x72, 107 | /* 1. */ 0x63, 0x02, 0x01, 108 | /* List (1) */ 0x71, 109 | /* 1. */ 0x01, 110 | /* 5. CRC */ 0x63, 0x6a, 0x53, 111 | /* 6. */ 0x00, 112 | 113 | 0x00, 114 | 0x1b, 0x1b, 0x1b, 0x1b, 115 | 0x1a, 0x01, 0xba, 0x1a 116 | }; 117 | const unsigned int ehz_bin_len = 319; 118 | 119 | -------------------------------------------------------------------------------- /test/test/test_56bit/test.cpp: -------------------------------------------------------------------------------- 1 | #include "ehz_bin.h" 2 | #include "sml.h" 3 | #include "unity.h" 4 | #ifdef ARDUINO 5 | #include "arduino.h" 6 | #endif 7 | 8 | typedef struct { 9 | const unsigned char OBIS[6]; 10 | void (*Handler)(); 11 | } OBISHandler; 12 | 13 | #define MAX_STR_MANUF 5 14 | unsigned char manuf[MAX_STR_MANUF]; 15 | double SumWh = -2; 16 | long long int T1Wh = -2; 17 | bool isFinal = false; 18 | 19 | void Manufacturer() { smlOBISManufacturer(manuf, MAX_STR_MANUF); } 20 | void PowerT1() 21 | { 22 | signed char sc = 0; 23 | smlOBISByUnit(T1Wh, sc, SML_WATT_HOUR); 24 | } 25 | 26 | void PowerSum() { smlOBISWh(SumWh); } 27 | 28 | // clang-format off 29 | OBISHandler OBISHandlers[] = { 30 | {{ 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff }, &Manufacturer}, /* 129-129:199.130.3*255 */ 31 | {{ 0x01, 0x00, 0x01, 0x08, 0x01, 0xff }, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 32 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 33 | {{ 0, 0 }} 34 | }; 35 | // clang-format on 36 | 37 | void setUp(void) 38 | { 39 | unsigned int i = 0; 40 | int iHandler = 0; 41 | unsigned char c; 42 | sml_states_t s; 43 | manuf[0] = 0; 44 | 45 | for (i = 0; i < ehz_bin_len; ++i) { 46 | c = ehz_bin[i]; 47 | s = smlState(c); 48 | if (s == SML_LISTEND) { 49 | /* check handlers on last received list */ 50 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 51 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 52 | iHandler++) 53 | ; 54 | if (OBISHandlers[iHandler].Handler != 0) { 55 | OBISHandlers[iHandler].Handler(); 56 | } 57 | } 58 | if (s == SML_FINAL) { 59 | isFinal = true; 60 | } 61 | } 62 | } 63 | 64 | void test_should_return_manufacturer(void) 65 | { 66 | TEST_ASSERT_EQUAL_STRING("EMH", manuf); 67 | } 68 | 69 | void test_should_return_t1_56bit(void) 70 | { 71 | TEST_ASSERT_EQUAL_INT(72057594037927935, T1Wh); 72 | } 73 | 74 | void test_should_return_SumWh(void) 75 | { 76 | TEST_ASSERT_EQUAL_DOUBLE(7238000, SumWh); 77 | } 78 | 79 | void test_should_be_final(void) { TEST_ASSERT_EQUAL_INT(1, isFinal); } 80 | 81 | int runUnityTests(void) 82 | { 83 | UNITY_BEGIN(); 84 | RUN_TEST(test_should_return_manufacturer); 85 | RUN_TEST(test_should_return_t1_56bit); 86 | RUN_TEST(test_should_return_SumWh); 87 | RUN_TEST(test_should_be_final); 88 | return UNITY_END(); 89 | } 90 | 91 | /** 92 | * For native dev-platform or for some embedded frameworks 93 | */ 94 | int main(void) { return runUnityTests(); } 95 | 96 | /** 97 | * For Arduino framework 98 | */ 99 | void setup() 100 | { 101 | // Wait ~2 seconds before the Unity test runner 102 | // establishes connection with a board Serial interface 103 | #ifdef ARDUINO 104 | delay(2000); 105 | #endif 106 | runUnityTests(); 107 | } 108 | void loop() {} 109 | 110 | /** 111 | * For ESP-IDF framework 112 | */ 113 | void app_main() { runUnityTests(); } 114 | -------------------------------------------------------------------------------- /test/test/test_EMH/ehz_bin.h: -------------------------------------------------------------------------------- 1 | // clang-format off 2 | // Formatted example data from https://github.com/devZer0/libsml-testing 3 | 4 | const unsigned char ehz_bin[] = { 5 | /* Start */ 0x1b, 0x1b, 0x1b, 0x1b, 6 | /* Version */ 0x01, 0x01, 0x01, 0x01, 7 | 8 | /* List (6 entries) */ 0x76, 9 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2d, 10 | /* 2. Group No */ 0x62, 0x00, 11 | /* 3. Abort On Error */ 0x62, 0x00, 12 | /* 4. List (2 entries) */ 0x72, 13 | /* 1. getOpenResponse */ 0x63, 0x01, 0x01, 14 | /* 2. List (6 entries) */ 0x76, 15 | /* 1. code page */ 0x01, 16 | /* 2. clientid */ 0x01, 17 | /* 3. Transaction ID */ 0x07, 0x00, 0x0c, 0x06, 0x9e, 0x2d, 0x0f, 18 | /* 4. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 19 | /* 5. List name */ 0x01, 20 | /* 6. Time */ 0x01, 21 | /* 5. CRC */ 0x63, 0x2b, 0x8e, 22 | /* 6. END */ 0x00, 23 | 24 | /* List (6 entries) */ 0x76, 25 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2e, 26 | /* 2. Group No */ 0x62, 0x00, 27 | /* 3. Abort On Error */ 0x62, 0x00, 28 | /* 4. Message Body (2) */ 0x72, 29 | /* 1. getListResponse */ 0x63, 0x07, 0x01, 30 | /* 2. List (7) */ 0x77, 31 | /* 1. ClientId */ 0x01, 32 | /* 2. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 33 | /* 3. ?? */ 0x01, 34 | /* 4. List (2) */ 0x72, 35 | /* 1. ?? */ 0x62, 0x01, 36 | /* 2. ?? */ 0x65, 0x06, 0x9e, 0xfa, 0x83, 37 | /* 5. List (7) */ 0x77, 38 | /* 1. List (7) */ 0x77, 39 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 40 | /* 2. */ 0x01, 41 | /* 3. */ 0x01, 42 | /* 4. */ 0x01, 43 | /* 5. */ 0x01, 44 | /* 6. */ 0x04, 0x45, 0x4d, 0x48, 45 | /* 7. */ 0x01, 46 | /* 2. List (7) */ 0x77, 47 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 48 | /* 2. */ 0x01, 49 | /* 3. */ 0x01, 50 | /* 4. */ 0x01, 51 | /* 5. */ 0x01, 52 | /* 6. */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 53 | /* 7. */ 0x01, 54 | /* 3. List (7) */ 0x77, 55 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 56 | /* 2. */ 0x63, 0x01, 0x82, 57 | /* 3. */ 0x01, 58 | /* 4. */ 0x62, 0x1e, 59 | /* 5. */ 0x52, 0x03, 60 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x1C, 0x46, 61 | /* 7. */ 0x01, 62 | /* 4. List (7) */ 0x77, 63 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x01, 0xff, 64 | /* 2. */ 0x01, 65 | /* 3. */ 0x01, 66 | /* 4. Unit */ 0x62, 0x1e, 67 | /* 5. Scaler */ 0x52, 0xff, 68 | /* 6 Value */ 0x59, 0x00, 0x00, 0x00, 0x00, 0x07, 0x5b, 0xcd, 0x15, 69 | /* 7 */ 0x01, 70 | /* 5. List (7) */ 0x77, 71 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x02, 0xff, 72 | /* 2. */ 0x01, 73 | /* 3. */ 0x01, 74 | /* 4. */ 0x62, 0x1e, 75 | /* 5. */ 0x52, 0x03, 76 | /* 6. */ 0x56, 0x00, 0x00, 0x00, 0x1C, 0x46, 77 | /* 7. */ 0x01, 78 | /* 6. List (7) */ 0x77, 79 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x0f, 0x07, 0x00, 0xff, 80 | /* 2. */ 0x01, 81 | /* 3. */ 0x01, 82 | /* 4. */ 0x62, 0x1b, 83 | /* 5. */ 0x52, 0xff, 84 | /* 6. */ 0x55, 0x00, 0x00, 0x2f, 0x65, 85 | /* 7. */ 0x01, 86 | /* 7. List (7) */ 0x77, 87 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 88 | /* 2. */ 0x01, 89 | /* 3. */ 0x01, 90 | /* 4. */ 0x01, 91 | /* 5. */ 0x01, 92 | /* 6. Public Key */ 0x83, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 93 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 94 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 95 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 96 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 97 | /* 7. */ 0x01, 98 | 0x01, 99 | 0x01, 100 | 0x63, 0xb9, 0x3f, 101 | 0x00, 102 | /* List (6) */ 0x76, 103 | /* 1. */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x31, 104 | /* 2. */ 0x62, 0x00, 105 | /* 3. */ 0x62, 0x00, 106 | /* 4. List (2) */ 0x72, 107 | /* 1. */ 0x63, 0x02, 0x01, 108 | /* List (1) */ 0x71, 109 | /* 1. */ 0x01, 110 | /* 5. CRC */ 0x63, 0x6a, 0x53, 111 | /* 6. */ 0x00, 112 | 113 | 0x00, 114 | 0x1b, 0x1b, 0x1b, 0x1b, 115 | 0x1a, 0x01, 0xe8, 0xc6 116 | }; 117 | const unsigned int ehz_bin_len = 319; 118 | 119 | -------------------------------------------------------------------------------- /test/test/test_EMH/test.cpp: -------------------------------------------------------------------------------- 1 | #include "ehz_bin.h" 2 | #include "sml.h" 3 | #include "unity.h" 4 | #ifdef ARDUINO 5 | #include "arduino.h" 6 | #endif 7 | 8 | typedef struct { 9 | const unsigned char OBIS[6]; 10 | void (*Handler)(); 11 | } OBISHandler; 12 | 13 | #define MAX_STR_MANUF 5 14 | unsigned char manuf[MAX_STR_MANUF]; 15 | double T1Wh = -2, SumWh = -2; 16 | bool isFinal = false; 17 | 18 | void Manufacturer() { smlOBISManufacturer(manuf, MAX_STR_MANUF); } 19 | void PowerT1() { smlOBISWh(T1Wh); } 20 | void PowerSum() { smlOBISWh(SumWh); } 21 | 22 | // clang-format off 23 | OBISHandler OBISHandlers[] = { 24 | {{ 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff }, &Manufacturer}, /* 129-129:199.130.3*255 */ 25 | {{ 0x01, 0x00, 0x01, 0x08, 0x01, 0xff }, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 26 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 27 | {{ 0, 0 }} 28 | }; 29 | // clang-format on 30 | 31 | void setUp(void) 32 | { 33 | unsigned int i = 0; 34 | int iHandler = 0; 35 | unsigned char c; 36 | sml_states_t s; 37 | manuf[0] = 0; 38 | 39 | for (i = 0; i < ehz_bin_len; ++i) { 40 | c = ehz_bin[i]; 41 | s = smlState(c); 42 | if (s == SML_LISTEND) { 43 | /* check handlers on last received list */ 44 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 45 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 46 | iHandler++) 47 | ; 48 | if (OBISHandlers[iHandler].Handler != 0) { 49 | OBISHandlers[iHandler].Handler(); 50 | } 51 | } 52 | if (s == SML_FINAL) { 53 | isFinal = true; 54 | } 55 | } 56 | } 57 | 58 | void test_should_return_manufacturer(void) 59 | { 60 | TEST_ASSERT_EQUAL_STRING("EMH", manuf); 61 | } 62 | 63 | void test_should_return_t1(void) { TEST_ASSERT_EQUAL_DOUBLE(12345678.9, T1Wh); } 64 | 65 | void test_should_return_SumWh(void) 66 | { 67 | TEST_ASSERT_EQUAL_DOUBLE(7238000, SumWh); 68 | } 69 | 70 | void test_should_be_final(void) { TEST_ASSERT_EQUAL_INT(1, isFinal); } 71 | 72 | int runUnityTests(void) 73 | { 74 | UNITY_BEGIN(); 75 | RUN_TEST(test_should_return_manufacturer); 76 | RUN_TEST(test_should_return_t1); 77 | RUN_TEST(test_should_return_SumWh); 78 | RUN_TEST(test_should_be_final); 79 | return UNITY_END(); 80 | } 81 | 82 | /** 83 | * For native dev-platform or for some embedded frameworks 84 | */ 85 | int main(void) { return runUnityTests(); } 86 | 87 | /** 88 | * For Arduino framework 89 | */ 90 | void setup() 91 | { 92 | // Wait ~2 seconds before the Unity test runner 93 | // establishes connection with a board Serial interface 94 | #ifdef ARDUINO 95 | delay(2000); 96 | #endif 97 | runUnityTests(); 98 | } 99 | void loop() {} 100 | 101 | /** 102 | * For ESP-IDF framework 103 | */ 104 | void app_main() { runUnityTests(); } 105 | -------------------------------------------------------------------------------- /test/test/test_ESY/data_bin.h: -------------------------------------------------------------------------------- 1 | 2 | #ifdef ARDUINO 3 | #include 4 | static const unsigned char data_bin[] PROGMEM = 5 | #else 6 | static const unsigned char data_bin[] = 7 | #endif 8 | {0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xf2, 9 | 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 0x09, 10 | 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 0x00, 11 | 0x62, 0x0a, 0xff, 0xff, 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 0x6d, 12 | 0x7e, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 0x01, 13 | 0x01, 0x04, 0x45, 0x53, 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 14 | 0x09, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 15 | 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 0x08, 16 | 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 17 | 0x00, 0x00, 0x00, 0x06, 0xd9, 0x5b, 0x83, 0x57, 0x01, 0x77, 0x07, 0x01, 18 | 0x00, 0x02, 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 19 | 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 0x01, 20 | 0x77, 0x07, 0x01, 0x00, 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 21 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2a, 0x16, 0x01, 22 | 0x77, 0x07, 0x01, 0x00, 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 23 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x0a, 0x01, 24 | 0x77, 0x07, 0x01, 0x00, 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 25 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xf4, 0x01, 26 | 0x77, 0x07, 0x01, 0x00, 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 27 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x18, 0x01, 28 | 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 0x01, 29 | 0x83, 0x02, 0x1a, 0x24, 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 0x10, 30 | 0x93, 0x05, 0x5b, 0xee, 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 0xd1, 31 | 0x9d, 0x4f, 0xaf, 0x3e, 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 0xda, 32 | 0xe9, 0xea, 0x15, 0x66, 0xed, 0x72, 0x7d, 0x23, 0x6a, 0xaf, 0x5a, 0xb0, 33 | 0x9a, 0x5b, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 34 | 0x01, 0x01, 0x01, 0x0f, 0x31, 0x45, 0x53, 0x59, 0x31, 0x31, 0x36, 0x32, 35 | 0x32, 0x33, 0x32, 0x39, 0x39, 0x37, 0x01, 0x77, 0x07, 0x01, 0x00, 0x20, 36 | 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x15, 37 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x34, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 38 | 0x23, 0x52, 0xff, 0x63, 0x09, 0x06, 0x01, 0x77, 0x07, 0x01, 0x00, 0x48, 39 | 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x15, 40 | 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0xf0, 0x06, 0xff, 0x01, 0x01, 0x01, 41 | 0x01, 0x04, 0x01, 0x07, 0x1e, 0x01, 0x01, 0x01, 0x63, 0x87, 0xc1, 0x00, 42 | 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xf3, 43 | 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 0xd3, 44 | 0xec, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x03, 0x3a, 45 | 0x23, 0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01, 0x76, 0x0b, 0x45, 46 | 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xf4, 0x62, 0x00, 0x62, 47 | 0x00, 0x72, 0x63, 0x01, 0x01, 0x76, 0x01, 0x04, 0x45, 0x53, 0x59, 0x08, 48 | 0x45, 0x53, 0x59, 0xdf, 0x6e, 0x9a, 0xf4, 0x0b, 0x09, 0x01, 0x45, 0x53, 49 | 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x01, 0x63, 0x8c, 0xff, 0x00, 50 | 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xf5, 51 | 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 0x09, 52 | 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 0x00, 53 | 0x62, 0x0a, 0xff, 0xff, 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 0x6e, 54 | 0x7e, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 0x01, 55 | 0x01, 0x04, 0x45, 0x53, 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 56 | 0x09, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 57 | 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 0x08, 58 | 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 59 | 0x00, 0x00, 0x00, 0x06, 0xd9, 0x5b, 0x8c, 0x64, 0x01, 0x77, 0x07, 0x01, 60 | 0x00, 0x02, 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 61 | 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 0x01, 62 | 0x77, 0x07, 0x01, 0x00, 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 63 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x45, 0xbd, 0x01, 64 | 0x77, 0x07, 0x01, 0x00, 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 65 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x58, 0x01, 66 | 0x77, 0x07, 0x01, 0x00, 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 67 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x3e, 0x01, 68 | 0x77, 0x07, 0x01, 0x00, 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 69 | 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x25, 0x01, 70 | 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 0x01, 71 | 0x83, 0x02, 0x1a, 0x24, 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 0x10, 72 | 0x93, 0x05, 0x5b, 0xee, 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 0xd1, 73 | 0x9d, 0x4f, 0xaf, 0x3e, 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 0xda, 74 | 0xe9, 0xea, 0x15, 0x66, 0xed, 0x72, 0x7d, 0x23, 0x6a, 0xaf, 0x5a, 0xb0, 75 | 0x9a, 0x5b, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 76 | 0x01, 0x01, 0x01, 0x0f, 0x31, 0x45, 0x53, 0x59, 0x31, 0x31, 0x36, 0x32, 77 | 0x32, 0x33, 0x32, 0x39, 0x39, 0x37, 0x01, 0x77, 0x07, 0x01, 0x00, 0x20, 78 | 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x16, 79 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x34, 0x07, 0x00, 0xff, 0x52, 0xff, 0x63, 80 | 0x09, 0x07, 0x01, 0x77, 0x07, 0x01, 0x00, 0x48, 0x07, 0x00, 0xff, 0x01, 81 | 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x16, 0x01, 0x77, 0x07, 0x81, 82 | 0x81, 0xc7, 0xf0, 0x06, 0xff, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x07, 83 | 0x1e, 0x01, 0x01, 0x01, 0x63, 0x8d, 0xa4, 0x00, 0x76, 0x0b, 0x45, 0x53, 84 | 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xf6, 0x62, 0x00, 0x62, 0x00, 85 | 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 0x17, 0xe7, 0x00, 0x00, 0x00, 86 | 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x03, 0x7b, 0xd3, 0x1b, 0x1b, 0x1b, 87 | 0x1b, 0x01, 0x01, 0x01, 0x01, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 88 | 0xa5, 0x02, 0xea, 0x9a, 0xf7, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x01, 89 | 0x01, 0x76, 0x01, 0x04, 0x45, 0x53, 0x59, 0x08, 0x45, 0x53, 0x59, 0xdf, 90 | 0x6f, 0x9a, 0xf7, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 91 | 0x99, 0xa5, 0x01, 0x01, 0x63, 0x62, 0x0e, 0x00, 0x76, 0x0b, 0x45, 0x53, 92 | 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xf8, 0x62, 0x00, 0x62, 0x00, 93 | 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 94 | 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 0x00, 0x62, 0x0a, 0xff, 0xff, 95 | 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 0x6f, 0x7e, 0x77, 0x07, 0x81, 96 | 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 0x01, 0x01, 0x04, 0x45, 0x53, 97 | 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 0x01, 0x01, 98 | 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 99 | 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 0x64, 0x00, 100 | 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x06, 101 | 0xd9, 0x5b, 0x95, 0x2e, 0x01, 0x77, 0x07, 0x01, 0x00, 0x02, 0x08, 0x00, 102 | 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 0x00, 103 | 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 0x01, 0x77, 0x07, 0x01, 0x00, 104 | 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 105 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x3c, 0x82, 0x01, 0x77, 0x07, 0x01, 0x00, 106 | 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 107 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x5b, 0x01, 0x77, 0x07, 0x01, 0x00, 108 | 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xaf, 0x01, 0x77, 0x07, 0x01, 0x00, 110 | 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 111 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x77, 0x01, 0x77, 0x07, 0x81, 0x81, 112 | 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 0x01, 0x83, 0x02, 0x1a, 0x24, 113 | 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 0x10, 0x93, 0x05, 0x5b, 0xee, 114 | 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 0xd1, 0x9d, 0x4f, 0xaf, 0x3e, 115 | 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 0xda, 0xe9, 0xea, 0x15, 0x66, 116 | 0xed, 0x72, 0x7d, 0x23, 0x6a, 0xaf, 0x5a, 0xb0, 0x9a, 0x5b, 0x01, 0x77, 117 | 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0f, 118 | 0x31, 0x45, 0x53, 0x59, 0x31, 0x31, 0x36, 0x32, 0x32, 0x33, 0x32, 0x39, 119 | 0x39, 0x37, 0x01, 0x77, 0x07, 0x01, 0x00, 0x20, 0x07, 0x00, 0xff, 0x01, 120 | 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x15, 0x01, 0x77, 0x07, 0x01, 121 | 0x00, 0x34, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 122 | 0x09, 0x03, 0x01, 0x77, 0x07, 0x01, 0x00, 0x48, 0x07, 0x00, 0xff, 0x01, 123 | 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x15, 0x01, 0x77, 0x07, 0x81, 124 | 0x81, 0xc7, 0xf0, 0x06, 0xff, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x07, 125 | 0x1e, 0x01, 0x01, 0x01, 0x63, 0x62, 0xbc, 0x00, 0x76, 0x0b, 0x45, 0x53, 126 | 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xf9, 0x62, 0x00, 0x62, 0x00, 127 | 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 0x5b, 0xfb, 0x00, 0x00, 0x00, 128 | 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x03, 0xf8, 0xb1, 0x1b, 0x1b, 0x1b, 129 | 0x1b, 0x01, 0x01, 0x01, 0x01, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 130 | 0xa5, 0x02, 0xea, 0x9a, 0xfa, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x01, 131 | 0x01, 0x76, 0x01, 0x04, 0x45, 0x53, 0x59, 0x08, 0x45, 0x53, 0x59, 0xdf, 132 | 0x70, 0x9a, 0xfa, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 133 | 0x99, 0xa5, 0x01, 0x01, 0x63, 0x21, 0x68, 0x00, 0x76, 0x0b, 0x45, 0x53, 134 | 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xfb, 0x62, 0x00, 0x62, 0x00, 135 | 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 136 | 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 0x00, 0x62, 0x0a, 0xff, 0xff, 137 | 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 0x70, 0x7e, 0x77, 0x07, 0x81, 138 | 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 0x01, 0x01, 0x04, 0x45, 0x53, 139 | 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 0x01, 0x01, 140 | 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 141 | 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 0x64, 0x00, 142 | 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x06, 143 | 0xd9, 0x5b, 0x9d, 0x76, 0x01, 0x77, 0x07, 0x01, 0x00, 0x02, 0x08, 0x00, 144 | 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 0x00, 145 | 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 0x01, 0x77, 0x07, 0x01, 0x00, 146 | 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 147 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x2a, 0x14, 0x01, 0x77, 0x07, 0x01, 0x00, 148 | 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 149 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xee, 0x01, 0x77, 0x07, 0x01, 0x00, 150 | 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 151 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x2f, 0x01, 0x77, 0x07, 0x01, 0x00, 152 | 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 153 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0xf6, 0x01, 0x77, 0x07, 0x81, 0x81, 154 | 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 0x01, 0x83, 0x02, 0x1a, 0x24, 155 | 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 0x10, 0x93, 0x05, 0x5b, 0xee, 156 | 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 0xd1, 0x9d, 0x4f, 0xaf, 0x3e, 157 | 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 0xda, 0xe9, 0xea, 0x15, 0x66, 158 | 0xed, 0x72, 0x7d, 0x23, 0x6a, 0xaf, 0x5a, 0xb0, 0x9a, 0x5b, 0x01, 0x77, 159 | 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0f, 160 | 0x31, 0x45, 0x53, 0x59, 0x31, 0x31, 0x36, 0x32, 0x32, 0x33, 0x32, 0x39, 161 | 0x39, 0x37, 0x01, 0x77, 0x07, 0x01, 0x00, 0x20, 0x07, 0x00, 0xff, 0x01, 162 | 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x14, 0x01, 0x77, 0x07, 0x01, 163 | 0x00, 0x34, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 164 | 0x09, 0x02, 0x01, 0x77, 0x07, 0x01, 0x00, 0x48, 0x07, 0x00, 0xff, 0x01, 165 | 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x12, 0x01, 0x77, 0x07, 0x81, 166 | 0x81, 0xc7, 0xf0, 0x06, 0xff, 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x07, 167 | 0x1e, 0x01, 0x01, 0x01, 0x63, 0x25, 0x0c, 0x00, 0x76, 0x0b, 0x45, 0x53, 168 | 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xfc, 0x62, 0x00, 0x62, 0x00, 169 | 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 0x9f, 0xf0, 0x00, 0x00, 0x00, 170 | 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x03, 0x34, 0x5c, 0x1b, 0x1b, 0x1b, 171 | 0x1b, 0x01, 0x01, 0x01, 0x01, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 172 | 0xa5, 0x02, 0xea, 0x9a, 0xfd, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x01, 173 | 0x01, 0x76, 0x01, 0x04, 0x45, 0x53, 0x59, 0x08, 0x45, 0x53, 0x59, 0xdf, 174 | 0x71, 0x9a, 0xfd, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 175 | 0x99, 0xa5, 0x01, 0x01, 0x63, 0x68, 0xcb, 0x00, 0x76, 0x0b, 0x45, 0x53, 176 | 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9a, 0xfe, 0x62, 0x00, 0x62, 0x00, 177 | 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 178 | 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 0x00, 0x62, 0x0a, 0xff, 0xff, 179 | 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 0x71, 0x7e, 0x77, 0x07, 0x81, 180 | 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 0x01, 0x01, 0x04, 0x45, 0x53, 181 | 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 0x01, 0x01, 182 | 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 183 | 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 0x64, 0x00, 184 | 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x06, 185 | 0xd9, 0x5b, 0xa5, 0x6c, 0x01, 0x77, 0x07, 0x01, 0x00, 0x02, 0x08, 0x00, 186 | 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 0x59, 0x00, 187 | 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 0x01, 0x77, 0x07, 0x01, 0x00, 188 | 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 189 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x1e, 0x96, 0x01, 0x77, 0x07, 0x01, 0x00, 190 | 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 191 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x88, 0x01, 0x77, 0x07, 0x01, 0x00, 192 | 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 193 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x45, 0x01, 0x77, 0x07, 0x01, 0x00, 194 | 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x1b, 0x52, 0xfe, 0x59, 0x00, 195 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0xc8, 0x01, 0x77, 0x07, 0x81, 0x81, 196 | 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 0x01, 0x83, 0x02, 0x1a, 0x24, 197 | 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 0x10, 0x93, 0x05, 0x5b, 0xee, 198 | 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 0xd1, 0x9d, 0x4f, 0xaf, 0x3e, 199 | 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 0xed, 0x72, 0x7d, 0x23, 0x6a, 200 | 0xaf, 0x5a, 0xb0, 0x9a, 0x5b, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 201 | 0x00, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0f, 0x31, 0x45, 0x53, 0x59, 0x31, 202 | 0x31, 0x36, 0x32, 0x32, 0x33, 0x32, 0x39, 0x39, 0x37, 0x01, 0x77, 0x07, 203 | 0x01, 0x00, 0x20, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 204 | 0x63, 0x09, 0x14, 0x01, 0x77, 0x07, 0x01, 0x00, 0x34, 0x07, 0x00, 0xff, 205 | 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x05, 0x01, 0x77, 0x07, 206 | 0x01, 0x00, 0x48, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 207 | 0x63, 0x09, 0x13, 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0xf0, 0x06, 0xff, 208 | 0x01, 0x01, 0x01, 0x01, 0x04, 0x01, 0x07, 0x1e, 0x01, 0x01, 0x01, 0x63, 209 | 0xdc, 0x32, 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 210 | 0xea, 0x9a, 0xff, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x02, 0x01, 0x71, 211 | 0x01, 0x63, 0x2c, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 212 | 0x1a, 0x03, 0x02, 0xf5, 0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01, 213 | 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 0x00, 214 | 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x01, 0x01, 0x76, 0x01, 0x04, 0x45, 215 | 0x53, 0x59, 0x08, 0x45, 0x53, 0x59, 0xa5, 0x01, 0x01, 0x63, 0x88, 0x47, 216 | 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 217 | 0x01, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 218 | 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 219 | 0x00, 0x62, 0x0a, 0xff, 0xff, 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 220 | 0x72, 0x7e, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 221 | 0x01, 0x01, 0x04, 0x45, 0x53, 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 222 | 0x00, 0x09, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 223 | 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 224 | 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 225 | 0x59, 0x00, 0x00, 0x00, 0x06, 0xd9, 0x5b, 0xad, 0x32, 0x01, 0x77, 0x07, 226 | 0x01, 0x00, 0x02, 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 227 | 0x1e, 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 228 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 229 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x17, 0xdf, 230 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 231 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x96, 232 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 233 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xf9, 234 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 235 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x50, 236 | 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 237 | 0x01, 0x83, 0x02, 0x1a, 0x24, 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 238 | 0x10, 0x93, 0x05, 0x5b, 0xee, 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 239 | 0xd1, 0x9d, 0x4f, 0xaf, 0x3e, 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 240 | 0xda, 0xe9, 0xea, 0x15, 0x66, 0xed, 0x72, 0x7d, 0x23, 0x6a, 0xaf, 0x5a, 241 | 0xb0, 0x9a, 0x5b, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 242 | 0x01, 0x01, 0x01, 0x01, 0x0f, 0x31, 0x45, 0x53, 0x59, 0x31, 0x31, 0x36, 243 | 0x32, 0x32, 0x33, 0x32, 0x39, 0x39, 0x37, 0x01, 0x77, 0x07, 0x01, 0x00, 244 | 0x20, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 245 | 0x13, 0x01, 0x77, 0x07, 0x01, 0x00, 0x34, 0x07, 0x00, 0xff, 0x01, 0x01, 246 | 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x05, 0x01, 0x77, 0x07, 0x01, 0x00, 247 | 0x48, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 248 | 0x15, 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0xf0, 0x06, 0xff, 0x01, 0x01, 249 | 0x01, 0x01, 0x04, 0x01, 0x07, 0x1e, 0x01, 0x01, 0x01, 0x63, 0x06, 0x0a, 250 | 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 251 | 0x02, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 252 | 0xc6, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x03, 253 | 0xf9, 0x08, 0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01, 0x76, 0x0b, 254 | 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 0x03, 0x62, 0x00, 255 | 0x62, 0x00, 0x72, 0x63, 0x01, 0x01, 0x76, 0x01, 0x04, 0x45, 0x53, 0x59, 256 | 0x08, 0x45, 0x53, 0x59, 0xdf, 0x73, 0x9b, 0x03, 0x0b, 0x09, 0x01, 0x45, 257 | 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x01, 0x63, 0x66, 0xb6, 258 | 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 259 | 0x04, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 260 | 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 261 | 0x00, 0x62, 0x0a, 0xff, 0xff, 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 262 | 0x73, 0x7e, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 263 | 0x01, 0x01, 0x04, 0x45, 0x53, 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 264 | 0x00, 0x09, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 265 | 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 266 | 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 267 | 0x59, 0x00, 0x00, 0x00, 0x06, 0xd9, 0x5b, 0xb4, 0xd3, 0x01, 0x77, 0x07, 268 | 0x01, 0x00, 0x02, 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 269 | 0x1e, 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 270 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 271 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x12, 0xa4, 272 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 273 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0x96, 274 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 275 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x95, 276 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 277 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x78, 278 | 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 279 | 0x01, 0x83, 0x02, 0x1a, 0x24, 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 280 | 0x10, 0x93, 0x05, 0x5b, 0xee, 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 281 | 0xd1, 0x9d, 0x4f, 0xaf, 0x3e, 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 282 | 0xda, 0xe9, 0xea, 0x15, 0x66, 0xed, 0x72, 0x7d, 0x23, 0x6a, 0xaf, 0x5a, 283 | 0xb0, 0x9a, 0x5b, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 284 | 0x01, 0x01, 0x01, 0x01, 0x0f, 0x31, 0x45, 0x53, 0x59, 0x31, 0x31, 0x36, 285 | 0x32, 0x32, 0x33, 0x32, 0x39, 0x39, 0x37, 0x01, 0x77, 0x07, 0x01, 0x00, 286 | 0x20, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 287 | 0x12, 0x01, 0x77, 0x07, 0x01, 0x00, 0x34, 0x07, 0x00, 0xff, 0x01, 0x01, 288 | 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x02, 0x01, 0x77, 0x07, 0x01, 0x00, 289 | 0x48, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 290 | 0x13, 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0xf0, 0x06, 0xff, 0x01, 0x01, 291 | 0x01, 0x01, 0x04, 0x01, 0x07, 0x1e, 0x01, 0x01, 0x01, 0x63, 0xb5, 0xf6, 292 | 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 293 | 0x05, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 294 | 0x20, 0x50, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x03, 295 | 0x2d, 0x91, 0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01, 0x76, 0x0b, 296 | 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 0x06, 0x62, 0x00, 297 | 0x62, 0x00, 0x72, 0x63, 0x01, 0x01, 0x76, 0x01, 0x04, 0x45, 0x53, 0x59, 298 | 0x08, 0x45, 0x53, 0x59, 0xdf, 0x74, 0x9b, 0x06, 0x0b, 0x09, 0x01, 0x45, 299 | 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x01, 0x63, 0x27, 0x84, 300 | 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 301 | 0x07, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 302 | 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 303 | 0x00, 0x62, 0x0a, 0xff, 0xff, 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 304 | 0x74, 0x7e, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 305 | 0x01, 0x01, 0x04, 0x45, 0x53, 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 306 | 0x00, 0x09, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 307 | 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x77, 0x07, 0x01, 0x00, 0x01, 308 | 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 0x1e, 0x52, 0xfc, 309 | 0x59, 0x00, 0x00, 0x00, 0x06, 0xd9, 0x5b, 0xbc, 0x4a, 0x01, 0x77, 0x07, 310 | 0x01, 0x00, 0x02, 0x08, 0x00, 0xff, 0x64, 0x00, 0x00, 0x80, 0x01, 0x62, 311 | 0x1e, 0x52, 0xfc, 0x59, 0x00, 0x00, 0x00, 0x00, 0x41, 0x9b, 0xd4, 0xd3, 312 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x10, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 313 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0c, 0xb2, 314 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x24, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 315 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb3, 0x05, 316 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x38, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 317 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa8, 318 | 0x01, 0x77, 0x07, 0x01, 0x00, 0x4c, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 319 | 0x1b, 0x52, 0xfe, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x04, 320 | 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 0x01, 0x01, 0x01, 321 | 0x01, 0x83, 0x02, 0x1a, 0x24, 0x68, 0x7a, 0x27, 0x7e, 0x98, 0x56, 0x5e, 322 | 0x10, 0x93, 0x05, 0x5b, 0xee, 0x0f, 0x70, 0x4e, 0x58, 0xfd, 0xaa, 0x3d, 323 | 0xd1, 0x9d, 0x4f, 0xaf, 0x3e, 0xe0, 0x67, 0xc1, 0x64, 0xc3, 0x04, 0x94, 324 | 0xda, 0xe9, 0xea, 0x15, 0x66, 0xed, 0x72, 0x7d, 0x23, 0x6a, 0xaf, 0x5a, 325 | 0xb0, 0x9a, 0x5b, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0xff, 326 | 0x01, 0x01, 0x01, 0x01, 0x0f, 0x31, 0x45, 0x53, 0x59, 0x31, 0x31, 0x36, 327 | 0x32, 0x32, 0x33, 0x32, 0x39, 0x39, 0x37, 0x01, 0x77, 0x07, 0x01, 0x00, 328 | 0x20, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 329 | 0x12, 0x01, 0x77, 0x07, 0x01, 0x00, 0x34, 0x07, 0x00, 0xff, 0x01, 0x01, 330 | 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 0x01, 0x01, 0x77, 0x07, 0x01, 0x00, 331 | 0x48, 0x07, 0x00, 0xff, 0x01, 0x01, 0x62, 0x23, 0x52, 0xff, 0x63, 0x09, 332 | 0x10, 0x01, 0x77, 0x07, 0x81, 0x81, 0xc7, 0xf0, 0x06, 0xff, 0x01, 0x01, 333 | 0x01, 0x01, 0x04, 0x01, 0x07, 0x1e, 0x01, 0x01, 0x01, 0x63, 0x16, 0x0d, 334 | 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 335 | 0x08, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x02, 0x01, 0x71, 0x01, 0x63, 336 | 0x4e, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x1b, 0x1b, 0x1b, 0x1a, 0x03, 337 | 0xa2, 0x22, 0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01, 0x76, 0x0b, 338 | 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 0x09, 0x62, 0x00, 339 | 0x62, 0x00, 0x72, 0x63, 0x01, 0x01, 0x76, 0x01, 0x04, 0x45, 0x53, 0x59, 340 | 0x08, 0x45, 0x53, 0x59, 0xdf, 0x75, 0x9b, 0x09, 0x0b, 0x09, 0x01, 0x45, 341 | 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x01, 0x01, 0x63, 0x20, 0x82, 342 | 0x00, 0x76, 0x0b, 0x45, 0x53, 0x59, 0x41, 0x99, 0xa5, 0x02, 0xea, 0x9b, 343 | 0x0a, 0x62, 0x00, 0x62, 0x00, 0x72, 0x63, 0x07, 0x01, 0x77, 0x01, 0x0b, 344 | 0x09, 0x01, 0x45, 0x53, 0x59, 0x11, 0x03, 0xb5, 0x99, 0xa5, 0x07, 0x01, 345 | 0x00, 0x62, 0x0a, 0xff, 0xff, 0x72, 0x62, 0x01, 0x65, 0x00, 0xf8, 0xdf, 346 | 0x75, 0x7e, 0x77, 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 0x01, 0x01, 347 | 0x01, 0x01, 0x04, 0x45, 0x53, 0x59, 0x01, 0x77, 0x07, 0x01, 0x00, 0x00, 348 | 0x00, 0x09, 0xff, 0x01, 0x01, 0x01, 0x01, 0x0b, 0x09, 0x01, 0x45, 0x53, 349 | 0x59, 0x11, 0x03, 0xb5}; 350 | unsigned int data_bin_len = 4096; 351 | -------------------------------------------------------------------------------- /test/test/test_ESY/test.cpp: -------------------------------------------------------------------------------- 1 | #include "data_bin.h" 2 | #include "sml.h" 3 | #include "unity.h" 4 | #ifdef ARDUINO 5 | #include "arduino.h" 6 | #endif 7 | 8 | typedef struct { 9 | const unsigned char OBIS[6]; 10 | void (*Handler)(); 11 | } OBISHandler; 12 | 13 | #define MAX_STR_MANUF 5 14 | unsigned char manuf[MAX_STR_MANUF]; 15 | long long int SumWh = -2; 16 | bool isFinal = false; 17 | 18 | void Manufacturer() { smlOBISManufacturer(manuf, MAX_STR_MANUF); } 19 | 20 | void PowerSum() 21 | { 22 | // Double on Arduino UNO is just 32 bit, so we must test against long int 23 | signed char sc = 0; 24 | smlOBISByUnit(SumWh, sc, SML_WATT_HOUR); 25 | } 26 | 27 | // clang-format off 28 | OBISHandler OBISHandlers[] = { 29 | {{ 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff }, &Manufacturer}, /* 129-129:199.130.3*255 */ 30 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 31 | {{ 0, 0 }} 32 | }; 33 | // clang-format on 34 | 35 | void setUp(void) 36 | { 37 | unsigned int i = 0; 38 | int iHandler = 0; 39 | unsigned char c; 40 | sml_states_t s; 41 | manuf[0] = 0; 42 | 43 | for (i = 0; i < data_bin_len; ++i) { 44 | #ifdef ARDUINO 45 | c = pgm_read_word_near(data_bin + i); 46 | #else 47 | c = data_bin[i]; 48 | #endif 49 | 50 | s = smlState(c); 51 | if (s == SML_LISTEND) { 52 | /* check handlers on last received list */ 53 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 54 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 55 | iHandler++) 56 | ; 57 | if (OBISHandlers[iHandler].Handler != 0) { 58 | OBISHandlers[iHandler].Handler(); 59 | } 60 | } 61 | if (s == SML_FINAL) { 62 | isFinal = true; 63 | } 64 | } 65 | } 66 | 67 | void test_should_return_manufacturer(void) 68 | { 69 | TEST_ASSERT_EQUAL_STRING("ESY", manuf); 70 | } 71 | 72 | void test_should_return_SumWh(void) 73 | { 74 | TEST_ASSERT_EQUAL_INT(29416471626, SumWh); 75 | } 76 | 77 | void test_should_be_final(void) { TEST_ASSERT_EQUAL_INT(1, isFinal); } 78 | 79 | int runUnityTests(void) 80 | { 81 | UNITY_BEGIN(); 82 | RUN_TEST(test_should_return_manufacturer); 83 | // RUN_TEST(test_should_return_t1); 84 | RUN_TEST(test_should_return_SumWh); 85 | RUN_TEST(test_should_be_final); 86 | return UNITY_END(); 87 | } 88 | 89 | /** 90 | * For native dev-platform or for some embedded frameworks 91 | */ 92 | int main(void) { return runUnityTests(); } 93 | 94 | /** 95 | * For Arduino framework 96 | */ 97 | void setup() 98 | { 99 | // Wait ~2 seconds before the Unity test runner 100 | // establishes connection with a board Serial interface 101 | #ifdef ARDUINO 102 | delay(2000); 103 | #endif 104 | runUnityTests(); 105 | } 106 | void loop() {} 107 | 108 | /** 109 | * For ESP-IDF framework 110 | */ 111 | void app_main() { runUnityTests(); } 112 | -------------------------------------------------------------------------------- /test/test/test_efr_sgm_c2/ehz_bin.h: -------------------------------------------------------------------------------- 1 | const unsigned char ehz_bin[] = {0x1B,0x1B,0x1B,0x1B,0x01,0x01,0x01,0x01,0x76,0x05,0x01,0x1F,0xF2,0x51,0x62,0x00,0x62,0x00,0x72,0x63,0x01,0x01,0x76,0x01,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x05,0x00,0x5F,0xFB,0x71,0x0B,0x0A,0x01,0x45,0x46,0x52,0x21,0x01,0xE8,0xB2,0xF0,0x72,0x62,0x01,0x65,0x01,0x08,0xC9,0x7F,0x01,0x63,0x13,0x33,0x00,0x76,0x05,0x01,0x1F,0xF2,0x52,0x62,0x00,0x62,0x00,0x72,0x63,0x07,0x01,0x77,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0B,0x0A,0x01,0x45,0x46,0x52,0x21,0x01,0xE8,0xB2,0xF0,0x07,0x01,0x00,0x62,0x0A,0xFF,0xFF,0x72,0x62,0x01,0x65,0x01,0x08,0xC9,0x7F,0x7E,0x77,0x07,0x01,0x00,0x60,0x32,0x01,0x01,0x01,0x01,0x01,0x01,0x04,0x45,0x46,0x52,0x01,0x77,0x07,0x01,0x00,0x60,0x01,0x00,0xFF,0x01,0x01,0x01,0x01,0x0B,0x0A,0x01,0x45,0x46,0x52,0x21,0x01,0xE8,0xB2,0xF0,0x01,0x77,0x07,0x01,0x00,0x01,0x08,0x00,0xFF,0x64,0x04,0x01,0x04,0x72,0x62,0x01,0x65,0x01,0x08,0xC9,0x7F,0x62,0x1E,0x52,0xFF,0x64,0xF5,0x75,0xFA,0x01,0x77,0x07,0x01,0x00,0x02,0x08,0x00,0xFF,0x01,0x72,0x62,0x01,0x65,0x01,0x08,0xC9,0x7F,0x62,0x1E,0x52,0xFF,0x62,0x00,0x01,0x77,0x07,0x01,0x00,0x10,0x07,0x00,0xFF,0x01,0x01,0x62,0x1B,0x52,0x00,0x53,0x00,0x91,0x01,0x77,0x07,0x01,0x00,0x20,0x07,0x00,0xFF,0x01,0x01,0x62,0x23,0x52,0xFF,0x63,0x09,0x05,0x01,0x77,0x07,0x01,0x00,0x1F,0x07,0x00,0xFF,0x01,0x01,0x62,0x21,0x52,0xFE,0x62,0x49,0x01,0x77,0x07,0x01,0x00,0x51,0x07,0x04,0xFF,0x01,0x01,0x62,0x08,0x52,0x00,0x53,0x01,0x4A,0x01,0x77,0x07,0x01,0x00,0x0E,0x07,0x00,0xFF,0x01,0x01,0x62,0x2C,0x52,0xFF,0x63,0x01,0xF4,0x01,0x77,0x07,0x01,0x00,0x00,0x02,0x00,0x00,0x01,0x01,0x01,0x01,0x06,0x30,0x31,0x2E,0x30,0x37,0x01,0x77,0x07,0x01,0x00,0x60,0x5A,0x02,0x01,0x01,0x01,0x01,0x01,0x03,0xA9,0x0A,0x01,0x77,0x07,0x01,0x00,0x61,0x61,0x00,0x00,0x01,0x01,0x01,0x01,0x03,0x00,0x00,0x01,0x77,0x07,0x01,0x00,0x60,0x32,0x01,0x04,0x01,0x01,0x01,0x01,0x09,0x50,0x31,0x2E,0x30,0x33,0x2E,0x30,0x36,0x01,0x77,0x07,0x01,0x00,0x60,0x32,0x04,0x04,0x01,0x01,0x01,0x01,0x03,0x04,0x23,0x01,0x01,0x01,0x63,0x75,0x61,0x00,0x76,0x05,0x01,0x1F,0xF2,0x53,0x62,0x00,0x62,0x00,0x72,0x63,0x02,0x01,0x71,0x01,0x63,0x8A,0x8E,0x00,0x00,0x1B,0x1B,0x1B,0x1B,0x1A,0x01,0x70,0x98}; 2 | const unsigned int ehz_bin_len = 416; 3 | -------------------------------------------------------------------------------- /test/test/test_efr_sgm_c2/test.cpp: -------------------------------------------------------------------------------- 1 | #include "ehz_bin.h" 2 | #include "sml.h" 3 | #include "unity.h" 4 | #ifdef ARDUINO 5 | #include "arduino.h" 6 | #endif 7 | 8 | typedef struct { 9 | const unsigned char OBIS[6]; 10 | void (*Handler)(); 11 | } OBISHandler; 12 | 13 | #define MAX_STR_MANUF 5 14 | unsigned char manuf[MAX_STR_MANUF]; 15 | double T1Wh = -2, SumWh = -2; 16 | bool isFinal = false; 17 | 18 | void PowerSum() { smlOBISWh(SumWh); } 19 | 20 | // clang-format off 21 | OBISHandler OBISHandlers[] = { 22 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 23 | {{ 0, 0 }} 24 | }; 25 | // clang-format on 26 | 27 | void setUp(void) 28 | { 29 | unsigned int i = 0; 30 | int iHandler = 0; 31 | unsigned char c; 32 | sml_states_t s; 33 | manuf[0] = 0; 34 | 35 | for (i = 0; i < ehz_bin_len; ++i) { 36 | c = ehz_bin[i]; 37 | s = smlState(c); 38 | if (s == SML_LISTEND) { 39 | /* check handlers on last received list */ 40 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 41 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 42 | iHandler++) 43 | ; 44 | if (OBISHandlers[iHandler].Handler != 0) { 45 | OBISHandlers[iHandler].Handler(); 46 | } 47 | } 48 | if (s == SML_FINAL) { 49 | isFinal = true; 50 | } 51 | } 52 | } 53 | 54 | 55 | void test_should_return_SumWh(void) 56 | { 57 | TEST_ASSERT_EQUAL_DOUBLE(1608652.2, SumWh); 58 | } 59 | 60 | void test_should_be_final(void) { TEST_ASSERT_EQUAL_INT(1, isFinal); } 61 | 62 | int runUnityTests(void) 63 | { 64 | UNITY_BEGIN(); 65 | RUN_TEST(test_should_return_SumWh); 66 | RUN_TEST(test_should_be_final); 67 | return UNITY_END(); 68 | } 69 | 70 | /** 71 | * For native dev-platform or for some embedded frameworks 72 | */ 73 | int main(void) { return runUnityTests(); } 74 | 75 | /** 76 | * For Arduino framework 77 | */ 78 | void setup() 79 | { 80 | // Wait ~2 seconds before the Unity test runner 81 | // establishes connection with a board Serial interface 82 | #ifdef ARDUINO 83 | delay(2000); 84 | #endif 85 | runUnityTests(); 86 | } 87 | void loop() {} 88 | 89 | /** 90 | * For ESP-IDF framework 91 | */ 92 | void app_main() { runUnityTests(); } 93 | -------------------------------------------------------------------------------- /test/test/test_negative/ehz_bin.h: -------------------------------------------------------------------------------- 1 | // clang-format off 2 | // Formatted example data from https://github.com/devZer0/libsml-testing 3 | 4 | const unsigned char ehz_bin[] = { 5 | /* Start */ 0x1b, 0x1b, 0x1b, 0x1b, 6 | /* Version */ 0x01, 0x01, 0x01, 0x01, 7 | 8 | /* List (6 entries) */ 0x76, 9 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2d, 10 | /* 2. Group No */ 0x62, 0x00, 11 | /* 3. Abort On Error */ 0x62, 0x00, 12 | /* 4. List (2 entries) */ 0x72, 13 | /* 1. getOpenResponse */ 0x63, 0x01, 0x01, 14 | /* 2. List (6 entries) */ 0x76, 15 | /* 1. code page */ 0x01, 16 | /* 2. clientid */ 0x01, 17 | /* 3. Transaction ID */ 0x07, 0x00, 0x0c, 0x06, 0x9e, 0x2d, 0x0f, 18 | /* 4. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 19 | /* 5. List name */ 0x01, 20 | /* 6. Time */ 0x01, 21 | /* 5. CRC */ 0x63, 0x2b, 0x8e, 22 | /* 6. END */ 0x00, 23 | 24 | /* List (6 entries) */ 0x76, 25 | /* 1. Transaktion ID */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x2e, 26 | /* 2. Group No */ 0x62, 0x00, 27 | /* 3. Abort On Error */ 0x62, 0x00, 28 | /* 4. Message Body (2) */ 0x72, 29 | /* 1. getListResponse */ 0x63, 0x07, 0x01, 30 | /* 2. List (7) */ 0x77, 31 | /* 1. ClientId */ 0x01, 32 | /* 2. ServerID */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 33 | /* 3. ?? */ 0x01, 34 | /* 4. List (2) */ 0x72, 35 | /* 1. ?? */ 0x62, 0x01, 36 | /* 2. ?? */ 0x65, 0x06, 0x9e, 0xfa, 0x83, 37 | /* 5. List (7) */ 0x77, 38 | /* 1. List (7) */ 0x77, 39 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff, 40 | /* 2. */ 0x01, 41 | /* 3. */ 0x01, 42 | /* 4. */ 0x01, 43 | /* 5. */ 0x01, 44 | /* 6. */ 0x04, 0x45, 0x4d, 0x48, 45 | /* 7. */ 0x01, 46 | /* 2. List (7) */ 0x77, 47 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x00, 0x00, 0x09, 0xff, 48 | /* 2. */ 0x01, 49 | /* 3. */ 0x01, 50 | /* 4. */ 0x01, 51 | /* 5. */ 0x01, 52 | /* 6. */ 0x0b, 0x06, 0x45, 0x4d, 0x48, 0x01, 0x00, 0x1d, 0x46, 0x15, 0xca, 53 | /* 7. */ 0x01, 54 | /* 3. List (7) */ 0x77, 55 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x00, 0xff, 56 | /* 2. */ 0x63, 0x01, 0x82, 57 | /* 3. */ 0x01, 58 | /* 4. */ 0x62, 0x1e, 59 | /* 5. */ 0x52, 0x00, 60 | /* 6. */ 0x53, 0xfe, 0xfb, 61 | /* 7. */ 0x01, 62 | /* 4. List (7) */ 0x77, 63 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x01, 0xff, 64 | /* 2. */ 0x01, 65 | /* 3. */ 0x01, 66 | /* 4. Unit */ 0x62, 0x1e, 67 | /* 5. Scaler */ 0x52, 0x00, 68 | /* 6 Value */ 0x62, 0xf4, 69 | /* 7 */ 0x01, 70 | /* 5. List (7) */ 0x77, 71 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x01, 0x08, 0x02, 0xff, 72 | /* 2. */ 0x01, 73 | /* 3. */ 0x01, 74 | /* 4. */ 0x62, 0x1e, 75 | /* 5. */ 0x52, 0x00, 76 | /* 6. */ 0x63, 0xfe, 0xfb, 77 | /* 7. */ 0x01, 78 | /* 6. List (7) */ 0x77, 79 | /* 1. OBIS */ 0x07, 0x01, 0x00, 0x0f, 0x07, 0x00, 0xff, 80 | /* 2. */ 0x01, 81 | /* 3. */ 0x01, 82 | /* 4. */ 0x62, 0x1b, 83 | /* 5. */ 0x52, 0xff, 84 | /* 6. */ 0x55, 0x00, 0x00, 0x2f, 0x65, 85 | /* 7. */ 0x01, 86 | /* 7. List (7) */ 0x77, 87 | /* 1. OBIS */ 0x07, 0x81, 0x81, 0xc7, 0x82, 0x05, 0xff, 88 | /* 2. */ 0x01, 89 | /* 3. */ 0x01, 90 | /* 4. */ 0x01, 91 | /* 5. */ 0x01, 92 | /* 6. Public Key */ 0x83, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 93 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 94 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 95 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 96 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 97 | /* 7. */ 0x01, 98 | 0x01, 99 | 0x01, 100 | 0x63, 0xb9, 0x3f, 101 | 0x00, 102 | /* List (6) */ 0x76, 103 | /* 1. */ 0x07, 0x00, 0x0c, 0x04, 0x08, 0x87, 0x31, 104 | /* 2. */ 0x62, 0x00, 105 | /* 3. */ 0x62, 0x00, 106 | /* 4. List (2) */ 0x72, 107 | /* 1. */ 0x63, 0x02, 0x01, 108 | /* List (1) */ 0x71, 109 | /* 1. */ 0x01, 110 | /* 5. CRC */ 0x63, 0x6a, 0x53, 111 | /* 6. */ 0x00, 112 | 113 | 0x00, 114 | 0x1b, 0x1b, 0x1b, 0x1b, 115 | 0x1a, 0x01, 0x61, 0x6b 116 | 117 | }; 118 | 119 | 120 | const unsigned int ehz_bin_len = 306; 121 | 122 | -------------------------------------------------------------------------------- /test/test/test_negative/test.cpp: -------------------------------------------------------------------------------- 1 | #include "ehz_bin.h" 2 | #include "sml.h" 3 | #include "unity.h" 4 | #ifdef ARDUINO 5 | #include "arduino.h" 6 | #endif 7 | 8 | typedef struct { 9 | const unsigned char OBIS[6]; 10 | void (*Handler)(); 11 | } OBISHandler; 12 | 13 | #define MAX_STR_MANUF 5 14 | unsigned char manuf[MAX_STR_MANUF]; 15 | double T1Wh = -2, SumWh = -2; 16 | bool isFinal = false; 17 | 18 | void Manufacturer() { smlOBISManufacturer(manuf, MAX_STR_MANUF); } 19 | void PowerT1() { smlOBISWh(T1Wh); } 20 | void PowerSum() { smlOBISWh(SumWh); } 21 | 22 | // clang-format off 23 | OBISHandler OBISHandlers[] = { 24 | {{ 0x81, 0x81, 0xc7, 0x82, 0x03, 0xff }, &Manufacturer}, /* 129-129:199.130.3*255 */ 25 | {{ 0x01, 0x00, 0x01, 0x08, 0x01, 0xff }, &PowerT1}, /* 1- 0: 1. 8.1*255 (T1) */ 26 | {{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &PowerSum}, /* 1- 0: 1. 8.0*255 (T1 + T2) */ 27 | {{ 0, 0 }} 28 | }; 29 | // clang-format on 30 | 31 | void setUp(void) 32 | { 33 | unsigned int i = 0; 34 | int iHandler = 0; 35 | unsigned char c; 36 | sml_states_t s; 37 | manuf[0] = 0; 38 | 39 | for (i = 0; i < ehz_bin_len; ++i) { 40 | c = ehz_bin[i]; 41 | s = smlState(c); 42 | if (s == SML_LISTEND) { 43 | /* check handlers on last received list */ 44 | for (iHandler = 0; OBISHandlers[iHandler].Handler != 0 && 45 | !(smlOBISCheck(OBISHandlers[iHandler].OBIS)); 46 | iHandler++) 47 | ; 48 | if (OBISHandlers[iHandler].Handler != 0) { 49 | OBISHandlers[iHandler].Handler(); 50 | } 51 | } 52 | if (s == SML_FINAL) { 53 | isFinal = true; 54 | } 55 | } 56 | } 57 | 58 | void test_should_return_manufacturer(void) 59 | { 60 | TEST_ASSERT_EQUAL_STRING("EMH", manuf); 61 | } 62 | 63 | void test_should_return_t1(void) { TEST_ASSERT_EQUAL_DOUBLE(244, T1Wh); } 64 | 65 | void test_should_return_SumWh(void) { TEST_ASSERT_EQUAL_DOUBLE(-261, SumWh); } 66 | 67 | void test_should_be_final(void) { TEST_ASSERT_EQUAL_INT(1, isFinal); } 68 | 69 | int runUnityTests(void) 70 | { 71 | UNITY_BEGIN(); 72 | RUN_TEST(test_should_return_manufacturer); 73 | RUN_TEST(test_should_return_t1); 74 | RUN_TEST(test_should_return_SumWh); 75 | RUN_TEST(test_should_be_final); 76 | return UNITY_END(); 77 | } 78 | 79 | /** 80 | * For native dev-platform or for some embedded frameworks 81 | */ 82 | int main(void) { return runUnityTests(); } 83 | 84 | /** 85 | * For Arduino framework 86 | */ 87 | void setup() 88 | { 89 | // Wait ~2 seconds before the Unity test runner 90 | // establishes connection with a board Serial interface 91 | #ifdef ARDUINO 92 | delay(2000); 93 | #endif 94 | runUnityTests(); 95 | } 96 | void loop() {} 97 | 98 | /** 99 | * For ESP-IDF framework 100 | */ 101 | void app_main() { runUnityTests(); } 102 | --------------------------------------------------------------------------------