Loosing signal while reading bus systems under C

Victor Andres victor at cymonline.com
Mon Nov 15 02:19:37 PST 2010


Hello,
I'm trying to use dbus to send information from one process to other, using low level C. The frecuency that this application send signal is about 1200 per seconds, and each signal is a struct of 4 or 7 basic datas (there are 2 different signals).
I think I'm writing signal correctly (at less I can monitory them correctly from dbus-monitor utility), but when I'm reading it from the other application, I have some loosing data (or not received signal) randomly.

This is my receive method using C



void receive()
{
   DBusMessage* msg, *msgaux;
   DBusMessageIter args, item;
   DBusConnection* conn;
   DBusError err;
   int ret;
   unsigned short datox, datoy, datoz;
   unsigned short datox2, datoy2, datoz2;
   unsigned int time;

   // initialise the errors
   dbus_error_init(&err);

 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
   if (dbus_error_is_set(&err)) {
      fprintf(stderr, "Connection Error (%s)\n", err.message);
      dbus_error_free(&err);
   }
   if (NULL == conn) {
      exit(1);
   }

   // add a rule for which messages we want to see
   dbus_bus_add_match(conn, "type='signal',interface='device.sensors.rawdata'", &err); // see signals from the given interface
   dbus_connection_flush(conn);
   if (dbus_error_is_set(&err)) {
      fprintf(stderr, "Match Error (%s)\n", err.message);
      exit(1);
   }
   printf("Match rule sent\n");

   // loop listening for signals being emmitted
   while (true)
   {
      // non blocking read of the next available message
      dbus_connection_read_write(conn, -1);

      msgaux = dbus_connection_pop_message(conn);
      while (msgaux!= NULL)
      {
       msg = msgaux;
       msgaux = dbus_connection_pop_message(conn);
      }

      // check if the message is a signal from the correct interface and with the correct name
      if (dbus_message_is_signal(msg, "device.sensors.rawdata", "MGData"))
      {
         // read the parameters
         if (!dbus_message_iter_init(msg, &args))
            fprintf(stderr, "Message Has No Parameters\n");
         else
         {
    dbus_message_iter_recurse(&args, &item);
    dbus_message_iter_get_basic(&item, &datox);
    dbus_message_iter_next(&item);
    dbus_message_iter_get_basic(&item, &datoy);
    dbus_message_iter_next(&item);
    dbus_message_iter_get_basic(&item, &datoz);
    dbus_message_iter_next(&item);
    dbus_message_iter_get_basic(&item, &time);
    dbus_message_iter_next(&item);
    dbus_message_iter_next(&args);
    printf("\n\tMg: %d, %d, %d, time: %d\n", datox, datoy, datoz, time);
         }
      }

  if (dbus_message_is_signal(msg, "device.sensors.rawdata", "ACData"))
  {
     // read the parameters
     if (!dbus_message_iter_init(msg, &args))
     fprintf(stderr, "Message Has No Parameters\n");
     else
     {
     dbus_message_iter_recurse(&args, &item);
     dbus_message_iter_get_basic(&item, &datox);
     dbus_message_iter_next(&item);
     dbus_message_iter_get_basic(&item, &datoy);
     dbus_message_iter_next(&item);
     dbus_message_iter_get_basic(&item, &datoz);
     dbus_message_iter_next(&item);
     dbus_message_iter_get_basic(&item, &datox2);
     dbus_message_iter_next(&item);
     dbus_message_iter_get_basic(&item, &datoy2);
     dbus_message_iter_next(&item);
     dbus_message_iter_get_basic(&item, &datoz2);
     dbus_message_iter_next(&item);
     dbus_message_iter_get_basic(&item, &time);
     dbus_message_iter_next(&item);
     dbus_message_iter_next(&args);

     printf("\n\tAce 1: %d, %d, %d \tAce 2: %d, %d, %d, time: %d\n", datox, datoy, datoz, datox2, datoy2, datoz2, time);
     }
  }
      // free the message
      dbus_message_unref(msg);
   }
}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20101115/8d6400d7/attachment.htm>


More information about the dbus mailing list