CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Filesystem/AP_Filesystem_Mission.h
Views: 1798
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
#pragma once
17
18
#include "AP_Filesystem_config.h"
19
20
#if AP_FILESYSTEM_MISSION_ENABLED
21
22
#include "AP_Filesystem_backend.h"
23
#include <GCS_MAVLink/GCS_MAVLink.h>
24
#include <AP_Common/ExpandingString.h>
25
26
class AP_Filesystem_Mission : public AP_Filesystem_Backend
27
{
28
public:
29
// functions that closely match the equivalent posix calls
30
int open(const char *fname, int flags, bool allow_absolute_paths = false) override;
31
int close(int fd) override;
32
int32_t read(int fd, void *buf, uint32_t count) override;
33
int32_t lseek(int fd, int32_t offset, int whence) override;
34
int32_t write(int fd, const void *buf, uint32_t count) override;
35
int stat(const char *pathname, struct stat *stbuf) override;
36
37
private:
38
// only allow up to 4 files at a time
39
static constexpr uint8_t max_open_file = 4;
40
41
static constexpr uint16_t mission_magic = 0x763d;
42
43
enum class Options {
44
NO_CLEAR = (1U<<0), // don't clear the old mission
45
};
46
47
// header at front of the file
48
struct header {
49
uint16_t magic = mission_magic;
50
uint16_t data_type; // MAV_MISSION_TYPE_*
51
uint16_t options; // optional features
52
uint16_t start; // first WP num, 0 for full upload
53
uint16_t num_items;
54
};
55
56
struct rfile {
57
bool open;
58
ExpandingString *writebuf;
59
uint32_t file_ofs;
60
uint32_t num_items;
61
enum MAV_MISSION_TYPE mtype;
62
uint32_t last_op_ms;
63
} file[max_open_file];
64
65
bool check_file_name(const char *fname, enum MAV_MISSION_TYPE &mtype);
66
67
// get one item
68
bool get_item(uint32_t idx, enum MAV_MISSION_TYPE mtype, mavlink_mission_item_int_t &item) const;
69
70
// get number of items
71
uint32_t get_num_items(enum MAV_MISSION_TYPE mtype) const;
72
73
// finish loading items
74
bool finish_upload(const rfile &r);
75
bool finish_upload_mission(const struct header &hdr, const rfile &r, const uint8_t *b);
76
bool finish_upload_fence(const struct header &hdr, const rfile &r, const uint8_t *b);
77
bool finish_upload_rally(const struct header &hdr, const rfile &r, const uint8_t *b);
78
79
// see if a block of memory is all zero
80
bool all_zero(const uint8_t *b, uint8_t size) const;
81
};
82
83
#endif // AP_FILESYSTEM_MISSION_ENABLED
84
85