doc:lua_make-your-own-scripts
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| doc:lua_make-your-own-scripts [2014/10/13 18:22] – admin | doc:lua_make-your-own-scripts [2019/04/08 18:43] (current) – [The IO Commands] admin | ||
|---|---|---|---|
| Line 136: | Line 136: | ||
| - | ==== The Communication | + | ==== The Communication Commands ==== |
| Line 186: | Line 186: | ||
| - | === ioInput(file name , | + | === ioInput(file_name |
| Line 192: | Line 192: | ||
| - | ^ filename | + | ^ filename |
| - | |/ | + | |/ |
| - | |/ | + | |/ |
| - | |URL like '' | + | |URL like '' |
| - | |URL like '' | + | |URL like '' |
| + | |||
| + | After opening the file with IOInput(), it can be read with ioRead() | ||
| === ioRead(" | === ioRead(" | ||
| - | Read one line of the input file ending with either | + | Read one line of the input file ending with either< |
| - | + | ||
| === ioRead (" | === ioRead (" | ||
| Line 211: | Line 211: | ||
| - | === ioRead (count) === | + | === ioRead (" |
| - | Read count number | + | Here it's assumed that the input file consists |
| - | === ioOutput(URL[, | + | === ioRead |
| - | Try to opens '' | + | This mainly for testing purposes. It returns |
| - | === ioWrite (String) === | + | |
| - | Attaches the string content to the output file | + | \\ |
| + | ==== The Buffer Commands ==== | ||
| - | ==== loadbuffer ==== | + | FIXME this whole Buffer section is not implemented and actual just here as a reference for discussion |
| - | loadbuffer(start: | + | |
| - | Reads the file " | ||
| - | The number of bytes read will be returned in " | + | === loadbuffer === |
| + | len, newfilename= loadbuffer(start , filelen , file_name , file_extension , message) | ||
| + | |||
| + | Reads the file " | ||
| + | |||
| + | The data source can be defined as explained for the ioInput command. | ||
| + | |||
| + | The number of bytes read will be returned in " | ||
| The following conditions apply: | The following conditions apply: | ||
| - | * If the filename is "" | + | * The selected filename will be returned in " |
| - | * If len is 0, the whole file will be read. If the length exceeds the telegram length, an error will be raised. | + | * If filename |
| - | ==== savebuffer | + | === savebuffer === |
| - | savebuffer(start: longint; VAR filelen: longint; | + | |
| Writes the telegram buffer starting at position " | Writes the telegram buffer starting at position " | ||
| - | The number of bytes written will be returned in " | + | The number of bytes written will be returned in " |
| The following conditions apply: | The following conditions apply: | ||
| - | * If the filename is "" | + | * The selected file name will be returned in " |
| * If len is 0, the whole telegram buffer will be written. | * If len is 0, the whole telegram buffer will be written. | ||
| - | ==== setbuffer | + | === setbuffer === |
| - | setBuffer(bufferNr | + | setBuffer(bufferNr |
| - | Changes the actual buffer used to buffer number " | + | Changes the actual buffer used to buffer number " |
| - | If newsize is <> 0, the old buffer is deleted and new memory with size newmem is allocated. The maximal memsize is 2^31 = 2147483648 bytes | + | If newsize is <> 0, the old buffer is deleted and new memory with size newmem is allocated |
| - | ==== copyBuffer | + | === copyBuffer === |
| - | copyBuffer(bufferNr | + | copyBuffer(bufferNr ) |
| - | Copies the content of buffer | + | Copies the content of buffer |
| - | ==== BlitBuffer | + | === BlitBuffer === |
| - | BlitBuffer(frombuffer: byte; startpos: longint; | + | BlitBuffer(frombuffer |
| Copies a memory block from the buffer " | Copies a memory block from the buffer " | ||
| Line 276: | Line 281: | ||
| In case the buffer len needs to be bigger, the buffer len is increased accourdingly. | In case the buffer len needs to be bigger, the buffer len is increased accourdingly. | ||
| - | ==== SetBufferLen | + | === SetBufferLen === |
| - | | + | |
| All other buffer commands can increase the ' | All other buffer commands can increase the ' | ||
| Line 285: | Line 290: | ||
| SetBufferLen sets the ' | SetBufferLen sets the ' | ||
| - | The success of the SetBufferLen - operation is returned | + | The success of the SetBufferLen - operation is returned |
| - | ^ input value of newSize | + | ^ input value of newSize |
| | < = 0 | available size of the buffer in bytes. This can be used to read the real allocated memory size of that buffer | | < = 0 | available size of the buffer in bytes. This can be used to read the real allocated memory size of that buffer | ||
| | 1.. available size | new available size (= requested size) | | | 1.. available size | new available size (= requested size) | | ||
| Line 295: | Line 300: | ||
| - | ==== Miscellaneous | + | === SendBuffer |
| + | Sends the actual buffer | ||
| - | === serDisplayWrite(String) === | ||
| - | Writes | + | ==== WriteString Command Syntax ==== |
| + | |||
| + | As default the command | ||
| + | |||
| + | serDisplayWrite(String) | ||
| + | |||
| + | |||
| + | writes | ||
| + | |||
| + | serDisplayWrite(parameter, | ||
| + | |||
| + | The different commands have the following effects: | ||
| + | |||
| + | ^ parameter | ||
| + | | buffername | ||
| + | | - | clear | clears actual buffer content | | ||
| + | | - | clearall | ||
| + | | filename | ||
| + | | filename | ||
| + | | filename | ||
| + | | filename | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ==== Miscellaneous | ||
| === dbLookup(db-File , searchstring) === | === dbLookup(db-File , searchstring) === | ||
| - | Searches in the //db-file// for all entries with index // | + | |
| + | Searches in the //db-file// for all entries with index // | ||
| dbLookup() returns a Lua table | dbLookup() returns a Lua table | ||
| - | | + | |
| - | myTable = dbLookup(" | + | |
| + | < | ||
| + | myTable = dbLookup(" | ||
| + | </ | ||
| // | // | ||
| - | * if // | ||
| - | * if // | ||
| - | * if // | ||
| - | When something has been found, than //myTable// contains two sections, //header// and //data//. | + | |
| + | * if // | ||
| + | * if // | ||
| + | * if // | ||
| + | |||
| + | |||
| + | When something has been found, than // | ||
| 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[" | ||
| - | print (col) | ||
| - | 2 | ||
| - | |||
| - | // | ||
| + | < | ||
| + | col= myTable.header[" | ||
| + | print (col) | ||
| + | 2 | ||
| + | </ | ||
| - | The //data// section then contains the found data itself, arranged as a two dimensional array, sorted by rows and columns. | ||
| - | | + | // |
| - | + | ||
| - | **ATTENTION**: | + | |
| + | The // | ||
| + | |||
| + | |||
| + | < | ||
| + | | ||
| + | </ | ||
| + | |||
| + | |||
| + | **ATTENTION**: | ||
| + | |||
| + | |||
| + | < | ||
| + | column=3 | ||
| + | row=2 | ||
| + | result=myTable.data[tostring(row)][tostring(column)]) | ||
| + | </ | ||
| + | |||
| + | |||
| + | Here after all a piece of sample code | ||
| - | 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(" | myTable= dbLookupCall(" | ||
| + | |||
| print (" | print (" | ||
| for k,v in pairs (myTable.header) do | for k,v in pairs (myTable.header) do | ||
| print (k," | print (k," | ||
| end | end | ||
| + | |||
| nrOfColumns = myTable.header.size | nrOfColumns = myTable.header.size | ||
| nrOfRows = myTable.len | nrOfRows = myTable.len | ||
| + | |||
| print ("Rows x Columns:" | print ("Rows x Columns:" | ||
| - | + | ||
| + | |||
| for row = 1 , nrOfRows , 1 do | for row = 1 , nrOfRows , 1 do | ||
| for column = 1 , nrOfColumns, | for column = 1 , nrOfColumns, | ||
| - | | + | |
| print (cy, cx, myTable.data[tostring(row)][tostring(column)]) | print (cy, cx, myTable.data[tostring(row)][tostring(column)]) | ||
| end | end | ||
| end | end | ||
| </ | </ | ||
| + | |||
| === openXCVehicleData(lua table) === | === openXCVehicleData(lua table) === | ||
| - | OOBD can work as VehicleDatasource for [[http:// | + | |
| + | OOBD can work as VehicleDatasource for [[http:// | ||
| To do so, a lua table is filled with the right indentifiers and correct formated values accourding to the [[https:// | To do so, a lua table is filled with the right indentifiers and correct formated values accourding to the [[https:// | ||
| + | |||
| 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, | ||
| + | </ | ||
| + | |||
| 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.1413217340.txt.gz · Last modified: 2014/10/13 18:22 by admin
