lunedì 18 marzo 2013

RFObasic! per android: comunicazione con Bluetooth

comincio da RFObasic!
manuale pagina 181
estratto
programma tutorial:

Copyright© Paul Laughton, 2011, 2012  Page 181  De Re BASIC!


f35_bluetooth.bas 
!! 
This program demonstrates using bluetooth as both an application that listens for a connection 
or makes a connection to a listener. 

Before running this program use the Android "Settings" application to enable Bluetooth and to pair 
with the device(s) that you will talk to. 

This program will send and receive data bytes to and from a connected device. 

You can use this program to  (among many other things) set up a chat between two Android 
devices. 

Note: The UUID used by default is the standard serial port UUID. This can be changed. Read the manual. 

!! 

! Begin by opening Bluetooth 
! If Bluetooth is not enabled 
! the program will stop here. 

bt.open 

! When BT is opened, the program 
! will start listening for another 
! device to connect. At this time 
! the user can continue to wait 
! for a connection are can attempt 
! to connect to another device 
! that is waiting for a connection 

! Ask user what to do 

array.load type$[], "Connect to listener", "Continue to listen for connection", "Quit" 
msg$ = "Select operation mode" 

new_connection: 

select type, type$[], msg$ 

! If the user pressed the back 
! key or selected quit then quit 
! otherwise try to connect to 
! a listener 

if (type = 0) | (type =3) 
 print "Thanks for playing" 
 bt.close 
 end 
elseif type = 1 
 bt.connect 
endif 

! Read status until 
! a connection is made 


Do 
 bt.status s 
 if s = 1  
  print "Listening 
  elseif s =2 
   print "Connecting" 
   elseif s = 3 
    print "Connected" 
 endif 
 pause 1000 

until s =3 

! When a connection is made 
! get the name of the connected 
! device 

bt.device.name device$ 

! *** Read/Write Loop **** 

RW_Loop: 

Do 

! Read status to insure 
! that we remain connected. 
! If disconnected, program 
! reverts to listen mode. 
! In that case, ask user 
! what to do. 

 bt.status s 
 if s<> 3 
  print "Connection lost" 
  goto new_connection 
 endif 

! Read messages until 
! the message queue is 
! empty 

 Do 
  bt.read.ready rr 
  if rr 
   bt.read.bytes msg$ 
   print device$;": ";msg$ 
  endif 
 until rr = 0 

! Message Queue is empty 
! Send a message 
! Note: If no text is entered 
! then no text will be sent 

 Input "Text to send", msg$ 
 if (msg$ <> "") & (msg$<> "*") 
  bt.write msg$ 
  print "Me: "; msg$ 
 endif 

until msg$ = "*"  

! if msg$ is "*" then close connection 
! and restart 

bt.close 
bt.open 
goto new_connection 

quale sistema di sviluppo per android per comunicare BT?

