You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

103 lines
2.1 KiB

  1. /*
  2. * Labjack Tools
  3. * Copyright (c) 2003-2007 Jim Paris <jim@jtan.com>
  4. *
  5. * This is free software; you can redistribute it and/or modify it and
  6. * it is provided under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation; see COPYING.
  8. */
  9. /* ljconfig: display/change comm/control processor configuration */
  10. #include <stdint.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <errno.h>
  15. #include <unistd.h>
  16. #include "debug.h"
  17. #include "ue9.h"
  18. #include "ue9error.h"
  19. #include "opt.h"
  20. #include "version.h"
  21. #define DEFAULT_HOST "192.168.1.209"
  22. #define UE9_COMMAND_PORT 52360
  23. struct options opt[] = {
  24. {'a', "address", "string", "host/address of UE9 (192.168.1.209)"},
  25. {'h', "help", NULL, "this help"},
  26. {'v', "verbose", NULL, "be verbose"},
  27. {'V', "version", NULL, "show version number and exit"},
  28. {0, NULL, NULL, NULL}
  29. };
  30. int
  31. main (int argc, char *argv[])
  32. {
  33. int optind;
  34. char *optarg;
  35. char c;
  36. FILE *help = stderr;
  37. char *address = strdup (DEFAULT_HOST);
  38. int fd;
  39. int ret;
  40. /* Parse arguments */
  41. opt_init (&optind);
  42. while ((c = opt_parse (argc, argv, &optind, &optarg, opt)) != 0)
  43. {
  44. switch (c)
  45. {
  46. case 'a':
  47. free (address);
  48. address = strdup (optarg);
  49. break;
  50. case 'v':
  51. verb_count++;
  52. break;
  53. case 'V':
  54. printf ("ljconfig " VERSION "\n");
  55. printf ("Written by Jim Paris <jim@jtan.com>\n");
  56. printf ("This program comes with no warranty and is "
  57. "provided under the GPLv2.\n");
  58. return 0;
  59. break;
  60. case 'h':
  61. help = stdout;
  62. default:
  63. printhelp:
  64. fprintf (help, "Usage: %s [options]\n", *argv);
  65. opt_help (opt, help);
  66. fprintf (help, "Displays/changes Labjack UE9 config.\n");
  67. return (help == stdout) ? 0 : 1;
  68. }
  69. }
  70. if (optind < argc)
  71. {
  72. info ("Error: too many arguments (%s)\n\n", argv[optind]);
  73. goto printhelp;
  74. }
  75. ret = 1;
  76. /* Open */
  77. fd = ue9_open (address, UE9_COMMAND_PORT);
  78. if (fd < 0)
  79. {
  80. info ("Connect failed: %s:%d\n", address, UE9_COMMAND_PORT);
  81. goto out0;
  82. }
  83. goto out1;
  84. ret = 0;
  85. out1:
  86. /* Close */
  87. ue9_close (fd);
  88. out0:
  89. return ret;
  90. }