コード例 #1
0
ファイル: mprogmodetoggle.c プロジェクト: 1stsetup/knxd
int
main (int ac, char *ag[])
{
  int len;
  EIBConnection *con;
  eibaddr_t dest;
  char *prog = ag[0];

  parseKey (&ac, &ag);
  if (ac != 3)
    die ("usage: %s [-k key] url eibaddr", prog);
  con = EIBSocketURL (ag[1]);
  if (!con)
    die ("Open failed");
  dest = readaddr (ag[2]);

  if (EIB_MC_Connect (con, dest) == -1)
    die ("Connect failed");
  auth (con);

  len = EIB_MC_Progmode_Toggle (con);
  if (len == -1)
    die ("Set failed");

  EIBClose (con);
  return 0;
}
コード例 #2
0
ファイル: mread.c プロジェクト: 1stsetup/knxd
int
main (int ac, char *ag[])
{
  int len, addr;
  EIBConnection *con;
  uchar buf[255];
  eibaddr_t dest;
  char *prog = ag[0];

  parseKey (&ac, &ag);
  if (ac != 5)
    die ("usage: %s url [-k key] eibaddr addr count", prog);
  con = EIBSocketURL (ag[1]);
  if (!con)
    die ("Open failed");
  dest = readaddr (ag[2]);
  addr = readHex (ag[3]);
  len = atoi (ag[4]);

  if (EIB_MC_Connect (con, dest) == -1)
    die ("Connect failed");
  auth (con);

  len = EIB_MC_Read (con, addr, len, buf);
  if (len == -1)
    die ("Read failed");
  printHex (len, buf);

  EIBClose (con);
  return 0;
}
コード例 #3
0
ファイル: mpropscanpoll.c プロジェクト: 1stsetup/knxd
int
main (int ac, char *ag[])
{
  uchar buf[10000];
  int len;
  int i;
  EIBConnection *con;
  eibaddr_t dest;
  fd_set read;
  char *prog = ag[0];

  parseKey (&ac, &ag);
  if (ac != 3)
    die ("usage: %s [-k key] url eibaddr", prog);
  con = EIBSocketURL (ag[1]);
  if (!con)
    die ("Open failed");
  dest = readaddr (ag[2]);

  if (EIB_MC_Connect (con, dest) == -1)
    die ("Connect failed");
  auth (con);

  len = EIB_MC_PropertyScan_async (con, sizeof (buf), buf);
  if (len == -1)
    die ("Read failed");

lp:
  FD_ZERO (&read);
  FD_SET (EIB_Poll_FD (con), &read);
  printf ("Waiting\n");
  if (select (EIB_Poll_FD (con) + 1, &read, 0, 0, 0) == -1)
    die ("select failed");
  printf ("Data available\n");
  len = EIB_Poll_Complete (con);
  if (len == -1)
    die ("Read failed");
  if (len == 0)
    goto lp;
  printf ("Completed\n");

  len = EIBComplete (con);

  for (i = 0; i < len; i += 6)
    if (buf[i + 1] == 1 && buf[i + 2] == 4)
      printf ("Obj: %d Property: %d Type: %d Objtype:%d Access:%02X\n",
	      buf[i + 0], buf[i + 1], buf[i + 2],
	      (buf[i + 3] << 8) | buf[i + 4], buf[i + 5]);
    else
      printf ("Obj: %d Property: %d Type: %d Count:%d Access:%02X\n",
	      buf[i + 0], buf[i + 1], buf[i + 2],
	      (buf[i + 3] << 8) | buf[i + 4], buf[i + 5]);

  EIBClose (con);
  return 0;
}
コード例 #4
0
ファイル: 32.c プロジェクト: Xstarfct/Cgames
main()/*本主函数示意上述输入输出函数的用法*/
{
    struct addr p[100];
    int i,j;
    clrscr();
    for(i=0; readaddr(p+i); i++);
    for(j=0; j<i; j++) writeaddr(p+j);
    puts("\n Press any key to quit...");
    getch();
}
コード例 #5
0
ファイル: writeaddress.c プロジェクト: 1stsetup/knxd
int
main (int ac, char *ag[])
{
  int len;
  EIBConnection *con;
  eibaddr_t dest;
  if (ac != 3)
    die ("usage: %s url eibaddr", ag[0]);
  con = EIBSocketURL (ag[1]);
  if (!con)
    die ("Open failed");
  dest = readaddr (ag[2]);

  len = EIB_M_WriteIndividualAddress (con, dest);
  if (len == -1)
    die ("Set failed");

  EIBClose (con);
  return 0;
}
コード例 #6
0
ファイル: maskver.c プロジェクト: 1stsetup/knxd
int
main (int ac, char *ag[])
{
  int len;
  EIBConnection *con;
  eibaddr_t dest;
  if (ac != 3)
    die ("usage: %s url eibaddr", ag[0]);
  con = EIBSocketURL (ag[1]);
  if (!con)
    die ("Open failed");
  dest = readaddr (ag[2]);

  len = EIB_M_GetMaskVersion (con, dest);
  if (len == -1)
    die ("Read failed");
  printf ("Mask: %04X\n", len);

  EIBClose (con);
  return 0;
}
コード例 #7
0
ファイル: xpropwrite.c プロジェクト: 1stsetup/knxd
int
main (int ac, char *ag[])
{
  int len, obj, prop, start, nr_of_elem;
  EIBConnection *con;
  uchar buf[255];
  uchar res[255];
  eibaddr_t dest;
  char *prog = ag[0];

  if (ac < 7)
    die ("usage: %s url eibaddr obj prop start nr_of_elem [xx xx ..]", prog);
  con = EIBSocketURL (ag[1]);
  if (!con)
    die ("Open failed");
  dest = readaddr (ag[2]);
  obj = atoi (ag[3]);
  prop = atoi (ag[4]);
  start = atoi (ag[5]);
  nr_of_elem = atoi (ag[6]);
  len = readBlock (buf, sizeof (buf), ac - 7, ag + 7);

  if (EIB_MC_Individual_Open (con, dest) == -1)
    die ("Connect failed");

  printf ("Write: ");
  printHex (len, buf);
  printf ("\n");
  len =
    EIB_MC_PropertyWrite (con, obj, prop, start, nr_of_elem, len, buf,
			  sizeof (res), res);
  if (len == -1)
    die ("Write failed");
  printHex (len, res);

  EIBClose (con);
  return 0;
}
コード例 #8
0
ファイル: knxd.cpp プロジェクト: 1stsetup/knxd
/** parses and stores an option */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = (struct arguments *) state->input;
  switch (key)
    {
    case 'T':
      arguments->tunnel = 1;
      arguments->has_work++;
      break;
    case 'R':
      arguments->route = 1;
      arguments->has_work++;
      break;
    case 'D':
      arguments->discover = 1;
      break;
    case 'S':
      {
        const char *serverip;
        const char *name = arguments->eibnetname;

        EIBnetServer *c;
        int port = 0;
        char *a = strdup (OPT_ARG(arg, state, ""));
        char *b;
        if (!a)
          die ("out of memory");
        b = strchr (a, ':');
        if (b)
          {
            *b++ = 0;
            port = atoi (b);
          }
        if (port <= 0)
          port = 3671;
        serverip = a;
        if (!*serverip) 
          serverip = "224.0.23.12";

        c = new EIBnetServer (serverip, port, arguments->tunnel, arguments->route, arguments->discover,
                              arguments->l3(), arguments->tracer(),
                              (name && *name) ? name : "knxd");
        if (!c->init ())
          die ("initialization of the EIBnet/IP server failed");
        free (a);
        arguments->tunnel = false;
        arguments->route = false;
        arguments->discover = false;
        arguments->eibnetname = 0;
      }
      break;
    case 'u':
      {
        BaseServer *s;
        const char *name = OPT_ARG(arg,state,"/run/knx");
        s = new LocalServer (arguments->l3(), arguments->tracer(), name);
        if (!s->init ())
          die ("initialisation of the knxd unix protocol failed");
        arguments->has_work++;
      }
      break;
    case 'i':
      {
        BaseServer *s = NULL;
        int port = atoi(OPT_ARG(arg,state,"6720"));
        if (port > 0)
          s = new InetServer (arguments->l3(), arguments->tracer(), port);
        if (!s || !s->init ())
          die ("initialisation of the knxd inet protocol failed");
        arguments->has_work++;
      }
      break;
    case 't':
      if (arg)
	{
	  char *x;
	  unsigned long level = strtoul(arg, &x, 0);
	  if (*x)
	    die ("Trace level: '%s' is not a number", arg);
          arguments->tracer(true)->SetTraceLevel (level);
	}
      else
        arguments->tracer(true)->SetTraceLevel (0);
      break;
    case 'f':
      arguments->tracer(true)->SetErrorLevel (arg ? atoi (arg) : 0);
      break;
    case 'e':
      if (arguments->has_l3 ())
	{
	  die ("You need to specify '-e' earlier");
	}
      arguments->addr = readaddr (arg);
      break;
    case 'p':
      arguments->pidfile = arg;
      break;
    case 'd':
      arguments->daemon = OPT_ARG(arg,state,"/dev/null");
      break;
    case 'c':
      if (!CreateGroupCache (arguments->l3(), arguments->tracer(), true))
        die ("initialisation of the group cache failed");
      break;
    case 'n':
      arguments->eibnetname = (char *)arg;
      if(arguments->eibnetname[0] == '=')
	arguments->eibnetname++;
      if(strlen(arguments->eibnetname) >= 30)
	die("EIBnetServer/IP name must be shorter than 30 bytes");
      break;
    case OPT_FORCE_BROADCAST:
      arguments->force_broadcast = true;
      break;
    case OPT_STOP_NOW:
      arguments->stop_now = true;
      break;
    case OPT_BACK_TUNNEL_NOQUEUE:
      arguments->l2opts.flags |= FLAG_B_TUNNEL_NOQUEUE;
      break;
    case OPT_BACK_TPUARTS_ACKGROUP:
      arguments->l2opts.flags |= FLAG_B_TPUARTS_ACKGROUP;
      break;
    case OPT_BACK_TPUARTS_ACKINDIVIDUAL:
      arguments->l2opts.flags |= FLAG_B_TPUARTS_ACKINDIVIDUAL;
      break;
    case OPT_BACK_TPUARTS_DISCH_RESET:
      arguments->l2opts.flags |= FLAG_B_TPUARTS_DISCH_RESET;
      break;
    case OPT_BACK_EMI_NOQUEUE:
      arguments->l2opts.flags |= FLAG_B_EMI_NOQUEUE;
      break;
    case 'N':
      arguments->l2opts.flags |= FLAG_B_NO_MONITOR;
      break;
    case ARGP_KEY_ARG:
    case 'b':
      {
	arguments->l2opts.t = arguments->tracer ();
        Layer2 *l2 = Create (arg, &arguments->l2opts, arguments->l3 ());
        if (!l2 || !l2->init ())
          die ("initialisation of backend '%s' failed", arg);
	if (arguments->l2opts.flags)
          die ("You provided options which '%s' does not recognize", arg);
        memset(&arguments->l2opts, 0, sizeof(arguments->l2opts));
        arguments->has_work++;
        break;
      }
    case ARGP_KEY_FINI:
      if (arguments->l2opts.flags)
        die ("You need to use backend flags in front of the affected backend");

#ifdef HAVE_SYSTEMD
      {
        BaseServer *s = NULL;
        const int num_fds = sd_listen_fds(0);

        if( num_fds < 0 )
          die("Error getting fds from systemd.");
        // zero FDs from systemd is not a bug

        for( int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START+num_fds; ++fd )
          {
            if( sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1) <= 0 )
              die("Error: socket not of expected type.");

            s = new SystemdServer(arguments->l3(), arguments->tracer(), fd);
            if (!s->init ())
              die ("initialisation of the systemd socket failed");
            arguments->has_work++;
          }
      }
