doc:lua_make-your-own-scripts
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
doc:lua_make-your-own-scripts [2014/03/02 07:24] – created admin | doc:lua_make-your-own-scripts [2014/08/17 12:53] – [The Communication Commands] admin | ||
---|---|---|---|
Line 5: | Line 5: | ||
- | ===== What is Lua? ===== | ||
- | Simply said, [[http:// | ||
- | |||
- | |||
- | This allows to make a program now but change its behavior later as needed. This is widely used in the OOBD script engine: The script engine is there from the beginning, but what it does is defined by the script which is loaded at runtime. Another script, another functionality.. | ||
- | |||
- | |||
- | Luckely Lua became quite popular in the last years, so it's available for all major platforms, like Desktop PCs, Smartphone and Mobile Phones. | ||
- | |||
- | |||
- | There are tons of documentation about Lua available in the internet, so we'll not explain the wheel here once more, we'll just focus on how Lua works inside OOBD. | ||
Line 112: | Line 101: | ||
* function: Each menu is assigned to a Lua function, where one function can be shared between several menu items. The name of this function is given here (please take care about correct upper/lower characters) | * function: Each menu is assigned to a Lua function, where one function can be shared between several menu items. The name of this function is given here (please take care about correct upper/lower characters) | ||
* initialValue(String): | * initialValue(String): | ||
- | * Flagset(Integer): | + | * Flagset(Integer): |
* id(String): The id is used to add an individual marker to a menu item. This is widely used when one single Lua function should support many menu items. This is descripted in detail in the [[# | * id(String): The id is used to add an individual marker to a menu item. This is widely used when one single Lua function should support many menu items. This is descripted in detail in the [[# | ||
Line 148: | Line 137: | ||
==== The Communication | ==== The Communication | ||
+ | |||
OOBD uses (actual) serial communication to talk to the diagnostic device. To allow Lua to send and receive data from the serial port, a few extended Lua functions exists: | OOBD uses (actual) serial communication to talk to the diagnostic device. To allow Lua to send and receive data from the serial port, a few extended Lua functions exists: | ||
+ | |||
=== serFlush() === | === serFlush() === | ||
+ | |||
It just clears the input buffer (from anything which was maybe received in the meantime and which is not needed anymore) | It just clears the input buffer (from anything which was maybe received in the meantime and which is not needed anymore) | ||
Line 157: | Line 149: | ||
=== serWrite(String) === | === serWrite(String) === | ||
- | |||
- | Sends //String// to the output (which is normally the serial port) | ||
+ | Sends //String// to the output (which is normally the serial port) | ||
=== serSleep(milliseconds) === | === serSleep(milliseconds) === | ||
- | waits // | ||
+ | waits // | ||
=== serReadLn(msTimeout) === | === serReadLn(msTimeout) === | ||
+ | |||
reads from input until a LF (dez. 10 hex 0x0A) appears and returns that input as String | reads from input until a LF (dez. 10 hex 0x0A) appears and returns that input as String | ||
+ | |||
=== serWait(OptionString, | === serWait(OptionString, | ||
+ | |||
In case you want to wait for some input strings, of which several could appear, you fill the // | In case you want to wait for some input strings, of which several could appear, you fill the // | ||
+ | |||
+ | |||
+ | ==== The IO Commands ==== | ||
+ | |||
+ | FIXME the whole IO section is in pure experimental state. There' | ||
+ | |||
+ | |||
+ | OOBD uses its own scheme for file IO, mainly driven by the restriction of a remote user and the need of complex data buffer handling. | ||
+ | |||
+ | Similar to the LUA simple IO model, OOBD has always only just input and output file handle. As long as not redirected, these are stdin and stdout. | ||
+ | |||
+ | As OOBD knows more as only one type of data sources, filenames are given as URL, not just as simple path. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | === ioInput(URL[, | ||
+ | |||
+ | Set the actual input file stream to URL, where URL could be | ||
+ | |||
+ | ^ URL ^ Description | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | |||
+ | === ioRead(" | ||
+ | Read one line of the input file ending with either \r\n or \n as string without the EOL. In case of input EOF or read errors the function returns nil | ||
+ | |||
+ | === ioRead (" | ||
+ | Read the whole file as string | ||
+ | |||
+ | === ioRead (count) === | ||
+ | Read count number of bytes as string | ||
+ | |||
+ | === ioOutput(URL[, | ||
+ | |||
+ | Try to opens '' | ||
+ | |||
+ | === ioWrite (String) === | ||
+ | Attaches the string content to the output file | ||
Line 183: | Line 217: | ||
=== 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 | ||
Line 239: | Line 273: | ||
end | end | ||
</ | </ | ||
+ | |||
+ | === openXCVehicleData(lua table) === | ||
+ | |||
+ | 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:// | ||
+ | |||
+ | 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. | ||
===== Some Programming Tricks ===== | ===== Some Programming Tricks ===== |
doc/lua_make-your-own-scripts.txt · Last modified: 2019/04/08 18:43 by admin