123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #pragma once
- #include <AP_HAL/AP_HAL.h>
- #if HAL_STORAGE_SIZE >= 16384
- #define STORAGE_NUM_AREAS 14
- #elif HAL_STORAGE_SIZE >= 15360
- #define STORAGE_NUM_AREAS 11
- #elif HAL_STORAGE_SIZE >= 8192
- #define STORAGE_NUM_AREAS 10
- #elif HAL_STORAGE_SIZE >= 4096
- #define STORAGE_NUM_AREAS 4
- #elif HAL_STORAGE_SIZE > 0
- #define STORAGE_NUM_AREAS 1
- #else
- #error "Unsupported storage size"
- #endif
- class StorageManager {
- friend class StorageAccess;
- public:
- enum StorageType {
- StorageParam = 0,
- StorageFence = 1,
- StorageRally = 2,
- StorageMission = 3,
- StorageKeys = 4,
- StorageBindInfo= 5
- };
-
- static void erase(void);
-
- static void set_layout_copter(void) { layout = layout_copter; }
- private:
- struct StorageArea {
- StorageType type;
- uint16_t offset;
- uint16_t length;
- };
-
- static const StorageArea layout_copter[STORAGE_NUM_AREAS];
- static const StorageArea layout_default[STORAGE_NUM_AREAS];
- static const StorageArea *layout;
- };
- class StorageAccess {
- public:
-
- StorageAccess(StorageManager::StorageType _type);
-
- uint16_t size(void) const { return total_size; }
-
- bool read_block(void *dst, uint16_t src, size_t n) const;
- bool write_block(uint16_t dst, const void* src, size_t n) const;
-
- uint8_t read_byte(uint16_t loc) const;
- uint16_t read_uint16(uint16_t loc) const;
- uint32_t read_uint32(uint16_t loc) const;
- void write_byte(uint16_t loc, uint8_t value) const;
- void write_uint16(uint16_t loc, uint16_t value) const;
- void write_uint32(uint16_t loc, uint32_t value) const;
- private:
- const StorageManager::StorageType type;
- uint16_t total_size;
- };
|