#endif

	  errno = 0;
      if (arguments->tunnel || arguments->route || arguments->discover || 
          arguments->eibnetname)
        die ("Option '-S' starts the multicast server.\n"
             "-T/-R/-D/-n after or without that option are useless.");
      if (arguments->l2opts.flags)
	die ("You provided L2 flags after specifying an L2 interface.");
      if (arguments->has_work == 0)
        die ("I know about no interface. Nothing to do. Giving up.");
      if (arguments->has_work == 1)
        die ("I only have one interface. Nothing to do. Giving up.");
      arguments->finish_l3();
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
コード例 #9
0
ファイル: knxd.cpp プロジェクト: RichiH/knxd
/** parses and stores an option */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = (struct arguments *) state->input;
  switch (key)
    {
    case 'T':
      arguments->tunnel = 1;
      break;
    case 'R':
      arguments->route = 1;
      break;
    case 'D':
      arguments->discover = 1;
      break;
    case 'S':
      arguments->serverip = (arg ? arg : "224.0.23.12");
      break;
    case 'u':
      arguments->name = (char *) (arg ? arg : "/tmp/eib");
      break;
    case 'i':
      arguments->port = (arg ? atoi (arg) : 6720);
      break;
    case 't':
      arguments->tracelevel = (arg ? atoi (arg) : 0);
      break;
    case 'f':
      arguments->errorlevel = (arg ? atoi (arg) : 0);
      break;
    case 'e':
      arguments->addr = readaddr (arg);
      break;
    case 'p':
      arguments->pidfile = arg;
      break;
    case 'd':
      arguments->daemon = (char *) (arg ? arg : "/dev/null");
      break;
    case 'c':
      arguments->groupcache = 1;
      break;
    case 'n':
          if(!arg)
              die("Name must be given, if you add -n to your arg list");
      arguments->eibnetname = (char *)arg;
      break;
    case OPT_BACK_TUNNEL_NOQUEUE:
      arguments->backendflags |= FLAG_B_TUNNEL_NOQUEUE;
      break;
    case OPT_BACK_TPUARTS_ACKGROUP:
      arguments->backendflags |= FLAG_B_TPUARTS_ACKGROUP;
      break;
    case OPT_BACK_TPUARTS_ACKINDIVIDUAL:
      arguments->backendflags |= FLAG_B_TPUARTS_ACKINDIVIDUAL;
      break;
    case OPT_BACK_TPUARTS_DISCH_RESET:
      arguments->backendflags |= FLAG_B_TPUARTS_DISCH_RESET;
      break;
    case OPT_BACK_EMI_NOQUEUE:
      arguments->backendflags |= FLAG_B_EMI_NOQUEUE;
      break;
    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}
