Ejemplo n.º 1
0
from time import sleep
from Acspy.Clients.SimpleClient import PySimpleClient
from Acspy.Common.Callbacks     import CBvoid
from ACS import CBDescIn

compName = argv[1]
compMethod = argv[2]

print "Parameters to this generic test script are:", argv[1:]

# Make an instance of the PySimpleClient
simpleClient = PySimpleClient()
comp = simpleClient.getComponent(compName)

myCB = CBvoid()
myCorbaCB = simpleClient.activateOffShoot(myCB)
myDescIn = CBDescIn(0L, 0L, 0L)

joe = eval("comp." + compMethod + "(myCorbaCB, myDescIn)")
print "Method executed...now just waiting on CB status"

for i in range(0, 50):
    if myCB.status == 'DONE':
        print "The callback has finished!"
        break
    else:
        sleep(1)
    
simpleClient.releaseComponent(compName)
simpleClient.disconnect()
Ejemplo n.º 2
0
        DevIO.__init__(self, 3.14)

    def read(self):
        return 3.14
#-------------------------------------------------------
class MyCallback(CBvoid):
     def working (self, completion, desc):
         '''
         '''
         print "Ramped PowerSupply startRamping CB: working method called"

#-------------------------------------------------------
from time import sleep
if __name__=="__main__":
    compName = "TEST_RPS_1"

    # Make an instance of the PySimpleClient
    simpleClient = PySimpleClient()
    comp = simpleClient.getComponent(compName)

    myCB = MyCallback()
    myCorbaCB = simpleClient.activateOffShoot(myCB)
    myDescIn = ACS.CBDescIn(0L, 0L, 0L)
    
    print "Ramped PowerSupply readback value:", comp._get_readback().get_sync()[0]

    comp.startRamping(1L, myCorbaCB, myDescIn)
    
    simpleClient.releaseComponent(compName)
    simpleClient.disconnect()
Ejemplo n.º 3
0
from Acspy.Clients.SimpleClient import PySimpleClient

# Make an instance of the PySimpleClient
simpleClient = PySimpleClient()

# Get the standard MOUNT1 Mount device
mount = simpleClient.getComponent("MOUNT1")

# Get the actAz property and print it out
print "MOUNT1 actual azimuth: ", mount._get_actAz().get_sync()[0]

# See what's available
components = [c.name for c in simpleClient.availableComponents()]
components.sort()
print "Available components: ", components

from ACS__POA import OffShoot


class MyOffShoot(OffShoot):
    pass


simpleClient.activateOffShoot(MyOffShoot())

#cleanly disconnect
simpleClient.releaseComponent("MOUNT1")
simpleClient.disconnect()

