Skip to content

Commit

Permalink
Init resync julia client
Browse files Browse the repository at this point in the history
  • Loading branch information
rp_local committed Sep 24, 2024
1 parent d820174 commit 268702b
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions src/client/julia/src/Sequence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,19 @@ abstract type RampingSequence <: AbstractSequence end
struct SimpleRampingSequence <: AbstractSequence
lut::SequenceLUT
enable::Union{Array{Bool}, Nothing}
resync::Union{Array{Bool}, Nothing}
rampUp::SequenceLUT
rampDown::SequenceLUT
function SimpleRampingSequencee(lut::SequenceLUT, up::SequenceLUT, down::SequenceLUT, enable::Union{Array{Bool}, Nothing}=nothing)
function SimpleRampingSequencee(lut::SequenceLUT, up::SequenceLUT, down::SequenceLUT, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
if !isnothing(enable) && size(values(lut)) != size(enable)
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
end
return new(SequenceLUT(lut, repetitions), enable, up, down)
return new(SequenceLUT(lut, repetitions), enable, resync, up, down)
end
end

enableLUT(seq::SimpleRampingSequence) = seq.enable
resyncLUT(seq::SimpleRampingSequence) = seq.resync
valueLUT(seq::SimpleRampingSequence) = seq.lut
rampUpLUT(seq::SimpleRampingSequence) = nothing
rampDownLUT(seq::SimpleRampingSequence) = nothing
Expand All @@ -158,6 +160,7 @@ end
struct HoldBorderRampingSequence <: RampingSequence
lut::SequenceLUT
enable::Union{Array{Bool}, Nothing}
resync::Union{Array{Bool}, Nothing}
rampUp::SequenceLUT
rampDown::SequenceLUT

Expand All @@ -170,13 +173,13 @@ struct HoldBorderRampingSequence <: RampingSequence
- `lut`,`repetitions`,`enable` are used the same as for a `SimpleSequence`
- `rampingSteps` is the number of steps the first and last value of the given sequence are repeated before the sequence is started
"""
function HoldBorderRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing)
function HoldBorderRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
if !isnothing(enable) && size(lut) != size(enable)
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
end
up = SequenceLUT(lut[:, 1], rampingSteps)
down = SequenceLUT(lut[:, end], rampingSteps)
return new(SequenceLUT(lut, repetitions), enable, up, down)
return new(SequenceLUT(lut, repetitions), enable, resync, up, down)
end
end

Expand All @@ -190,38 +193,42 @@ function HoldBorderRampingSequence(rp::RedPitaya, lut, repetitions, enable=nothi
end

enableLUT(seq::HoldBorderRampingSequence) = seq.enable
resyncLUT(seq::HoldBorderRampingSequence) = seq.resync
valueLUT(seq::HoldBorderRampingSequence) = seq.lut
rampUpLUT(seq::HoldBorderRampingSequence) = seq.rampUp
rampDownLUT(seq::HoldBorderRampingSequence) = seq.rampDown

struct ConstantRampingSequence <: RampingSequence
lut::SequenceLUT
enable::Union{Array{Bool}, Nothing}
resync::Union{Array{Bool}, Nothing}
ramping::SequenceLUT

function ConstantRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingValue::Float32, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing)
function ConstantRampingSequence(lut::Array{Float32}, repetitions::Integer, rampingValue::Float32, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
if !isnothing(enable) && size(lut) != size(enable)
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
end
rampingLut = SequenceLUT([rampingValue for i = 1:size(lut, 1)], rampingSteps)
return new(SequenceLUT(lut, repetitions), enable, rampingLut)
return new(SequenceLUT(lut, repetitions), enable, resync, rampingLut)
end
end
ConstantRampingSequence(lut::Array{T}, repetitions::Integer, rampingValue::Real, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = ConstantRampingSequence(map(Float32, lut), repetitions, Float32(rampingValue), rampingSteps, enable)
ConstantRampingSequence(lut::Vector{Float32}, repetitions::Integer, rampingValue::Float32, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) = ConstantRampingSequence(reshape(lut, 1, :), repetitions, rampingValue, rampingSteps, enable)
ConstantRampingSequence(lut::Vector{T}, repetitions::Integer, rampingValue::Real, rampingSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = ConstantRampingSequence(reshape(lut, 1, :), repetitions, rampingValue, rampingSteps, enable)

enableLUT(seq::ConstantRampingSequence) = seq.enable
resyncLUT(seq::ConstantRampingSequence) = seq.resync
valueLUT(seq::ConstantRampingSequence) = seq.lut
rampUpLUT(seq::ConstantRampingSequence) = seq.ramping
rampDownLUT(seq::ConstantRampingSequence) = seq.ramping

struct StartUpSequence <: RampingSequence
lut::SequenceLUT
enable::Union{Array{Bool}, Nothing}
resync::Union{Array{Bool}, Nothing}
rampUp::SequenceLUT
rampDown::SequenceLUT
function StartUpSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing)
function StartUpSequence(lut::Array{Float32}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing, resync::Union{Array{Bool}, Nothing}=nothing)
if !isnothing(enable) && size(lut) != size(enable)
throw(DimensionMismatch("Size of enable LUT does not match size of value LUT"))
end
Expand All @@ -239,14 +246,15 @@ struct StartUpSequence <: RampingSequence
end
up = SequenceLUT(upLut, 1)
down = SequenceLUT(lut[:, end], rampingSteps)
return new(SequenceLUT(lut, repetitions), enable, up, down)
return new(SequenceLUT(lut, repetitions), enable, resync, up, down)
end
end
StartUpSequence(lut::Array{T}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = StartUpSequence(map(Float32, lut), repetitions, rampingSteps, startUpSteps, enable)
#StartUpSequence(lut::Vector{Float32}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) = StartUpSequence(reshape(lut, 1, :), repetitions, rampingSteps, startUpSteps, enable)
StartUpSequence(lut::Vector{T}, repetitions::Integer, rampingSteps::Integer, startUpSteps::Integer, enable::Union{Array{Bool}, Nothing}=nothing) where T <: Real = StartUpSequence(reshape(lut, 1, :), repetitions, rampingSteps, startUpSteps, enable)

enableLUT(seq::StartUpSequence) = seq.enable
resyncLUT(seq::StartUpSequence) = seq.resync
valueLUT(seq::StartUpSequence) = seq.lut
rampUpLUT(seq::StartUpSequence) = seq.rampUp
rampDownLUT(seq::StartUpSequence) = seq.rampDown
Expand All @@ -269,10 +277,11 @@ Transmit the client-side representation `seq` to the server and append it to the
"""
function sequence!(rp::RedPitaya, seq::AbstractSequence)
result = true
result &= valueLUT!(rp, valueLUT(seq))
result &= enableLUT!(rp, enableLUT(seq))
result &= rampUpLUT!(rp, rampUpLUT(seq))
result &= rampDownLUT!(rp, rampDownLUT(seq))
result &= valueLUT!(rp, seq)
result &= enableLUT!(rp, seq)
result &= resyncLUT!(rp, seq)
result &= rampUpLUT!(rp, seq)
result &= rampDownLUT!(rp, seq)
result &= setSequence!(rp)
return result
end
Expand All @@ -283,11 +292,13 @@ function transmitLUT!(rp::RedPitaya, lut::Array{Float32}, cmd::String, repetitio
return parse(Bool, receive(rp))
end

valueLUT!(rp::RedPitaya, lut::AbstractSequence) = valueLUT!(rp, valueLUT(lut))
function valueLUT!(rp::RedPitaya, lut::SequenceLUT)
lutFloat32 = map(Float32, values(lut))
return transmitLUT!(rp, lutFloat32, "RP:DAC:SEQ:LUT", repetitions(lut))
end

rampUpLUT!(rp::RedPitaya, lut::AbstractSequence) = rampUpLUT!(rp, rampUpLUT(lut))
function rampUpLUT!(rp::RedPitaya, lut::SequenceLUT)
lutFloat32 = map(Float32, values(lut))
return transmitLUT!(rp, lutFloat32, "RP:DAC:SEQ:LUT:UP", repetitions(lut))
Expand All @@ -298,6 +309,7 @@ function rampUpLUT!(rp::RedPitaya, lut::Nothing)
return true
end

rampDownLUT!(rp::RedPitaya, lut::AbstractSequence) = rampDownLUT!(rp, rampDownLUT(lut))
function rampDownLUT!(rp::RedPitaya, lut::SequenceLUT)
lutFloat32 = map(Float32, values(lut))
return transmitLUT!(rp, lutFloat32, "RP:DAC:SEQ:LUT:DOWN", repetitions(lut))
Expand All @@ -308,6 +320,7 @@ function rampDownLUT!(rp::RedPitaya, lut::Nothing)
return true
end

enableLUT!(rp::RedPitaya, lut::AbstractSequence) = enableLUT!(rp, enableLUT(lut))
function enableLUT!(rp::RedPitaya, lut::Array)
lutBool = map(Bool, lut)
send(rp, string("RP:DAC:SEQ:LUT:ENaBle"))
Expand All @@ -322,6 +335,21 @@ function enableLUT!(rp::RedPitaya, lut::Nothing)
return true
end

resyncLUT!(rp::RedPitaya, lut::AbstractSequence) = resyncLUT!(rp, resyncLUT(lut))
function resyncLUT!(rp::RedPitaya, lut::Array)
lutBool = map(Bool, lut)
send(rp, string("RP:DAC:SEQ:LUT:ReSYNC"))
@debug "Writing resync DAC LUT"
write(rp.dataSocket, lutBool)
reply = receive(rp)
return parse(Bool, reply)
end

function resyncLUT!(rp::RedPitaya, lut::Nothing)
# NOP
return true
end

function seqTiming(seq::AbstractSequence)
up = 0
if !isnothing(rampUpLUT(seq))
Expand Down

0 comments on commit 268702b

Please sign in to comment.