Skip to content

Commit 699eb1f

Browse files
save last packet
add handling for missing telem
1 parent acb6b23 commit 699eb1f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pd.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,21 @@ def decode(self):
160160
dshot_value = DshotCmd(self.dshot_cfg)
161161
telem_value = DshotTelem(self.dshot_cfg)
162162

163+
last_dshot_value = DshotCmd(self.dshot_cfg)
164+
last_telem_value = DshotTelem(self.dshot_cfg)
165+
166+
max_time_before_telem = 40e-6
167+
max_samples_before_telem = int(max_time_before_telem / (1 / self.samplerate))
168+
163169
#bitseq = BitDshot()
164170
while True:
165171

166172
match self.state:
167173
case State.CMD:
168174
match self.state_dshot:
169175
case State_Dshot.RESET:
176+
if dshot_value.crc_ok:
177+
last_dshot_value = dshot_value
170178
dshot_value = DshotCmd(self.dshot_cfg)
171179
self.state_dshot = State_Dshot.START
172180

@@ -175,6 +183,10 @@ def decode(self):
175183
pins = self.wait([{0: 'r'}, {0: 'f'}, {'skip': self.dshot_cfg.samples_after_motorcmd}])
176184
else:
177185
pins = self.wait([{0: 'f'}, {0: 'r'}, {'skip': self.dshot_cfg.samples_after_motorcmd}])
186+
187+
#if self.samplenum == (self.samplenum + (1/self.samplerate * 30e-6):
188+
print((self.samplenum + (1/self.samplerate * 30e-6)))
189+
178190
#TODO: Increase skip to maximum time for effiency
179191
#TODO: Mark any changes in this time as errors? Option to reduce load?
180192

@@ -195,6 +207,8 @@ def decode(self):
195207
if result:
196208
self.display_dshot(dshot_value)
197209
self.state_dshot = State_Dshot.RESET
210+
#TODO: Change??
211+
dshot_value.packet.es = self.samplenum
198212
if result and self.dshot_cfg.bidirectional:
199213
self.state = State.TELEM
200214

@@ -221,10 +235,15 @@ def decode(self):
221235
self.state_telem = State_Dshot.START
222236

223237
case State_Dshot.START:
238+
if last_dshot_value.packet.es is not None:
239+
if self.samplenum >= last_dshot_value.packet.es + max_samples_before_telem:
240+
self.state_telem = State_Dshot.RESET
241+
self.state = State.CMD
242+
continue
224243
# First wait for falling edge (idle high)
225244
pins = self.wait([{0: 'f'}])
226245
# Save start pulse
227-
tlm_start = self.samplenum
246+
telem_value.packet.ss = self.samplenum
228247
# Switch to receiving state
229248
self.state_telem = State_Dshot.RECV
230249
# TODO: Check if still low after 1/8 bitlength for error det?

protoDshot/protocols_motor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from functools import reduce
22
from enum import Enum
3+
from .dshot_bits import Sequence
34

45
gcr_tables = {
56
"0b11001": 0x0,
@@ -53,6 +54,7 @@ def __init__(self,settings_Dshot=DshotSettings()):
5354
self.crc_ok = False
5455
self.bits = 0
5556
self.results = []
57+
self.packet = Sequence()
5658

5759
def checkCRC(self,data,crc_recv):
5860
self.crc_recv = crc_recv

0 commit comments

Comments
 (0)