-
Notifications
You must be signed in to change notification settings - Fork 682
sensors/netsensor: applications supporting networked uORB sensors #3341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Adds a new application which allows the registration of a uORB sensor (similar to faksensor) that publishes data received over a UDP socket to a uORB topic of the user's choosing. Implemented in userspace. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Added a program which allows the user to stream uORB data from their selected topic over UDP in a form which can be interpreted by a netsensor device. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
| const struct orb_metadata *meta; | ||
| struct sockaddr_in addr; /* TODO: IPv6 support */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@linguini1 not an issue, but normally structs and complex types are defined early inside a function, I think this is just a convention that Greg created, but in some cases it avoids misalignment, i.e. it you have an uint8_t followed by a struct definition. Maybe others here have a better explanation why this convention is used, since the C compiler don't care much about the variables position
|
|
||
| /* Set up topic advertisement */ | ||
|
|
||
| if (usedevno) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (usedevno) | |
| if (usedevno > 0) |
| * Private Functions | ||
| ****************************************************************************/ | ||
|
|
||
| static void print_usage(FILE *sink) { fprintf(sink, HELP_TEXT); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static void print_usage(FILE *sink) { fprintf(sink, HELP_TEXT); } | |
| static void print_usage(FAR FILE *sink) { fprintf(sink, HELP_TEXT); } |
add FAR to all pointer
|
|
||
| int main(int argc, char **argv) | ||
| { | ||
| int err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's sort these var.
|
|
||
| /* Allocate memory for receiving UDP messages containing data */ | ||
|
|
||
| dbuf = malloc(meta->o_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| dbuf = malloc(meta->o_size); | |
| dbuf = malloc(meta->o_size * queue_len); |
| port); | ||
| for (;;) | ||
| { | ||
| brecvd = recv(sock, dbuf, meta->o_size, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| brecvd = recv(sock, dbuf, meta->o_size, 0); | |
| brecvd = recv(sock, dbuf, buflen, 0); |
let's define a temp var buflen = meta->o_size * qeue_len; reuse it at some place.
|
|
||
| /* Publish the data to the topic */ | ||
|
|
||
| err = orb_publish(meta, netfd, dbuf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| err = orb_publish(meta, netfd, dbuf); | |
| err = orb_publish_multiple(meta, netfd, dbuf, ret/meta->o_size); |
|
|
||
| /* Get topic metadata */ | ||
|
|
||
| fd = orb_subscribe(&meta); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where init meta? it's random value
| continue; /* Try again */ | ||
| } | ||
|
|
||
| err = orb_copy(&meta, fd, dbuf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orb_copy_multi
| addr.sin_port = HTONS(port); | ||
| addr.sin_addr.s_addr = HTONL(INADDR_ANY); | ||
|
|
||
| sock = socket(AF_INET, SOCK_DGRAM, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best to encapsulate a transport layer, which could be UDP, TCP, or even more protocols. This code should preferably be operated through certain operations.
Summary
Introduces a user-space
netsensor: a uORB sensor which publishes data receivedover UDP as a uORB topic.
A second application,
netsensor_stream, allows users to stream a uORB topic oftheir choosing over UDP. This can interface with a
netsensorinstance on adifferent device over the network.
Impact
This new sensor will allow users to conduct more complex testing using uORB.
Small network devices no longer need large CSV files containing simulated data
for
fakesensoruORB testing, but instead can receive this data piece-wise overthe network.
In addition, this opens the door to easy sensor network development with NuttX,
as sensors from other network nodes can be read from as regular uORB topics.
Testing
TBD, this is a draft.