print "The end __oOo__"
Ejemplo n.º 4
0
"""

from Acspy.Clients.SimpleClient import PySimpleClient

# Make an instance of the PySimpleClient
simpleClient = PySimpleClient()

# Get the standard MOUNT1 Mount device
mount = simpleClient.getComponent("MOUNT1")

# Get the actAz property and print it out
print "MOUNT1 actual azimuth: ", mount._get_actAz().get_sync()[0]

# See what's available
components = [ c.name for c in simpleClient.availableComponents() ]
components.sort()
print "Available components: ", components

from ACS__POA import OffShoot

class MyOffShoot(OffShoot):
    pass

simpleClient.activateOffShoot(MyOffShoot())

#cleanly disconnect
simpleClient.releaseComponent("MOUNT1")
simpleClient.disconnect()

print "The end __oOo__"
Ejemplo n.º 5
0
simpleClient = PySimpleClient()

# Get the current time from the standard CLOCK1 Clock device and add 3 seconds to it
# This is when the timeout will occur.
start = long(getTimeStamp().value) + long(30000000)

# Get the standard Timer component which will
# schedule the timeout
timer = simpleClient.getDefaultComponent("IDL:alma/acstime/Timer:1.0")

# Create timeout handler and schedule its timeout
myHandler = TimeoutHandlerImpl()
myHandler2 = TimeoutHandlerImpl()

# A Duration of 0 implies the timeout will only occur once
id1 = timer.schedule(simpleClient.activateOffShoot(myHandler),
                     acstime.Epoch(start),
                     acstime.Duration(long(20000000)))

# A Duration of 0 implies the timeout will only occur once
id2 = timer.schedule(simpleClient.activateOffShoot(myHandler2),
                     acstime.Epoch(start),
                     acstime.Duration(long(0)))

# Give it ten seconds to run
sleep(10)

timer.cancel(long(id1))

# Give it ten more seconds to run
sleep(10)
Ejemplo n.º 6
0
class MockSched():
    # ------------------------------------------------------------------
    #
    # ------------------------------------------------------------------
    def __init__(self, site_type):
        self.log = my_log(title=__name__)
        self.log.info([['y', " - MockSched - "], ['g', site_type]])

        self.site_type = site_type
        self.tel_ids = tel_ids[site_type]

        self.debug = False
        self.expire = 86400  # one day

        self.cycle_blocks = []
        self.acs_blocks = dict()
        self.acs_blocks['sched_block'] = dict()
        self.acs_blocks['metadata'] = dict()

        self.active_sched_block = 0

        self.client = PySimpleClient()
        self.supervisor = self.client.getComponent("ArraySupervisor")
        # print 'got ArraySupervisor ............'

        self.n_sched_block = [5, 15]
        self.max_n_obs_block = 7 if self.site_type == "N" else 32
        self.max_n_obs_block = min(self.max_n_obs_block, len(self.tel_ids))
        # self.max_n_obs_block = len(self.tel_ids)
        self.loop_sleep = 4

        self.az_min_max = [0, 360]
        self.zen_min_max_tel = [0, 70]
        self.zen_min_max_pnt = [0, 20]

        rnd_seed = getTime()
        rnd_seed = 10987268332
        self.rnd_gen = Random(rnd_seed)

        print 'xxxxxxxxxxx'
        active = self.supervisor.listSchedulingBlocks()
        print '-----', active

        self.cancel_sched_blocks(active[0])
        print 'sleep...'
        sleep(10)
        print 'check...'
        print '---', len(
            self.supervisor.getSbOperationStatus(active[0]).ob_statuses
        ), '------------', self.supervisor.getSbOperationStatus(active[0]).ob_statuses
        print '---', self.supervisor.getSbOperationStatus(active[0]
                                                          ).ob_statuses[-1].status
        activeNow = self.supervisor.listSchedulingBlocks()
        print 'active now ....', activeNow

        # self.threads = []
        # run_event = threading.Event()
        # run_event.set()

        # t = threading.Thread(target=self.loop, args = (run_event,))
        # t.start()
        # self.threads.append(t)

        # try:
        #   while 1:
        #     sleep(.1)
        # except KeyboardInterrupt:
        #   run_event.clear()
        #   for t in self.threads:
        #     t.join()

        return

    # ------------------------------------------------------------------
    #
    # ------------------------------------------------------------------
    def cancel_sched_blocks(self, sched_blk_id):
        class MyVoid(ACS__POA.CBvoid):
            def working(self, completion, desc):
                # print "bbbbbbbbbb Callback working",sched_blk_id
                return

            def done(self, completion, desc):
                # print "bbbbbbbbbbbbb Callback done",sched_blk_id
                return

        desc = CBDescIn(0L, 0L, 0L)
        cb = MyVoid()

        self.log.info([['r', " ---- MockSched.cancel_sched_blocks() ... "],
                       ['g', sched_blk_id]])
        self.supervisor.cancelSchedulingBlock(
            sched_blk_id, self.client.activateOffShoot(cb), desc
        )
        self.log.info([['r', " ++++ MockSched.cancel_sched_blocks() ... "],
                       ['g', sched_blk_id]])

        return

    # ------------------------------------------------------------------
    #
    # ------------------------------------------------------------------
    def cancel_zombie_sched_blocks(self, sched_block_ids=None):
        if sched_block_ids is None:
            try:
                active = self.supervisor.listSchedulingBlocks()
            except Exception as e:
                self.log.debug([['b', "- Exception - MockSched.listSchedulingBlocks: "],
                                ['r', e]])
                active = []
            sched_block_ids = [
                x for x in active if x not in self.acs_blocks['sched_block']
            ]

        sched_block_ids = active

        if len(sched_block_ids) == 0:
            return

        self.log.info([['r', " - MockSched.cancel_zombie_sched_blocks() ..."],
                       ['y', sched_block_ids]])
        for sched_block_id_now in sched_block_ids:
            self.cancel_sched_blocks(sched_block_id_now)
            # t = threading.Thread(target=self.cancel_sched_blocks,args=(sched_block_id_now,))
            # t.start()
            # t.join()
            # self.threads.append(t)

        return

    # ------------------------------------------------------------------
    #
    # ------------------------------------------------------------------
    def init_block_cycle(self):
        self.log.info([['p', " - MockSched.init_block_cycle() ..."]])

        script_name = "guiACS_sched_blocks_script0"
        self.nCycles = [1, 5]
        self.n_sched_block = 40
        self.max_n_obs_block = 1
        self.obs_block_seconds = 20

        # cancel sched_blocks which should have expired
        # self.cancel_zombie_sched_blocks()

        # init local bookkeeping objects
        self.cycle_blocks = []
        self.acs_blocks = dict()
        self.acs_blocks['sched_block'] = dict()
        self.acs_blocks['metadata'] = dict()

        nCycles = self.rnd_gen.randint(self.nCycles[0], self.nCycles[1])
        for n_cycle_now in range(nCycles):
            base_name = str(getTime()) + "_"

            tel_ids = copy.deepcopy(self.tel_ids)
            n_tels = len(tel_ids)
            # n_sched_blocks = self.rnd_gen.randint(1, min(n_tels, self.n_sched_block))
            n_sched_blocks = self.n_sched_block

            # generate random target/pointing ids
            target_pos = dict()
            blockTrgs = dict()
            blockTrgPnt = dict()
            n_trgs = self.rnd_gen.randint(1, n_sched_blocks)
            for n_trg_try in range(n_sched_blocks):
                n_trg_now = self.rnd_gen.randint(0, n_trgs - 1)
                if n_trg_now not in blockTrgs:
                    blockTrgs[n_trg_now] = [n_trg_try]
                else:
                    blockTrgs[n_trg_now].append(n_trg_try)

                blockTrgPnt[n_trg_try] = {
                    "n_trg": n_trg_now,
                    "n_pnt": len(blockTrgs[n_trg_now]) - 1
                }

            cycle_blocks = []
            for n_sched_block_now in range(n_sched_blocks):
                sched_block_id = "schBlock_" + base_name + str(n_sched_block_now)

                n_tel_now = self.rnd_gen.randint(1, max(1, len(tel_ids) - n_sched_blocks))

                # sched_tel_ids = random.sample(tel_ids, n_tel_now)
                # tel_ids = [x for x in tel_ids if x not in sched_tel_ids]

                sub_arr = []
                # for sched_tel_id_now in sched_tel_ids:
                #   tel_type = sb.SST if sched_tel_id_now[0] == 'S' else sb.MST if sched_tel_id_now[0] == 'M' else sb.LST
                #   sub_arr += [ sb.Telescope(sched_tel_id_now, tel_type) ]

                sched_conf = sb.Configuration(
                    sb.InstrumentConfiguration(
                        sb.PointingMode(2, sb._divergent(2)), sb.Subarray([], sub_arr)
                    ), "camera", "rta"
                )

                n_obs_blocks = self.rnd_gen.randint(1, self.max_n_obs_block)

                n_trg = blockTrgPnt[n_sched_block_now]["n_trg"]
                n_pnt = blockTrgPnt[n_sched_block_now]["n_pnt"]

                if not n_trg in target_pos:
                    target_pos[n_trg] = [
                        (
                            self.rnd_gen.random() *
                            (self.az_min_max[1] - self.az_min_max[0])
                        ) + self.az_min_max[0],
                        (
                            self.rnd_gen.random() *
                            (self.zen_min_max_tel[1] - self.zen_min_max_tel[0])
                        ) + self.zen_min_max_tel[0]
                    ]

                target_id = "target_" + str(n_trg)

                obs_blocks = []
                for n_blockNow in range(n_obs_blocks):
                    obs_block_id = "obs_block_" + str(getTime())

                    point_pos = copy.deepcopy(target_pos[n_trg])
                    point_pos[0] += (self.rnd_gen.random() - 0.5) * 10
                    point_pos[1] += (self.rnd_gen.random() - 0.5) * 10

                    if point_pos[0] > self.az_min_max[1]:
                        point_pos[0] -= 360
                    elif point_pos[0] < self.az_min_max[0]:
                        point_pos[0] += 360

                    obs_coords = sb.Coordinates(
                        2,
                        sb.HorizontalCoordinates(
                            target_pos[n_trg][1], target_pos[n_trg][0]
                        )
                    )
                    # obs_coords = sb.Coordinates(3,sb.GalacticCoordinates(target_pos[n_trg][1],target_pos[n_trg][0]))
                    obs_mode = sb.ObservingMode(
                        sb.Slewing(1), sb.ObservingType(2, sb.GridSurvey(1, 1, 1))
                    )
                    obs_source = sb.Source(
                        target_id, sb.placeholder, sb.High, sb.RegionOfInterest(100),
                        obs_mode, obs_coords
                    )
                    obs_conds = sb.ObservingConditions(
                        sb.DateTime(1), self.obs_block_seconds, 1, sb.Quality(1, 1, 1),
                        sb.Weather(1, 1, 1, 1)
                    )
                    obs_block = sb.ObservationBlock(
                        obs_block_id, obs_source, obs_conds, script_name, 0
                    )

                    obs_blocks += [obs_block]

                    # temporary way to store meta-data
                    # should be replaced by global coordinate access function
                    self.acs_blocks['metadata'][obs_block_id + "_"
                                                + "point_pos"] = point_pos

                sched_block = sb.SchedulingBlock(
                    sched_block_id, sb.Proposal("proposalId"), sched_conf, obs_blocks
                )

                cycle_blocks.append(sched_block)

                self.acs_blocks['sched_block'][sched_block_id] = sched_block

            self.cycle_blocks.append(cycle_blocks)

        return

    # ------------------------------------------------------------------
    # move one from wait to run
    # ------------------------------------------------------------------
    def submit_block_cycle(self):
        self.log.info([['g', " - starting MockSched.submit_block_cycle ..."]])

        if len(self.cycle_blocks) >= self.active_sched_block:
            self.active_sched_block = 0
            self.init_block_cycle()

        # grab the current sched_block from the queue
        blockCycle = self.cycle_blocks[self.active_sched_block]
        self.active_sched_block += 1

        # submit the scheduling blocks
        self.log.info([['g', " - submitting ..."]])
        for sched_block in blockCycle:
            try:
                self.log.info([['y', " --- try putSchedulingBlock ", sched_block.id]])
                complt = self.supervisor.putSchedulingBlock(sched_block)
            except Exception as e:
                self.log.debug([['b', "- Exception - MockSched.putSchedulingBlock: "],
                                ['r', e]])

        self.log.info([['y', " ----- try putSchedulingBlock done !"]])
        return

    # ------------------------------------------------------------------
    # move one from wait to run
    # ------------------------------------------------------------------
    def check_sched_blocks(self):
        self.log.debug([['b', " - starting MockSched.check_sched_blocks ..."]])

        try:
            active = self.supervisor.listSchedulingBlocks()
        except Exception as e:
            self.log.debug([['b', "- Exception - MockSched.listSchedulingBlocks: "],
                            ['r', e]])
            active = []

        active = [x for x in active if x in self.acs_blocks['sched_block']]

        self.log.debug([['b', " --- got ", len(active), " active blocks"]])

        # for block_name in active:
        #   status = self.supervisor.getSchedulingBlockStatus(block_name)
        #   opstatus = self.supervisor.getSbOperationStatus(block_name)
        #   self.log.info([['y'," - active_scheduling_blocks - "],['g',active,'-> '],['y',status,' ']])

        #   for nob in range(len(opstatus.ob_statuses)):
        #     phases = opstatus.ob_statuses[nob].phases
        #     # for p in phases:
        #     #   self.log.info([['y'," -- phases - ",block_name,' ',opstatus.ob_statuses[nob].id,' ',opstatus.ob_statuses[nob].status,' '],['g',p.heartbeat_counter,' ',p.name,' ',p.status,' ',p.progress_message]])
        #     #   break

        return len(active)

    # ------------------------------------------------------------------
    #
    # ------------------------------------------------------------------
    def loop(self, run_event):
        self.log.info([['g', " - starting MockSched.loop ..."]])

        self.submit_block_cycle()

        while run_event.is_set():
            n_sched_blocks = self.check_sched_blocks()
            self.log.info([['g', " - will now wait for 5 sec ..."]])
            sleep(5)
            self.log.info([['g', " - will now try to cancel all ..."]])
            self.cancel_zombie_sched_blocks()

            if n_sched_blocks == 0:
                self.submit_block_cycle()

            sleep(self.loop_sleep)

        return
Ejemplo n.º 7
0
# Make an instance of the PySimpleClient
simpleClient = PySimpleClient()

# Do something on a device.
simpleClient.getLogger().logInfo("We can directly manipulate a device once we get it, which is easy!!")

# Get the standard MOUNT1 Mount device
mount = simpleClient.getComponent("MOUNT1")
# Get the actAz property
actAzProperty = mount._get_actAz()

# Create a callback monitor for the actAz Property
cbMon = MyMonitor("actAz")
# Activate the callback monitor
cbMonServant = simpleClient.activateOffShoot(cbMon)
# Create the real monitor registered with MOUNT1
desc = ACS.CBDescIn(0L, 0L, 0L)
actMon = actAzProperty.create_monitor(cbMonServant, desc)

# Tell MOUNT1 that the monitor's working method should be invoked 1 once second
actMon.set_timer_trigger(10000000)
# destroy the monitor after ten seconds
from time import sleep
sleep(10)
actMon.destroy()
sleep(5)

# Release it
simpleClient.releaseComponent("MOUNT1")
Ejemplo n.º 8
0
# Make an instance of the PySimpleClient
simpleClient = PySimpleClient()

# Do something on a device.
simpleClient.getLogger().logInfo(
    "We can directly manipulate a device once we get it, which is easy!!")

# Get the standard MOUNT1 Mount device
mount = simpleClient.getComponent("MOUNT1")
# Get the actAz property
actAzProperty = mount._get_actAz()

# Create a callback monitor for the actAz Property
cbMon = MyMonitor("actAz")
# Activate the callback monitor
cbMonServant = simpleClient.activateOffShoot(cbMon)
# Create the real monitor registered with MOUNT1
desc = ACS.CBDescIn(0L, 0L, 0L)
actMon = actAzProperty.create_monitor(cbMonServant, desc)

# Tell MOUNT1 that the monitor's working method should be invoked 1 once second
actMon.set_timer_trigger(10000000)
# destroy the monitor after ten seconds
from time import sleep
sleep(10)
actMon.destroy()
sleep(5)

# Release it
simpleClient.releaseComponent("MOUNT1")