/test/capture_test.c

http://bdremote-ng.googlecode.com/ · C · 130 lines · 71 code · 21 blank · 38 comment · 6 complexity · 558cf7ae456f2d4b9967c59bb6292782 MD5 · raw file

  1. /*
  2. * bdremoteng - helper daemon for Sony(R) BD Remote Control
  3. * Based on bdremoted, written by Anton Starikov <antst@mail.ru>.
  4. *
  5. * Copyright (C) 2009 Michael Wojciechowski <wojci@wojci.dk>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. /** \ingroup Test */
  24. /*\@{*/
  25. /*! \file capture_test.c
  26. \brief Test bluetooth capture.
  27. Test application which should print something when the remote
  28. connects and sends data.
  29. Notice the hardcoded destination address.
  30. */
  31. #include <globaldefs.h>
  32. #include <captureif.h>
  33. #include <stdio.h>
  34. #include <assert.h>
  35. #include <string.h>
  36. #include <l.h>
  37. unsigned int globalLogMask =
  38. MODULEMASK_LIRC_THR | MODULEMASK_LIRC_SOCK |
  39. MODULEMASK_LIRC_CB | MODULEMASK_BT_IF | MODULEMASK_BT_IMPL |
  40. MODULEMASK_QUEUE | MODULEMASK_SPARE | MODULEMASK_MAIN;
  41. static const unsigned int moduleMask = MODULEMASK_MAIN;
  42. /** Capture interface implementation. */
  43. void RemoteConnected(void* _p)
  44. {
  45. assert(_p);
  46. printf("Remote connected.\n");
  47. }
  48. /** Capture interface implementation. */
  49. void DataInd(void* _p, const char* _data, const int _size)
  50. {
  51. assert(_p);
  52. assert(_data);
  53. printf("Remote data indication, %d bytes.\n", _size);
  54. }
  55. /** Capture interface implementation. */
  56. void RemoteDisconnected(void* _p)
  57. {
  58. assert(_p);
  59. printf("Remote disconnected.\n");
  60. }
  61. void RemoteBatteryCharge(void* _p, int _val)
  62. {
  63. assert(_p);
  64. printf("Battery charge %d %%.\n", _val);
  65. }
  66. /** Capture test. */
  67. int main(int argc, char *argv[])
  68. {
  69. /* Address of the remote. */
  70. const char* destinationAddress = "00:19:C1:58:C3:B7";
  71. configuration config;
  72. captureData cd;
  73. void* p = (void*)0x1; /* Unused here. */
  74. int res = BDREMOTE_FAIL;
  75. int i = 0;
  76. if (argc > 1)
  77. {
  78. printf("Arguments are not supported.\n");
  79. for (i = 1; i < argc; i++)
  80. {
  81. printf("Unhandled argument: %s.\n", argv[i]);
  82. }
  83. return -1;
  84. }
  85. setDefaultLog();
  86. memset(&config, 0, sizeof(config));
  87. memset(&cd, 0, sizeof(cd));
  88. setDefaults(&config);
  89. setRemoteAddress(&config, destinationAddress);
  90. InitCaptureData(&cd,
  91. &config,
  92. p);
  93. res = InitcaptureLoop(&cd);
  94. if (res == BDREMOTE_FAIL)
  95. {
  96. BDREMOTE_DBG(config.debug, "InitcaptureLoop failed.");
  97. return BDREMOTE_FAIL;
  98. }
  99. /* Run capture loop. */
  100. res = captureLoop(&cd);
  101. if (res == BDREMOTE_FAIL)
  102. {
  103. BDREMOTE_ERR("captureLoop failed.");
  104. return BDREMOTE_FAIL;
  105. }
  106. return BDREMOTE_OK;
  107. }
  108. /*\@}*/