Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.2 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. [![Build Status](https://travis-ci.com/olagrottvik/encdec8b10b.svg?token=jVu3gMDvjaqfNCVgNVai&branch=master)](https://travis-ci.com/olagrottvik/encdec8b10b)
  2. # encdec8b10b
  3. Encode and decode 8B10B encoding
  4. ## Get
  5. ```
  6. python3 -m pip install encdec8b10b
  7. ```
  8. ## Usage
  9. ### Encode Data Byte
  10. ```
  11. from encdec8b10b import EncDec8B10B
  12. running_disp = 0
  13. byte_to_enc = 0xf
  14. running_disp, encoded = EncDec8B10B.enc_8b10b(byte_to_enc, running_disp)
  15. print(hex(encoded))
  16. Output >> 0xba
  17. ```
  18. ### Encode Control Byte
  19. ```
  20. from encdec8b10b import EncDec8B10B
  21. running_disp = 0
  22. byte_to_enc = 0xbc # comma
  23. ctrl = 1
  24. running_disp, encoded = EncDec8B10B.enc_8b10b(byte_to_enc, running_disp, ctrl)
  25. print(hex(encoded))
  26. Output >> 0x17c
  27. ```
  28. ### Decode Data Byte
  29. ```
  30. from encdec8b10b import EncDec8B10B
  31. byte_to_dec = 0xba
  32. ctrl, decoded = EncDec8B10B.dec_8b10b(byte_to_dec)
  33. print(hex(decoded))
  34. Output >> 0xf
  35. # ctrl variable confirm that it was a data byte
  36. print(ctrl)
  37. Output >> 0
  38. ```
  39. ### Decode Control Byte
  40. ```
  41. from encdec8b10b import EncDec8B10B
  42. byte_to_dec = 0x17c # comma encoded
  43. ctrl, decoded = EncDec8B10B.dec_8b10b(byte_to_dec)
  44. print(hex(decoded))
  45. Output >> 0xbc
  46. # ctrl variable confirm that it was a control byte
  47. print(ctrl)
  48. Output >> 1
  49. ```
  50. ### Verbosity
  51. Both functions have a verbose-mode to make it easier to confirm everything that's happening:
  52. ```
  53. from encdec8b10b import EncDec8B10B
  54. running_disp = 0
  55. byte_to_enc = 0xA0
  56. running_disp, encoded = EncDec8B10B.enc_8b10b(byte_to_enc, running_disp, verbose=True)
  57. Output >> Encoder - In: A0 - Encoded: 146 - Running Disparity: 0
  58. ctrl, decoded = EncDec8B10B.dec_8b10b(encoded, verbose=True)
  59. Output >> Decoded: A0 - Control: 0
  60. ```
  61. ## 8B10B
  62. 8B10B Encoding were implemented by Al Widmer and Peter Franaszek in 1983. It is still widely used in high-speed electronics.
  63. - [Original article](https://ieeexplore.ieee.org/document/5390392)
  64. - [Wikipedia](https://en.wikipedia.org/wiki/8b/10b_encoding)
  65. ### Thanks
  66. - [Ryu Shinhyung](https://opencores.org/projects/async_8b10b_encoder_decoder) for creating the tables used in this module
  67. - [Chuck Benz](http://asics.chuckbenz.com/) for creating awesome combinational 8B10B modules
  68. - [Alex Forencich](http://www.alexforencich.com/wiki/en/scripts/matlab/enc8b10b) for his 8B10B Matlab script