emitlib.h 4.4 KB

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