Otpvondoiats opened a new pull request, #2604:
URL: https://github.com/apache/nuttx-apps/pull/2604
## Summary
1. Added urob loop function module and supported epoll.
```
struct orb_handle_s g_handle;
struct orb_handle_s g_handle1;
struct orb_loop_s g_loop;
void *test_loop(void *arg)
{
struct orb_loop_s *loop = arg;
if ( loop == NULL)
{
return ((void *)0);
}
if(orb_loop_run(loop) < 0)
{
syslog(1, "&&&& THREAD error!\n");
}
syslog(1, "&&&& THREAD exit !\n");
return ((void *)0);
}
int print_accel(FAR struct orb_handle_s *handle, FAR void *arg)
{
int ret;
struct sensor_accel accel;
pthread_t id = pthread_self();
ret = orb_copy(ORB_ID(sensor_accel), handle->fd, &accel);
if (ret == OK)
{
syslog(1, "data [%d] -> fd:%d, x:%f, y:%f, z:%f handle:%p,
threadid:%d",
(int)arg, handle->fd, accel.x, accel.y, accel.z, handle, id);
}
count++;
return OK;
}
int flush_accel(FAR struct orb_handle_s *handle, FAR void *arg)
{
int ret;
struct sensor_accel accel;
pthread_t id = pthread_self();
ret = orb_copy(ORB_ID(sensor_accel), handle->fd, &accel);
if (ret == OK)
{
syslog(1, "flush [%d] -> fd:%d, x:%f, y:%f, z:%f handle:%p,
threadid:%d",
(int)arg, handle->fd, accel.x, accel.y, accel.z, handle, id);
}
return OK;
}
int state_accel(FAR struct orb_handle_s *handle, FAR void *arg)
{
int ret;
struct orb_state state;
pthread_t id = pthread_self();
ret = orb_get_state(handle->fd, &state);
if (ret == OK)
{
syslog(1, "/// state [%d] -> fd:%d, max:%u, min:%u, que:%u nsu:%u, " \
"gen:%lu, handle:%p, threadid:%d",
(int)arg, handle->fd, state.max_frequency,
state.min_batch_interval,
state.queue_size, state.nsubscribers, state.generation, handle,
id);
}
return OK;
}
int start_loop(void)
{
pthread_t ntid;
int err;
int fd_handle;
int fd_handle1;
fd_handle = orb_subscribe_multi(ORB_ID(sensor_accel), 0);
err = orb_loop_init(&g_loop, ORB_EPOLL_TYPE);
if (err < 0)
{
syslog(1, "init g_loop error! error:%d\n", err);
}
err = orb_handle_init(&g_handle, fd_handle, EPOLLIN,
(FAR void *)0, print_accel, flush_accel,
state_accel);
if (err < 0)
{
syslog(1, "init g_handle error! error:%d\n", err);
}
err = orb_handle_start(&g_loop, &g_handle);
if (err < 0)
{
syslog(1, "initg_ handle start error! error:%d\n", err);
}
err = pthread_create(&ntid, NULL, test_loop, &g_loop);
if (err != 0)
{
syslog(1, "can't create thread\n");
}
usleep(100000);
/* add handle 1; */
fd_handle1 = orb_subscribe_multi(ORB_ID(sensor_accel), 1);
err = orb_handle_init(&g_handle1, fd_handle1, EPOLLIN,
(FAR void *)1, print_accel, flush_accel,
state_accel);
if (err < 0)
{
syslog(1, "init g_handle error! error:%d\n", err);
}
err = orb_handle_start(&g_loop, &g_handle1);
if (err < 0)
{
syslog(1, "initg_ handle start error! error:%d\n", err);
}
usleep(500000);
while (1)
{
if( count < 200)
{
usleep(50000);
continue;
}
err = orb_loop_deinit(&g_loop);
if (err < 0)
{
syslog(1, "deinit loop error! error:%d\n", err);
}
break;
}
orb_unsubscribe(fd_handle);
syslog(1, "main thread exit\n");
}
```
## Impact
n/a
## Testing
- Environment:
OS and Version: Ubuntu 20.04.6 LTS x86_64
GCC Version: 13.1.0
SIM: ./tools/configure.sh sim:nsh
- Order:
./nuttx
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]