emitlib.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #include <stdio.h>
  2. typedef struct {
  3. unsigned long int byteSize;
  4. unsigned int bitSize;
  5. char* data;
  6. } BIT_BUFFER;
  7. typedef struct {
  8. unsigned long int size;
  9. char* data;
  10. } BYTE_BUFFER;
  11. #define BIT0 0
  12. #define BIT1 1
  13. #define START_OF_FRAME 2
  14. #define END_OF_DATA 3
  15. #define ON 1
  16. #define OFF 0
  17. #define NUMBER1 0
  18. #define NUMBER2 1
  19. #define NUMBER3 2
  20. #define NUMBER4 3
  21. #define SECTION_A 0
  22. #define SECTION_B 1
  23. #define SECTION_C 2
  24. #define SECTION_D 3
  25. #define GLOBAL 1
  26. #define NO_GLOBAL 0
  27. /**
  28. * Create a new bit buffer
  29. *
  30. * @return the created buffer
  31. */
  32. BIT_BUFFER createBitBuffer();
  33. /**
  34. * Release the memory
  35. *
  36. * @param buffer the buffer to destroy
  37. */
  38. void destroyBitBuffer(BIT_BUFFER buffer);
  39. /**
  40. * Create a new byte buffer
  41. *
  42. * @return the created buffer
  43. */
  44. BIT_BUFFER createByteBuffer();
  45. /**
  46. * Release the memory
  47. *
  48. * @param buffer the buffer to destroy
  49. */
  50. void destroyByteBuffer(BIT_BUFFER buffer);
  51. /**
  52. * Print all the bits from a buffer
  53. *
  54. * @param buffer the buffer holding the data
  55. */
  56. void printfBitBuffer(BIT_BUFFER buffer);
  57. /**
  58. * Print all the bytes from a buffer
  59. *
  60. * @param buffer the buffer holding the data
  61. */
  62. void printfByteBuffer(BYTE_BUFFER buffer);
  63. /**
  64. * Push a bit in a buffer
  65. *
  66. * @param buffer the buffer holding the data
  67. * @param bit the bit to push
  68. */
  69. void pushBit(BIT_BUFFER* buffer, unsigned char bit);
  70. /**
  71. * Push a byte in a buffer
  72. *
  73. * @param buffer the buffer holding the data
  74. * @param byt the byte to push
  75. */
  76. void pushByte(BYTE_BUFFER* buffer, unsigned char byte);
  77. /**
  78. * Push some bytes in a buffer
  79. *
  80. * @param buffer the buffer holding the data
  81. * @param bytes the bytes to push
  82. * @param len the number of bytes to push
  83. */
  84. void pushBytes(BYTE_BUFFER* buffer, unsigned char *byte, unsigned int len);
  85. /**
  86. * Encode bits with HomeEasy encoding (1 => 10, 0 => 01)
  87. *
  88. * @param buffer the buffuer to encode
  89. *
  90. * @return new buffer
  91. * */
  92. BYTE_BUFFER homeEasyEncode(BYTE_BUFFER *buffer);
  93. /**
  94. * Decode bits with HomeEasy encoding (1 => 10, 0 => 01)
  95. *
  96. * @param buffer the buffuer to decode
  97. *
  98. * @return new buffer
  99. * */
  100. BYTE_BUFFER homeEasyDecode(BYTE_BUFFER *buffer);
  101. /**
  102. * Encode a byte according to HomeEasy
  103. *
  104. * @param byte the byte to encode
  105. *
  106. * @return the encoded byte
  107. */
  108. unsigned char encodeByte(unsigned char byte);
  109. /**
  110. * Decode a byte according to HomeEasy
  111. *
  112. * @param byte the byte to decode
  113. *
  114. * @return the decoded byte
  115. */
  116. unsigned char decodeByte(unsigned char byte);
  117. /**
  118. * Append a bit that will be emitted for a specific time
  119. *
  120. * @param buffer the buffer holding the data
  121. * @param bit the bit to push
  122. * @param usec time in µs
  123. * @param clock frequency
  124. */
  125. void appendBit(BIT_BUFFER* buffer, unsigned char bit, unsigned int usec, unsigned int freq);
  126. /**
  127. * Append data according to Chacon protocole
  128. *
  129. * @param buffer the buffer holding the data
  130. * @param type data type (BIT0 | BIT1 | START_OF_FRAME | END_OF_DATA)
  131. * @param clock frequency
  132. */
  133. void appendData(BIT_BUFFER* buffer, unsigned int type, unsigned int freq);
  134. /**
  135. * Append a byte according to Chacon protocole
  136. *
  137. * @param buffer the buffer holding the data
  138. * @param byte the byte to append
  139. * @param clock frequency
  140. */
  141. void appendByte(BIT_BUFFER* buffer, unsigned char byte, unsigned int freq);
  142. /**
  143. * Append a complete command according to Chacon protocole
  144. *
  145. * @param buffer the buffer holding the data
  146. * @param id command id (refer to your remote)
  147. * @param section button section (0:A, 1:B, 2:C, 3:D)
  148. * @param nb button number(1, 2, 3, 4)
  149. * @param on boolean for on/off
  150. * @param global if true G button is selected (nb will be ignore)
  151. * @param clock frequency
  152. */
  153. void pushCode(BIT_BUFFER* buffer, unsigned char* id, unsigned char section, unsigned char nb, unsigned char on, unsigned char global, unsigned int freq);