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