Update chopstx
authorNIIBE Yutaka <gniibe@fsij.org>
Thu, 13 Oct 2016 07:51:10 +0000 (16:51 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Thu, 13 Oct 2016 07:56:12 +0000 (16:56 +0900)
ChangeLog
chopstx
src/main.c
tool/hub_ctrl.py
tool/intel_hex.py

index fcf97f2..571a261 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-10-13  Niibe Yutaka  <gniibe@fsij.org>
+
+       * tool/intel_hex.py, tool/hub_ctrl.py: Update from Gnuk.
+
+       * chopstx: Update to 1.2.
+
 2016-07-15  Kenji Rikitake  <kenji@k2r.org>
 
        * src/main.c (main): Fix call of chopstx_poll to follow
 2016-07-15  Kenji Rikitake  <kenji@k2r.org>
 
        * src/main.c (main): Fix call of chopstx_poll to follow
diff --git a/chopstx b/chopstx
index 09f2770..d448d3c 160000 (submodule)
--- a/chopstx
+++ b/chopstx
@@ -1 +1 @@
-Subproject commit 09f27704f5be59ffe12dcb2a8e54083f44b014ee
+Subproject commit d448d3c678245b71a28b44652c053968ea70fa56
index bca7603..ede7f25 100644 (file)
@@ -1082,11 +1082,11 @@ main (int argc, char **argv)
       chopstx_mutex_unlock (&usb_mtx);
       while (1)
        {
       chopstx_mutex_unlock (&usb_mtx);
       while (1)
        {
+         uint32_t usec = 5000*1000;
          chopstx_poll_cond_t poll_desc;
          struct chx_poll_head *pd_array[1] = {
            (struct chx_poll_head *)&poll_desc
          };
          chopstx_poll_cond_t poll_desc;
          struct chx_poll_head *pd_array[1] = {
            (struct chx_poll_head *)&poll_desc
          };
-         uint32_t usec = 5000*1000;
 
          poll_desc.type = CHOPSTX_POLL_COND;
          poll_desc.ready = 0;
 
          poll_desc.type = CHOPSTX_POLL_COND;
          poll_desc.ready = 0;
index 684b3bd..5ace897 100755 (executable)
@@ -3,7 +3,7 @@
 """
 hub_ctrl.py - a tool to control port power/led of USB hub
 
 """
 hub_ctrl.py - a tool to control port power/led of USB hub
 
-Copyright (C) 2006, 2011 Free Software Initiative of Japan
+Copyright (C) 2006, 2011, 2016 Free Software Initiative of Japan
 
 Author: NIIBE Yutaka  <gniibe@fsij.org>
 
 
 Author: NIIBE Yutaka  <gniibe@fsij.org>
 
@@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
+from __future__ import print_function
 import usb
 
 USB_RT_HUB             =       (usb.TYPE_CLASS | usb.RECIP_DEVICE)
 import usb
 
 USB_RT_HUB             =       (usb.TYPE_CLASS | usb.RECIP_DEVICE)
@@ -43,7 +44,7 @@ def find_hubs(listing, verbose, busnum=None, devnum=None, hub=None):
     hubs = []
     busses = usb.busses()
     if not busses:
     hubs = []
     busses = usb.busses()
     if not busses:
-        raise ValueError, "can't access USB"
+        raise ValueError("can't access USB")
 
     for bus in busses:
         devices = bus.devices
 
     for bus in busses:
         devices = bus.devices
@@ -79,17 +80,17 @@ def find_hubs(listing, verbose, busnum=None, devnum=None, hub=None):
                 continue
 
             if printout_enable:
                 continue
 
             if printout_enable:
-                print "Hub #%d at %s:%03d" % (number_of_hubs_with_feature,
-                                              bus.dirname, dev.devnum)
+                print("Hub #%d at %s:%03d" % (number_of_hubs_with_feature,
+                                              bus.dirname, dev.devnum))
                 if (desc[3] & 0x03) == 0:
                 if (desc[3] & 0x03) == 0:
-                    print " INFO: ganged power switching."
+                    print(" INFO: ganged power switching.")
                 elif (desc[3] & 0x03) == 1:
                 elif (desc[3] & 0x03) == 1:
-                    print " INFO: individual power switching."
+                    print(" INFO: individual power switching.")
                 elif (desc[3] & 0x03) == 2 or (desc[3] & 0x03) == 3:
                 elif (desc[3] & 0x03) == 2 or (desc[3] & 0x03) == 3:
-                    print " WARN: no power switching."
+                    print(" WARN: no power switching.")
 
                 if (desc[3] & 0x80) == 0:
 
                 if (desc[3] & 0x80) == 0:
-                    print " WARN: Port indicators are NOT supported."
+                    print(" WARN: Port indicators are NOT supported.")
 
             hubs.append({ 'busnum' : bus.dirname, 'devnum' : dev.devnum,
                           'indicator_support' : (desc[3] & 0x80) == 0x80,
 
             hubs.append({ 'busnum' : bus.dirname, 'devnum' : dev.devnum,
                           'indicator_support' : (desc[3] & 0x80) == 0x80,
@@ -99,7 +100,7 @@ def find_hubs(listing, verbose, busnum=None, devnum=None, hub=None):
     return hubs
 
 def hub_port_status(handle, num_ports):
     return hubs
 
 def hub_port_status(handle, num_ports):
-    print " Hub Port Status:"
+    print(" Hub Port Status:")
     for i in range(num_ports):
         port = i + 1
         status = handle.controlMsg(requestType = USB_RT_PORT | usb.ENDPOINT_IN, 
     for i in range(num_ports):
         port = i + 1
         status = handle.controlMsg(requestType = USB_RT_PORT | usb.ENDPOINT_IN, 
@@ -108,31 +109,31 @@ def hub_port_status(handle, num_ports):
                                    index = port, buffer = 4,
                                    timeout = 1000)
 
                                    index = port, buffer = 4,
                                    timeout = 1000)
 
-        print "   Port %d: %02x%02x.%02x%02x" % (port, status[3], status[2],
-                                                 status[1], status[0]),
+        print("   Port %d: %02x%02x.%02x%02x" % (port, status[3], status[2],
+                                                 status[1], status[0]),)
         if status[1] & 0x10:
         if status[1] & 0x10:
-            print " indicator", 
+            print(" indicator", end='')
         if status[1] & 0x08:
         if status[1] & 0x08:
-            print " test" ,
+            print(" test" , end='')
         if status[1] & 0x04:
         if status[1] & 0x04:
-            print " highspeed",
+            print(" highspeed", end='')
         if status[1] & 0x02:
         if status[1] & 0x02:
-            print " lowspeed",
+            print(" lowspeed", end='')
         if status[1] & 0x01:
         if status[1] & 0x01:
-            print " power",
+            print(" power", end='')
 
         if status[0] & 0x10:
 
         if status[0] & 0x10:
-            print " RESET",
+            print(" RESET", end='')
         if status[0] & 0x08:
         if status[0] & 0x08:
-            print " oc",
+            print(" oc", end='')
         if status[0] & 0x04:
         if status[0] & 0x04:
-            print " suspend",
+            print(" suspend", end='')
         if status[0] & 0x02:
         if status[0] & 0x02:
-            print " enable",
+            print(" enable", end='')
         if status[0] & 0x01:
         if status[0] & 0x01:
-            print " connect",
+            print(" connect", end='')
 
 
-        print 
+        print()
 
 import sys
 
 
 import sys
 
@@ -142,9 +143,9 @@ COMMAND_SET_POWER = 2
 HUB_LED_GREEN  = 2
 
 def usage(progname):
 HUB_LED_GREEN  = 2
 
 def usage(progname):
-    print >> sys.stderr, """Usage: %s [{-h HUBNUM | -b BUSNUM -d DEVNUM}]
+    print("""Usage: %s [{-h HUBNUM | -b BUSNUM -d DEVNUM}]
           [-P PORT] [{-p [VALUE]|-l [VALUE]}]
           [-P PORT] [{-p [VALUE]|-l [VALUE]}]
-""" % progname
+""" % progname, file=sys.stderr)
 
 def exit_with_usage(progname):
     usage(progname)
 
 def exit_with_usage(progname):
     usage(progname)
@@ -219,7 +220,7 @@ if __name__ == '__main__':
 
     hubs = find_hubs(listing, verbose, busnum, devnum, hub)
     if len(hubs) == 0:
 
     hubs = find_hubs(listing, verbose, busnum, devnum, hub)
     if len(hubs) == 0:
-        print >> sys.stderr, "No hubs found."
+        print("No hubs found.", file=sys.stderr)
         exit(1)
     if listing:
         exit(0)
         exit(1)
     if listing:
         exit(0)
@@ -246,11 +247,11 @@ if __name__ == '__main__':
         feature = USB_PORT_FEAT_INDICATOR
         index = (value << 8) | port
     if verbose:
         feature = USB_PORT_FEAT_INDICATOR
         index = (value << 8) | port
     if verbose:
-        print "Send control message (REQUEST=%d, FEATURE=%d, INDEX=%d) " % (request, feature, index)
+        print("Send control message (REQUEST=%d, FEATURE=%d, INDEX=%d) " % (request, feature, index))
 
     uh.controlMsg(requestType = USB_RT_PORT, request = request, value = feature,
                   index = index, buffer = None, timeout = 1000)
     if verbose:
 
     uh.controlMsg(requestType = USB_RT_PORT, request = request, value = feature,
                   index = index, buffer = None, timeout = 1000)
     if verbose:
-       hub_port_status(uh,nports)
+        hub_port_status(uh,nports)
 
     del uh
 
     del uh
index a2b0e28..e9c7c2e 100644 (file)
@@ -9,7 +9,7 @@ You can use/distribute/modify/etc. this for any purpose.
 
 import binascii
 
 
 import binascii
 
-class intel_hex:
+class intel_hex(object):
     def __init__(self, filename):
         self.start_address = 0
         self.address = 0
     def __init__(self, filename):
         self.start_address = 0
         self.address = 0
@@ -36,7 +36,7 @@ class intel_hex:
                 memory[addr] = data
                 prev_addr = addr
                 prev_data_len = len(data)
                 memory[addr] = data
                 prev_addr = addr
                 prev_data_len = len(data)
-       self.memory = memory
+        self.memory = memory
 
     def calc_checksum(self, byte_count, offset, type_code, data):
         s = byte_count
 
     def calc_checksum(self, byte_count, offset, type_code, data):
         s = byte_count
@@ -57,19 +57,19 @@ class intel_hex:
         except:
             pass
         else:
         except:
             pass
         else:
-            raise ValueError, "data overwritten (%d)" % self.lineno
+            raise ValueError("data overwritten (%d)" % self.lineno)
         self.memory[address] = data
 
     def parse_line(self, line):
         if line[0] != ':':
         self.memory[address] = data
 
     def parse_line(self, line):
         if line[0] != ':':
-            raise ValueError, "invalid line (%d)" % self.lineno
+            raise ValueError("invalid line (%d)" % self.lineno)
         count = int(line[1:3], 16)
         offset = int(line[3:7], 16)
         type_code = int(line[7:9], 16)
         data = binascii.unhexlify(line[9:(9+count*2)])
         check_sum = int(line[(9+count*2):], 16)
         if check_sum != self.calc_checksum(count, offset, type_code, data):
         count = int(line[1:3], 16)
         offset = int(line[3:7], 16)
         type_code = int(line[7:9], 16)
         data = binascii.unhexlify(line[9:(9+count*2)])
         check_sum = int(line[(9+count*2):], 16)
         if check_sum != self.calc_checksum(count, offset, type_code, data):
-            raise ValueError, "invalid checksum (%d)" % self.lineno
+            raise ValueError("invalid checksum (%d)" % self.lineno)
         if type_code == 0x00:
             self.add_data(count, offset, data)
             return 0
         if type_code == 0x00:
             self.add_data(count, offset, data)
             return 0
@@ -77,18 +77,18 @@ class intel_hex:
             return 1
         elif type_code == 0x04:
             if count != 2:
             return 1
         elif type_code == 0x04:
             if count != 2:
-                raise ValueError"invalid count (%d): (%d) Expected 2" \
-                    % (self.lineno, count)
+                raise ValueError("invalid count (%d): (%d) Expected 2" \
+                                 % (self.lineno, count))
             self.address = ((ord(data[0])&0xff)<<24) + ((ord(data[1])&0xff)<<16)
             return 0
         elif type_code == 0x05:
             if count != 4:
             self.address = ((ord(data[0])&0xff)<<24) + ((ord(data[1])&0xff)<<16)
             return 0
         elif type_code == 0x05:
             if count != 4:
-                raise ValueError"invalid count (%d): (%d) Expected 4" \
-                    % (self.lineno, count)
+                raise ValueError("invalid count (%d): (%d) Expected 4" \
+                                 % (self.lineno, count))
             self.start_address \
                 = ((ord(data[0])&0xff)<<24) + ((ord(data[1])&0xff)<<16) \
                 + ((ord(data[2])&0xff)<<8) + ((ord(data[3])&0xff))
             return 0
         else:
             self.start_address \
                 = ((ord(data[0])&0xff)<<24) + ((ord(data[1])&0xff)<<16) \
                 + ((ord(data[2])&0xff)<<8) + ((ord(data[3])&0xff))
             return 0
         else:
-            raise ValueError"invalid type code (%d): (%d)" \
-                % (self.lineno, type_code)
+            raise ValueError("invalid type code (%d): (%d)" \
+                             % (self.lineno, type_code))