aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--binding/iiodevices-binding.c51
2 files changed, 19 insertions, 44 deletions
diff --git a/README.md b/README.md
index f40a37f..aa285fb 100644
--- a/README.md
+++ b/README.md
@@ -10,15 +10,14 @@ to get data from acceleration, gyroscope and electronic compass.
As soon as a client subscribes to the agl-service-iiodevices binding,
the binding gets values from sensors and send it to subscribers as events.
Subscribers can choose their frequency and indicates what values they wants at
-subscription. For now, subscribers have also to indicates an uid in order to
-create differents events, if arguments differ between clients.
+subscription.
## Verbs
| Name | Description | JSON Parameters |
|:-------------------|:--------------------------------------------|:--------------------------------------------------------------- |
-| subscribe | subscribe to 9 axis events | *Request:* {"event": "accel", "uid": "X", "args":"xy", "frequency": "10" }|
-| unsubscribe | unsubscribe to accelero events | *Request:* {"event": "accel", "uid": "X"} |
+| subscribe | subscribe to 9 axis events | *Request:* {"event": "accel", "args":"xy", "frequency": "10" }|
+| unsubscribe | unsubscribe to accelero events | *Request:* {"event": "accel" } |
## Events
@@ -28,10 +27,13 @@ For now, there are 3 different events matching with the different available sens
* "magn": is for gyroscope data
* "anglvel": is for electronic compass data
+## Frequency
+
+Frequency is in Hertz, if the frequency is not filled, events are triggered via file descriptor.
+
## Remaining issues
- Provide a json config file so that configures the device name and the channel name.
-- Remove the uid json argument and using context_make to identify session and better handle events
- Rework on channel structure and split it into client structure
- Handle several values simultaneously, see trigger
- Update it to other iiodevices
diff --git a/binding/iiodevices-binding.c b/binding/iiodevices-binding.c
index cb233e2..45d0f61 100644
--- a/binding/iiodevices-binding.c
+++ b/binding/iiodevices-binding.c
@@ -22,7 +22,6 @@
struct client_channels {
struct iio_channel *chn;
int index;
- char uid[100];
int fd;
uint64_t u_period;
enum iio_elements iioelts;
@@ -240,7 +239,6 @@ static int read_data(struct client_channels *cl_chn, sd_event_source* src)
char val[10];
struct client_channels *p_cl_chn = cl_chn->first;
- AFB_DEBUG("TOTOTO %p", p_cl_chn);
while(p_cl_chn) {
chn = p_cl_chn->chn;
if(!chn) {
@@ -336,7 +334,6 @@ static struct client_channels *set_channel(const int index,
if(g_index > channels.nb) {
channels.channels[g_index].event = channels.channels[channels.nb].event;
channels.channels[g_index - 1].next = &channels.channels[g_index];
- strcpy(channels.channels[g_index].uid, first->uid);
}
iio_channel_enable(channels.channels[g_index].chn);
return &channels.channels[g_index];
@@ -381,7 +378,7 @@ static struct afb_event* is_allocation_needed(struct iio_info *infos,
static void init_channel(struct iio_device *dev,
struct iio_info *infos, const int iioelts, struct client_channels **first,
- const uint64_t u_period, const char* uid)
+ const uint64_t u_period)
{
if(!dev || !infos) {
AFB_ERROR("dev=%p or infos=%p is null", dev, infos);
@@ -408,7 +405,6 @@ static void init_channel(struct iio_device *dev,
channels.channels[channels.nb].u_period = u_period;
channels.channels[channels.nb].dev = dev;
channels.channels[channels.nb].infos = infos;
- strcpy(channels.channels[channels.nb].uid, uid);
*first = &channels.channels[channels.nb];
}
else
@@ -446,47 +442,24 @@ static bool is_new_event_needed(struct iio_info *infos, const uint64_t u_period)
return true;
}
-struct client_channels *looking_for_chn(struct iio_info *infos, const char* uid)
-{
- struct client_channels *cl_chn = NULL;
- int i = 0;
- while(i < channels.nb) {
- cl_chn = &channels.channels[i];
- if(!strcasecmp(uid, cl_chn->uid) && cl_chn->infos == infos)
- return cl_chn;
- i++;
- }
- return NULL;
-}
-
-static bool is_uid_used(struct iio_info *infos, const char* uid)
-{
- return looking_for_chn(infos, uid);
-}
-
static void subscribe(struct afb_req request)
{
const char *value = afb_req_value(request, "event");
- const char *uid = afb_req_value(request, "uid");
const char *s_iioelts = afb_req_value(request, "args");
const char *freq = afb_req_value(request, "frequency");
- if(!value || !uid || !s_iioelts) {
- afb_req_fail(request, "failed", "please, fill 'event', 'uid' and 'args' fields");
+ if(!value || !s_iioelts) {
+ afb_req_fail(request, "failed", "please, fill 'event' and 'args' fields");
return;
}
- AFB_INFO("subscription with: value=%s, uid=%s, s_iioelts=%s, freq=%s",
- value, uid, s_iioelts, freq);
+ AFB_INFO("subscription with: value=%s, s_iioelts=%s, freq=%s",
+ value, s_iioelts, freq);
bool found = false;
for(int i = 0; i < IIO_INFOS_SIZE; i++) {
if(!strcasecmp(value, iio_infos[i].id)) {
found = true;
- if(is_uid_used(&iio_infos[i], uid)) {
- afb_req_fail(request, "failed", "uid is already used for this event, please changed");
- return;
- }
struct iio_device *dev = init_dev(iio_infos[i].dev_name);
@@ -502,8 +475,7 @@ static void subscribe(struct afb_req request)
&iioelts, &first);
}
if(!p_event || event_needed) { //new cl_chn or event_needed
- init_channel(dev, &iio_infos[i], iioelts, &first, u_period,
- uid);
+ init_channel(dev, &iio_infos[i], iioelts, &first, u_period);
if(!first) {
AFB_ERROR("first is null");
return;
@@ -511,6 +483,7 @@ static void subscribe(struct afb_req request)
init_event_io(dev, first);
p_event = first->event;
}
+ afb_req_context_set(request, first, NULL);
if(afb_req_subscribe(request, *p_event) != 0) {
afb_req_fail(request, "failed", "subscription failed");
@@ -528,9 +501,8 @@ static void subscribe(struct afb_req request)
static void unsubscribe(struct afb_req request)
{
const char *value = afb_req_value(request, "event");
- const char *uid = afb_req_value(request, "uid");
- if(!value || !uid) {
- afb_req_fail(request, "failed", "please, fill 'event', 'uid' fields");
+ if(!value) {
+ afb_req_fail(request, "failed", "please, fill 'event' fields");
return;
}
@@ -539,9 +511,10 @@ static void unsubscribe(struct afb_req request)
for(int i = 0; i < IIO_INFOS_SIZE; i++) {
if(!strcasecmp(value, iio_infos[i].id)) {
found = true;
- struct client_channels *cl_chn = looking_for_chn(&iio_infos[i], uid);
+ struct client_channels *cl_chn = (struct client_channels *)afb_req_context_get(request);
if(!cl_chn) {
- AFB_ERROR("cannot find %s event with uid=%s", value, uid);
+ AFB_ERROR("cannot find %s event, it seems that there was \
+ no subscription", value);
return;
}
if(afb_req_unsubscribe(request, *cl_chn->event) != 0) {