Commit caf2d113 authored by Lucas Russo's avatar Lucas Russo

examples/client.c: update client example

Now, the client is more structurized and
explores how the clienty should be used with
its API
parent b9a14c24
......@@ -6,28 +6,64 @@
#include <mdp.h>
#include <inttypes.h>
#define LEDS_OPERATION 0
/* Our tructure */
typedef struct _bpm_client_t {
mdp_client_t *mdp_client;
} bpm_client_t;
/* Our API */
bpm_client_t *bpm_client_new (char *broker_endp, int verbose)
{
bpm_client_t *self = zmalloc (sizeof *self);
self->mdp_client = mdp_client_new (broker_endp, verbose);
return self;
}
void bpm_client_destroy (bpm_client_t **self_p)
{
assert (self_p);
if (*self_p) {
bpm_client_t *self = *self_p;
mdp_client_destroy (&self->mdp_client);
*self_p = NULL;
}
}
int bpm_blink_leds (bpm_client_t *self, char *service, uint32_t leds)
{
uint32_t operation = LEDS_OPERATION;
zmsg_t *request = zmsg_new ();
zmsg_addmem (request, &operation, sizeof (operation));
zmsg_addmem (request, &leds, sizeof (leds));
mdp_client_send (self->mdp_client, service, &request);
return 0;
}
int main (int argc, char *argv [])
{
int verbose = (argc > 1 && streq (argv [1], "-v"));
mdp_client_t *client = mdp_client_new ("ipc:///tmp/bpm/0", verbose);
bpm_client_t *bpm_client = bpm_client_new ("ipc:///tmp/bpm/0", verbose);
unsigned i;
for (i = 0; i < 32768; ++i) {
unsigned int j;
uint32_t operation = 0;
uint32_t leds = (1 << 1);
unsigned int j;
for (j = 0; j < 3; ++j) {
if (!zctx_interrupted) {
zmsg_t *request = zmsg_new ();
zmsg_addmem (request, &operation, sizeof (operation));
zmsg_addmem (request, &leds, sizeof (leds));
mdp_client_send (client, "BPM0:DEVIO:FMC130M_4CH", &request);
bpm_blink_leds (bpm_client, "BPM0:DEVIO:FMC130M_4CH", leds);
usleep (80000);
leds <<= 1;
}
}
}
mdp_client_destroy (&client);
bpm_client_destroy (&bpm_client);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment