demo_hr_receiver.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #ifndef __HR_RECEIVER_H__
  9. #define __HR_RECEIVER_H__
  10. #include "types.h"
  11. #include "dsi_framer_ant.hpp"
  12. //#include "dsi_thread.h"
  13. #include "dsi_serial_generic.hpp"
  14. //#include "dsi_debug.hpp"
  15. #include <stdio.h>
  16. //#include <stdlib.h>
  17. #include <assert.h>
  18. //#include <string.h>
  19. #define CHANNEL_TYPE_MASTER (0)
  20. #define CHANNEL_TYPE_SLAVE (1)
  21. #define CHANNEL_TYPE_INVALID (2)
  22. #define ENABLE_EXTENDED_MESSAGES
  23. #define USER_BAUDRATE (57600) // For AT3/AP2, use 57600
  24. // Page decoding constants
  25. #define TOGGLE_MASK ((UCHAR)0x80) // For removing the toggle bit for HRM decoding
  26. #define INVALID_TOGGLE_BIT ((BOOL)0xFF) // Invalid BOOL, can be initialised because BOOL is just int
  27. #define PAGE_0 ((UCHAR)0x00)
  28. #define PAGE_1 ((UCHAR)0x01)
  29. #define PAGE_2 ((UCHAR)0x02)
  30. #define PAGE_3 ((UCHAR)0x03)
  31. #define PAGE_4 ((UCHAR)0x04)
  32. #define MAX_TOGGLE_ATTEMPTS ((UCHAR)0x06) // 1 extra to provide some margin
  33. #define LEGACY_DEVICE ((UCHAR)0x10) // Arbitrarily chosen definition
  34. #define CURRENT_DEVICE ((UCHAR)0x11) // Arbitrarily chosen definition
  35. #define INVALID_DEVICE ((UCHAR)0xFF) // Arbitrarily chosen definition
  36. // Channel configuration specs for HRM Receiever (including network config defaults)
  37. #define USER_ANTCHANNEL (0) // Arbitrarily chosen as default
  38. #define USER_NETWORK_KEY {0xB9, 0xA5, 0x21, 0xFB, 0xBD, 0x72, 0xC3, 0x45} // ANT+ network key
  39. #define USER_RADIOFREQ (57) // ANT+ spec
  40. #define USER_TRANSTYPE (0) // Wildcarded for pairing (default)
  41. #define USER_DEVICETYPE (120) // ANT+ HRM
  42. #define USER_DEVICENUM (0) // Wildcarded for pairing (default)
  43. #define MESSAGE_TIMEOUT (12) // = 12*2.5 = 30 seconds
  44. #define USER_NETWORK_NUM (0) // The network key is assigned to this network number (default)
  45. // Permitted ANT+ HRM Message periods
  46. #define USER_MESSAGE_PERIODS {(USHORT)8070, (USHORT)16140, (USHORT)32280}
  47. // Indexes into message recieved from ANT
  48. #define MESSAGE_BUFFER_DATA1_INDEX ((UCHAR) 0)
  49. #define MESSAGE_BUFFER_DATA2_INDEX ((UCHAR) 1)
  50. #define MESSAGE_BUFFER_DATA3_INDEX ((UCHAR) 2)
  51. #define MESSAGE_BUFFER_DATA4_INDEX ((UCHAR) 3)
  52. #define MESSAGE_BUFFER_DATA5_INDEX ((UCHAR) 4)
  53. #define MESSAGE_BUFFER_DATA6_INDEX ((UCHAR) 5)
  54. #define MESSAGE_BUFFER_DATA7_INDEX ((UCHAR) 6)
  55. #define MESSAGE_BUFFER_DATA8_INDEX ((UCHAR) 7)
  56. #define MESSAGE_BUFFER_DATA9_INDEX ((UCHAR) 8)
  57. #define MESSAGE_BUFFER_DATA10_INDEX ((UCHAR) 9)
  58. #define MESSAGE_BUFFER_DATA11_INDEX ((UCHAR) 10)
  59. #define MESSAGE_BUFFER_DATA12_INDEX ((UCHAR) 11)
  60. #define MESSAGE_BUFFER_DATA13_INDEX ((UCHAR) 12)
  61. #define MESSAGE_BUFFER_DATA14_INDEX ((UCHAR) 13)
  62. ////////////////////////////////////////////////////////////////////////////////
  63. // HRMReceiver (Heart Rate Receiver) class.
  64. ////////////////////////////////////////////////////////////////////////////////
  65. class HRMReceiver {
  66. public:
  67. HRMReceiver();
  68. virtual ~HRMReceiver();
  69. BOOL Init(UCHAR ucDeviceNumber_);
  70. void Start();
  71. void Close();
  72. private:
  73. BOOL InitANT();
  74. // Starts the Message thread.
  75. static DSI_THREAD_RETURN RunMessageThread(void *pvParameter_);
  76. // Listens for a response from the module
  77. void MessageThread();
  78. // Decodes the received message
  79. void ProcessMessage(ANT_MESSAGE stMessage, USHORT usSize_);
  80. // Print user menu
  81. void PrintMenu();
  82. // Detect transmitter device type: current or legacy
  83. void DetectDevice(UCHAR &ucDeviceType_, BOOL &bOldToggleBit_, UCHAR &ucToggleAttempts_, BOOL bToggleBit);
  84. // Network variables
  85. UCHAR ucAntChannel;
  86. UCHAR ucTransType;
  87. USHORT usDeviceNum;
  88. UCHAR ucNetworkNum;
  89. USHORT usMessagePeriod;
  90. BOOL bBursting; // Holds whether the bursting phase of the test has started
  91. BOOL bBroadcasting;
  92. BOOL bMyDone;
  93. BOOL bDone;
  94. UCHAR ucChannelType;
  95. DSISerialGeneric* pclSerialObject;
  96. DSIFramerANT* pclMessageObject;
  97. DSI_THREAD_ID uiDSIThread;
  98. DSI_CONDITION_VAR condTestDone;
  99. DSI_MUTEX mutexTestDone;
  100. BOOL bDisplay;
  101. BOOL bProcessedData;
  102. };
  103. #endif