|
# LUA MAIN WIKI PAGE
|
|
# LUA MAIN WIKI PAGE
|
|
|
|
|
|
|
|
## Intro
|
|
|
|
* Lua Version 5.2.4 from Fw 3.1.0 (https://www.lua.org/manual/5.2/)
|
|
|
|
* Experimental from 3.0.1 RC1
|
|
|
|
* From 3.2.0 available
|
|
|
|
* 3.1.0 only one script running in on own Thread in Safe Mode
|
|
|
|
* From 3.2.0 file access available
|
|
|
|
* multiple parallel Scripts run in one Thread in Safe Mode
|
|
|
|
* Full LUA support
|
|
|
|
* Execute any PFAL cmd -> avl.pfal("command")
|
|
|
|
* Get Answer as String and Execution State
|
|
|
|
* PFAL event call back -> avl.event(timeout)
|
|
|
|
* PFAL state request -> avl.state(type[,index])
|
|
|
|
|
|
|
|
# prerequisite Setup
|
|
|
|
* use you preferred OS
|
|
|
|
* install a bash and zip to compile a frp
|
|
|
|
- on Windows you can use WSL(https://docs.microsoft.com/en-us/windows/wsl/install-win10) or Cygwin (https://www.cygwin.com/)
|
|
|
|
- on Linux its build in or add via 'apt-get install bash unzip'
|
|
|
|
- on MacOSX its build in
|
|
|
|
* setup your favorite IDE - preferred with build in LUA Highlight and/or COde check we can recommend :
|
|
|
|
- IntelliJ (https://www.jetbrains.com/idea/) CE Edition is free of use
|
|
|
|
- Eclipse (https://www.eclipse.org)
|
|
|
|
* there is NO need to have a local LUA Interpreter (https://www.lua.org) but you can use this for other projects as well
|
|
|
|
|
|
|
|
|
|
|
|
# Sample Code
|
|
|
|
Sample is in the master branch of this project.
|
|
|
|
so please checkout this project from here : git@git.falcom.de:pub/demo_lua.git
|
|
|
|
The master branch will contain all snippets and demo script as well as a shell script to build OTA update package for FALCOM AVL.
|
|
|
|
|
|
|
|
|
|
|
|
## built in function
|
|
|
|
|
|
|
|
# Built in callback function
|
|
|
|
* sResult := avl.version()
|
|
|
|
* iResult := avl.timer(index)
|
|
|
|
* iResult := avl.trigger(index)
|
|
|
|
* iResult := avl.counter(index)
|
|
|
|
* iResult := avl.nvcounter(index)
|
|
|
|
* sValue := avl.gps_version()
|
|
|
|
* tResult := avl.gps_data()
|
|
|
|
* tResult := avl.gps_sats()
|
|
|
|
* sValue := avl.gsm_version()
|
|
|
|
* tResult := avl.gsm_data()
|
|
|
|
* sValue := avl.gsm_imei()
|
|
|
|
* sValue := avl.gsm_imsi()
|
|
|
|
* sValue := avl.gsm_iccid()
|
|
|
|
|
|
|
|
# Event Notification ev := [
|
|
|
|
ev.type // integer event type
|
|
|
|
ev.time // integer timestamp
|
|
|
|
ev.idx // integer subindex
|
|
|
|
ev.u_value // integer value type
|
|
|
|
ev.u_string // string value type
|
|
|
|
ev.u_starttype // integer starttype
|
|
|
|
ev.u_startreason // integer startreason
|
|
|
|
ev.u_recvdata // string recvdata buffer
|
|
|
|
ev.u_recvlen // integer recvlen length
|
|
|
|
ev.u_ipadress // string ipaddress
|
|
|
|
ev.u_opid // integer operator id
|
|
|
|
ev.u_opname // string operator name
|
|
|
|
ev.u_callid // string caller name
|
|
|
|
ev.u_smsnum // string SMS number
|
|
|
|
ev.u_smstext // string SMS text
|
|
|
|
]
|
|
|
|
|
|
|
|
# State Requests state := [
|
|
|
|
state.type // integer state type
|
|
|
|
state.idx // integer subindex
|
|
|
|
state.u_bool // boolean value type
|
|
|
|
state.u_value // integer value type
|
|
|
|
state.u_string // string value type
|
|
|
|
state.u_starttype // integer starttype
|
|
|
|
state.u_startreason // integer startreason
|
|
|
|
state.u_opid // integer operator id
|
|
|
|
state.u_opname // string operator name
|
|
|
|
]
|
|
|
|
|
|
|
|
# GPS data record := [
|
|
|
|
lat // Latidude (degree)
|
|
|
|
lon // Latidude (degree)
|
|
|
|
alt // Altidude (meter)
|
|
|
|
speed // speed (m/s)
|
|
|
|
course // course (degree)
|
|
|
|
ecef_x // ECEF-X (meter)
|
|
|
|
ecef_y // ECEF-Y (meter)
|
|
|
|
ecef_z // ECEF-Z (meter)
|
|
|
|
dop // pdop value
|
|
|
|
time // time (seconds)
|
|
|
|
fix // fix (boolean)
|
|
|
|
]
|
|
|
|
|
|
|
|
# GPS satellites record := [
|
|
|
|
gps_num // Number of GPS satellites
|
|
|
|
gps_sat1 // Dump of satellite data
|
|
|
|
.. // "SatID,Elevation,Azimuth,AvgCNo,Used"
|
|
|
|
gps_sat12
|
|
|
|
gls_num // Number of GLS satellites
|
|
|
|
gls_sat1 // Dump of satellite data
|
|
|
|
.. // "SatID,Elevation,Azimuth,AvgCNo,Used"
|
|
|
|
gls_sat12
|
|
|
|
]
|
|
|
|
|
|
|
|
# GSM data record := [
|
|
|
|
state // GSM state
|
|
|
|
csq // CSQ value
|
|
|
|
creg // CREG value
|
|
|
|
cpas // CPAS value
|
|
|
|
lac // local area code
|
|
|
|
cellid // cell id
|
|
|
|
opid // operator id
|
|
|
|
opname // operator name (string)
|
|
|
|
callstate // call state
|
|
|
|
callnumber // caller number (string)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# Motion data record := [
|
|
|
|
val_x // Current X acceleration
|
|
|
|
val_y // Current Y acceleration
|
|
|
|
val_z // Current Z acceleration
|
|
|
|
min_x // Min. X acceleration in <g_coe> interval
|
|
|
|
min_y // Min. Y acceleration
|
|
|
|
min_z // Min. Z acceleration
|
|
|
|
max_x // Max. X acceleration in <g_coe> interval
|
|
|
|
max_y // Max. Y acceleration
|
|
|
|
max_z // Max. Z acceleration
|
|
|
|
nsum_x // Normal X gravitation in <g_coe> interval
|
|
|
|
nsum_y // Normal Y gravitation
|
|
|
|
nsum_z // Normal Z gravitation
|
|
|
|
]
|
|
|
|
|
|
|
|
# TCP Socket
|
|
|
|
```lua
|
|
|
|
socket := net.create_socket([type, param])
|
|
|
|
socket:connect(<"IP"|"URL">, port)
|
|
|
|
socket:close([flush])
|
|
|
|
socket:flush() - flush socket data
|
|
|
|
socket:hold() - hold the socket
|
|
|
|
socket:unhold() - unhold the socket
|
|
|
|
|
|
|
|
tVal := socket:ttl([ttl]) - Set/Read ttl value
|
|
|
|
tVal := socket:bufsize([bytes]) - Set/Read buffer size
|
|
|
|
tBytes := socket:send(data) - Send data to socket
|
|
|
|
data, tBytes := socket:recv() - Read data from socket
|
|
|
|
tIP, tPort := socket:getaddr()
|
|
|
|
tIP, tPort := socket:getpeer()
|
|
|
|
tIP := net.dns_resolve("URL")
|
|
|
|
|
|
|
|
socket:on(<"connection"|"disconnection"|"sent"|"receive">, function())
|
|
|
|
```
|
|
|
|
|
|
|
|
# Constant Types
|
|
|
|
NET_TCP, NET_UDP - socket type
|
|
|
|
|
|
|
|
ALARM_TCP_SOCKET_IFUP, ALARM_TCP_SOCKET_IFDOWN, ALARM_TCP_SOCKET_CONNECTED,
|
|
|
|
ALARM_TCP_SOCKET_DISCONNECTED, ALARM_TCP_SOCKET_RECV, ALARM_TCP_SOCKET_SENT
|
|
|
|
|
|
|
|
ALARM_SYS_DEVICE_WAKEUP, ALARM_SYS_DEVICE_START, ALARM_SYS_DEVICE_SHUTDOWN, ALARM_SYS_DEVICE_OVERVOLTAGE, ALARM_SYS_TIMER, ALARM_SYS_TRIGGER, ALARM_SYS_COUNTER,
|
|
|
|
ALARM_SYS_nvCOUNTER, ALARM_SYS_ERROR, ALARM_SYS_USEREVENT0, ALARM_SYS_USEREVENT1, ALARM_SYS_USEREVENT2, ALARM_SYS_USEREVENT3, ALARM_SYS_USEREVENT4, ALARM_SYS_USEREVENT5,
|
|
|
|
ALARM_SYS_USEREVENT6, ALARM_SYS_USEREVENT7, ALARM_SYS_USEREVENT8, ALARM_SYS_USEREVENT9, ALARM_SYS_SERIALDATA0, ALARM_SYS_SERIALDATA1, ALARM_SYS_USBDATA, ALARM_SYS_CAN,
|
|
|
|
ALARM_SYS_TIMESYNC, ALARM_SYS_OBDII_DTC, ALARM_SYS_OBDII, ALARM_SYS_FMS_VAR, ALARM_SYS_J1939_VAR, ALARM_SYS_FMS, ALARM_SYS_J1939, ALARM_SYS_1WIRE_REGISTER,
|
|
|
|
ALARM_SYS_1WIRE_RELEASE, ALARM_SYS_BAT_LOWBAT, ALARM_SYS_BAT_CHARGE, ALARM_SYS_POWER_DETECTED, ALARM_SYS_POWER_DROPPED, ALARM_IO_IN,
|
|
|
|
ALARM_IO_MOTION_MOVING, ALARM_IO_MOTION_STANDING, ALARM_IO_MOTION_FORCE, ALARM_IO_MOTION_3DFORCE, ALARM_IO_MOTION_CRASH, ALARM_IO_MOTION_INTERNAL,
|
|
|
|
ALARM_IO_MOTION_EXTERNAL, ALARM_IO_ORIENTATION, ALARM_GPS_NAV_FIX, ALARM_GPS_NAV_HEADING, ALARM_GPS_NAV_HEADING2, ALARM_GPS_GEOFENCE, ALARM_GPS_AREA,
|
|
|
|
ALARM_GPS_MULTI_GEOFENCE, ALARM_GPS_WAYPOINT_GEOFENCE, ALARM_GPS_HISTORY_TAUT, LARM_GPS_HISTORY_PUSH_FINISH, ALARM_GPS_JAMMING, ALARM_GPS_ANT_PLUGGED,
|
|
|
|
ALARM_GPS_ANT_UNPLUGGED, ALARM_GSM_OPFOUND, ALARM_GSM_OPLOST, ALARM_GSM_CELLCHANGE,ALARM_GSM_CBM, ALARM_GSM_SIMLOST, ALARM_GSM_MCCCHANGE, ALARM_GSM_JAMMING,
|
|
|
|
ALARM_GSM_VOICECALL_INCOMING_RING, ALARM_GSM_VOICECALL_RING_STOPPED, ALARM_GSM_VOICECALL_OUTGOING_DIAL, ALARM_GSM_VOICECALL_CALL_ESTABLISHED,
|
|
|
|
ALARM_GSM_VOICECALL_CALL_FINISHED, ALARM_GSM_SMS_INCOMING, ALARM_GSM_SMS_SENT, ALARM_GSM_GPRS_CONNECTING, ALARM_GSM_GPRS_CONNECTED, ALARM_GSM_GPRS_DISCONNECTING,
|
|
|
|
ALARM_GSM_GPRS_DISCONNECTED, ALARM_TCP_CLIENT_CONNECTING, ALARM_TCP_CLIENT_CONNECTED, ALARM_TCP_CLIENT_PACKETSENT, ALARM_TCP_CLIENT_PINGSENT, ALARM_TCP_CLIENT_RECEIVED,
|
|
|
|
ALARM_TCP_CLIENT_DISCONNECTING, ALARM_TCP_CLIENT_DISCONNECTED, ALARM_TCP_CLIENT_BUFFER_EMPTY, ALARM_TCP_CLIENT_FLASHBUFFER_EMPTY, ALARM_TCP_SMTP_SENT, ALARM_TCP_SMTP_FAILED,
|
|
|
|
ALARM_FILE_AVAILABLE, ALARM_ECODRIVE_START, ALARM_ECODRIVE_STOP, ALARM_ECODRIVE_TURN, ALARM_ECODRIVE_BRAKE, ALARM_ECODRIVE_ACCELERATE,{{STATE_SYS_DEVICE_START, STATE_SYS_TIMER, STATE_SYS_TRIGGER, STATE_SYS_COUNTER,
|
|
|
|
STATE_SYS_nvCOUNTER, STATE_SYS_CAN, STATE_SYS_BAT_VOLTAGE, STATE_SYS_BAT_CHARGE,
|
|
|
|
STATE_SYS_BAT_MODE, STATE_SYS_POWER_VOLTAGE, STATE_IO_IN, STATE_IO_ANA, STATE_IO_PULSECNT,
|
|
|
|
STATE_IO_MOTION_MOVING, STATE_IO_MOTION_STANDING, STATE_GPS_NAV_FIX, STATE_GPS_NAV_SPEED,
|
|
|
|
STATE_GPS_NAV_POSITION, STATE_GPS_NAV_DIST, STATE_GPS_NAV_DELTASPEED, STATE_GPS_HISTORY_DIST,
|
|
|
|
STATE_GPS_AREA, STATE_GPS_GEOFENCE, STATE_GPS_MULTI_GEOFENCE, STATE_GPS_WAYPOINT_GEOFENCE
|
|
|
|
STATE_GSM_OPVALID, STATE_GSM_HOME, STATE_GSM_ROAMING, STATE_GSM_VOICECALL_READY_FOR_CALL,
|
|
|
|
STATE_GSM_VOICECALL_INCOMING_RING, STATE_GSM_VOICECALL_NUMBER_OF_RINGS,
|
|
|
|
STATE_GSM_VOICECALL_OUTGOING_DIAL, STATE_GSM_VOICECALL_INSIDE, STATE_GSM_GPRS_CONNECTING,
|
|
|
|
STATE_GSM_GPRS_CONNECTED, STATE_GSM_GPRS_DISCONNECTING, STATE_GSM_GPRS_DISCONNECTED,
|
|
|
|
STATE_TCP_CLIENT_IDLE, STATE_TCP_CLIENT_CONNECTING, STATE_TCP_CLIENT_CONNECTED,
|
|
|
|
STATE_TCP_CLIENT_DISCONECTING, STATE_TCP_CLIENT_DISCONECTED, STATE_ECODRIVE_START,
|
|
|
|
STATE_ECODRIVE_STOP, STATE_ECODRIVE_SPEED1, STATE_ECODRIVE_SPEED2, STATE_ECODRIVE_SPEED3,
|
|
|
|
GSM_DISABLED, GSM_SLEEP, GSM_IDLE, GSM_INIT_BASE, GSM_INIT_MAIN, GSM_INIT_NET,
|
|
|
|
GSM_VERSION, GSM_IMSI_CHECK, GSM_SMS_CHECK, READY_FOR_CALL, INCOMING_VOICE_CALL,
|
|
|
|
INCOMING_DATA_CALL, INCOMING_FAX_CALL, OUTGOING_VOICE_CALL, INSIDE_VOICE_CALL
|
|
|
|
TIMER_ERASED, TIMER_INACTIVE, TIMER_PAUSED, TIMER_RUNNING
|
|
|
|
|
|
|
|
## LUA library:
|
|
|
|
# LUA "os" library:
|
|
|
|
os.clock(), os.date(), os.time(), os.difftime(), os.exit(), os.execute(),
|
|
|
|
os.getenv(), os.setenv(), os.setlocale()
|
|
|
|
|
|
|
|
# LUA "coroutine" library:
|
|
|
|
coroutine.create(), coroutine.resume(), coroutine.running(),
|
|
|
|
coroutine.status(), coroutine.wrap(), coroutine.yield()
|
|
|
|
|
|
|
|
# LUA "string" library:
|
|
|
|
string.byte(), string.char(), string.dump(), string.find(), string.format(),
|
|
|
|
string.gmatch(), string.gsub(), string.len(), string.lower(), string.match(),
|
|
|
|
string.rep(), string.reverse(), string.sub(), string.upper(), string.replace()
|
|
|
|
|
|
|
|
# LUA "table" library:
|
|
|
|
table.concat(), table.insert(), table.pack(), table.unpack(), table.remove(),
|
|
|
|
table.sort()
|
|
|
|
|
|
|
|
# LUA "math" library:
|
|
|
|
math.abs(), math.acos(), math.asin(), math.atan2(), math.atan(), math.ceil(),
|
|
|
|
math.cosh(), math.cos(), math.deg(), math.exp(), math.floor(), math.fmod(),
|
|
|
|
math.frexp(), math.ldexp(), math.log(), math.max(), math.min(), math.modf(),
|
|
|
|
math.pow(), math.rad(), math.random(), math.randomseed(), math.sinh(),
|
|
|
|
math.sin(), math.sqrt(), math.tanh(), math.tan()
|
|
|
|
|
|
|
|
# LUA "bit32" library:
|
|
|
|
bit32.arshift(), bit32.band(), bit32.bnot(), bit32.bor(), bit32.bxor(),
|
|
|
|
bit32.btest(), bit32.extract(), bit32.lrotate(), bit32.lshift(),
|
|
|
|
bit32.replace(), bit32.rrotate(), bit32.rshift()
|
|
|
|
}} |
|
|
|
\ No newline at end of file |