BT device choice in launcher

This commit is contained in:
shrlnm 2023-01-03 08:43:03 +03:00
parent 6238916b25
commit 6be4ce6639
2 changed files with 31 additions and 18 deletions

32
main.py
View File

@ -285,8 +285,6 @@ def run(s, cmd):
# sys.argv.append('--demo')
if cmd == 'ddt':
sys.argv.append('--demo')
# if cmd == 'pids':
# sys.argv = [ 'mod_ecu.py', 'ask', s.lang, 'torq']
os.chdir(s.path)
cmdr.main()
sys.exit()
@ -934,10 +932,10 @@ else:
self.save.csvOption = self.csvl[int(self.droid.fullQueryDetail("sp_csv").result['selectedItemPosition'])]
if self.droid.fullQueryDetail("rb_bt").result['checked'] == 'false':
self.save.port = self.droid.fullQueryDetail("in_wifi").result['text']
self.save.port = '192.168.0.10:3500'
else:
portName = self.droid.fullQueryDetail("in_wifi").result['text']
upPortName = portName.upper()
portName = self.dev_list[int(self.droid.fullQueryDetail("in_wifi").result['selectedItemPosition'])]
upPortName = portName.upper().split(';')[0]
MAC = ''
if re.match (r"^[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}$", upPortName) or \
re.match (r"^[0-9A-F]{4}.[0-9A-F]{4}.[0-9A-F]{4}$", upPortName) or \
@ -1007,18 +1005,23 @@ else:
self.csvl = csvl
if self.save.port == '':
self.save.port = "192.168.0.10:35000"
self.save.port = "192.168.0.10:35000;WiFi"
self.dev_list.append(self.save.port)
if self.save.port.upper().endswith('BT'):
MAC = ""
if ';' in self.save.port:
MAC = self.save.port.split(';')[0]
for d in self.dev_list:
if MAC in d:
self.dev_list.insert(0, self.dev_list.pop(self.dev_list.index(d)))
self.droid.fullSetProperty("rb_bt", "checked", "true")
self.droid.fullSetProperty("rb_wifi", "checked", "false")
self.droid.fullSetProperty("in_wifi", "text", MAC)
self.droid.fullSetList("in_wifi", self.dev_list)
else:
self.droid.fullSetProperty("rb_bt", "checked", "false")
self.droid.fullSetProperty("rb_wifi", "checked", "true")
self.droid.fullSetProperty("in_wifi", "text", self.save.port)
self.droid.fullSetList("in_wifi", [self.save.port])
self.droid.fullSetProperty("in_logname", "text", self.save.logName)
if self.save.log:
@ -1123,16 +1126,14 @@ else:
android:checked="false"
android:text="WiFi" />
</RadioGroup>
<EditText
<Spinner
android:id="@+id/in_wifi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/tx_elm"
android:layout_toRightOf="@id/radioGroup"
android:layout_marginLeft="20dp"
android:ems="10"
android:text="192.168.0.10:35000" />
android:layout_marginLeft="20dp" />
<TextView
android:id="@+id/tx_log"
android:layout_width="wrap_content"
@ -1331,6 +1332,13 @@ else:
try:
self.droid = android.Android()
self.droid.fullShow(self.lay)
self.dev_list = ['192.168.0.10:35000;WiFi']
try:
tmp = self.droid.bluetoothGetBondedDevices().result
for i in range(0, len(tmp), 2):
self.dev_list.append( tmp[i]+';'+tmp[i+1])
except:
pass
self.loadSettings()
self.eventloop()
finally:

View File

@ -237,7 +237,8 @@ class DDTECU():
''' 0 1 2 3 4 5 6 7 '''
''' 01234567890123456789012345678901234567890123456789012345678901234567890123456'''
IdRsp = '61 80 34 36 33 32 52 45 34 42 45 30 30 33 37 52 00 83 9D 00 1A 90 01 01 00 88 AA'
#IdRsp = '61 80 34 36 33 32 52 45 34 42 45 30 30 33 37 52 00 83 9D 00 1A 90 01 01 00 88 AA'
#IdRsp = '61 80 30 33 32 32 53 44 34 36 34 36 34 31 39 52 43 10 34 00 25 80 01 01 01 88 00'
''' -- -------- ----- ----- '''
''' DiagVersion--+ | | +--Version '''
''' Supplier--+ +--Soft '''
@ -1161,11 +1162,15 @@ def AutoIdents_distance( DiagVersion, Supplier, Soft, Version, ai ):
#normalize supplier in such cases
#DiagVersion="12" Supplier="746" Soft="2470" Version="A600"
#DiagVersion="12" Supplier="39324d" Soft="0052" Version="0400"
if len( ai['Supplier'] ) == 6 and \
len( ai['Soft'] ) == 4 and \
len( ai['Version'] ) == 4:
ai['Supplier'] = bytes.fromhex(ai['Supplier']).decode('utf-8')
try:
if len( ai['Supplier'] ) == 6 and \
len( ai['Soft'] ) == 4 and \
len( ai['Version'] ) == 4:
ai['Supplier'] = bytes.fromhex(ai['Supplier']).decode('utf-8')
except:
#catch not hex supplier with len 6
pass
d = distance( DiagVersion, ai['DiagVersion']) * 0.25
d = d + distance( Supplier, ai['Supplier']) * 0.25
d = d + distance( Soft, ai['Soft']) * 0.25