emitlib.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 a word in a buffer
  79. *
  80. * @param buffer the buffer holding the data
  81. * @param word the word to push
  82. */
  83. void pushWord(BYTE_BUFFER* buffer, unsigned short int word)
  84. /**
  85. * Push some bytes in a buffer
  86. *
  87. * @param buffer the buffer holding the data
  88. * @param bytes the bytes to push
  89. * @param len the number of bytes to push
  90. */
  91. void pushBytes(BYTE_BUFFER* buffer, unsigned char *byte, unsigned int len);
  92. /**
  93. * Encode bits with HomeEasy encoding (1 => 10, 0 => 01)
  94. *
  95. * @param buffer the buffuer to encode
  96. *
  97. * @return new buffer
  98. * */
  99. BYTE_BUFFER homeEasyEncode(BYTE_BUFFER *buffer);
  100. /**
  101. * Decode bits with HomeEasy encoding (1 => 10, 0 => 01)
  102. *
  103. * @param buffer the buffuer to decode
  104. *
  105. * @return new buffer
  106. * */
  107. BYTE_BUFFER homeEasyDecode(BYTE_BUFFER *buffer);
  108. /**
  109. * Encode a byte according to HomeEasy
  110. *
  111. * @param byte the byte to encode
  112. *
  113. * @return the encoded byte
  114. */
  115. unsigned char encodeByte(unsigned char byte);
  116. /**
  117. * Decode a byte according to HomeEasy
  118. *
  119. * @param byte the byte to decode
  120. *
  121. * @return the decoded byte
  122. */
  123. unsigned char decodeByte(unsigned char byte);
  124. /**
  125. * Append a bit that will be emitted for a specific time
  126. *
  127. * @param buffer the buffer holding the data
  128. * @param bit the bit to push
  129. * @param usec time in µs
  130. * @param clock frequency
  131. */
  132. void appendBit(BIT_BUFFER* buffer, unsigned char bit, unsigned int usec, unsigned int freq);
  133. /**
  134. * Append data according to Chacon protocole
  135. *
  136. * @param buffer the buffer holding the data
  137. * @param type data type (BIT0 | BIT1 | START_OF_FRAME | END_OF_DATA)
  138. * @param clock frequency
  139. */
  140. void appendData(BIT_BUFFER* buffer, unsigned int type, unsigned int freq);
  141. /**
  142. * Append a byte according to Chacon protocole
  143. *
  144. * @param buffer the buffer holding the data
  145. * @param byte the byte to append
  146. * @param clock frequency
  147. */
  148. void appendByte(BIT_BUFFER* buffer, unsigned char byte, unsigned int freq);
  149. /**
  150. * Append a complete command according to Chacon protocole
  151. *
  152. * @param buffer the buffer holding the data
  153. * @param id command id (refer to your remote)
  154. * @param section button section (0:A, 1:B, 2:C, 3:D)
  155. * @param nb button number(1, 2, 3, 4)
  156. * @param on boolean for on/off
  157. * @param global if true G button is selected (nb will be ignore)
  158. * @param clock frequency
  159. */
  160. void pushCode(BIT_BUFFER* buffer, unsigned char* id, unsigned char section, unsigned char nb, unsigned char on, unsigned char global, unsigned int freq);