35 #if defined(PIOS_INCLUDE_UAVTALKRCVR)
39 #ifndef PIOS_UAVTALKRCVR_TIMEOUT_MS
40 #define PIOS_UAVTALKRCVR_TIMEOUT_MS 350
43 static UAVTalkReceiverData uavreceiverdata;
46 static int32_t PIOS_UAVTALKRCVR_Get(uintptr_t rcvr_id, uint8_t channel);
47 static void PIOS_uavtalkrcvr_Supervisor(uintptr_t rcvr_id);
50 .
read = PIOS_UAVTALKRCVR_Get,
54 enum pios_uavtalkrcvr_dev_magic {
55 PIOS_UAVTALKRCVR_DEV_MAGIC = 0xe9da5c56,
58 struct pios_uavtalkrcvr_dev {
59 enum pios_uavtalkrcvr_dev_magic
magic;
65 static struct pios_uavtalkrcvr_dev *global_uavtalkrcvr_dev;
67 static bool PIOS_uavtalkrcvr_validate(
struct pios_uavtalkrcvr_dev *uavtalkrcvr_dev)
69 return (uavtalkrcvr_dev->magic == PIOS_UAVTALKRCVR_DEV_MAGIC);
72 static struct pios_uavtalkrcvr_dev *PIOS_uavtalkrcvr_alloc(
void)
74 struct pios_uavtalkrcvr_dev * uavtalkrcvr_dev;
76 uavtalkrcvr_dev = (
struct pios_uavtalkrcvr_dev *)
PIOS_malloc(
sizeof(*uavtalkrcvr_dev));
77 if (!uavtalkrcvr_dev)
return(NULL);
79 uavtalkrcvr_dev->magic = PIOS_UAVTALKRCVR_DEV_MAGIC;
80 uavtalkrcvr_dev->Fresh =
false;
81 uavtalkrcvr_dev->supv_timer = 0;
84 global_uavtalkrcvr_dev = uavtalkrcvr_dev;
86 return(uavtalkrcvr_dev);
89 static void uavreceiver_updated(
const UAVObjEvent *ev,
90 void *ctx,
void *obj,
int len)
92 struct pios_uavtalkrcvr_dev *uavtalkrcvr_dev = global_uavtalkrcvr_dev;
93 if (ev->
obj == UAVTalkReceiverHandle()) {
95 UAVTalkReceiverGet(&uavreceiverdata);
97 uavtalkrcvr_dev->Fresh =
true;
103 struct pios_uavtalkrcvr_dev *uavtalkrcvr_dev;
106 uavtalkrcvr_dev = (
struct pios_uavtalkrcvr_dev *)PIOS_uavtalkrcvr_alloc();
107 if (!uavtalkrcvr_dev)
110 for (uint8_t
i = 0;
i < UAVTALKRECEIVER_CHANNEL_NUMELEM;
i++) {
116 UAVTalkReceiverConnectCallback(uavreceiver_updated);
133 static int32_t PIOS_UAVTALKRCVR_Get(uintptr_t rcvr_id, uint8_t channel)
135 if (channel >= UAVTALKRECEIVER_CHANNEL_NUMELEM) {
140 return (uavreceiverdata.Channel[channel]);
143 static void PIOS_uavtalkrcvr_Supervisor(uintptr_t uavtalkrcvr_id) {
145 struct pios_uavtalkrcvr_dev * uavtalkrcvr_dev = (
struct pios_uavtalkrcvr_dev *)uavtalkrcvr_id;
147 if (!PIOS_uavtalkrcvr_validate(uavtalkrcvr_dev)) {
153 if ((++uavtalkrcvr_dev->supv_timer) <
157 uavtalkrcvr_dev->supv_timer = 0;
159 if (!uavtalkrcvr_dev->Fresh) {
160 for (int32_t
i = 0;
i < UAVTALKRECEIVER_CHANNEL_NUMELEM;
i++)
164 uavtalkrcvr_dev->Fresh =
false;
int32_t(* read)(uintptr_t id, uint8_t channel)
Main PiOS header to include all the compiled in PiOS options.
#define PIOS_DEBUG_Assert(test)
void * PIOS_malloc(size_t size)
bool PIOS_RTC_RegisterTickCallback(void(*fn)(uintptr_t id), uintptr_t data)
int32_t PIOS_UAVTALKRCVR_Init(uintptr_t *gcsrcvr_id)
GCS receiver private functions.
const struct pios_rcvr_driver pios_uavtalk_rcvr_driver