int uORB::DeviceNode::ioctl(struct file *filp, int cmd, unsigned long arg) { SubscriberData *sd = filp_to_sd(filp); switch (cmd) { case ORBIOCLASTUPDATE: { irqstate_t state = px4_enter_critical_section(); *(hrt_abstime *)arg = _last_update; px4_leave_critical_section(state); return OK; } case ORBIOCUPDATED: *(bool *)arg = appears_updated(sd); return OK; case ORBIOCSETINTERVAL: { int ret = PX4_OK; lock(); if (arg == 0) { if (sd->update_interval) { delete(sd->update_interval); sd->update_interval = nullptr; } } else { if (sd->update_interval) { sd->update_interval->interval = arg; } else { sd->update_interval = new UpdateIntervalData(); if (sd->update_interval) { memset(&sd->update_interval->update_call, 0, sizeof(hrt_call)); sd->update_interval->interval = arg; } else { ret = -ENOMEM; } } } unlock(); return ret; } case ORBIOCGADVERTISER: *(uintptr_t *)arg = (uintptr_t)this; return OK; case ORBIOCGPRIORITY: *(int *)arg = sd->priority(); return OK; case ORBIOCSETQUEUESIZE: //no need for locking here, since this is used only during the advertisement call, //and only one advertiser is allowed to open the DeviceNode at the same time. return update_queue_size(arg); case ORBIOCGETINTERVAL: if (sd->update_interval) { *(unsigned *)arg = sd->update_interval->interval; } else { *(unsigned *)arg = 0; } return OK; default: /* give it to the superclass */ return CDev::ioctl(filp, cmd, arg); } }
int uORB::DeviceNode::ioctl(cdev::file_t *filp, int cmd, unsigned long arg) { SubscriberData *sd = filp_to_sd(filp); switch (cmd) { case ORBIOCLASTUPDATE: { ATOMIC_ENTER; *(hrt_abstime *)arg = _last_update; ATOMIC_LEAVE; return PX4_OK; } case ORBIOCUPDATED: #ifndef __PX4_NUTTX lock(); #endif *(bool *)arg = appears_updated(sd); #ifndef __PX4_NUTTX unlock(); #endif return PX4_OK; case ORBIOCSETINTERVAL: { int ret = PX4_OK; lock(); if (arg == 0) { if (sd->update_interval) { delete (sd->update_interval); sd->update_interval = nullptr; } } else { if (sd->update_interval) { sd->update_interval->interval = arg; #ifndef __PX4_NUTTX sd->update_interval->last_update = hrt_absolute_time(); #endif } else { sd->update_interval = new UpdateIntervalData(); if (sd->update_interval) { memset(&sd->update_interval->update_call, 0, sizeof(hrt_call)); sd->update_interval->interval = arg; #ifndef __PX4_NUTTX sd->update_interval->last_update = hrt_absolute_time(); #endif } else { ret = -ENOMEM; } } } unlock(); return ret; } case ORBIOCGADVERTISER: *(uintptr_t *)arg = (uintptr_t)this; return PX4_OK; case ORBIOCGPRIORITY: *(int *)arg = sd->priority(); return PX4_OK; case ORBIOCSETQUEUESIZE: //no need for locking here, since this is used only during the advertisement call, //and only one advertiser is allowed to open the DeviceNode at the same time. return update_queue_size(arg); case ORBIOCGETINTERVAL: if (sd->update_interval) { *(unsigned *)arg = sd->update_interval->interval; } else { *(unsigned *)arg = 0; } return OK; case ORBIOCISPUBLISHED: *(unsigned long *)arg = _published; return OK; default: /* give it to the superclass */ return CDev::ioctl(filp, cmd, arg); } }