Opzione 1: RFO-basic! per android  http://laughton.com/basic/help/De_Re_BASIC%21.htm#_Toc349156658
(per editare da remoto NON usare

WiFi Keyboard

Ivan Volosyuk.
che fa schifo (meglio "airdroid" o "wifi file transfer")

qualcuno ci sta gia' provando:
http://rfobasic.freeforums.org/post6406.html?hilit=OBD#p6406
e come primo effetto c'e' stato un aggiornamento del BT.flush in RFObasic


Opzione2 : MIT APPInventor , in particolare l'approccio ShivalWolf al Bluetooth (qui si trovano i sorgenti)


per debuggare e' utile avere il software per PC e un portatile con Bluetooth; esempio di SW scaricabile

ovviamente la base di partenza e' una app android gia' funzionante (che e' quella che voglio imitare) che funziona sullo smartphone disponibile:
https://play.google.com/store/apps/details?id=org.prowl.torque&hl=it
e un simulatore di OBD per non andare sempre in garage a provare.

OBD: Lista dei parametri

Lista dei parametri e degli Identificativi di parametro (numero esadecimale e decimale):

http://www.outilsobdfacile.com/obd-mode-pid.html#OBD_PIDs
MODI 1 e 2
0000Determine PIDs supported (range 01h to 20h )
0101Trouble codes and on board test information
0202Freeze frame trouble code
0303Fuel system status
0404Calculated load value
0505Coolant temperature
0606Short term fuel % trim Bank 1
0707Long term fuel % trim Bank 1
0808Short term fuel % trim Bank 2
0909Long term fuel % trim Bank 2
0A10Fuel pressure
0B11Intake Manifold Pressure
0C12Engine RPM
0D13Vehicle speed
0E14Timing advance
0F15Intake air temperature
1016Maf air flow
1117Absolute Throttle sensor position
1218Secondary air status
1319Oxygen sensor locations bank/sensor
1420Oxy. sensor voltage bank1 sensor1
1521Oxy. sensor voltage bank1 sensor2
1622Oxy. sensor voltage bank1 sensor3
1723Oxy. sensor voltage bank1 sensor4
1824Oxy. sensor voltage bank2 sensor1
1925Oxy. sensor voltage bank2 sensor2
1A26Oxy. sensor voltage bank2 sensor3
1B27Oxy. sensor voltage bank2 sensor4
1C28Design OBD requirements
1D29Alternate Oxy sensor locations
1E30Auxilliary input status
1F31Time since engine start
2032Determine PIDs supported (range 21h to 40h )
2133Distance traveled while MIL is activated
2234Fuel rail pressure relative manifold
2335Fuel rail pressure
2436Bank 1 - sensor 1 (wide range O2S)
2537Bank 1 - sensor 2 (wide range O2S)
2638Bank 1 - sensor 3 (wide range O2S)
2739Bank 1 - sensor 4 (wide range O2S)
2840Bank 2 - sensor 1 (wide range O2S)
2941Bank 2 - sensor 2 (wide range O2S)
2A42Bank 2 - sensor 3 (wide range O2S)
2B43Bank 2 - sensor 4 (wide range O2S)
2C44Commanded EGR
2D45EGR error
2E46Commanded evaporative purge
2F47Fuel level input
3048Number of warn-ups since DTCs cleared
3149Distance traveled since DTCs cleared
3250Evap system vapor pressure
3351Barometric pressure
3452Bank 1 - sensor 1 (wide range O2S)
3553Bank 1 - sensor 2 (wide range O2S)
3654Bank 1 - sensor 3 (wide range O2S)
3755Bank 1 - sensor 4 (wide range O2S)
3856Bank 2 - sensor 1 (wide range O2S)
3957Bank 2 - sensor 2 (wide range O2S)
3A58Bank 2 - sensor 3 (wide range O2S)
3B59Bank 2 - sensor 4 (wide range O2S)
3C60Catalyst Temperature bank 1, sensor 1
3D61Catalyst Temperature bank 2, sensor 1
3E62Catalyst Temperature bank 1, sensor 2
3F63Catalyst Temperature bank 2, sensor 2
4064Determine PIDs supported (range 41h to 60h )
4165Monitor status this driving cycle
4266Control module voltage
4367Absolute load value
4468Fuel/air commanded equivalence ratio
4569Relative throttle position
4670Ambiant air temperature
4771Absolute throttle position B
4872Absolute throttle position C
4973Accelerator pedal position D
4A74Accelerator pedal position E
4B75Accelerator pedal position F
4C76Commanded throttle actuator control
4D77Engine run time while MIL is activated
4E78Engine run time since DTCs cleared
4F79External test equipment configuration information #1
5080External test equipment configuration information #2
5181Type of fuel currently being utilized by the vehicule
5282Alcohol fuel pourcentage
5383Absolute evap system vapor pressure
5484Evap system vapor pressure
5585Short term secondary O2 sensor fuel trim - bank 1 and 3
5686Long term secondary O2 sensor fuel trim - bank 1 and 3
5787Short term secondary O2 sensor fuel trim - bank 2 and 4
5888Long term secondary O2 sensor fuel trim - bank 2 and 4
5989Fuel rail pressure (absolute)
5A90Relative accelerator pedal position
5B91Hybrid battery pack remaining life
5C92Engine oil temperature
5D93Fuel injection timing
5E94Engine fuel rate
5F95Emission requirements to which vehicule is designed
6096Determine PIDs supported (range 61h to 80h )
6197Driver's demand engine - percent torque
6298Actual engine - percent torque
6399Engine reference torque
64100Engine percent torque data
65101Auxiliary inputs / outputs
66102Mass air flow sensor
67103Engine coolant temperature
68104Intake air temperature sensor
69105Commanded EGR and EGR error
6A106Commanded diesel intake air flow control and relative intake air flow position
6B107Exhaust gas recirculation temperature
6C108Commanded throttle actuator control and relative throttle position
6D109Fuel pressure control system
6E110Injection pressure control system
6F111Turbocharger compressor inlet pressure
70112Boost pressure control
71113Variable geometry turbo (VGT) control
72114Wastegate control
73115Exhaust pressure
74116Turbocharger RPM
75117Turbocharger A temperature
76118Turbocharger B temperature
77119Charge air cooler temperature (CACT)
78120Exhaust gas temperature (EGT) bank 1
79121Exhaust gas temperature (EGT) bank 2
7A122Diesel particulate filter (DPF) bank 1
7B123Diesel particulate filter (DPF) bank 2
7C124Diesel particulate filter (DPF) temperature
7D125Nox NTE control area status
7E126PM NTE control area status
7F127Engine run time
80128Determine PIDs supported (range 81h to A0h )
81129Engine run time for AECD #1 - #5
82130Engine run time for AECD #6 - #10
83131Nox sensor
84132Manifold surface temperature
85133Nox control system
86134Particulate matter (PM) sensor
87135Intake manifold absolute pressure
88136ISO/SAE reserved
89137Determine PIDs supported (range A1h to C0h )
8A138Determine PIDs supported (range C1h to E0h )
8B139Determine PIDs supported (range E1h to FFh )

modo 5
0000Determine PIDs supported (range 01h to 20h )
0101Rich to lean sensor threshold voltage
0202Lean to rich sensor threshold voltage
0303Low sensor voltage for switch time calculation
0404High sensor voltage for switch time calculation
0505Rich to lean sensor switch time
0606Lean to rich sensor switch time
0707Minimum sensor voltage for test cycle
0808Maximum sensor voltage for test cycle
0909Time between sensor transitions
0A0ASensor period
0B0BISO/SAE reserved

modo 6
00Determine PIDs supported (range 01h to 20h )
11Exhaust Gas Sensor Monitor Bank 1 - Sensor 1
22Exhaust Gas Sensor Monitor Bank 1 - Sensor 2
33Exhaust Gas Sensor Monitor Bank 1 - Sensor 3
44Exhaust Gas Sensor Monitor Bank 1 - Sensor 4
55Exhaust Gas Sensor Monitor Bank 2 - Sensor 1
66Exhaust Gas Sensor Monitor Bank 2 - Sensor 2
77Exhaust Gas Sensor Monitor Bank 2 - Sensor 3
88Exhaust Gas Sensor Monitor Bank 2 - Sensor 4
99Exhaust Gas Sensor Monitor Bank 3 - Sensor 1
0A10Exhaust Gas Sensor Monitor Bank 3 - Sensor 2
0B11Exhaust Gas Sensor Monitor Bank 3 - Sensor 3
0C12Exhaust Gas Sensor Monitor Bank 3 - Sensor 4
0D13Exhaust Gas Sensor Monitor Bank 4 - Sensor 1
0E14Exhaust Gas Sensor Monitor Bank 4 - Sensor 2
0F15Exhaust Gas Sensor Monitor Bank 4 - Sensor 3
1016Exhaust Gas Sensor Monitor Bank 4 - Sensor 4
1117Determine PIDs supported (range 21h to 40h )
1218Catalyst Monitor Bank 1
1319Catalyst Monitor Bank 2
1420Catalyst Monitor Bank 3
1521Catalyst Monitor Bank 4
1622EGR Monitor Bank 1
1723EGR Monitor Bank 2
1824EGR Monitor Bank 3
1925EGR Monitor Bank 4
1A26VVT Monitor Bank 1
1B27VVT Monitor Bank 2
1C28VVT Monitor Bank 3
1D29VVT Monitor Bank 4
1E30EVAP Monitor (Cap Off / 0.150")
1F31EVAP Monitor (0.090")
2032EVAP Monitor (0.040")
2133EVAP Monitor (0.020")
2234Purge Flow Monitor
2335Determine PIDs supported (range 41h to 60h )
2436Exhaust Gas Sensor Heater Monitor Bank 1 - Sensor 1
2537Exhaust Gas Sensor Heater Monitor Bank 1 - Sensor 2
2638Exhaust Gas Sensor Heater Monitor Bank 1 - Sensor 3
2739Exhaust Gas Sensor Heater Monitor Bank 1 - Sensor 4
2840Exhaust Gas Sensor Heater Monitor Bank 2 - Sensor 1
2941Exhaust Gas Sensor Heater Monitor Bank 2 - Sensor 2
2A42Exhaust Gas Sensor Heater Monitor Bank 2 - Sensor 3
2B43Exhaust Gas Sensor Heater Monitor Bank 2 - Sensor 4
2C44Exhaust Gas Sensor Heater Monitor Bank 3 - Sensor 1
2D45Exhaust Gas Sensor Heater Monitor Bank 3 - Sensor 2
2E46Exhaust Gas Sensor Heater Monitor Bank 3 - Sensor 3
2F47Exhaust Gas Sensor Heater Monitor Bank 3 - Sensor 4
3048Exhaust Gas Sensor Heater Monitor Bank 4 - Sensor 1
3149Exhaust Gas Sensor Heater Monitor Bank 4 - Sensor 2
3250Exhaust Gas Sensor Heater Monitor Bank 4 - Sensor 3
3351Exhaust Gas Sensor Heater Monitor Bank 4 - Sensor 4
3452Determine PIDs supported (range 61h to 80h )
3553Heated Catalyst Monitor Bank 1
3654Heated Catalyst Monitor Bank 2
3755Heated Catalyst Monitor Bank 3
3856Heated Catalyst Monitor Bank 4
3957Secondary Air Monitor 1
3A58Secondary Air Monitor 2
3B59Secondary Air Monitor 3
3C60Secondary Air Monitor 4
3D61Determine PIDs supported (range 81h to A0h )
3E62Fuel System Monitor Bank 1
3F63Fuel System Monitor Bank 2
4064Fuel System Monitor Bank 3
4165Fuel System Monitor Bank 4
4266Boost Pressure Control Monitor Bank 1
4367Boost Pressure Control Monitor Bank 2
4468NOx Adsorber Monitor Bank 1
4569NOx Adsorber Monitor Bank 2
4670NOx Catalyst Monitor Bank 1
4771NOx Catalyst Monitor Bank 2
4872Determine PIDs supported (range A1h to C0h )
4973Misfire Monitor General Data
4A74Misfire Cylinder 1 Data
4B75Misfire Cylinder 2 Data
4C76Misfire Cylinder 3 Data
4D77Misfire Cylinder 4 Data
4E78Misfire Cylinder 5 Data
4F79Misfire Cylinder 6 Data
5080Misfire Cylinder 7 Data
5181Misfire Cylinder 8 Data
5282Misfire Cylinder 9 Data
5383Misfire Cylinder 10 Data
5484Misfire Cylinder 11 Data
5585Misfire Cylinder 12 Data
5686Misfire Cylinder 13 Data
5787Misfire Cylinder 14 Data
5888Misfire Cylinder 15 Data
5989Misfire Cylinder 16 Data
5A90PM Filter Monitor Bank 1
5B91PM Filter Monitor Bank 2
5C92Determine PIDs supported (range C1h to E0h )
5D93Determine PIDs supported (range E1h to FFh )
5E94Manufacturer specific

modo 9
0000Determine PIDs supported (range 01h to 20h )
0101MessageCount VIN
0202Vehicle Identification Number
0303MessageCount CALID
0404Calibration Identifications
0505MessageCount CVN
0606Calibration Verification Numbers
0707MessageCount IPT
0808In-use Performance Tracking
0909MessageCount ECU name
0A10ECU name
0B11In-use Performance Tracking
0C-FF12-255ISO/SAE reserved