async def initConnections(matchPattern): global daliDownload global daliUpload daliDownload = simpleDali.SocketDataLink(host, port) #daliDownload = simpleDali.WebSocketDataLink(uri) #daliDownload.verbose = True serverId = await daliDownload.id(programname, username, processid, architecture) print("Connect Download: {}".format(serverId)) serverInfo = await daliDownload.info("STATUS") print("Info STATUS: {} ".format(serverInfo.message)) #serverInfo = await dali.info("STREAMS") #print("Info: {} ".format(serverInfo.message)) # # match all MSEED streams #r = await dali.match(".*/MSEED") # or match just 3605 HNZ r = await daliDownload.match(matchPattern) print("match() Response {}".format(r)) # create a separate upload datalink daliUpload = simpleDali.SocketDataLink(host, port) #daliUpload = simpleDali.WebSocketDataLink(uri) #daliUpload.verbose = True serverId = await daliUpload.id(programname, username, processid, architecture) print("Connect Upload: {}".format(serverId)) # Start data flowing r = await daliDownload.stream() print("data is flowing")
async def initDali(self): if self.uploadDali is not None: await self.uploadDali.close() if self.dali is not None: await self.dali.close() self.uploadDali = simpleDali.SocketDataLink(self.host, self.uploadPort) serverId = await self.uploadDali.id(self.programname, self.username, self.processid, self.architecture) print("Upload Id: {}".format(serverId)) self.dali = simpleDali.SocketDataLink(self.host, self.port) #self.dali = simpleDali.WebSocketDataLink(uri) #self.dali.verbose = True serverId = await self.dali.id(self.programname, self.username, self.processid, self.architecture) print("Resp: {}".format(serverId)) serverInfo = await self.dali.info("STATUS") print("Info: {} ".format(serverInfo.message)) #serverInfo = yield from self.dali.info("STREAMS") #print("Info: {} ".format(serverInfo.message)) r = await self.dali.match("(.*/MTRIG)|(.*/MAXACC)|(.*/ZMAXCFG)|(.*/IP)" ) print("match() Resonse {}".format(r)) if r.type.startswith("ERROR"): print( "match() Resonse {}, ringserver might not know about these packets?" .format(r)) else: print("match() Resonse m={}".format(r.message)) r = await self.dali.stream() print("stream response: {}".format(r))
async def doTest(loop): dali = simpleDali.SocketDataLink(host, port) #dali = simpleDali.WebSocketDataLink(uri) serverId = yield from dali.id(programname, username, processid, architecture) print("Resp: {}".format(serverId)) #serverInfo = yield from dali.info("STATUS") #print("Info: {} ".format(serverInfo.message)) #serverInfo = yield from dali.info("STREAMS") #print("Info: {} ".format(serverInfo.message)) network = "YY" station = "TEST" location = "00" channel = "HNZ" dutyOfficer = "Philip" trigtime = simpleDali.utcnowWithTz() streamid = "{}.{}.{}.{}/MTRIG".format(network, station, location, channel) hpdatastart = int(trigtime.timestamp() * simpleDali.MICROS) hpdataend = int(trigtime.timestamp() * simpleDali.MICROS) trigInfo = { "type": "manual", "dutyOfficer": dutyOfficer, "time": trigtime.isoformat(), "creation": trigtime.isoformat(), "override": { "modtime": trigtime.isoformat(), "value": "enable" } } trigBytes = json.dumps(trigInfo).encode('UTF-8') r = yield from dali.writeAck(streamid, hpdatastart, hpdataend, trigBytes) print("writem trigger resp {}".format(r)) dali.close()
async def initConnections(): global daliUpload # create a separate upload datalink daliUpload = simpleDali.SocketDataLink(host, port) #daliUpload = simpleDali.WebSocketDataLink(uri) #daliUpload.verbose = True serverId = await daliUpload.id(programname, username, processid, architecture) print("Connect Upload: {}".format(serverId))
def main(args): global keepGoing, verbose ############################################ # values to change: dataDir="Track_Data" netGlob = "XX" staGlob = "*" locGlob = "00" chanGlob = "HN[XYZ]" # if need seconds add :%S startTime = datetime.strptime("2018-10-14T11:00Z", "%Y-%m-%dT%H:%MZ") duration = timedelta(hours=2) #duration = timedelta(seconds=20) repeat = True # end values to change ############################################ host = "129.252.35.36" port = 15004 uri = "ws://www.seis.sc.edu/dragracews/datalink" programname="miniseedReplay" username="******" processid=0 architecture="python" # -1 means run forever, otherwise stop after MAX_COUNT packets, for testing MAX_COUNT=-1 # create a separate upload datalink if verbose: print("Init Datalink to {}:{}".format(host, port)) dali = simpleDali.SocketDataLink(host, port) #dali = simpleDali.WebSocketDataLink(uri) loop = asyncio.get_event_loop() #daliUpload.verbose = True idTask = loop.create_task(daliUpload.id(programname, username, processid, architecture)) loop.run_until_complete(idTask) serverId = idTask.result() print("Connect Upload: {}".format(serverId)) infoTask = loop.create_task(daliUpload.info("STATUS")) loop.run_until_complete(infoTask) info = infoTask.result() print("Connect Upload: {}".format(info)) replay = MiniseedReplay(daliUpload, dataDir, netGlob, staGlob, locGlob, chanGlob, startTime, duration=duration) trigTask = loop.create_task(replay.doDurationTrigger()) loop.run_until_complete(trigTask) while keepGoing: replay.sendOldRecords() time.sleep(0.5)
async def doReconnect(dali): if dali is None: #dali = simpleDali.WebSocketDataLink(uri) dali = simpleDali.SocketDataLink(host, port) await dali.reconnect() serverId = await dali.id(programname, username, processid, architecture) logging.info("Resp: {}".format(serverId)) serverInfo = await dali.info("STATUS") logging.info("Info: {} ".format(serverInfo.message)) r = await dali.match(".*/(MAXACC|MTRIG)") logging.info("match() Resonse {}".format(r)) r = await dali.stream() return dali
def doTest(loop): dali = simpleDali.SocketDataLink(host, port) #dali = simpleDali.WebSocketDataLink(uri, verbose=True) idTask = loop.create_task( dali.id(programname, username, processid, architecture)) loop.run_until_complete(idTask) serverId = idTask.result() #serverId = await dali.id(programname, username, processid, architecture) print("Resp: {}".format(serverId)) #serverInfo = yield from dali.info("STATUS") #print("Info: {} ".format(serverInfo.message)) #serverInfo = yield from dali.info("STREAMS") #print("Info: {} ".format(serverInfo.message)) # hptime = "1551313181711158" # print("Position after: {} {:d}".format(hptime, int(hptime))) # pafter = yield from dali.positionAfterHPTime(hptime) # print("PacketId after: {} {}".format(pafter.type, pafter.value)) # nextPacket = yield from dali.read(pafter.value) # print("next after: {} {} {}".format(nextPacket.type, nextPacket.dataStartTime, nextPacket.dataEndTime)) # print("hptime round trip: {} {}".format(hptime, simpleDali.datetimeToHPTime(simpleDali.hptimeToDatetime(int(hptime))))) # nowTime = datetime.utcnow() # print("hptime now: {} {}".format(hptime, simpleDali.datetimeToHPTime(simpleDali.hptimeToDatetime(int(hptime))))) network = "XX" station = "TEST" location = "00" channel = "HNZ" starttime = simpleDali.utcnowWithTz() numsamples = 100 sampleRate = 200 shortData = array("h") # shorts for i in range(numsamples): shortData.append(i) msh = simpleMiniseed.MiniseedHeader(network, station, location, channel, starttime, numsamples, sampleRate) msr = simpleMiniseed.MiniseedRecord(msh, shortData) # print("before writeMSeed") # sendTask = loop.create_task(dali.writeMSeed(msr)) # loop.run_until_complete(sendTask) # print("writemseed resp {}".format(sendTask.result())) closeTask = loop.create_task(dali.close()) loop.run_until_complete(closeTask)
def initDali(daliUri): print("Init Dali at {0}".format(daliUri)) #dl = simpleDali.WebSocketDataLink(daliUri) dl = simpleDali.SocketDataLink(daliHost, daliPort) return dl
async def connection(loop): try: dali = simpleDali.WebSocketDataLink(uri) await dali.parseResponse() except Exception: dali = simpleDali.SocketDataLink(host, port) dali.verbose = True serverId = await dali.id(programname, username, processid, architecture) print("Resp: {}".format(serverId)) serverInfo = await dali.info("STATUS") print("Info: {} ".format(serverInfo.message)) print("File directory?") channelLoc = input() if channelLoc == '0': r = await dali.match("XX.XB08.00.HN./MSEED") else: r = await dali.match(channelLoc) begintime = datetime.utcnow() - timedelta(seconds=2) r = await dali.positionAfter(begintime) if r.type.startswith("ERROR"): print( "positionAfter() Resonse {}, ringserver might not know about these packets?" .format(r)) else: print("positionAfter() Resonse m={}".format(r.message)) r = await dali.stream() sys.stdout.flush() while (keepGoing): peakPacket = await dali.parseResponse() if not peakPacket.type == "PACKET": print("parseResponse not a PACKET {} ".format(peakPacket)) else: peakInfo = {} devationValues = [] squares = [] peakInfo = simpleMiniseed.unpackMiniseedRecord( peakPacket.data).data channelX = simpleMiniseed.unpackMiniseedHeader( peakPacket.data).channel timestamp = simpleMiniseed.unpackMiniseedRecord( peakPacket.data).starttime() average = sum(peakInfo) / len(peakInfo) for x in range(len(peakInfo)): squares.append(peakInfo[x]**2) rms = math.sqrt(sum(squares) / len(peakInfo)) for x in range(len(peakInfo)): devationValues.append((peakInfo[x] - average)**2) devation = math.sqrt(sum(devationValues) / (len(peakInfo) - 1)) print('-========== Channel {} ==========-'.format(channelX)) print('standard dev = {}'.format(devation)) print('rms = {}'.format(rms)) print('max value = {}'.format(max(peakInfo))) print('min value = {}'.format(min(peakInfo))) print('average = {}'.format(average)) print('timestamp = {}'.format(timestamp)) peakInfo = {} sys.stdout.flush() dali.close()