/// @brief Sends the specified FTP response message out through mavlink void MavlinkFTP::_reply(mavlink_file_transfer_protocol_t *ftp_req) { PayloadHeader *payload = reinterpret_cast<PayloadHeader *>(&ftp_req->payload[0]); // keep a copy of the last sent response ((n)ack), so that if it gets lost and the GCS resends the request, // we can simply resend the response. // we only keep small responses to reduce RAM usage and avoid large memcpy's. The larger responses are all data // retrievals without side-effects, meaning it's ok to reexecute them if a response gets lost if (payload->size <= sizeof(uint32_t)) { _last_reply_valid = true; memcpy(_last_reply, ftp_req, sizeof(_last_reply)); } #ifdef MAVLINK_FTP_DEBUG warnx("FTP: %s seq_number: %d", payload->opcode == kRspAck ? "Ack" : "Nak", payload->seq_number); #endif ftp_req->target_network = 0; ftp_req->target_component = 0; #ifdef MAVLINK_FTP_UNIT_TEST // Unit test hook is set, call that instead _utRcvMsgFunc(ftp_req, _worker_data); #else mavlink_msg_file_transfer_protocol_send_struct(_mavlink->get_channel(), ftp_req); #endif }
/// @brief Sends the specified FTP reponse message out through mavlink void MavlinkFTP::_reply(Request *req) { PayloadHeader *payload = reinterpret_cast<PayloadHeader *>(&req->message.payload[0]); payload->seqNumber = payload->seqNumber + 1; mavlink_message_t msg; msg.checksum = 0; #ifndef MAVLINK_FTP_UNIT_TEST uint16_t len = #endif mavlink_msg_file_transfer_protocol_pack_chan(req->serverSystemId, // Sender system id req->serverComponentId, // Sender component id req->serverChannel, // Channel to send on &msg, // Message to pack payload into 0, // Target network req->targetSystemId, // Target system id 0, // Target component id (const uint8_t*)payload); // Payload to pack into message bool success = true; #ifdef MAVLINK_FTP_UNIT_TEST // Unit test hook is set, call that instead _utRcvMsgFunc(&msg, _ftp_test); #else Mavlink *mavlink = req->mavlink; mavlink->lockMessageBufferMutex(); success = mavlink->message_buffer_write(&msg, len); mavlink->unlockMessageBufferMutex(); #endif if (!success) { warnx("FTP TX ERR"); } #ifdef MAVLINK_FTP_DEBUG else { warnx("wrote: sys: %d, comp: %d, chan: %d, checksum: %d", req->serverSystemId, req->serverComponentId, req->serverChannel, msg.checksum); } #endif }
/// @brief Sends the specified FTP response message out through mavlink void MavlinkFTP::_reply(mavlink_file_transfer_protocol_t* ftp_req) { #ifdef MAVLINK_FTP_DEBUG PayloadHeader *payload = reinterpret_cast<PayloadHeader *>(&ftp_req->payload[0]); warnx("FTP: %s seq_number: %d", payload->opcode == kRspAck ? "Ack" : "Nak", payload->seq_number); #endif ftp_req->target_network = 0; ftp_req->target_component = 0; #ifdef MAVLINK_FTP_UNIT_TEST // Unit test hook is set, call that instead _utRcvMsgFunc(ftp_req, _worker_data); #else mavlink_msg_file_transfer_protocol_send_struct(_mavlink->get_channel(), ftp_req); #endif }