PowerDecoder.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2014
  6. All rights reserved.
  7. */
  8. #if !defined (POWER_DECODER_H)
  9. #define POWER_DECODER_H
  10. // We will designate the transmitting device type according to the
  11. // type of message that it sends.
  12. #define ANT_POWERONLY 0x10
  13. #define ANT_WHEELTORQUE 0x11
  14. #define ANT_CRANKTORQUE 0x12
  15. #define ANT_CRANKFREQ 0x20
  16. // We define the Torque Efficiency / Pedal Smoothness page here
  17. // even though it doesn't imply anything regarding the above types.
  18. #define ANT_TEPS 0x13
  19. // Calibration definitions
  20. #define ANT_CALIBRATION_MESSAGE (0x01)
  21. #define CALIBRATION_ID_BYTE (1)
  22. #define ANT_CTF_CALIBRATION_ID (0x10)
  23. #define ANT_CTF_CAL_TYPE_BYTE (2)
  24. #define ANT_CTF_CAL_ZERO (0x01)
  25. #define ANT_CTF_CAL_SLOPE (0x02)
  26. #define ANT_CTF_CAL_ESN (0x03)
  27. #define ANT_CTF_CAL_ACK (0xAC)
  28. #define ANT_CTF_CAL_ZERO_MSB_BYTE (6)
  29. #define ANT_CTF_CAL_ZERO_LSB_BYTE (7)
  30. #define MAXIMUM_TIME_GAP (240.0) // This is the power-down interval for several power meters...
  31. typedef struct _BPSAMPLER_t_
  32. {
  33. unsigned char ucPedalBalance;
  34. unsigned char ucCadence;
  35. unsigned long ulEventTime; // Quantized time of current event
  36. unsigned long ulLastRecordTime; // Quantized time of last resample output
  37. unsigned short usRecordInterval; // Quantized recording interval
  38. unsigned short usTimeBase; // Quantized event interval (for time based data)
  39. unsigned char ucRecordGapCount; // Number of resample outputs in message gap
  40. unsigned short usTorqueOffset; // CTF specific parameter
  41. float fPendingRotation; // Amount of rotation in latest event that will count towards the pending output
  42. float fGapRotation; // Amount of rotation in message gap
  43. float fAccumRotation; // Amount of rotation to carry forwards to next message event
  44. double dTotalRotation; // Total crank or wheel rotation (in rotations)
  45. float fPendingEnergy; // Amount of rotation in latest event that will count towards the pending output
  46. float fGapEnergy; // Amount of rotation in message gap
  47. float fAccumEnergy; // Amount of rotation to carry forwards to next message event
  48. double dTotalEnergy; // Total crank or wheel rotation (in rotations)
  49. double dLastRecordTime; // absolute time (in seconds) of last resample output
  50. double dLastMessageTime; // absolute time (in seconds) of last message
  51. unsigned short usLastAccumPeriod; // Accumulated period or timestamp in last received message
  52. unsigned short usLastAccumTorque; // Accumulated torque in last received message
  53. unsigned char ucLastEventCount; // Message Event count in last received message
  54. unsigned char ucLastRotationTicks; // Crank or Wheel rotation count in last received messsage
  55. } BPSAMPLER;
  56. // Power receiver signature
  57. typedef void(*PowerRecordReceiver) (double dLastRecordTime_, double dTotalRotation_, double dTotalEnergy_, float fAverageCadence_, float fAveragePower_);
  58. // Initializes the power decoder library with the record interval (s) and the power meter timebase (s) or event base (0).
  59. void InitPowerDecoder(double dRecordInterval_, double dTimeBase_, double dReSyncInterval_, PowerRecordReceiver powerRecordReceiverPtr_);
  60. // Pass Bike Power messages for the power decoder library to process
  61. void DecodePowerMessage(double dRxTime_, unsigned char messagePayload_[]);
  62. // 16 = Power Only, 17 = Wheel Torque, 18 = Crank Torque, 32 = Crank Torque Frequency, 255 = Unknown
  63. void SetPowerMeterType(unsigned char ucPowerMeterType_);
  64. #endif