1
|
|
|
from libAnt.core import lazyproperty |
2
|
|
|
|
3
|
|
|
from libAnt.profiles.factory import ProfileMessage |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class PowerProfileMessage(ProfileMessage): |
7
|
|
|
""" Message from Power Meter """ |
8
|
|
|
|
9
|
|
|
maxAccumulatedPower = 65536 |
10
|
|
|
maxEventCount = 256 |
11
|
|
|
|
12
|
|
|
@lazyproperty |
13
|
|
|
def dataPageNumber(self): |
14
|
|
|
""" |
15
|
|
|
:return: Data Page Number (int) |
16
|
|
|
""" |
17
|
|
|
return self.msg.content[0] |
18
|
|
|
|
19
|
|
|
@lazyproperty |
20
|
|
|
def eventCount(self): |
21
|
|
|
""" |
22
|
|
|
The update event count field is incremented each time the information in the message is updated. |
23
|
|
|
There are no invalid values for update event count. |
24
|
|
|
The update event count in this message refers to updates of the standard Power-Only main data page (0x10) |
25
|
|
|
:return: Power Event Count |
26
|
|
|
""" |
27
|
|
|
return self.msg.content[1] |
28
|
|
|
|
29
|
|
|
@lazyproperty |
30
|
|
|
def instantaneousCadence(self): |
31
|
|
|
""" |
32
|
|
|
The instantaneous cadence field is used to transmit the pedaling cadence recorded from the power sensor. |
33
|
|
|
This field is an instantaneous value only; it does not accumulate between messages. |
34
|
|
|
:return: Instantaneous Cadence (W) |
35
|
|
|
""" |
36
|
|
|
return self.msg.content[3] |
37
|
|
|
|
38
|
|
|
@lazyproperty |
39
|
|
|
def accumulatedPower(self): |
40
|
|
|
""" |
41
|
|
|
Accumulated power is the running sum of the instantaneous power data and is incremented at each update |
42
|
|
|
of the update event count. The accumulated power field rolls over at 65.535kW. |
43
|
|
|
:return: |
44
|
|
|
""" |
45
|
|
|
return (self.msg.content[5] << 8) | self.msg.content[4] |
46
|
|
|
|
47
|
|
|
@lazyproperty |
48
|
|
|
def instantaneousPower(self): |
49
|
|
|
""" Instantaneous power (W) """ |
50
|
|
|
return (self.msg.content[7] << 8) | self.msg.content[6] |
51
|
|
|
|
52
|
|
|
@lazyproperty |
53
|
|
|
def accumulatedPowerDiff(self): |
54
|
|
|
if self.previous is None: |
55
|
|
|
return None |
56
|
|
|
elif self.accumulatedPower < self.previous.accumulatedPower: |
57
|
|
|
# Rollover |
58
|
|
|
return (self.accumulatedPower - self.previous.accumulatedPower) + self.maxAccumulatedPower |
59
|
|
|
else: |
60
|
|
|
return self.accumulatedPower - self.previous.accumulatedPower |
61
|
|
|
|
62
|
|
|
@lazyproperty |
63
|
|
|
def eventCountDiff(self): |
64
|
|
|
if self.previous is None: |
65
|
|
|
return None |
66
|
|
|
elif self.eventCount < self.previous.eventCount: |
67
|
|
|
# Rollover |
68
|
|
|
return (self.eventCount - self.previous.eventCount) + self.maxEventCount |
69
|
|
|
else: |
70
|
|
|
return self.eventCount - self.previous.eventCount |
71
|
|
|
|
72
|
|
|
@lazyproperty |
73
|
|
|
def averagePower(self): |
74
|
|
|
""" |
75
|
|
|
Under normal conditions with complete RF reception, average power equals instantaneous power. |
76
|
|
|
In conditions where packets are lost, average power accurately calculates power over the interval |
77
|
|
|
between the received messages |
78
|
|
|
:return: Average power (Watts) |
79
|
|
|
""" |
80
|
|
|
if self.previous is None: |
81
|
|
|
return self.instantaneousPower |
82
|
|
|
if self.eventCount == self.previous.eventCount: |
83
|
|
|
return self.instantaneousPower |
84
|
|
|
return self.accumulatedPowerDiff / self.eventCountDiff |
85
|
|
|
|