User Tools

Site Tools


doc:lua_make-your-own-scripts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
doc:lua_make-your-own-scripts [2014/10/13 18:46] admindoc:lua_make-your-own-scripts [2015/11/15 13:49] – [Miscellaneous Commands] admin
Line 302: Line 302:
  
  
-====  Miscellaneous  Commands ====+==== WriteString Command Syntax ====
  
-=== serDisplayWrite(String) ===+As default the command 
  
 +  serDisplayWrite(String)
 +
 +
 +writes //String// to the build in output console. But with an optional secound parameter as command this behavior can be changed:
 +
 +  serDisplayWrite(parameter, command)
 +
 +The different commands have the following effects:
 +
 +^ parameter  ^ command  ^ Function  ^
 +| buffername  | setbuffer  | redirects the following DisplayWrite()'s output into buffer "bufferName". If the buffer does not exists, it's automatically generated \\ The default output window buffername, which is also active at start, is //display// To write some output there after using some other buffers before, set buffer back to //display// |
 +| -           | clear      | clears actual buffer content |
 +| -           | clearall   | clears all buffers. Senseful at start of scripts, if wanted, as the buffers contain their contents between scripts runs |
 +| filename    | save       | saves actual buffer to filename without further asking  |
 +| filename    | saveas       | saves actual buffer to filename by let the user first confirm the filename  |
 +| filename    | append       | appends actual buffer to filename without further asking  |
 +| filename    | appendas       | appends actual buffer to filename by let the user first confirm the filename  |
 +
 +
 +
 +
 +==== Miscellaneous  Commands ====
  
-Writes //String// to the build in output console. 
  
 === dbLookup(db-File , searchstring) === === dbLookup(db-File , searchstring) ===
  
-Searches in the //db-file// for all entries with index //searchstring//. The //db-file// needs to be in the same directory as the Lua- script itself. The //db-file// itself is made by [[tools_oodbcreate|oodbCreate]].+ 
 +Searches in the //db-file// for all entries with index //searchstring//. The //db-file// needs to be in the same directory as the Lua- script itself. The //db-file// itself is made by [[:doc:tools_oodbcreate|oodbCreate]]. 
  
 dbLookup() returns a Lua table dbLookup() returns a Lua table
-   + 
-  myTable = dbLookup("dtc.oodb", "0815")+ 
 +<code> 
 +myTable = dbLookup("dtc.oodb", "0815") 
 +</code> 
  
 //myTable.len// tells the success status: //myTable.len// tells the success status:
-  * if //myTable.len// < 0 then an error has occured 
-  * if //myTable.len// = 0 then //searchstring// has not been found 
-  * if //myTable.len// > 0 then //myTable.len// tells the number of entries found 
  
-When something has been found, than //myTable// contains two sections, //header// and //data//.+ 
 +    * if //myTable.len//  < 0 then an error has occured 
 +    * if //myTable.len//  = 0 then //searchstring//  has not been found 
 +    * if //myTable.len//  > 0 then //myTable.len//  tells the number of entries found 
 + 
 + 
 +When something has been found, than //myTable//  contains two sections, //header//  and //data//. 
  
 The header section is needed in case you don't know in which column your wanted result is stored; you can identify the column by its column header name instead: The header section is needed in case you don't know in which column your wanted result is stored; you can identify the column by its column header name instead:
  
-   col= myTable.header["DTC-Text"] 
-   print (col) 
-   2 
-    
- //myTable.header.size// tells the number of colums in total **without** the first index column, which is always surpressed. 
  
 +<code>
 + col= myTable.header["DTC-Text"]
 + print (col)
 + 2
 +</code>
 +
 +
 +//myTable.header.size//  tells the number of colums in total **without**  the first index column, which is always surpressed.
 +
 +
 +The //data//  section then contains the found data itself, arranged as a two dimensional array, sorted by rows and columns.
 +
 +
 +<code>
 +  result=myTable.data[row][column]
 +</code>
 +
 +
 +**ATTENTION**: Although the row and column indexes are expressed as numbers (1,2,3,4..), they are internally represented as string values (“1”,”2”,”3”,”4”…), so to read the result correctly, numeric row and column counters need to be converted to strings first to address the array correctly
 +
 +
 +<code>
 +  column=3
 +  row=2
 +  result=myTable.data[tostring(row)][tostring(column)])
 +</code>
  
-The //data// section then contains the found data itself, arranged as a two dimensional array, sorted by rows and columns.  
  
-    result=myTable.data[row][column] +Here after all a piece of sample code
-   +
-**ATTENTION**: Although the row and column indexes are expressed as numbers (1,2,3,4..), they are internally represented as string values ("1","2","3","4"...), so to read the result correctly, numeric row and column counters need to be converted to strings first to address the array correctly+
  
-    column=3 
-    row=2 
-    result=myTable.data[tostring(row)][tostring(column)]) 
-     
-     
- Here after all a piece of sample code 
  
 <code lua> <code lua>
 myTable= dbLookupCall("dtc.oodb","005") myTable= dbLookupCall("dtc.oodb","005")
 + 
 print ("header") print ("header")
 for k,v in pairs (myTable.header) do for k,v in pairs (myTable.header) do
     print (k,"=",v)     print (k,"=",v)
 end end
 + 
 nrOfColumns = myTable.header.size nrOfColumns = myTable.header.size
 nrOfRows = myTable.len nrOfRows = myTable.len
 + 
 print ("Rows x Columns:" ,nrOfRows, nrOfColumns) print ("Rows x Columns:" ,nrOfRows, nrOfColumns)
- +  
 + 
 for row = 1 , nrOfRows , 1 do for row = 1 , nrOfRows , 1 do
   for column = 1 , nrOfColumns, 1 do    for column = 1 , nrOfColumns, 1 do 
-  + 
    print (cy, cx, myTable.data[tostring(row)][tostring(column)])    print (cy, cx, myTable.data[tostring(row)][tostring(column)])
   end   end
 end end
 </code> </code>
 +
  
 === openXCVehicleData(lua table) === === openXCVehicleData(lua table) ===
  
-OOBD can work as VehicleDatasource for [[http://openxcplatform.com/|openXC]], which means OOBD can send datasets to the openXC system (which needs to be installed on the same android device too, obviously). + 
 +OOBD can work as VehicleDatasource for [[http://openxcplatform.com/|openXC]], which means OOBD can send datasets to the openXC system (which needs to be installed on the same android device too, obviously). 
  
 To do so, a lua table is filled with the right indentifiers and correct formated values accourding to the [[https://github.com/openxc/openxc-message-format|OpenXC Message Format Specification]], one value per call. To do so, a lua table is filled with the right indentifiers and correct formated values accourding to the [[https://github.com/openxc/openxc-message-format|OpenXC Message Format Specification]], one value per call.
 +
  
 With that table openXCVehicleData() is called and the data are been transferred to the openXC backbone task for further handling. With that table openXCVehicleData() is called and the data are been transferred to the openXC backbone task for further handling.
  
-  openXCVehicleData({timestamp= 1332794087.675514, name= "longitude", value= -83.237427}) + 
-  +<code> 
 +openXCVehicleData({timestamp= 1332794087.675514, name= "longitude", value= -83.237427}) 
 +</code> 
 + 
 So everything which is understood by openXC can be generated out of a OOBD lua script. So everything which is understood by openXC can be generated out of a OOBD lua script.
  
doc/lua_make-your-own-scripts.txt · Last modified: 2019/04/08 18:43 by admin