mirror of
https://gitlab.cern.ch/wotsubo/PSBoardDataBase.git
synced 2025-06-07 21:45:43 +09:00
new: SlaveLogParserV2 (for firmware/parameter writing campaign)
This commit is contained in:
parent
a2f3c36956
commit
18f5907d41
5 changed files with 2607 additions and 0 deletions
|
@ -12,6 +12,7 @@ using Dates
|
|||
include("QaqcMasterLog.jl")
|
||||
include("ClockParser.jl")
|
||||
include("SlaveLogParser.jl")
|
||||
include("SlaveLogParserV2.jl")
|
||||
|
||||
include("create_table.jl")
|
||||
include("DownloadCSVs.jl")
|
||||
|
|
105
src/SlaveLogParserV2.jl
Normal file
105
src/SlaveLogParserV2.jl
Normal file
|
@ -0,0 +1,105 @@
|
|||
"""
|
||||
Parser for slave log in PS board firmware & PSBID writing campaign on 2025-05-12 - 16.
|
||||
"""
|
||||
module SlaveLogParserV2
|
||||
|
||||
struct SlaveLogV2ParseError <: Exception
|
||||
line::Int32
|
||||
message::String
|
||||
end
|
||||
|
||||
Base.showerror(io::IO, e::SlaveLogV2ParseError) =
|
||||
print(io, "Invalid log format at $(e.line): ", e.message)
|
||||
|
||||
"""
|
||||
Returns psbid
|
||||
"""
|
||||
function parse_slave_log_v2(filename::AbstractString)
|
||||
lines_iter = Iterators.Stateful(eachline(filename) |> enumerate)
|
||||
|
||||
let
|
||||
i, line = popfirst!(lines_iter)
|
||||
if !isempty(strip(line))
|
||||
throw(SlaveLogV2ParseError(i, "must be empty"))
|
||||
end
|
||||
end
|
||||
|
||||
let
|
||||
i, line = popfirst!(lines_iter)
|
||||
expected = "=============== Test QAPIp Start ==============="
|
||||
if line != expected
|
||||
throw(SlaveLogV2ParseError(i, "invalid header, expected: $(expected)"))
|
||||
end
|
||||
end
|
||||
|
||||
psbid = let
|
||||
i, line = popfirst!(lines_iter)
|
||||
m = match(r"PSBID :(?<psbid>\d+)", line)
|
||||
if isnothing(m)
|
||||
throw(SlaveLogV2ParseError(i, "expected PSBID, got $(line)"))
|
||||
end
|
||||
parse(Int64, m[:psbid])
|
||||
end
|
||||
|
||||
for _ in 1:619
|
||||
_line = popfirst!(lines_iter)
|
||||
end
|
||||
|
||||
read_psbid_0 = parse_copyn_section!(lines_iter, 0)
|
||||
read_psbid_1 = parse_copyn_section!(lines_iter, 1)
|
||||
read_psbid_2 = parse_copyn_section!(lines_iter, 2)
|
||||
|
||||
for _ in 1:9
|
||||
_ = popfirst!(lines_iter)
|
||||
end
|
||||
|
||||
if !isempty(lines_iter)
|
||||
throw(SlaveLogV2ParseError(2495, "expected end of file"))
|
||||
end
|
||||
|
||||
if psbid != read_psbid_0
|
||||
error("read PSBID 0 didn't match: expected $(psbid), read $(read_psbid_0)")
|
||||
end
|
||||
if psbid != read_psbid_1
|
||||
error("read PSBID 0 didn't match: expected $(psbid), read $(read_psbid_0)")
|
||||
end
|
||||
if psbid != read_psbid_2
|
||||
error("read PSBID 0 didn't match: expected $(psbid), read $(read_psbid_0)")
|
||||
end
|
||||
psbid
|
||||
end
|
||||
|
||||
function line_expected(linenum, line, expected)
|
||||
if line != expected
|
||||
throw(SlaveLogV2ParseError(linenum, "expected $(expected), got $(line)"))
|
||||
end
|
||||
end
|
||||
|
||||
function parse_copyn_section!(lines_iter, n::Integer)
|
||||
i, line = popfirst!(lines_iter)
|
||||
line_expected(i, line, "------------ COPY$(n) ------------")
|
||||
|
||||
i, line = popfirst!(lines_iter)
|
||||
line_expected(i, line, " PS board ID ")
|
||||
|
||||
_ = popfirst!(lines_iter)
|
||||
|
||||
i, line = popfirst!(lines_iter)
|
||||
line_expected(i, line, "Address : 0x0000")
|
||||
|
||||
i, line = popfirst!(lines_iter)
|
||||
m = match(r"Data : \s*(?<read>\d+)", line)
|
||||
if isnothing(m)
|
||||
throw(SlaveLogV2ParseError(i, "expected read PSBID, got $(line)"))
|
||||
end
|
||||
read_psbid = parse(Int64, m[:read])
|
||||
|
||||
_ = popfirst!(lines_iter)
|
||||
for _ in 1:615
|
||||
_ = popfirst!(lines_iter)
|
||||
end
|
||||
|
||||
return read_psbid
|
||||
end
|
||||
|
||||
end
|
1
test/input/.gitignore
vendored
1
test/input/.gitignore
vendored
|
@ -10,3 +10,4 @@ slavelogs/main/*
|
|||
!slavelogs/main/430_100.txt
|
||||
!slavelogs/main/364_88_longrun.txt
|
||||
!slavelogs/main/127_172.txt
|
||||
!slavelogs/main/567_792.txt
|
||||
|
|
2494
test/input/slavelogs/main/567_792.txt
Normal file
2494
test/input/slavelogs/main/567_792.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -163,6 +163,12 @@ true || include("../src/PSBoardDataBase.jl")
|
|||
end
|
||||
end
|
||||
|
||||
@testset "Slave log parser v2 (firmware/parameter writing campaign)" begin
|
||||
@test PSBoardDataBase.SlaveLogParserV2.parse_slave_log_v2(
|
||||
"./input/slavelogs/main/567_792.txt",
|
||||
) == 567
|
||||
end
|
||||
|
||||
@testset "Download data csv" begin
|
||||
out = tempname()
|
||||
@test CSV.read(
|
||||
|
|
Loading…
Add table
Reference in a new issue