/ src / examples / groupcachereadsync.c
groupcachereadsync.c
 1  /*
 2      EIB Demo program
 3      Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
 4  
 5      This program is free software; you can redistribute it and/or modify
 6      it under the terms of the GNU General Public License as published by
 7      the Free Software Foundation; either version 2 of the License, or
 8      (at your option) any later version.
 9  
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19  #include "common.h"
20  
21  int
22  main (int ac, char *ag[])
23  {
24    int len;
25    uint16_t age = 0;
26    EIBConnection *con;
27    eibaddr_t dest;
28    eibaddr_t src;
29    uint8_t buf[200];
30  
31    if (ac != 3 && ac != 4)
32      die ("usage: %s url eibaddr [age]", ag[0]);
33    con = EIBSocketURL (ag[1]);
34    if (!con)
35      die ("Open failed");
36    dest = readgaddr (ag[2]);
37    if (ac == 4)
38      age = atoi (ag[3]);
39  
40    len = EIB_Cache_Read_Sync (con, dest, &src, sizeof (buf), buf, age);
41    if (len == -1)
42      die ("Read failed");
43  
44    switch (buf[1] & 0xC0)
45      {
46      case 0x40:
47        printf ("Response");
48        break;
49      case 0x80:
50        printf ("Write");
51        break;
52      }
53    printf (" from ");
54    printIndividual (src);
55    if (buf[1] & 0xC0)
56      {
57        printf (": ");
58        if (len == 2)
59          printf ("%02X", buf[1] & 0x3F);
60        else
61          printHex (len - 2, buf + 2);
62      }
63    printf ("\n");
64  
65    EIBClose (con);
66    return 0;
67  }