Files
2021-05-11 12:16:20 +02:00

134 lines
4.5 KiB
Lua

-- 20/01/2021
-- Include
require( 'EgtBase')
local NomeLibreriaTest ='Berny'
local S = require( NomeLibreriaTest)
local Results = {}
local ComandiCovertitore = {}
-- File contenente l'elenco dei comandi
Results.NomeFileCompleto =S.NomeFileComandi
Results.DirettorioBatch = S.NomeDirettorioBatch
local sY1 = 'Y1'
local sY2 = 'Y2'
local function StampaComandi( TabellaComandi, NomeFunzione, NomeTest)
if not EgtExistsDirectory( Results.DirettorioBatch) then
EgtCreateDirectory( Results.DirettorioBatch)
end
local file = io.open( Results.NomeFileCompleto, "w")
if not TabellaComandi then
return
end
if NomeFunzione and NomeTest then
file:write( '-- Funzione Test: '..NomeFunzione..', '..NomeTest ..'\n')
end
file:write( 'local S = require( "'..NomeLibreriaTest..'")\n')
file:write( 'S.PosizioniAttuali()\n\n')
for i = 1, #TabellaComandi, 1 do
file:write( TabellaComandi[i], "\n")
print( TabellaComandi[i])
end
file:close()
EgtCopyFile( Results.NomeFileCompleto, Results.DirettorioBatch.. "/Cmd_"..EgtTrim( NomeFunzione)..'_'..EgtTrim( NomeTest).. ".lua" )
end
--
local function StampaMessaggio(Titolo, Messaggio)
local sOutBoxStart = 'if not EgtOutBox( "'
local sOutBoxEnd = '") then \n return \nend'
local sMsg = sOutBoxStart ..Messaggio ..'","' ..Titolo ..sOutBoxEnd
return sMsg
end
--
-- Funzione utilizzata per impostare i nome dei carrelli
function Results.SetCarrelli( sCarrello1, sCarrello2)
sY1 = sCarrello1
sY2 = sCarrello2
end
--
function Results.Convertitore( vCmd, NomeFunzione, NomeTest)
local Titolo = 'Informazioni'
if NomeFunzione and NomeTest then
Titolo = Titolo.. ' : '.. NomeFunzione..'-'..NomeTest
end
local Tabella = {}
if not vCmd or #vCmd < 1 then
return
end
if #vCmd[1] < 2 then
return
end
for j = 1, #vCmd, 1 do
Tabella = vCmd[j]
if Tabella[1] == 12 then
if Tabella[2] == 0 then
table.insert( ComandiCovertitore, 'S.Apri_Morsa("2")')
else
table.insert( ComandiCovertitore, 'S.Chiudi_Morsa("2")')
end
elseif Tabella[1] == 11 then
if Tabella[2] == 0 then
table.insert( ComandiCovertitore, 'S.Apri_Morsa("1")')
else
table.insert( ComandiCovertitore, 'S.Chiudi_Morsa("1")')
end
elseif Tabella[1] == 1 or Tabella[1] == 2 or Tabella[1] == 3 then
local Y1Comando = "_,_"
local Y2Comando = "_,_"
local TComando = "_"
for i = 2, #Tabella, 2 do
if Tabella[i] == sY1 then
Y1Comando = '"1",'..tostring( Tabella[i+1])
--table.insert( ComandiCovertitore, 'S.Trasla_Morsa("1", '.. Tabella[ i + 1]..')')
elseif Tabella[i] == sY2 then
Y2Comando = '"2",'..tostring( Tabella[i+1])
--table.insert( ComandiCovertitore, 'S.Trasla_Morsa("2", '.. Tabella[ i + 1]..')')
elseif Tabella[i] == 'T' then
TComando = tostring( Tabella[i+1])
--table.insert( ComandiCovertitore, 'S.Trasla_Trave( '.. Tabella[ i + 1]..')')
end
end
table.insert( ComandiCovertitore, 'S.Trasla_Morse_Trave('..Y1Comando..','..Y2Comando..','..TComando..')')
if Tabella[1] == 1 and Tabella[2] ~= 'Z' then
table.insert( ComandiCovertitore, StampaMessaggio(Titolo, 'Morsa aperta ' ..tostring( Tabella[3]) ))
elseif Tabella[1] == 2 then
table.insert( ComandiCovertitore, StampaMessaggio(Titolo, 'Delta Morsa chiusa' ..tostring( Tabella[3] - Tabella[5]) ))
elseif Tabella[1] == 3 then
table.insert( ComandiCovertitore, StampaMessaggio(Titolo, 'DeltaY1 =' ..tostring( Tabella[3] - Tabella[7]) .. ' DeltaY2='..tostring( Tabella[5] - Tabella[7]) ))
end
end
end
StampaComandi( ComandiCovertitore, NomeFunzione, NomeTest)
end
-- ricerco il nome della funzione eseguita: il nome deve iniziare "*[NomeFunzione]" e deve essere attivo "Test=true"
function Results.CercaNomeFunzione( vCmd)
if #vCmd[1] < 2 then
return
end
for j = 1, #vCmd, 1 do
Tabella = vCmd[j]
if Tabella[1] == 0 then
local NomeFunzione = Tabella[2]
if string.match(NomeFunzione, "%*%[.*%]") then
NomeFunzione = string.gsub(NomeFunzione, "%*%[","")
NomeFunzione = string.gsub(NomeFunzione, "%]","")
return NomeFunzione
end
end
end
return ""
end
--
return Results
--Convertitore( vCmd)