std::pair<Message::Payload, Option<Error>> jsToJson(QJSValue value) { capnp::MallocMessageBuilder msg; auto json_builder = msg.initRoot<JsonValue>(); auto err = _::jsToJson(value, json_builder); Message::Payload pl; if (!err.has()) { pl = writePayload(msg); } return std::make_pair(std::move(pl), err); }
void StreamSubscriptionResponderBase::onNextImpl(Payload response) noexcept { debugCheckOnNextOnCompleteOnError(); switch (state_) { case State::RESPONDING: { debugCheckOnNextOnCompleteOnError(); writePayload(std::move(response), false); break; } case State::CLOSED: break; } }
void QRF24::startWrite( const void* buf, quint8 len ) { // Transmitter power-up writeRegister(CONFIG, ( readRegister(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) ); delayMicroseconds(150); // Send the payload writePayload( buf, len ); // Allons! bcm2835_gpio_write(ce_pin, HIGH); delayMicroseconds(15); bcm2835_gpio_write(ce_pin, LOW); }
TransferReceiver::ResultCode TransferReceiver::receive(const RxFrame& frame, TransferBufferAccessor& tba) { // Transfer timestamps are derived from the first frame if (frame.isFirst()) { this_transfer_ts_ = frame.getMonotonicTimestamp(); first_frame_ts_ = frame.getUtcTimestamp(); } if (frame.isFirst() && frame.isLast()) { tba.remove(); updateTransferTimings(); prepareForNextTransfer(); this_transfer_crc_ = 0; // SFT has no CRC return ResultSingleFrame; } // Payload write ITransferBuffer* buf = tba.access(); if (buf == NULL) { buf = tba.create(); } if (buf == NULL) { UAVCAN_TRACE("TransferReceiver", "Failed to access the buffer, %s", frame.toString().c_str()); prepareForNextTransfer(); registerError(); return ResultNotComplete; } if (!writePayload(frame, *buf)) { UAVCAN_TRACE("TransferReceiver", "Payload write failed, %s", frame.toString().c_str()); tba.remove(); prepareForNextTransfer(); registerError(); return ResultNotComplete; } next_frame_index_++; if (frame.isLast()) { updateTransferTimings(); prepareForNextTransfer(); return ResultComplete; } return ResultNotComplete; }
bool RADIO_Send(uint8_t *payload) { uint8_t fifo_status = readRegister(NRF_FIFO_STATUS); if (fifo_status & 0x20) { return false; } bufferCount++; writePayload(payload, NRF_PACKET_SIZE); return true; }
/****************************************************************************** Sends data through a USB endpoint. Parameters: data - Pointer to a buffer with the data to send. size - Size of the data buffer. callback - Optional callback function to invoke when the transfer is complete. argument - Optional argument to the callback function. ******************************************************************************/ void txUsbData(void *data, uint32_t size, TransferCallback_t callback, void *argument) { // Setup the transfer descriptor transfer.data = (void *) data; transfer.remaining = size; transfer.buffered = 0; transfer.transferred = 0; transfer.callback = callback; transfer.argument = argument; // Send the first packet epState = UDP_ENDPOINT_SENDING; while (UDP_CSR_TXPKTRDY == (UDP->UDP_CSR[EP_NUMBER] & UDP_CSR_TXPKTRDY)); writePayload(); setCSR(UDP_CSR_TXPKTRDY); }
/**************************************************************************//** \brief End point handler. ******************************************************************************/ static void epHandler(void) { uint16_t i; uint8_t *ptr; // wait for transaction on 0 endpoint while (!(UDP->UDP_ISR & UDP_ISR_EP0INT)); // acknowledge end point 0 interrupt UDP->UDP_ICR = UDP_ISR_EP0INT; epStatus = UDP->UDP_CSR[EP_NUMBER]; // Handle endpoint actions // IN packet sent if (epStatus & UDP_CSR_TXCOMP) { // Check that endpoint was in Sending state if (UDP_ENDPOINT_SENDING == epState) { if (transfer.buffered < END_POINT_MAX_SIZE) { // transfer is finished transfer.transferred += transfer.buffered; transfer.buffered = 0; clearCSR(UDP_CSR_TXCOMP); // Endpoint returns in Idle state epState = UDP_ENDPOINT_IDLE; endOfTransfer(); } else { // Transfer remaining data transfer.transferred += END_POINT_MAX_SIZE; transfer.buffered -= END_POINT_MAX_SIZE; // Send next packet writePayload(); setCSR(UDP_CSR_TXPKTRDY); clearCSR(UDP_CSR_TXCOMP); } } else { // Acknowledge transaction clearCSR(UDP_CSR_TXCOMP); } } // OUT packet received if (epStatus & UDP_RXDATA) { // Check that the endpoint is in Receiving state if (UDP_ENDPOINT_RECEIVING != epState) { // Check if an ACK has been received on a Control endpoint if ((epStatus & UDP_CSR_RXBYTECNT) == 0) { // Acknowledge the data and finish the current transfer // Notify USB peripheral device that data have been read in the FIFO's Bank 0. UDP->UDP_CSR[EP_NUMBER] &= ~UDP_CSR_RX_DATA_BK0; while ((UDP->UDP_CSR[EP_NUMBER] & UDP_CSR_RX_DATA_BK0) == UDP_CSR_RX_DATA_BK0); // Endpoint returns in Idle state epState = UDP_ENDPOINT_IDLE; endOfTransfer(); } // Check if the data has been STALLed else if (epStatus & UDP_CSR_FORCESTALL) { // Discard STALLed data // Notify USB peripheral device that data have been read in the FIFO's Bank 0. UDP->UDP_CSR[EP_NUMBER] &= ~UDP_CSR_RX_DATA_BK0; while ((UDP->UDP_CSR[EP_NUMBER] & UDP_CSR_RX_DATA_BK0) == UDP_CSR_RX_DATA_BK0); } } // Endpoint is in Read state else { // Retrieve data and store it into the current transfer buffer uint16_t size = (uint16_t)(epStatus >> 16); readPayload(size); // Notify USB peripheral device that data have been read in the FIFO's Bank 0. UDP->UDP_CSR[EP_NUMBER] &= ~UDP_CSR_RX_DATA_BK0; while ((UDP->UDP_CSR[EP_NUMBER] & UDP_CSR_RX_DATA_BK0) == UDP_CSR_RX_DATA_BK0); // Check if the transfer is finished if ((transfer.remaining == 0) || (size < END_POINT_MAX_SIZE)) { // Endpoint returns in Idle state epState = UDP_ENDPOINT_IDLE; endOfTransfer(); } } } // SETUP packet received if (epStatus & UDP_CSR_RXSETUP) { // If a transfer was pending, complete it // Handles the case where during the status phase of a control write // transfer, the host receives the device ZLP and ack it, but the ack // is not received by the device if ((UDP_ENDPOINT_RECEIVING == epState) || (UDP_ENDPOINT_SENDING == epState)) { // Endpoint returns in Idle state epState = UDP_ENDPOINT_IDLE; endOfTransfer(); } // Copy packet ptr = (uint8_t *)&request; for (i = 0; i < (uint16_t)(epStatus >> 16); i++) { *ptr = (uint8_t)UDP->UDP_FDR[EP_NUMBER]; ptr++; } // Set the DIR bit before clearing RXSETUP in Control IN sequence // Transfer direction is located in bit D7 of the bmRequestType field if (request.bmRequestType & 0x80) setCSR(UDP_CSR_DIR); clearCSR(UDP_CSR_RXSETUP); // Forward the request to the upper layer runtimeRequestHandler(); } // STALL sent if (epStatus & UDP_CSR_STALLSENTISOERROR) { // If the endpoint is not halted, clear the STALL condition clearCSR(UDP_CSR_STALLSENTISOERROR); clearCSR(UDP_CSR_FORCESTALL); } }