コード例 #10
0
ファイル: knxd_args.cpp プロジェクト: marcopiraccini/knxd
/** parses and stores an option */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = (struct arguments *) state->input;
  switch (key)
    {
    case 'T':
      arguments->stack("tunnel");
      (*ini["server"])["tunnel"] = "tunnel";
      arguments->want_server = true;
      break;
    case 'R':
      arguments->stack("router");
      (*ini["server"])["router"] = "router";
      arguments->want_server = true;
      // (*ini["router"])["driver"] = "ets-multicast";
      break;
    case 'D':
      arguments->stack("server"); // to allow for -t255 -DTRS
      arguments->want_server = true;
      (*ini["server"])["discover"] = "true";
      break;
    case OPT_SINGLE_PORT:
      (*ini["server"])["multi-port"] = "false";
      break;
    case OPT_MULTI_PORT:
      (*ini["server"])["multi-port"] = "true";
      break;
    case 'I':
      (*ini["server"])["interface"] = arg;
      break;
    case 'S':
      {
        if (arguments->filters.size())
          die("Use filters in front of -R or -T, not -S");
        ADD((*ini["main"])["connections"], "server");
        (*ini["server"])["server"] = "ets_router";
        arguments->want_server = false;
        // (*ini["server"])["driver"] = "ets-link";

        const char *serverip;
        const char *name = arguments->servername.c_str();
        std::string tracename;

        int port = 0;
        char *a = strdup (OPT_ARG(arg, state, ""));
        char *b = strchr (a, ':');
        if (b)
          {
            *b++ = 0;
            if (atoi (b) > 0)
              (*ini["server"])["port"] = b;
          }
        if (*a) 
          (*ini["server"])["multicast-address"] = a;

        if (!name || !*name) {
            name = "knxd";
            tracename = "mcast";
        } else {
            tracename = "mcast:";
            tracename += name;
        }
        (*ini["debug-server"])["name"] = tracename;
        (*ini["server"])["debug"] = "debug-server";
        arguments->stack("server");
        break;
      }

    case 'n':
      if (*arg == '=')
	arg++;
      if(strlen(arg) >= 30)
        die("Server name must be shorter than 30 bytes");
      (*ini["main"])["name"] = arg;
      break;

    case 'u':
      {
        if (arguments->want_server)
          die("You need -S after -D/-T/-R");
        link_to("unix");
        ADD((*ini["main"])["connections"], link);
        (*ini[link])["server"] = "knxd_unix";
        // (*ini[link])["driver"] = "knx-link";
        const char *name = OPT_ARG(arg,state,NULL);
        if (name)
          {
            (*ini[link])["path"] = name;
            (*ini[link])["systemd-ignore"] = "false";
          }
        else
          (*ini[link])["systemd-ignore"] = "true";
        arguments->stack(link);
      }
      break;

    case 'i':
      {
        if (arguments->want_server)
          die("You need -S after -D/-T/-R");
        link_to("tcp");
        ADD((*ini["main"])["connections"], link);
        (*ini[link])["server"] = "knxd_tcp";
        // (*ini[link])["driver"] = "knx-link";
        const char *port = OPT_ARG(arg,state,"");
        if (*port && atoi(port) > 0)
          {
            (*ini[link])["port"] = port;
            (*ini[link])["systemd-ignore"] = "false";
          }
        else
          (*ini[link])["systemd-ignore"] = "true";

        arguments->stack(link);
      }
      break;

    case 't':
      if (arg)
        {
          char *x;
          unsigned long level = strtoul(arg, &x, 0);
          if (*x)
            die ("Trace level: '%s' is not a number", arg);
          arguments->tracelevel = level;
        }
      else
        arguments->tracelevel = -1;
      break;
    case OPT_NO_TIMESTAMP:
      arguments->no_timestamps = true;
      break;
    case 'f':
      arguments->errorlevel = (arg ? atoi (arg) : 0);
      break;
    case 'e':
      if (arguments->l2opts.flags || arguments->l2opts.send_delay)
        die("You cannot use flags globally.");
      arguments->stack("main");
      readaddr (arg);
      break;
    case 'E':
      readaddrblock (arg);
      break;
    case 'p':
      (*ini["main"])["pidfile"] = arg;
      break;
    case 'd':
      {
        const char *arg = OPT_ARG(arg,state,NULL);
        (*ini["main"])["background"] = "true";
        if (arg)
          (*ini["main"])["logfile"] = arg;
      }
      break;
    case 'c':
      if (arguments->l2opts.flags || arguments->l2opts.send_delay)
        die("You cannot apply flags to the group cache.");

      link_to("cache");
      (*ini["main"])["cache"] = link;
      arguments->stack(link);
      break;
    case OPT_FORCE_BROADCAST:
      (*ini["main"])["force-broadcast"] = "true";
      break;
    case OPT_STOP_NOW:
      (*ini["main"])["stop-after-setup"] = "true";
      break;
    case OPT_BACK_TUNNEL_NOQUEUE: // obsolete
      fprintf(stderr,"The option '--no-tunnel-client-queuing' is obsolete.\n");
      fprintf(stderr,"Please use '--send-delay=30'.");
      arguments->l2opts.send_delay = 30; // msec
      break;
    case OPT_BACK_EMI_NOQUEUE: // obsolete
      fprintf(stderr,"The option '--no-emi-send-queuing' is obsolete.\n");
      fprintf(stderr,"Please use '--send-delay=500'.");
      arguments->l2opts.send_delay = 500; // msec
      break;
    case OPT_BACK_SEND_DELAY:
      arguments->l2opts.send_delay = atoi(OPT_ARG(arg,state,"30"));
      break;
    case OPT_BACK_TPUARTS_ACKGROUP:
      arguments->l2opts.flags |= FLAG_B_TPUARTS_ACKGROUP;
      break;
    case OPT_BACK_TPUARTS_ACKINDIVIDUAL:
      arguments->l2opts.flags |= FLAG_B_TPUARTS_ACKINDIVIDUAL;
      break;
    case OPT_BACK_TPUARTS_DISCH_RESET:
      arguments->l2opts.flags |= FLAG_B_TPUARTS_DISCH_RESET;
      break;
    case 'N':
      arguments->l2opts.flags |= FLAG_B_NO_MONITOR;
      break;
    case ARGP_KEY_ARG:
    case 'b':
      {
        if (arguments->want_server)
          die("You need -S after -D/-T/-R");
        link_to(arg);
        ADD((*ini["main"])["connections"], link);
        char *ap = strchr(arg,':');
        if (ap)
          *ap++ = '\0';
        driver_args(arg,ap);
        arguments->stack(link);
        break;
      }
    case 'B':
      arguments->do_filter(arg);
      break;
    case 'A':
      arguments->add_arg(arg);
      break;
    case ARGP_KEY_FINI:

      if (arguments->want_server)
        die("You need -S after -D/-T/-R");
#ifdef HAVE_SYSTEMD
      {
        (*ini["main"])["systemd"] = "systemd";
        // (*ini["systemd"])["server"] = "knxd_systemd";
        // (*ini["systemd"])["driver"] = "knx-link";
        arguments->stack("systemd");
      }
#endif
      if (arguments->filters.size() || arguments->more_args.size())
        die ("You need to use filters and arguments in front of the affected backend");
      if (arguments->l2opts.flags || arguments->l2opts.send_delay)
	die ("You provided flags after specifying an interface.");
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}