def __init__(self): self.count = 0 self.eventKey = EventKey(Prefix(Subsystems.CSW, "testassembly"), EventName("myAssemblyEvent")) self.eventSubscriber = EventSubscriber() self.eventThread = self.eventSubscriber.subscribe([self.eventKey], self.callback)
def __init__(self): intParam = Parameter("IntValue", KeyType.IntKey, [42], Units.arcsec) floatParam = Parameter("floatValue", KeyType.FloatKey, [float(42.1)], Units.arcsec) longParam = Parameter("longValue", KeyType.LongKey, [42], Units.arcsec) shortParam = Parameter("shortValue", KeyType.ShortKey, [42], Units.arcsec) byteParam = Parameter("byteValue", KeyType.ByteKey, b'\xDE\xAD\xBE\xEF') booleanParam = Parameter("booleanValue", KeyType.BooleanKey, [True, False], Units.arcsec) intArrayParam = Parameter("IntArrayValue", KeyType.IntArrayKey, [[1, 2, 3, 4], [5, 6, 7, 8]]) floatArrayParam = Parameter("FloatArrayValue", KeyType.FloatArrayKey, [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], Units.arcsec) doubleArrayParam = Parameter("DoubleArrayValue", KeyType.DoubleArrayKey, [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], Units.arcsec) byteArrayParam = Parameter("ByteArrayValue", KeyType.ByteArrayKey, [b'\xDE\xAD\xBE\xEF', bytes([1, 2, 3, 4])]) intMatrixParam = Parameter("IntMatrixValue", KeyType.IntMatrixKey, [[[1, 2, 3, 4], [5, 6, 7, 8]], [[-1, -2, -3, -4], [-5, -6, -7, -8]]], Units.meter) eqCoord = EqCoord.make(ra="12:13:14.15 hours", dec="-30:31:32.3 deg", frame=EqFrame.FK5, pm=(0.5, 2.33)) solarSystemCoord = SolarSystemCoord.make("BASE", SolarSystemObject.Venus) minorPlanetCoord = MinorPlanetCoord.make("GUIDER1", 2000, "90 deg", "2 deg", "100 deg", 1.4, 0.234, "220 deg") cometCoord = CometCoord.make("BASE", 2000.0, "90 deg", "2 deg", "100 deg", 1.4, 0.234) altAzCoord = AltAzCoord.make("301 deg", "42.5 deg") coordsParam = Parameter("CoordParam", KeyType.CoordKey, [eqCoord, solarSystemCoord, minorPlanetCoord, cometCoord, altAzCoord]) prefix = Prefix(Subsystems.CSW, "testassembly") eventName = EventName("myAssemblyEvent") paramSet = [coordsParam, byteParam, intParam, floatParam, longParam, shortParam, booleanParam, byteArrayParam, intArrayParam, floatArrayParam, doubleArrayParam, intMatrixParam] event = SystemEvent(prefix, eventName, paramSet) self.pub.publish(event)
def publishEvent1(self): keyName = "assemblyEventValue" keyType = KeyType.DoubleKey values = [42.0] param = Parameter(keyName, keyType, values) paramSet = [param] event = SystemEvent(self.prefix, EventName("testEvent1"), paramSet) self.log.debug(f"Publishing event {event}") self.pub.publish(event)
def test_event_key(): prefix = Prefix(Subsystems.TCS, "ENCAssembly") prefix2 = Prefix(Subsystems.TCS, "ENC.Assembly") eventName = EventName("CurrentPosition") k1 = EventKey(prefix, eventName) k2 = EventKey.from_str("TCS.ENCAssembly.CurrentPosition") assert k1 == k2 k1 = EventKey(prefix2, eventName) k2 = EventKey.from_str("TCS.ENC.Assembly.CurrentPosition") assert k1 == k2
def publishEvent4(self): keyName = "assemblyEventValue" keyType = KeyType.UTCTimeKey values = [UTCTime.from_str("2021-09-20T20:43:35.419053077Z")] param = Parameter(keyName, keyType, values) keyName2 = "assemblyEventValue2" keyType2 = KeyType.TAITimeKey values2 = [TAITime.from_str("2021-09-20T18:44:12.419084072Z")] param2 = Parameter(keyName2, keyType2, values2) paramSet = [param, param2] event = SystemEvent(self.prefix, EventName("testEvent4"), paramSet) self.log.debug(f"Publishing event {event}") self.pub.publish(event)
def publishEvent2(self): intParam = Parameter("IntValue", KeyType.IntKey, [42], Units.arcsec) intArrayParam = Parameter("IntArrayValue", KeyType.IntArrayKey, [[1, 2, 3, 4], [5, 6, 7, 8]]) floatArrayParam = Parameter("FloatArrayValue", KeyType.FloatArrayKey, [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], Units.marcsec) intMatrixParam = Parameter("IntMatrixValue", KeyType.IntMatrixKey, [[[1, 2, 3, 4], [5, 6, 7, 8]], [[-1, -2, -3, -4], [-5, -6, -7, -8]]], Units.meter) paramSet = [intParam, intArrayParam, floatArrayParam, intMatrixParam] event = SystemEvent(self.prefix, EventName("testEvent2"), paramSet) self.pub.publish(event)
def test_pub_sub(self): time.sleep(1.0) self.log.debug("Starting test...") thread = self.sub.subscribe([ EventKey(self.prefix, EventName("testEvent1")), EventKey(self.prefix, EventName("testEvent2")), EventKey(self.prefix, EventName("testEvent3")) ], self.callback) try: self.publishEvent1() self.publishEvent2() self.publishEvent3() self.publishEvent4() self.log.debug("Published three events...") # make sure assembly has time to write the file time.sleep(3) # compare file created from received events below with known good version assert filecmp.cmp(self.inFile, self.tmpInFile, False) # compare file created by assembly with known good version assert filecmp.cmp(self.outFile, self.tmpOutFile, False) self.log.info("Event pub/sub tests passed") finally: self.log.debug("Stopping subscriber...") thread.stop()
def test_pub_sub(self): pub = EventPublisher() sub = EventSubscriber() prefix = Prefix(Subsystems.CSW, "assembly") eventName = EventName("test_event") eventKey = EventKey(prefix, eventName) keyName = "testEventValue" keyType = KeyType.IntKey values = [42] param = Parameter(keyName, keyType, values) paramSet = [param] event = SystemEvent(prefix, eventName, paramSet) thread = sub.subscribe([eventKey], self.callback) pub.publish(event) time.sleep(1) e = sub.get(eventKey) assert (e == event) assert (self.count == 1) sub.unsubscribe([eventKey]) thread.stop()
from csw.Event import SystemEvent, EventName from csw.EventPublisher import EventPublisher from csw.KeyType import KeyType from csw.Parameter import Parameter from csw.Prefix import Prefix from csw.Subsystem import Subsystems # Test publishing events source = Prefix(Subsystems.CSW, "testassembly") eventName = EventName("myAssemblyEvent") keyName = "assemblyEventValue" keyType = KeyType.DoubleKey values = [42.0] param = Parameter(keyName, keyType, values) paramSet = [param] event = SystemEvent(source, eventName, paramSet) pub = EventPublisher() pub.publish(event)
def from_str(class_object, eventKeyStr: str): i = eventKeyStr.rindex('.') return EventKey(Prefix.from_str(eventKeyStr[:i]), EventName(eventKeyStr[i + 1:]))