Hello Holton,
Originally it is a "realease" version that I modified in open beta via the DOS command, the name of the folder is DCS. Thank you again for your help.
My complet DCS_NMEA.lua
---------------------------------------------------------------------------------------------------
-- Export start
---------------------------------------------------------------------------------------------------
dofile("./Config/World/World.lua") -- Required to get mission date
DCS_NMEA =
{
Start=function(self)
package.path = package.path..";.\\LuaSocket\\?.lua"
package.cpath = package.cpath..";.\\LuaSocket\\?.dll"
socket = require("socket")
----------------------------------------------------------------------------------------------------------------------------------------------
-- COMMUNICATIONS - Part 1
----------------------------------------------------------------------------------------------------------------------------------------------
-- For UDP and Serial Port there are three sections each to activate or deactivate depending on what method you like to use to connect.
-- One here in the Start() function, below. The second in the end of ActivityNextEvent() function. The third in the Stop() function.
-- UDP -----------------------------------------------------------------------------------------------------------------------------------
-- Use this to connect via UDP. Change IP to the devise you want to use. Alternatively the port too. Use the same port in your GPS device.
---[[To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
my_init = socket.protect(function()
host2, port2 = "192.168.1.11", 8080 --4353 -- replace IP with android device ip
udp = socket.try(socket.udp())
end)
my_init()
--]]
-- Serial Port ---------------------------------------------------------------------------------------------------------------------------
-- Use this to connect via Serial Port. Change COM Nr to the port you want to use.
-- One way to use this is by Bluetooth Virtual Serial Port to connect to a Bluetooth compatible device.
-- If Bluetooth is used, be aware that DCS will freeze as long as the used device isn't listening to the port. As soon as it listen, DCS will un-freeze.
-- I do not know if this freezing behavior exist when a physical serial port is used, since I one have one to test.
-- Remember to comment out the "dofile" line related to this MOD in Export.lua or all Serial Port sections in this file if you are not going to use it to avoid freezing.
--[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
sPort = "COM1"
com = io.open(sPort,"w+b")
--]]
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
-- Create a TXT file for debugging or a NMEA log or whatever
-- Same as for the communication options, need to be activated or de-activated at three locations, all located below corresponding communication section.
-- Remember to adjust the path below to DCS or DCS.openbeta or whatever path you have to your Saved Games section.
--[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
Test_file = os.getenv ("userprofile"):gsub("\\","/") .. "/Saved Games/DCS/Scripts/NMEA_Test.txt"
--Test_file = os.getenv ("userprofile"):gsub("\\","/") .. "/Saved Games/DCS.openbeta/Scripts/NMEA_Test.txt"
file = io.open(Test_file, "w")
--file:write(string.format("%s\r\n",Test_file))
--]]
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
xortbl = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, },
{ 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, },
{ 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13, },
{ 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, },
{ 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11, },
{ 5, 4, 7, 6, 1, 0, 3, 2, 13, 12, 15, 14, 9, 8, 11, 10, },
{ 6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9, },
{ 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, },
{ 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, },
{ 9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3, 2, 5, 4, 7, 6, },
{10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5, },
{11, 10, 9, 8, 15, 14, 13, 12, 3, 2, 1, 0, 7, 6, 5, 4, },
{12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3, },
{13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2, },
{14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1, },
{15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, },
}
end,
ActivityNextEvent=function(self,t)
--LoGetSelfData return the same result as LoGetObjectById but only for your aircraft and not depended on anti-cheat setting in Export/Config.lua
--Returned object table structure:
--{
--Name =
--Type = {level1,level2,level3,level4}, ( see Scripts/database/wsTypes.lua) Subtype is absent now
--Country = number ( see Scripts/database/db_countries.lua
--Coalition =
--CoalitionID = number ( 1 or 2 )
--LatLongAlt = { Lat = , Long = , Alt = }
--Heading = radians
--Pitch = radians
--Bank = radians
--Position = {x,y,z} -- in internal DCS coordinate system ( see convertion routnes below)
-- only for units ( Planes,Hellicopters,Tanks etc)
--UnitName = unit name from mission (UTF8)
--GroupName = unit name from mission (UTF8)
--}
local tNext = t
local year = MissionDate.Year
local month = MissionDate.Month
local day = MissionDate.Day
local pt = LoGetMissionStartTime()+LoGetModelTime()
local h = pt/3600
local hh = math.floor(h)
local m = (h-hh)*60
local mm = math.floor(m)
local s = (m-mm)*60
local SD = LoGetSelfData
local Lat = SD().LatLongAlt.Lat
local Long = SD().LatLongAlt.Long
local Alt = SD().LatLongAlt.Alt
local Velocity = LoGetVectorVelocity() --{x,y,z}
local VX = Velocity.x
local VY = Velocity.y
local VZ = Velocity.z
local Speed = math.sqrt(VX*VX+VZ*VZ)*1.9438444924574 -- Speed from m/s to knot
-- Course calculations
if VX==0 and VZ==0 then
radTC = 0
else
radTC = math.atan2(VZ,VX)
if radTC < 0 then
radTC = 2*math.pi + radTC
end
end
TC = radTC*180/math.pi
-- Coordinates from decimal degrees to degrees and decimal minutes
local dLat = math.floor(math.abs(Lat))
local dLong = math.floor(math.abs(Long))
local mLat = (math.abs(Lat)-dLat)*60
local mLong = (math.abs(Long)-dLong)*60
-- Cardinal directions
local sigLat = Lat/math.abs(Lat)
local sigLong = Long/math.abs(Long)
if sigLat<0 then NS='S'
else NS='N'
end
if sigLong<0 then EW='W'
else EW='E'
end
-- Various unimportant GPS values for the GGA sentence not derivable from game
local Q = 1
local nSat = 5
local HDOP = 1.3
local GeoSep = 00.0
-- GGA sentence
local GGA = string.format("GPGGA,%02d%02d%05.2f,%02d%010.7f,%s,%03d%0010.7f,%s,%1d,%02d,%03.1f,%06.1f,M,%04.0f,M,,", hh,mm,s,dLat,mLat,NS,dLong,mLong,EW,Q,nSat,HDOP,Alt,GeoSep)
local csGGA = 0
for c in string.gmatch(GGA,".") do
csGGA = bxor(csGGA, string.byte(c))
end
-- RMC sentence
local RMC = string.format("GPRMC,%02d%02d%05.2f,A,%02d%010.7f,%s,%03d%0010.7f,%s,%05.1f,%05.1f,%02d%02d%02d,0,E,A", hh,mm,s,dLat,mLat,NS,dLong,mLong,EW,Speed,TC,day,month,string.sub(year,3,4))
local csRMC = 0
for c in string.gmatch(RMC,".") do
csRMC = bxor(csRMC, string.byte(c))
end
----------------------------------------------------------------------------------------------------------------------------------------------
-- COMMUNICATIONS - Part 2
----------------------------------------------------------------------------------------------------------------------------------------------
-- UDP -----------------------------------------------------------------------------------------------------------------------------------
---[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
my_send = socket.protect(function()
local json = string.format("$%s*%x\r\n$%s*%x\r\n", GGA,csGGA,RMC,csRMC)
socket.try(udp:sendto(json, host2, port2))
end)
my_send()
--]]
-- Serial Port ---------------------------------------------------------------------------------------------------------------------------
--[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
com:write(string.format("$%s*%x\r\n$%s*%x\r\n", GGA,csGGA,RMC,csRMC)) -- fills the serial buffer
com:flush() -- send the serial buffer
--]]
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
--[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
file:write(string.format("$%s*%x\t$%s*%x\r\n", GGA,csGGA,RMC,csRMC))
--]]
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
-- Repeat every 0.5s
return tNext + 0.5
end,
Stop=function(self)
----------------------------------------------------------------------------------------------------------------------------------------------
-- COMMUNICATIONS - Part 3
----------------------------------------------------------------------------------------------------------------------------------------------
-- UDP -----------------------------------------------------------------------------------------------------------------------------------
---[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
my_close = socket.protect(function()
socket.try(udp:close())
end)
my_close()
--]]
-- Serial Port ---------------------------------------------------------------------------------------------------------------------------
--[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
com:close(sPort)
--]]
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
--[[ To activate section, add a "-" among the other two on this row. To deactivate remove one of the tree.
file:close()
--]]
----------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------
end
}
--[[ Perform a bitwise Exclusive OR (XOR) ]]--
function bxor(a,b)
local res, mult = 0, 1
while a > 0 and b > 0 do
local a2, b2 = a % 16, b % 16
res = res + xortbl[a2+1][b2+1] * mult
a = (a-a2) / 16
b = (b-b2) / 16
mult = mult * 16
end
res = res + (a+b) * mult
return res
end
-- =============
-- Overload
-- =============
do
local PrevLuaExportStart=LuaExportStart
LuaExportStart=function()
DCS_NMEA:Start()
if PrevLuaExportStart then
PrevLuaExportStart()
end
end
end
do
local PrevLuaExportActivityNextEvent=LuaExportActivityNextEvent
LuaExportActivityNextEvent=function(t)
local tNext = t
tNext = DCS_NMEA:ActivityNextEvent(t)
if PrevLuaExportActivityNextEvent then
PrevLuaExportActivityNextEvent()
end
return tNext
end
end
do
local PrevLuaExportStop=LuaExportStop
LuaExportStop=function()
DCS_NMEA:Stop()
if PrevLuaExportStop then
PrevLuaExportStop()
end
end
end
DCS.log
2019-02-03 20:00:04.100 ERROR Lua::Config: Call error LuaExportActivityNextEvent:[string "C:/Users/Stef/Saved Games/DCS/Scripts/DCS_NMEA.lua"]:132: attempt to index a nil value
stack traceback:
[C]: ?
[string "C:/Users/Stef/Saved Games/DCS/Scripts/DCS_NMEA.lua"]:132: in function 'ActivityNextEvent'
[string "C:/Users/Stef/Saved Games/DCS/Scripts/DCS_NMEA.lua"]:293: in function <[string "C:/Users/Stef/Saved Games/DCS/Scripts/DCS_NMEA.lua"]:291>.
2019-02-03 20:00:04.645 ERROR Lua::Config: Call error LuaExportAfterNextFrame:[string "C:\Users\Stef\Saved Games\DCS\Scripts\Export.lua"]:39: attempt to index local 'myData' (a nil value)
stack traceback:
[C]: ?
[string "C:\Users\Stef\Saved Games\DCS\Scripts\Export.lua"]:39: in function 'LuaExportAfterNextFrame'
[string "C:\Users\Stef\Saved Games\DCS\Scripts\DCS-BIOS\BIOS.lua"]:81: in function 'PrevLuaExportAfterNextFrame'