Logo Search packages:      
Sourcecode: nut version File versions  Download package

void upsdrv_initups ( void   )

Initialize UPS and variables from ups.conf.

Todo:
Allow binding based on firmware version (which seems to vary wildly from unit to unit)

Definition at line 1482 of file tripplite_usb.c.

References USBDevice_s::Product, USBDevice_s::ProductID, USBDevice_s::Vendor, and USBDevice_s::VendorID.

{
      char *regex_array[6];
      int r;

      /* process the UPS selection options */
      regex_array[0] = NULL; /* handled by USB IDs device table */
      regex_array[1] = getval("productid");
      regex_array[2] = getval("vendor"); /* vendor string */
      regex_array[3] = getval("product"); /* product string */
      regex_array[4] = getval("serial"); /* probably won't see this */
      regex_array[5] = getval("bus");

      r = USBNewRegexMatcher(&regex_matcher, regex_array, REG_ICASE | REG_EXTENDED);
      if (r==-1) {
            fatal_with_errno(EXIT_FAILURE, "USBNewRegexMatcher");
      } else if (r) {
            fatalx(EXIT_FAILURE, "invalid regular expression: %s", regex_array[r]);
      }

      /* link the matchers */
      regex_matcher->next = &subdriver_matcher;

      /* Search for the first supported UPS matching the regular
       *            expression */
      r = comm_driver->open(&udev, &curDevice, regex_matcher, NULL);
      if (r < 1) {
            fatalx(EXIT_FAILURE, "No matching USB/HID UPS found");
      }

      hd = &curDevice;
      
      upslogx(1, "Detected a UPS: %s/%s", hd->Vendor ? hd->Vendor : "unknown", hd->Product ? hd->Product : "unknown");

      dstate_setinfo("ups.vendorid", "%04x", hd->VendorID);
      dstate_setinfo("ups.productid", "%04x", hd->ProductID);

      /* create a new matcher for later reopening */
      r = USBNewExactMatcher(&reopen_matcher, hd);
      if (r) {
            fatal_with_errno(EXIT_FAILURE, "USBNewExactMatcher");
      }
      /* link the two matchers */
      reopen_matcher->next = regex_matcher;

      if (getval("offdelay"))
            offdelay = atoi(getval("offdelay"));
#if 0
      if (getval("startdelay"))
            startdelay = atoi(getval("startdelay"));
      if (getval("rebootdelay"))
            bootdelay = atoi(getval("rebootdelay"));
#endif
}

Generated by  Doxygen 1.6.0   Back to index