MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / ProcessReceivedData

Method ProcessReceivedData

src/Accelerometers/Accelerometers.cpp:567–664  ·  view source on GitHub ↗

Process accelerometer data received over CAN

Source from the content-addressed store, hash-verified

565
566// Process accelerometer data received over CAN
567void Accelerometers::ProcessReceivedData(CanAddress src, const CanMessageAccelerometerData& msg, size_t msgLen) noexcept
568{
569# ifdef DUET3_ATE
570 if (Duet3Ate::ProcessAccelerometerData(src, msg, msgLen))
571 {
572 return; // ATE has processed the data
573 }
574# endif
575
576 FileStore * const f = accelerometerFile;
577 if (f != nullptr)
578 {
579 if (msgLen < msg.GetActualDataLength())
580 {
581 f->Write("Received bad data\n");
582 f->Truncate(); // truncate the file in case we didn't write all the preallocated space
583 f->Close();
584 accelerometerFile = nullptr;
585 reprap.GetExpansion().AddAccelerometerRun(src, 0);
586 }
587 else if (msg.axes != expectedRemoteAxes || msg.firstSampleNumber != expectedRemoteSampleNumber || src != expectedRemoteBoardAddress)
588 {
589 f->Write("Received mismatched data\n");
590 f->Truncate(); // truncate the file in case we didn't write all the preallocated space
591 f->Close();
592 accelerometerFile = nullptr;
593 reprap.GetExpansion().AddAccelerometerRun(src, 0);
594 }
595 else
596 {
597 unsigned int numSamples = msg.numSamples;
598 const unsigned int numAxes = (expectedRemoteAxes & 1u) + ((expectedRemoteAxes >> 1) & 1u) + ((expectedRemoteAxes >> 2) & 1u);
599 size_t dataIndex = 0;
600 uint16_t currentBits = 0;
601 unsigned int bitsLeft = 0;
602 const unsigned int receivedResolution = msg.bitsPerSampleMinusOne + 1;
603 const uint16_t mask = (1u << receivedResolution) - 1;
604 const int decimalPlaces = GetDecimalPlaces(receivedResolution);
605 if (msg.overflowed)
606 {
607 ++numRemoteOverflows;
608 }
609
610 while (numSamples != 0)
611 {
612 String<StringLength50> temp;
613 temp.printf("%u", expectedRemoteSampleNumber);
614 ++expectedRemoteSampleNumber;
615
616 for (unsigned int axis = 0; axis < numAxes; ++axis)
617 {
618 // Extract one value from the message. A value spans at most two words in the buffer.
619 uint16_t val = currentBits;
620 if (bitsLeft >= receivedResolution)
621 {
622 bitsLeft -= receivedResolution;
623 currentBits >>= receivedResolution;
624 }

Callers

nothing calls this directly

Calls 9

GetDecimalPlacesFunction · 0.85
GetBitsAfterPointFunction · 0.85
TruncateMethod · 0.80
AddAccelerometerRunMethod · 0.80
catfMethod · 0.80
catMethod · 0.80
WriteMethod · 0.60
CloseMethod · 0.45
printfMethod · 0.45

Tested by

no test coverage detected