| 2064 | // USB port functions |
| 2065 | |
| 2066 | void Platform::AppendUsbReply(const GCodeBuffer *_ecv_null gb, OutputBuffer *buffer, bool rawMessage) noexcept |
| 2067 | { |
| 2068 | if (!SERIAL_MAIN_DEVICE.IsConnected()) |
| 2069 | { |
| 2070 | // If the serial USB line is not open, discard the message right away |
| 2071 | OutputBuffer::ReleaseAll(buffer); |
| 2072 | usbMessageSeq = 0; // reset the sequence number for when the USB port connects |
| 2073 | } |
| 2074 | else |
| 2075 | { |
| 2076 | // Else append incoming data to the stack |
| 2077 | MutexLocker lock(usbMutex); |
| 2078 | if (rawMessage || GetChannelMode(0) == AuxMode::raw) |
| 2079 | { |
| 2080 | usbOutput.Push(buffer); |
| 2081 | } |
| 2082 | else |
| 2083 | { |
| 2084 | OutputBuffer *buf; |
| 2085 | if (OutputBuffer::Allocate(buf)) |
| 2086 | { |
| 2087 | usbMessageSeq++; |
| 2088 | RepRap::StartJsonResponse(gb, buf); |
| 2089 | buf->catf("\"seq\":%" PRIu32 ",\"resp\":", usbMessageSeq); |
| 2090 | buf->EncodeReply(buffer); |
| 2091 | buf->cat("}\n"); |
| 2092 | usbOutput.Push(buf); |
| 2093 | } |
| 2094 | else |
| 2095 | { |
| 2096 | OutputBuffer::ReleaseAll(buffer); |
| 2097 | } |
| 2098 | } |
| 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | // Aux port functions |
| 2103 | |