| 162 | } |
| 163 | |
| 164 | void SbcInterface::ExchangeData() noexcept |
| 165 | { |
| 166 | // Process incoming packets |
| 167 | bool codeBufferAvailable = true; |
| 168 | for (size_t i = 0; i < transfer.PacketsToRead(); i++) |
| 169 | { |
| 170 | const PacketHeader * const packet = transfer.ReadPacket(); |
| 171 | if (packet == nullptr) |
| 172 | { |
| 173 | if (reprap.Debug(Module::SbcInterface)) |
| 174 | { |
| 175 | debugPrintf("Error trying to read next SPI packet\n"); |
| 176 | } |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | if (packet->request >= (uint16_t)SbcRequest::InvalidRequest) |
| 181 | { |
| 182 | REPORT_INTERNAL_ERROR; |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | bool packetAcknowledged = true; |
| 187 | switch ((SbcRequest)packet->request) |
| 188 | { |
| 189 | // Perform an emergency stop |
| 190 | case SbcRequest::EmergencyStop: |
| 191 | reprap.EmergencyStop(); |
| 192 | break; |
| 193 | |
| 194 | // Reset the controller |
| 195 | case SbcRequest::Reset: |
| 196 | reprap.EmergencyStop(); // turn off heaters and motors, tell expansion boards to reset |
| 197 | SoftwareReset(SoftwareResetReason::userFromSbc); |
| 198 | break; |
| 199 | |
| 200 | // Perform a G/M/T-code |
| 201 | case SbcRequest::Code: |
| 202 | { |
| 203 | // Read the next code |
| 204 | if (packet->length == 0) |
| 205 | { |
| 206 | reprap.GetPlatform().Message(WarningMessage, "Received empty binary code, discarding\n"); |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | const CodeHeader *code = reinterpret_cast<const CodeHeader*>(transfer.ReadData(packet->length)); |
| 211 | const GCodeChannel channel(code->channel); |
| 212 | if (channel.IsValid()) |
| 213 | { |
| 214 | GCodeBuffer * const gb = reprap.GetGCodes().GetGCodeBuffer(channel); |
| 215 | if (gb == nullptr) |
| 216 | { |
| 217 | REPORT_INTERNAL_ERROR; |
| 218 | break; |
| 219 | } |
| 220 | |
| 221 | if (gb->IsInvalidated()) |
nothing calls this directly
no test coverage detected