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 revisionNext revisionBoth sides next revision | ||
doc:lua_make-your-own-scripts [2014/03/10 07:48] – admin | doc:lua_make-your-own-scripts [2014/10/05 16:37] – [The IO 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 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 command 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, the parameter '' | ||
+ | |||
+ | . | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | === ioInput(file name , | ||
+ | |||
+ | Tries to open the file accourding to the following parameter combinations: | ||
+ | |||
+ | |||
+ | |||
+ | ^ filename | ||
+ | | / | ||
+ | | / | ||
+ | | URL like '' | ||
+ | | URL like '' | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | === 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 239: | Line 281: | ||
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