make_udev_install.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import sys
5 import tempfile
6 from subprocess import *
7 import subprocess
8 import shutil
9 
11  def setup_serial(self):
12  choice = raw_input("install setserial yes(y) or none(n) : ")
13  if choice in ['y', 'ye', 'yes']:
14  os.system('sudo apt-get install setserial')
15 
16  def usb_id_write(self):
17  with tempfile.NamedTemporaryFile() as tf:
18  self.filename = tf.name
19 
20  header = '#aero_controller\n'
21  upper_string = 'SUBSYSTEM=="tty",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6001",ATTRS{serial}=="111",MODE="666",SYMLINK+="aero_upper", RUN+="/bin/setserial /dev/aero_upper low_latency"\n'
22  lower_string = 'SUBSYSTEM=="tty",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6001",ATTRS{serial}=="123",MODE="666",SYMLINK+="aero_lower", RUN+="/bin/setserial /dev/aero_lower low_latency"\n'
23  space = '\n'
24  header_hokuyo = '#hokuyo urg\n'
25  hokuyo_string = 'SUBSYSTEM=="tty",ATTRS{idVendor}=="15d1",ATTRS{idProduct}=="0000",MODE="666",SYMLINK+="hokuyo"'
26 
27  print("Please insert upper USB to PC port")
28  choice = raw_input("yes(y) or none(n) : ")
29  if choice in ['y', 'yes']:
30  upper = upper_string.split(',')
31 
32  print(upper[3])
33  #prev_upper_id = upper.strip("ATTRS{serial}==")
34  p1 = subprocess.Popen(['udevadm','info','-n', '/dev/ttyUSB0'], stdout=subprocess.PIPE)
35  p2 = subprocess.Popen(['grep', 'SERIAL_SHORT'], stdin=p1.stdout, stdout=subprocess.PIPE)
36  #p1 = subprocess.Popen(['udevadm','info','-n', '/dev/tty0'], stdout=subprocess.PIPE)
37  #p2 = subprocess.Popen(['grep', 'MAJOR'], stdin=p1.stdout, stdout=subprocess.PIPE)
38  p1.stdout.close()
39 
40  out, err = p2.communicate()
41  upper[3] = "ATTRS{serial}==\"" + out.split('=')[1].strip() +"\""
42  print(upper[3])
43  print(upper)
44  upper_string = (','.join(upper))
45  print(upper_string)
46 
47  print("Please insert lower USB to PC port")
48  choice = raw_input("yes(y) or none(n) : ")
49  if choice in ['y', 'yes']:
50  lower = lower_string.split(',')
51 
52  print(lower[3])
53  #prev_upper_id = upper.strip("ATTRS{serial}==")
54  p1 = subprocess.Popen(['udevadm','info','-n', '/dev/ttyUSB0'], stdout=subprocess.PIPE)
55  p2 = subprocess.Popen(['grep', 'SERIAL_SHORT'], stdin=p1.stdout, stdout=subprocess.PIPE)
56  #p1 = subprocess.Popen(['udevadm','info','-n', '/dev/tty0'], stdout=subprocess.PIPE)
57  #p2 = subprocess.Popen(['grep', 'MAJOR'], stdin=p1.stdout, stdout=subprocess.PIPE)
58  p1.stdout.close()
59 
60  out, err = p2.communicate()
61  lower[3] = "ATTRS{serial}==\"" + out.split('=')[1].strip() + "\""
62  print(lower[3])
63  print(lower)
64  lower_string = (','.join(lower))
65  print(lower_string)
66 
67  print("write tempfile")
68  tf.write(header)
69  tf.write(upper_string)
70  tf.write(lower_string)
71  tf.write(space)
72  tf.write(header_hokuyo)
73  tf.write(hokuyo_string)
74  tf.seek(0)
75  print(tf.read())
76  subprocess.call(['sudo', 'cp', self.filename, '/etc/udev/rules.d/90-aero.rules'])
77 
78 
79 if __name__ == "__main__" :
80  ui = UdevInstall()
81  ui.setup_serial()
82  ui.usb_id_write()
83 
84 


seed_r7_bringup
Author(s):
autogenerated on Sun Apr 18 2021 02:40:52