sensors/netsensor: applications supporting networked uORB sensors#3341
sensors/netsensor: applications supporting networked uORB sensors#3341linguini1 wants to merge 2 commits intoapache:masterfrom
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.
@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.
| if (usedevno) | |
| if (usedevno > 0) |
| * Private Functions | ||
| ****************************************************************************/ | ||
|
|
||
| static void print_usage(FILE *sink) { fprintf(sink, HELP_TEXT); } |
There was a problem hiding this comment.
| 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; |
|
|
||
| /* Allocate memory for receiving UDP messages containing data */ | ||
|
|
||
| dbuf = malloc(meta->o_size); |
There was a problem hiding this comment.
| 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.
| 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.
| 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.
where init meta? it's random value
| continue; /* Try again */ | ||
| } | ||
|
|
||
| err = orb_copy(&meta, fd, dbuf); |
| 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.
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.