dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uavobjectmanager.h
Go to the documentation of this file.
1 /******************************************************************************
2  * @addtogroup FlightCore Core components
3  * @{
4  * @addtogroup UAVObjectHandling UAVObject handling code
5  * @{
6  *
7  * @file uavobjectmanager.h
8  * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
9  * @author Tau Labs, http://taulabs.org, Copyright (C) 2012-2014
10  * @author dRonin, http://dronin.org Copyright (C) 2015-2016
11  * @brief Object manager library. This library holds a collection of all objects.
12  * It can be used by all modules/libraries to find an object reference.
13  * @see The GNU Public License (GPL) Version 3
14  *
15  *****************************************************************************/
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  *
30  * Additional note on redistribution: The copyright and license notices above
31  * must be maintained in each individual source file that is a derivative work
32  * of this source file; otherwise redistribution is prohibited.
33  */
34 
35 #ifndef UAVOBJECTMANAGER_H
36 #define UAVOBJECTMANAGER_H
37 
38 #include "pios_queue.h"
39 
40 #define UAVOBJ_ALL_INSTANCES 0xFFFF
41 #define UAVOBJ_MAX_INSTANCES 1000
42 
43 /*
44  * Shifts and masks used to read/write metadata flags.
45  */
46 #define UAVOBJ_ACCESS_SHIFT 0
47 #define UAVOBJ_GCS_ACCESS_SHIFT 1
48 #define UAVOBJ_TELEMETRY_ACKED_SHIFT 2
49 #define UAVOBJ_GCS_TELEMETRY_ACKED_SHIFT 3
50 #define UAVOBJ_TELEMETRY_UPDATE_MODE_SHIFT 4
51 #define UAVOBJ_GCS_TELEMETRY_UPDATE_MODE_SHIFT 6
52 #define UAVOBJ_UPDATE_MODE_MASK 0x3
53 
54 typedef struct UAVOBase * UAVObjHandle;
55 
59 typedef enum {
65 
82 typedef struct {
83  uint8_t flags;
87 } __attribute__((packed)) UAVObjMetadata;
88 
92 typedef enum {
93  EV_NONE = 0x00,
94  EV_UNPACKED = 0x01,
95  EV_UPDATED = 0x02,
99 
103 #define EV_MASK_ALL 0
104 #define EV_MASK_ALL_UPDATES (EV_UNPACKED | EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATED_PERIODIC)
105 
109 typedef enum {
113 
117 typedef struct {
118  UAVObjHandle obj;
121 
122  uint16_t instId;
123 } UAVObjEvent;
124 
130 typedef void (*UAVObjEventCallback)(const UAVObjEvent *ev, void* cb_ctx,
131  void *uavo_data, int uavo_len);
132 
136 typedef void (*UAVObjInitializeCallback)(UAVObjHandle obj_handle, uint16_t instId);
137 
141 typedef struct {
146 } UAVObjStats;
147 
148 typedef void (*new_uavo_instance_cb_t)(uint32_t,uint32_t);
150 
151 int32_t UAVObjInitialize();
152 void UAVObjGetStats(UAVObjStats* statsOut);
153 void UAVObjClearStats();
154 UAVObjHandle UAVObjRegister(uint32_t id,
155  int32_t isSingleInstance, int32_t isSettings, uint32_t numBytes, UAVObjInitializeCallback initCb);
156 UAVObjHandle UAVObjGetByID(uint32_t id);
157 uint32_t UAVObjGetID(UAVObjHandle obj);
158 uint32_t UAVObjGetNumBytes(UAVObjHandle obj);
159 uint16_t UAVObjGetNumInstances(UAVObjHandle obj);
160 UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj);
161 uint16_t UAVObjCreateInstance(UAVObjHandle obj_handle, UAVObjInitializeCallback initCb);
162 bool UAVObjIsSingleInstance(UAVObjHandle obj);
163 bool UAVObjIsMetaobject(UAVObjHandle obj);
164 bool UAVObjIsSettings(UAVObjHandle obj);
165 int32_t UAVObjUnpack(UAVObjHandle obj_handle, uint16_t instId, const uint8_t* dataIn);
166 int32_t UAVObjPack(UAVObjHandle obj_handle, uint16_t instId, uint8_t* dataOut);
167 int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId);
168 int32_t UAVObjLoad(UAVObjHandle obj_handle, uint16_t instId);
169 int32_t UAVObjDeleteById(uint32_t obj_id, uint16_t inst_id);
170 #if defined(PIOS_INCLUDE_SDCARD)
171 int32_t UAVObjSaveToFile(UAVObjHandle obj_handle, uint16_t instId, FILEINFO* file);
172 UAVObjHandle UAVObjLoadFromFile(FILEINFO* file);
173 #endif
174 int32_t UAVObjSaveSettings();
175 int32_t UAVObjLoadSettings();
176 int32_t UAVObjDeleteSettings();
177 int32_t UAVObjSaveMetaobjects();
178 int32_t UAVObjLoadMetaobjects();
179 int32_t UAVObjDeleteMetaobjects();
180 int32_t UAVObjSetData(UAVObjHandle obj_handle, const void* dataIn);
181 int32_t UAVObjSetDataField(UAVObjHandle obj_handle, const void* dataIn, uint32_t offset, uint32_t size);
182 int32_t UAVObjGetData(UAVObjHandle obj_handle, void* dataOut);
183 int32_t UAVObjGetDataField(UAVObjHandle obj_handle, void* dataOut, uint32_t offset, uint32_t size);
184 int32_t UAVObjSetInstanceData(UAVObjHandle obj_handle, uint16_t instId, const void* dataIn);
185 int32_t UAVObjSetInstanceDataField(UAVObjHandle obj_handle, uint16_t instId, const void* dataIn, uint32_t offset, uint32_t size);
186 int32_t UAVObjGetInstanceData(UAVObjHandle obj_handle, uint16_t instId, void* dataOut);
187 int32_t UAVObjGetInstanceDataField(UAVObjHandle obj_handle, uint16_t instId, void* dataOut, uint32_t offset, uint32_t size);
188 int32_t UAVObjSetMetadata(UAVObjHandle obj_handle, const UAVObjMetadata* dataIn);
189 int32_t UAVObjGetMetadata(UAVObjHandle obj_handle, UAVObjMetadata* dataOut);
190 uint8_t UAVObjGetMetadataAccess(const UAVObjMetadata* dataOut);
191 UAVObjAccessType UAVObjGetAccess(const UAVObjMetadata* dataOut);
192 void UAVObjSetAccess(UAVObjMetadata* dataOut, UAVObjAccessType mode);
193 UAVObjAccessType UAVObjGetGcsAccess(const UAVObjMetadata* dataOut);
194 void UAVObjSetGcsAccess(UAVObjMetadata* dataOut, UAVObjAccessType mode);
195 uint8_t UAVObjGetTelemetryAcked(const UAVObjMetadata* dataOut);
196 void UAVObjSetTelemetryAcked( UAVObjMetadata* dataOut, uint8_t val);
197 uint8_t UAVObjGetGcsTelemetryAcked(const UAVObjMetadata* dataOut);
198 void UAVObjSetGcsTelemetryAcked(UAVObjMetadata* dataOut, uint8_t val);
199 UAVObjUpdateMode UAVObjGetTelemetryUpdateMode(const UAVObjMetadata* dataOut);
200 void UAVObjSetTelemetryUpdateMode(UAVObjMetadata* dataOut, UAVObjUpdateMode val);
201 UAVObjUpdateMode UAVObjGetGcsTelemetryUpdateMode(const UAVObjMetadata* dataOut);
202 void UAVObjSetTelemetryGcsUpdateMode(UAVObjMetadata* dataOut, UAVObjUpdateMode val);
203 int8_t UAVObjReadOnly(UAVObjHandle obj);
204 int32_t UAVObjConnectQueue(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask);
205 int32_t UAVObjDisconnectQueue(UAVObjHandle obj_handle, struct pios_queue *queue);
206 int32_t UAVObjConnectQueueThrottled(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask, uint16_t interval);
207 int32_t UAVObjConnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask);
208 int32_t UAVObjConnectCallbackThrottled(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask, uint16_t interval);
209 void UAVObjUnblockThrottle(struct ObjectEventEntryThrottled *throttled);
210 int32_t UAVObjDisconnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx);
211 void UAVObjUpdated(UAVObjHandle obj);
212 void UAVObjInstanceUpdated(UAVObjHandle obj_handle, uint16_t instId);
213 void UAVObjIterate(void (*iterator)(UAVObjHandle obj));
214 int32_t getEventMask(UAVObjHandle obj_handle, struct pios_queue *queue);
215 uint8_t UAVObjCount();
216 uint32_t UAVObjIDByIndex(uint8_t index);
217 void UAVObjCbSetFlag(const UAVObjEvent *objEv, void *ctx, void *obj, int len);
218 void UAVObjCbCopyData(const UAVObjEvent *objEv, void *ctx, void *obj, int len);
219 
220 #endif // UAVOBJECTMANAGER_H
221 
int32_t UAVObjSaveMetaobjects()
uint8_t UAVObjCount()
void UAVObjSetTelemetryAcked(UAVObjMetadata *dataOut, uint8_t val)
uint32_t UAVObjIDByIndex(uint8_t index)
void UAVObjClearStats()
void UAVObjSetTelemetryGcsUpdateMode(UAVObjMetadata *dataOut, UAVObjUpdateMode val)
uint16_t UAVObjCreateInstance(UAVObjHandle obj_handle, UAVObjInitializeCallback initCb)
void UAVObjSetTelemetryUpdateMode(UAVObjMetadata *dataOut, UAVObjUpdateMode val)
uint32_t lastCallbackErrorID
UAVObjHandle UAVObjGetByID(uint32_t id)
int32_t UAVObjSetInstanceData(UAVObjHandle obj_handle, uint16_t instId, const void *dataIn)
bool UAVObjIsMetaobject(UAVObjHandle obj)
int32_t UAVObjDisconnectQueue(UAVObjHandle obj_handle, struct pios_queue *queue)
UAVObjUpdateMode UAVObjGetGcsTelemetryUpdateMode(const UAVObjMetadata *dataOut)
bool UAVObjIsSettings(UAVObjHandle obj)
UAVObjUpdateMode
UAVObjAccessType
int32_t UAVObjLoadSettings()
int32_t UAVObjUnpack(UAVObjHandle obj_handle, uint16_t instId, const uint8_t *dataIn)
int32_t UAVObjSaveSettings()
uint32_t UAVObjGetNumBytes(UAVObjHandle obj)
int32_t UAVObjPack(UAVObjHandle obj_handle, uint16_t instId, uint8_t *dataOut)
int32_t UAVObjConnectCallbackThrottled(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask, uint16_t interval)
void UAVObjCbSetFlag(const UAVObjEvent *objEv, void *ctx, void *obj, int len)
UAVObjAccessType UAVObjGetGcsAccess(const UAVObjMetadata *dataOut)
int32_t UAVObjSave(UAVObjHandle obj_handle, uint16_t instId)
uint16_t loggingUpdatePeriod
int32_t UAVObjConnectQueueThrottled(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask, uint16_t interval)
uint32_t eventQueueErrors
UAVObjAccessType UAVObjGetAccess(const UAVObjMetadata *dataOut)
uint16_t telemetryUpdatePeriod
int32_t UAVObjSetDataField(UAVObjHandle obj_handle, const void *dataIn, uint32_t offset, uint32_t size)
UAVObjHandle obj
uint32_t lastQueueErrorID
void UAVObjGetStats(UAVObjStats *statsOut)
uint16_t gcsTelemetryUpdatePeriod
uint8_t UAVObjGetTelemetryAcked(const UAVObjMetadata *dataOut)
int32_t UAVObjGetInstanceDataField(UAVObjHandle obj_handle, uint16_t instId, void *dataOut, uint32_t offset, uint32_t size)
uint8_t UAVObjGetGcsTelemetryAcked(const UAVObjMetadata *dataOut)
uint32_t UAVObjGetID(UAVObjHandle obj)
bool UAVObjIsSingleInstance(UAVObjHandle obj)
int32_t UAVObjGetInstanceData(UAVObjHandle obj_handle, uint16_t instId, void *dataOut)
void UAVObjInstanceUpdated(UAVObjHandle obj_handle, uint16_t instId)
void(* UAVObjInitializeCallback)(UAVObjHandle obj_handle, uint16_t instId)
UAVObjUpdateMode UAVObjGetTelemetryUpdateMode(const UAVObjMetadata *dataOut)
enum channel_mode mode
Definition: pios_servo.c:58
int32_t UAVObjConnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx, uint8_t eventMask)
uint32_t obj_id
int32_t UAVObjSetInstanceDataField(UAVObjHandle obj_handle, uint16_t instId, const void *dataIn, uint32_t offset, uint32_t size)
void UAVObjUnblockThrottle(struct ObjectEventEntryThrottled *throttled)
UAVObjEventType
struct UAVOBase * UAVObjHandle
int32_t UAVObjDeleteById(uint32_t obj_id, uint16_t inst_id)
int32_t UAVObjSetMetadata(UAVObjHandle obj_handle, const UAVObjMetadata *dataIn)
void(* UAVObjEventCallback)(const UAVObjEvent *ev, void *cb_ctx, void *uavo_data, int uavo_len)
void UAVObjCbCopyData(const UAVObjEvent *objEv, void *ctx, void *obj, int len)
int32_t UAVObjConnectQueue(UAVObjHandle obj_handle, struct pios_queue *queue, uint8_t eventMask)
uint8_t UAVObjGetMetadataAccess(const UAVObjMetadata *dataOut)
uint32_t offset
Definition: uavtalk_priv.h:51
int32_t getEventMask(UAVObjHandle obj_handle, struct pios_queue *queue)
int32_t UAVObjLoadMetaobjects()
int32_t UAVObjGetMetadata(UAVObjHandle obj_handle, UAVObjMetadata *dataOut)
void UAVObjSetGcsTelemetryAcked(UAVObjMetadata *dataOut, uint8_t val)
UAVObjHandle UAVObjGetLinkedObj(UAVObjHandle obj)
uint32_t eventCallbackErrors
void UAVObjUpdated(UAVObjHandle obj)
UAVObjEventType event
uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
int32_t UAVObjDeleteMetaobjects()
void(* new_uavo_instance_cb_t)(uint32_t, uint32_t)
int8_t UAVObjReadOnly(UAVObjHandle obj)
int32_t UAVObjLoad(UAVObjHandle obj_handle, uint16_t instId)
int32_t UAVObjSetData(UAVObjHandle obj_handle, const void *dataIn)
static struct pios_queue * queue
Definition: actuator.c:82
int32_t UAVObjInitialize()
int32_t UAVObjGetData(UAVObjHandle obj_handle, void *dataOut)
UAVObjHandle UAVObjRegister(uint32_t id, int32_t isSingleInstance, int32_t isSettings, uint32_t numBytes, UAVObjInitializeCallback initCb)
struct ObjectEventEntryThrottled * throttle
void UAVObjRegisterNewInstanceCB(new_uavo_instance_cb_t callback)
int32_t UAVObjGetDataField(UAVObjHandle obj_handle, void *dataOut, uint32_t offset, uint32_t size)
void UAVObjSetGcsAccess(UAVObjMetadata *dataOut, UAVObjAccessType mode)
typedef __attribute__
Definition: serial_4way.h:43
#define FILEINFO
Definition: pios_posix.h:41
int32_t UAVObjDisconnectCallback(UAVObjHandle obj_handle, UAVObjEventCallback cb, void *cbCtx)
void UAVObjSetAccess(UAVObjMetadata *dataOut, UAVObjAccessType mode)
void UAVObjIterate(void(*iterator)(UAVObjHandle obj))
int32_t UAVObjDeleteSettings()