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: ed00ca148570
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: 2c15bd3e4408
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 18, 2015

  1. Copy the full SHA
    600e833 View commit details
  2. Copy the full SHA
    2c15bd3 View commit details
Showing with 37 additions and 21 deletions.
  1. +24 −20 artiq/frontend/artiq_influxdb.py
  2. +7 −1 examples/master/ddb.pyon
  3. +6 −0 soc/targets/artiq_kc705.py
44 changes: 24 additions & 20 deletions artiq/frontend/artiq_influxdb.py
Original file line number Diff line number Diff line change
@@ -59,6 +59,26 @@ def get_argparser():
return parser


def influxdb_str(s):
return '"' + s.replace('"', '\\"') + '"'


def format_influxdb(v):
if isinstance(v, bool):
if v:
return "bool", "t"
else:
return "bool", "f"
elif np.issubdtype(type(v), int):
return "int", "{}i".format(v)
elif np.issubdtype(type(v), float):
return "float", "{}".format(v)
elif isinstance(v, str):
return "str", influxdb_str(v)
else:
return "pyon", influxdb_str(pyon.encode(v))


class DBWriter(TaskObject):
def __init__(self, base_url, user, password, database, table):
self.base_url = base_url
@@ -83,7 +103,8 @@ def _do(self):
url = self.base_url + "/write"
params = {"u": self.user, "p": self.password, "db": self.database,
"consistency": "any", "precision": "n"}
data = "{} {}={}".format(self.table, k, v)
fmt_ty, fmt_v = format_influxdb(v)
data = "{},parameter={} {}={}".format(self.table, k, fmt_ty, fmt_v)
try:
response = yield from aiohttp.request(
"POST", url, params=params, data=data)
@@ -101,31 +122,14 @@ def _do(self):
response.close()


def format_influxdb(v):
if isinstance(v, bool):
if v:
return "t"
else:
return "f"
elif np.issubdtype(type(v), int):
return "{}i".format(v)
elif np.issubdtype(type(v), float):
return "{}".format(v)
elif isinstance(v, str):
return '"' + v.replace('"', '\\"') + '"'
else:
return None


class Parameters:
def __init__(self, filter_function, writer, init):
self.filter_function = filter_function
self.writer = writer

def __setitem__(self, k, v):
v_db = format_influxdb(v)
if v_db is not None and self.filter_function(k):
self.writer.update(k, v_db)
if self.filter_function(k):
self.writer.update(k, v)

def __delitem__(self, k):
pass
8 changes: 7 additions & 1 deletion examples/master/ddb.pyon
Original file line number Diff line number Diff line change
@@ -49,11 +49,17 @@
"class": "TTLOut",
"arguments": {"channel": 5}
},
"ttl_sma": {
"type": "local",
"module": "artiq.coredevice.ttl",
"class": "TTLInOut",
"arguments": {"channel": 17}
},
"led": {
"type": "local",
"module": "artiq.coredevice.ttl",
"class": "TTLOut",
"arguments": {"channel": 17}
"arguments": {"channel": 18}
},

"dds_bus": {
6 changes: 6 additions & 0 deletions soc/targets/artiq_kc705.py
Original file line number Diff line number Diff line change
@@ -148,6 +148,9 @@ def __init__(self, platform, cpu_type="or1k", **kwargs):
self.submodules += phy
rtio_channels.append(rtio.Channel.from_phy(phy))

phy = ttl_simple.Inout(platform.request("user_sma_gpio_n"))
self.submodules += phy
rtio_channels.append(rtio.Channel.from_phy(phy))
phy = ttl_simple.Output(platform.request("user_led", 2))
self.submodules += phy
rtio_channels.append(rtio.Channel.from_phy(phy))
@@ -187,6 +190,9 @@ def __init__(self, platform, cpu_type="or1k", **kwargs):
self.submodules += phy
rtio_channels.append(rtio.Channel.from_phy(phy))

phy = ttl_simple.Inout(platform.request("user_sma_gpio_n"))
self.submodules += phy
rtio_channels.append(rtio.Channel.from_phy(phy))
phy = ttl_simple.Output(platform.request("user_led", 2))
self.submodules += phy
rtio_channels.append(rtio.Channel.from_phy(phy))