[Nut-upsdev] [nut-commits] svn commit r1136 - in trunk: . drivers

Alexander I. Gordeev lasaine at lvk.cs.msu.su
Mon Oct 8 23:11:31 UTC 2007


On Fri, 05 Oct 2007 22:32:46 +0400, Arjen de Korte <nut+devel at de-korte.org> wrote:

> Alexander I. Gordeev wrote:
>
>> But I don't want to duplicate the code! I just didn't look that far in
>> the future ;) (Btw, if a new subdriver appears it could need flushing in
>> a copletely different way. Then it would be simpier to have several
>> functions for specific _methods_ and pointers to them in the subdriver
>> definition.)
>
> There never will be another way to flush the I/O buffers, that's not how
> USB works. A RS232 connected device may choose to send data at will,
> which will be kept in the OS input buffer until an application reads it
> or chooses to flush the buffer. Therefor, the ser_flush_io() function
> may be useful for almost *all* serial drivers. USB works in a polling
> mode, which means that the device can never send data without being
> asked to do so. Therefor, the only buffers that may need flushing, are
> the ones internal in the USB device. The only way to empty these, is to
> read from them.
>
> [...]
>
>> P.S. Well, maybe there is a problem with our upsdebugx() semantics: we
>> mix harmless messages and potentially cautionary ones. I'd better introduce
>> a new one - upswarning().
>
> We already have major problems that driver authors don't know how to use
> upsdebugx() messages. Even you don't seen to know (no pun intended). A
> upsdebugx() message is used to tell the developer why a program is
> making a certain decision, not if something is (possibly) an error. The
> level you give to it, should reflect the severity. So something that is
> potentially cautionary would have a debug level of 1 or 2, while a
> strictly informational message would get probably 5 or higher. By doing
> so, you can easily adjust the amount of information presented.
>
> Best regards, Arjen
>

Ok, I've got it.

Sorry for the delay, here is a patch I've promised.
Comments are welcome :)

Index: drivers/megatec_usb.c
===================================================================
--- drivers/megatec_usb.c	(revision 1141)
+++ drivers/megatec_usb.c	(working copy)
@@ -47,33 +47,36 @@
  static usb_dev_handle *udev = NULL;
  static USBDevice_t usbdevice;

+enum subdriver_flags_t {
+	SF_NONE = 0,			/* no flags set */
+	SF_FLUSH_NOT_SUPPORTED = 1	/* subdriver doesn't support flushing IO buffers */
+};
+
  typedef struct {
  	char	*name;
-	void	(*init) ();
+	char	flags;
  	int	(*get_data) (char *buffer, int buffer_size);
  	int	(*set_data) (const char *str);
  } subdriver_t;

  /* agiler subdriver definition */
-static void init_agiler();
  static int get_data_agiler(char *buffer, int buffer_size);
  static int set_data_agiler(const char *str);

  static subdriver_t agiler_subdriver = {
  	"agiler",
-	init_agiler,
+	SF_NONE,
  	get_data_agiler,
  	set_data_agiler
  };

  /* krauler (ablerex) subdriver definition */
-static void init_krauler();
  static int get_data_krauler(char *buffer, int buffer_size);
  static int set_data_krauler(const char *str);

  static subdriver_t krauler_subdriver = {
  	"krauler",
-	init_krauler,
+	SF_FLUSH_NOT_SUPPORTED,
  	get_data_krauler,
  	set_data_krauler
  };
@@ -218,7 +221,8 @@
  	/* TODO: Add make exact matcher for reconnecting feature support */
  	USBFreeRegexMatcher(regex_matcher);

-	if(subdriver) subdriver->init();
+	/* This is here until ser_flush_io() is used in megatec.c */
+	ser_flush_io(0);

  	return 0;
  }
@@ -238,6 +242,21 @@
  	return 0;
  }

+int ser_flush_io(int fd)
+{
+	char flush_buf[256];
+	int i;
+
+	if(!(subdriver->flags & SF_FLUSH_NOT_SUPPORTED))
+		/* flush input buffers */
+		for (i = 0; i < 10; i++) {
+			if (subdriver->get_data(flush_buf, sizeof(flush_buf)) < 1)
+				break;
+		}
+
+	return 0;
+}
+
  int ser_close(int fd, const char *port)
  {
  	usb->close(udev);
@@ -313,18 +332,6 @@
      All constants are hardcoded in windows driver
  */

-static void init_agiler()
-{
-	char flush_buf[256];
-	int i;
-
-	/* flush input buffers */
-	for (i = 0; i < 10; i++) {
-		if (get_data_agiler(flush_buf, sizeof(flush_buf)) < 1)
-			break;
-	}
-}
-
  static int set_data_agiler(const char *str)
  {
  	return usb->set_report(udev, 0, (unsigned char *)str, strlen(str));
@@ -367,10 +374,6 @@

  static krauler_command_t *command = NULL;

-static void init_krauler()
-{
-}
-
  static int set_data_krauler(const char *str)
  {
  	/*


-- 
   Alexander



More information about the Nut-upsdev mailing list