def __init__(self): intParam = Parameter("IntValue", "IntKey", [42], "arcsec") intArrayParam = Parameter("IntArrayValue", "IntArrayKey", [[1,2,3,4], [5,6,7,8]]) floatArrayParam = Parameter("FloatArrayValue", "FloatArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "marcsec") intMatrixParam = Parameter("IntMatrixValue", "IntMatrixKey", [[[1,2,3,4], [5,6,7,8]],[[-1,-2,-3,-4], [-5,-6,-7,-8]]], "meter") event = SystemEvent("CSW.testassembly", "myAssemblyEvent", [intParam, intArrayParam, floatArrayParam, intMatrixParam]) self.pub.publish(event)
def __init__(self): intParam = Parameter("IntValue", "IntKey", [42], "arcsec") floatParam = Parameter("floatValue", "FloatKey", [float(42.1)], "arcsec") longParam = Parameter("longValue", "LongKey", [42], "arcsec") shortParam = Parameter("shortValue", "ShortKey", [42], "arcsec") byteParam = Parameter("byteValue", "ByteKey", b'\xDE\xAD\xBE\xEF') booleanParam = Parameter("booleanValue", "BooleanKey", [True, False], "arcsec") intArrayParam = Parameter("IntArrayValue", "IntArrayKey", [[1, 2, 3, 4], [5, 6, 7, 8]]) floatArrayParam = Parameter("FloatArrayValue", "FloatArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "arcsec") doubleArrayParam = Parameter("DoubleArrayValue", "DoubleArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "arcsec") byteArrayParam = Parameter("ByteArrayValue", "ByteArrayKey", [b'\xDE\xAD\xBE\xEF', bytes([1, 2, 3, 4])]) intMatrixParam = Parameter("IntMatrixValue", "IntMatrixKey", [[[1, 2, 3, 4], [5, 6, 7, 8]], [[-1, -2, -3, -4], [-5, -6, -7, -8]]], "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", "CoordKey", [eqCoord, solarSystemCoord, minorPlanetCoord, cometCoord, altAzCoord]) structParam = Parameter("MyStruct", "StructKey", [Struct( [coordsParam, intParam, floatParam, longParam, shortParam, booleanParam, intArrayParam, floatArrayParam, doubleArrayParam, intMatrixParam])]) paramSet = [coordsParam, byteParam, intParam, floatParam, longParam, shortParam, booleanParam, byteArrayParam, intArrayParam, floatArrayParam, doubleArrayParam, intMatrixParam, structParam] event = SystemEvent("CSW.testassembly", "myAssemblyEvent", 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 publishEvent1(self): keyName = "assemblyEventValue" keyType = 'DoubleKey' values = [42.0] param = Parameter(keyName, keyType, values) paramSet = [param] event = SystemEvent(self.prefix, "testEvent1", paramSet) print(f"Publishing event {event}") self.pub.publish(event)
def publishEvent3(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 ]) paramSet = [ coordsParam, byteParam, intParam, floatParam, longParam, shortParam, booleanParam, byteArrayParam, intArrayParam, floatArrayParam, doubleArrayParam, intMatrixParam ] event = SystemEvent(self.prefix, EventName("testEvent3"), paramSet) self.pub.publish(event)
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 publishEvent2(self): intParam = Parameter("IntValue", "IntKey", [42], "arcsec") intArrayParam = Parameter("IntArrayValue", "IntArrayKey", [[1, 2, 3, 4], [5, 6, 7, 8]]) floatArrayParam = Parameter("FloatArrayValue", "FloatArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "marcsec") intMatrixParam = Parameter("IntMatrixValue", "IntMatrixKey", [[[1, 2, 3, 4], [5, 6, 7, 8]], [[-1, -2, -3, -4], [-5, -6, -7, -8]]], "meter") event = SystemEvent( self.prefix, "testEvent2", [intParam, intArrayParam, floatArrayParam, intMatrixParam]) self.pub.publish(event)
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)
from csw.Event import SystemEvent, EventName from csw.EventPublisher import EventPublisher from csw.Parameter import Parameter from csw.KeyType import KeyType from csw.Prefix import Prefix from csw.Subsystem import Subsystems # Test publishing events from csw.UTCTime import UTCTime prefix = Prefix(Subsystems.CSW, "testassembly") eventName = EventName("myAssemblyEvent") keyName = "assemblyEventValue" keyType = KeyType.UTCTimeKey values = [UTCTime.fromSystem()] param = Parameter(keyName, keyType, values) paramSet = [param] event = SystemEvent(prefix, eventName, paramSet) pub = EventPublisher() pub.publish(event)