#version 1; November 2025
#Assumes laser has been connected with it.connect(x,9600)
#assumes laser has been calibrated for cleanjump and calibration values are loaded in unit
#Requires PPCL700 or PPCL550 laser
#Run with: it.script("examples\\CleanJumpManualChannelLoad.txt")
#---- Settings
FREQUENCY=194.56 #THz
POWER=13.2 #dBm
TARGETCHANNEL1=4  #we download the data from this channel and then use it to do a manual jump
#-----

import time

it.resena(mr=1)  #reset the unit
time.sleep(3)    #wait a couple of seconds
it.fcf1(int(FREQUENCY))
it.fcf2(10000*(FREQUENCY-int(FREQUENCY)))

it.pwr(int(POWER*100))

it.resena(sena=1) #enable laser

reftime=time.perf_counter()
while it.nop()[1].data()&0xff00 and time.perf_counter()-reftime<60:  #wait until pending flags drop, with timeout
    time.sleep(1)

print("Laser ON after %.1f seconds" %(time.perf_counter()-reftime))

time.sleep(5) #wait 5 more seconds to ensure stability

it.cleanMode(2)  #start whispermode

time.sleep(5)

it.cleanJumpEnable(0)
writepacket=it.toModulePacket()
writepacket.register(0xD0) #needed for verson 3.2.11 not for later versons
it.cleanJumpEnable()
readpacket=it.toModulePacket()
readpacket.register(0xD0)  #needed for verson 3.2.11 not for later versons

writepacket.data(0x4000+TARGETCHANNEL1)
it.packet(writepacket) #needed for verson 3.2.11 not for later versons    it.cleanJumpEnable(0x4000+TARGETCHANNEL1) #set the next cleanjump

counter=0
jumpdata=[]
#download the data
while counter<32:
    readpacket.data(0x8000+counter)
    jumpdata.append(it.packet(readpacket).data()&0xff)
    counter=counter+1

print("Downloaded CleanJump Data: %s" %(str(jumpdata)))

writepacket.data(0x4000+TARGETCHANNEL1+1)
it.packet(writepacket) #needed for verson 3.2.11 not for later versons    it.cleanJumpEnable(0x4000+TARGETCHANNEL1+1) #set the next cleanjump


#upload the data
counter=0
while counter<32:
    writepacket.data(0x8000+counter*256+jumpdata[counter])
    it.packet(writepacket)
    counter=counter+1

time.sleep(1)

writepacket.data(1)
it.packet(writepacket)  #needed for verson 3.2.11 not for later versons, later use it.cleanJumpEnable(1)  #start the cleanjump

print("Performed Clean Jump to manually entered channel.")