4 #include "stubborn_receiver.h"
6 StubbornReceiver::StubbornReceiver()
13 void StubbornReceiver::setMaxPackageIndex(uint8_t maxPackageIndex
)
15 if (this->maxPackageIndex
!= maxPackageIndex
)
17 this->maxPackageIndex
= maxPackageIndex
;
22 void StubbornReceiver::ResetState()
26 telemetryConfirm
= false;
29 bool StubbornReceiver::GetCurrentConfirm()
31 return telemetryConfirm
;
34 void StubbornReceiver::SetDataToReceive(uint8_t* dataToReceive
, uint8_t maxLength
)
43 void StubbornReceiver::ReceiveData(uint8_t const packageIndex
, uint8_t const * const receiveData
, uint8_t dataLen
)
46 if (packageIndex
== maxPackageIndex
)
48 telemetryConfirm
= !telemetryConfirm
;
60 bool acceptData
= false;
61 // If this is the last package, accept as being complete
62 if (packageIndex
== 0 && currentPackage
> 1)
64 // PackageIndex 0 (the final packet) can also contain data
68 // If this package is the expected index, accept and advance index
69 else if (packageIndex
== currentPackage
)
73 // If this is the first package from the sender, and we're mid-receive
74 // assume the sender has restarted without resync or is freshly booted
75 // skip the resync process entirely and just pretend this is a fresh boot too
76 else if (packageIndex
== 1 && currentPackage
> 1)
85 uint8_t len
= std::min((uint8_t)(length
- currentOffset
), dataLen
);
86 memcpy(&data
[currentOffset
], receiveData
, len
);
89 telemetryConfirm
= !telemetryConfirm
;
93 bool StubbornReceiver::HasFinishedData()
98 void StubbornReceiver::Unlock()
104 finishedData
= false;