Exemplo n.º 1
0
/// @brief Tests for correct reponse to a payload which an invalid data size field.
bool MavlinkFtpTest::_bad_datasize_test(void)
{
	mavlink_message_t			msg;
	MavlinkFTP::PayloadHeader		payload;
	mavlink_file_transfer_protocol_t	ftp_msg;
	MavlinkFTP::PayloadHeader		*reply;
	
	payload.opcode = MavlinkFTP::kCmdListDirectory;
	
	_setup_ftp_msg(&payload, 0, nullptr, &msg);
	
	// Set the data size to be one larger than is legal
	((MavlinkFTP::PayloadHeader*)((mavlink_file_transfer_protocol_t*)msg.payload64)->payload)->size = MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN + 1;
	
	_ftp_server->handle_message(nullptr /* mavlink */, &msg);
	
	if (!_decode_message(&_reply_msg, &ftp_msg, &reply)) {
		return false;
	}
	
	ut_compare("Didn't get Nak back", reply->opcode, MavlinkFTP::kRspNak);
	ut_compare("Incorrect payload size", reply->size, 1);
	ut_compare("Incorrect error code", reply->data[0], MavlinkFTP::kErrInvalidDataSize);
	
	return true;
}
Exemplo n.º 2
0
/// @brief Sends the specified FTP message to the server and returns response
bool MavlinkFtpTest::_send_receive_msg(MavlinkFTP::PayloadHeader	*payload_header,	///< FTP payload header
				       uint8_t				size,			///< size in bytes of data
				       const uint8_t			*data,			///< Data to start into FTP message payload
				       const MavlinkFTP::PayloadHeader	**payload_reply)	///< Payload inside FTP message response
{
	mavlink_message_t msg;

	_setup_ftp_msg(payload_header, size, data, &msg);
	_ftp_server->handle_message(&msg);
	return _decode_message(&_reply_msg, payload_reply);
}
Exemplo n.º 3
0
/// @brief Sends the specified FTP message to the server and returns response
bool MavlinkFtpTest::_send_receive_msg(MavlinkFTP::PayloadHeader	*payload_header,	///< FTP payload header
				      uint8_t				size,			///< size in bytes of data
				      const uint8_t			*data,			///< Data to start into FTP message payload
				      mavlink_file_transfer_protocol_t	*ftp_msg_reply,		///< Response from server
				      MavlinkFTP::PayloadHeader		**payload_reply)	///< Payload inside FTP message response
{
	mavlink_message_t msg;

	_setup_ftp_msg(payload_header, size, data, &msg);
	_ftp_server->handle_message(nullptr /* mavlink */, &msg);
	return _decode_message(&_reply_msg, ftp_msg_reply, payload_reply);
}
Exemplo n.º 4
0
bool MavlinkFtpTest::_receive_message_handler_burst(const mavlink_file_transfer_protocol_t *ftp_msg,
		BurstInfo *burst_info)
{
	hrt_abstime t = 0;
	const MavlinkFTP::PayloadHeader *reply;
	uint32_t full_packet_bytes = MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN - sizeof(MavlinkFTP::PayloadHeader);
	uint32_t expected_bytes;

	_decode_message(ftp_msg, &reply);

	switch (burst_info->burst_state) {
	case burst_state_first_ack:
		ut_compare("Didn't get Ack back", reply->opcode, MavlinkFTP::kRspAck);
		ut_compare("Offset incorrect", reply->offset, 0);

		expected_bytes = burst_info->single_packet_file ? burst_info->file_size : full_packet_bytes;
		ut_compare("Payload size incorrect", reply->size, expected_bytes);
		ut_compare("burst_complete incorrect", reply->burst_complete, 0);
		ut_compare("File contents differ", memcmp(reply->data, burst_info->file_bytes, expected_bytes), 0);

		// Setup for next expected message
		burst_info->burst_state = burst_info->single_packet_file ? burst_state_nak_eof : burst_state_last_ack;

		ut_assert("Remaining stream packets missing", _ftp_server->get_size());
		_ftp_server->send(t);
		break;

	case burst_state_last_ack:
		ut_compare("Didn't get Ack back", reply->opcode, MavlinkFTP::kRspAck);
		ut_compare("Offset incorrect", reply->offset, full_packet_bytes);

		expected_bytes = burst_info->file_size - full_packet_bytes;
		ut_compare("Payload size incorrect", reply->size, expected_bytes);
		ut_compare("burst_complete incorrect", reply->burst_complete, 0);
		ut_compare("File contents differ", memcmp(reply->data, &burst_info->file_bytes[full_packet_bytes], expected_bytes), 0);

		// Setup for next expected message
		burst_info->burst_state = burst_state_nak_eof;

		ut_assert("Remaining stream packets missing", _ftp_server->get_size());
		_ftp_server->send(t);
		break;

	case burst_state_nak_eof:
		// Signal complete
		burst_info->burst_state = burst_state_complete;
		ut_compare("All packets should have been seent", _ftp_server->get_size(), 0);
		break;

	}

	return true;
}