Using SCOM Ports
Lua interacts with the rest of the OEM7 receiver using SCOM ports. SCOM ports are similar to ICOM ports, except they have fixed socket port numbers and use only UDP.
The Lua socket library is compiled into the OEM7 receiver and is used to communicate with the SCOM ports. Details on the Lua socket library can be found here: https://github.com/diegonehab/luasocket
These are the steps to setup an SCOM connection in Lua.
-
Use the Lua require function to initialize the socket library.
SocketLib = require("socket")
-
Use the socket library to get an instance of a UDP object.
SocketSCOM1 = SocketLib.udp()
UDP communication is used to improve performance. Although the UDP protocol is normally considered "unreliable" over Ethernet, it is very reliable and efficient for connections on a local host.
-
Setup the socket.
-
Since the Lua interpreter is running on the OEM7 receiver, use the localhost (127.0.0.1) IP address.
-
Use the NovAtel-added scom module to convert from the SCOM number to the socket port number.
-
Wrap the calls with the assert function to check for errors.
assert(SocketSCOM1:setsockname("*",0))
assert(SocketSCOM1:setpeername("127.0.0.1",scom.GetSCOMPort(1)))
assert(SocketSCOM1:settimeout(3))
-
-
The socket is now ready to send and receive data. Use the :send() method to issue a command to the receiver through the SCOM socket. Use the :receive() method to retrieve the receiver's response to the command and also to receive the requested logs or other data from the receiver.
This example shows how to use the socket object created above to collect a VERSIONA log:
SocketSCOM1:send("log versiona\r")
while(true) do
Buffer = SocketSCOM1:receive()
if Buffer == nil then
print("... timed out")
break
end
print("> ", Buffer)
end