Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 52102a1a79a2
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 10d4bfba387c
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 18, 2015

  1. Copy the full SHA
    0832c71 View commit details
  2. Copy the full SHA
    10d4bfb View commit details
Showing with 53 additions and 13 deletions.
  1. +23 −6 artiq/coredevice/comm_tcp.py
  2. +30 −7 artiq/frontend/artiq_coretool.py
29 changes: 23 additions & 6 deletions artiq/coredevice/comm_tcp.py
Original file line number Diff line number Diff line change
@@ -24,20 +24,26 @@ def set_keepalive(sock, after_idle, interval, max_fails):
sys.platform)


def initialize_connection(host, port):
sock = socket.create_connection((host, port), 5.0)
sock.settimeout(None)
set_keepalive(sock, 3, 2, 3)
logger.debug("connected to host %s on port %d", host, port)
sock.sendall(b"ARTIQ coredev\n")
return sock


class Comm(CommGeneric):
def __init__(self, dmgr, host, port=1381):
def __init__(self, dmgr, host, port=1381, port_analyzer=1382):
super().__init__()
self.host = host
self.port = port
self.port_analyzer = port_analyzer

def open(self):
if hasattr(self, "socket"):
return
self.socket = socket.create_connection((self.host, self.port), 5.0)
self.socket.settimeout(None)
set_keepalive(self.socket, 3, 2, 3)
logger.debug("connected to host %s on port %d", self.host, self.port)
self.write(b"ARTIQ coredev\n")
self.socket = initialize_connection(self.host, self.port)

def close(self):
if not hasattr(self, "socket"):
@@ -57,3 +63,14 @@ def read(self, length):

def write(self, data):
self.socket.sendall(data)

def get_analyzer_dump(self):
sock = initialize_connection(self.host, self.port_analyzer)
r = bytes()
while True:
buf = sock.recv(8192)
if not buf:
break
r += buf
sock.close()
return r
37 changes: 30 additions & 7 deletions artiq/frontend/artiq_coretool.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
#!/usr/bin/env python3.5

import argparse
import struct

from artiq.master.databases import DeviceDB
from artiq.master.worker_db import DeviceManager


def print_analyzer_dump(dump):
sent_bytes, total_byte_count, overflow_occured = struct.unpack(">IQI", dump[:16])
dump = dump[16:]
print(sent_bytes, total_byte_count, overflow_occured)

while dump:
message_type_channel = struct.unpack(">I", dump[28:32])[0]
message_type = message_type_channel & 0b11
channel = message_type_channel >> 2

if message_type == 2:
exception_type, rtio_counter = struct.unpack(">BQ", dump[11:20])
print("EXC exception_type={} channel={} rtio_counter={}"
.format(exception_type, channel, rtio_counter))
else:
(data, address_padding, rtio_counter, timestamp) = struct.unpack(">QIQQ", dump[:28])
print("IO type={} channel={} timestamp={} rtio_counter={} address_padding={} data={}"
.format(message_type, channel, timestamp, rtio_counter, address_padding, data))
dump = dump[32:]


def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ core device "
"remote access tool")
@@ -15,17 +37,14 @@ def get_argparser():
subparsers = parser.add_subparsers(dest="action")
subparsers.required = True

# Log Read command
subparsers.add_parser("log",
help="read from the core device log ring buffer")

# Configuration Read command
p_read = subparsers.add_parser("cfg-read",
help="read key from core device config")
p_read.add_argument("key", type=str,
help="key to be read from core device config")

# Configuration Write command
p_write = subparsers.add_parser("cfg-write",
help="write key-value records to core "
"device config")
@@ -39,16 +58,16 @@ def get_argparser():
help="key and file whose content to be written to "
"core device config")

# Configuration Delete command
p_delete = subparsers.add_parser("cfg-delete",
help="delete key from core device config")
p_delete.add_argument("key", nargs=argparse.REMAINDER,
default=[], type=str,
help="key to be deleted from core device config")

# Configuration Erase command
subparsers.add_parser("cfg-erase", help="erase core device config")

subparsers.add_parser("analyzer-dump")

return parser


@@ -57,7 +76,8 @@ def main():
device_mgr = DeviceManager(DeviceDB(args.device_db))
try:
comm = device_mgr.get("comm")
comm.check_ident()
if args.action != "analyzer-dump":
comm.check_ident()

if args.action == "log":
print(comm.get_log(), end="")
@@ -77,7 +97,10 @@ def main():
for key in args.key:
comm.flash_storage_remove(key)
elif args.action == "cfg-erase":
comm.flash_storage_erase()
comm.flash_storage_erase()
elif args.action == "analyzer-dump":
dump = comm.get_analyzer_dump()
print_analyzer_dump(dump)
finally:
device_mgr.close_devices()