PX4 Firmware
PX4 Autopilot Software http://px4.io
mavlink_ftp_test.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2014 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /// @file mavlink_ftp_test.h
35 /// @author Don Gagne <don@thegagnes.com>
36 
37 #pragma once
38 
39 #include <unit_test.h>
40 #include "../mavlink_bridge_header.h"
41 #include "../mavlink_ftp.h"
42 
43 class MavlinkFtpTest : public UnitTest
44 {
45 public:
47  virtual ~MavlinkFtpTest() = default;
48 
49  virtual bool run_tests(void);
50 
51  static void receive_message_handler_generic(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data);
52 
53  /// Worker data for stream handler
54  struct BurstInfo {
58  uint32_t file_size;
59  uint8_t *file_bytes;
60  };
61 
62  static void receive_message_handler_burst(const mavlink_file_transfer_protocol_t *ftp_req, void *worker_data);
63 
64  static const uint8_t serverSystemId = 50; ///< System ID for server
65  static const uint8_t serverComponentId = 1; ///< Component ID for server
66  static const uint8_t serverChannel = 0; ///< Channel to send to
67 
68  static const uint8_t clientSystemId = 1; ///< System ID for client
69  static const uint8_t clientComponentId = 0; ///< Component ID for client
70 
71  // We don't want any of these
74 
75 private:
76  virtual void _init(void);
77  virtual void _cleanup(void);
78 
79  bool _ack_test(void);
80  bool _bad_opcode_test(void);
81  bool _bad_datasize_test(void);
82  bool _list_test(void);
83  bool _list_eof_test(void);
84  bool _open_badfile_test(void);
85  bool _open_terminate_test(void);
86  bool _terminate_badsession_test(void);
87  bool _read_test(void);
88  bool _read_badsession_test(void);
89  bool _burst_test(void);
90  bool _removedirectory_test(void);
91  bool _createdirectory_test(void);
92  bool _removefile_test(void);
93 
94  void _receive_message_handler_generic(const mavlink_file_transfer_protocol_t *ftp_req);
95  void _setup_ftp_msg(const MavlinkFTP::PayloadHeader *payload_header, uint8_t size, const uint8_t *data,
96  mavlink_message_t *msg);
97  bool _decode_message(const mavlink_file_transfer_protocol_t *ftp_msg, const MavlinkFTP::PayloadHeader **payload);
98  bool _send_receive_msg(MavlinkFTP::PayloadHeader *payload_header,
99  uint8_t size,
100  const uint8_t *data,
101  const MavlinkFTP::PayloadHeader **payload_reply);
102  void _cleanup_microsd(void);
103 
104  /// A single download test case
106  const char *file;
107  const uint16_t length;
110  };
111 
112  /// The set of test cases for download testing
114 
115  /// States for stream download handler
116  enum {
121  };
122 
123  bool _receive_message_handler_burst(const mavlink_file_transfer_protocol_t *ftp_req, BurstInfo *burst_info);
124 
127 
128  mavlink_file_transfer_protocol_t _reply_msg;
129 
130  static const char _unittest_microsd_dir[];
131  static const char _unittest_microsd_file[];
132 };
133 
134 bool mavlink_ftp_test(void);
Base class to be used for unit tests.
Definition: unit_test.h:54
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
Definition: px4io.c:89
uint8_t * data
Definition: dataman.cpp:149