emit.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <stdio.h>
  2. #include "home_easy.h"
  3. #include "buffer.h"
  4. #include <malloc.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <errno.h>
  8. /**
  9. * Usage of this program
  10. */
  11. void usage(char** argv)
  12. {
  13. fprintf(stderr, "Chacon command V1.0\nC. Meichel\n2013, October\n");
  14. fprintf(stderr, "Syntaxe : %s [options]\n", argv[0]);
  15. fprintf(stderr, "\t-b button\n\t\tbutton (A-D1-4|G). For instance A1, G, D3\n");
  16. fprintf(stderr, "\t-x:\n\t\tOff (default On)\n");
  17. fprintf(stderr, "\t-r number:\n\t\tnumber of repeatitions\n");
  18. fprintf(stderr, "\t-d id:\n\t\thexadecimal id from your command (13 letters <=> 52 bits)\n");
  19. fprintf(stderr, "\t-v: verbose bits\n");
  20. }
  21. /**
  22. * Main program
  23. *
  24. * @param argc number of arguments passed to the program
  25. * @param argv array of arguments passed to the program
  26. *
  27. * @return status
  28. */
  29. int main(int argc, char** argv)
  30. {
  31. unsigned long int command;
  32. BYTE_BUFFER encoded;
  33. int i;
  34. char optstring[] = "xvb:d:r:";
  35. int option;
  36. unsigned char number = 1;
  37. unsigned char section = 'A';
  38. char *idString=0;
  39. unsigned long int id=0;
  40. unsigned char onOff = ON;
  41. unsigned int verbose = 0;
  42. unsigned repeat = 5;
  43. #if 0
  44. /* reading options */
  45. //opterr=0; /* Pas de message d'erreur automatique */
  46. while ((option = getopt(argc, argv, optstring)) != -1) {
  47. switch (option) {
  48. case 'b':
  49. // Decode the button ie : A3
  50. section = optarg[0] - (optarg[0]<'Z' ? 0 : 'a' - 'A');
  51. if (strlen(optarg)>1) {
  52. number = optarg[1] - '0';
  53. }
  54. break;
  55. case 'r':
  56. // repeatition code
  57. sscanf(optarg, "%d", &repeat);
  58. break;
  59. case 'd':
  60. // command id
  61. sscanf(optarg, "%08X", &id);
  62. break;
  63. case 'x':
  64. // OFF ?
  65. onOff = OFF;
  66. break;
  67. case 'v':
  68. // Show the bits to send ?
  69. verbose = 1;
  70. break;
  71. default:
  72. usage(argv);
  73. return 0;
  74. break;
  75. }
  76. }
  77. // Show informations
  78. printf("device id: %08X\n", id);
  79. if (section == 'G') {
  80. printf("Sending command G: %s\n", (onOff == OFF) ? "OFF" : "ON");
  81. } else {
  82. printf("Sending command %c%d: %s\n", section, number, (onOff == OFF) ? "OFF" : "ON");
  83. }
  84. // Display mor information
  85. if (verbose) {
  86. command = createHomeEasyCommand(id, section, number, onOff);
  87. printf("Frame to send: %08X\n", command);
  88. printf("Code to emit:\n");
  89. encoded = homeEasyEncode(command);
  90. printfByteBuffer(encoded);
  91. // release the memory
  92. destroyByteBuffer(encoded);
  93. }
  94. // Send the data
  95. initIO();
  96. sendHomeEasyCommand(id, section, number, onOff, repeat);
  97. #endif
  98. initIO();
  99. sendPortailCommand(0,0,200);
  100. return 0;
  101. }