Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inc parameter to counters #65

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ibek-defs
4 changes: 4 additions & 0 deletions src/ibek/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def render_text(self, instance: Entity, text: str, once=False, suffix="") -> str
have been rendered already. The suffix can be used where a given
Entity has more than one element to render once (e.g. functions)
"""

if once:
name = instance.__definition__.name + suffix
if name not in self.once_done:
Expand All @@ -64,6 +65,9 @@ def render_text(self, instance: Entity, text: str, once=False, suffix="") -> str
jinja_template = Template(result)
result = jinja_template.render(self._to_dict(instance)) # type: ignore

if result == "":
return ""

return result + "\n"

def render_function(self, instance: Entity, function: Function) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/ibek/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Function:

name: A[str, desc("Name of the function to call")]
args: A[Dict[str, Any], desc("The arguments IOC instance should supply")]
header: A[str, desc("commands/comments to appear before the function")]
header: A[str, desc("commands/comments to appear before the function")] = ""
once: A[bool, desc("If true, only call the function once")] = False
type: Literal["function"] = "function"

Expand Down
12 changes: 7 additions & 5 deletions src/ibek/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Counter:
current: int
stop: int

def increment(self):
self.current += 1
def increment(self, count: int):
self.current += count
if self.current > self.stop:
raise ValueError(
f"Counter {self.current} exceeded stop value of {self.stop}"
Expand All @@ -48,9 +48,11 @@ def get_var(self, key: str) -> Any:
# Intentionally raises a KeyError if the key doesn't exist
return self.variables[key]

def counter(self, name: str, start: int = 0, stop: int = 65535) -> int:
def counter(
self, name: str, start: int = 0, stop: int = 65535, inc: int = 1
) -> int:
"""
get a named counter that increments each time it is called
get a named counter that increments by inc each time it is called

creates a new counter if it does not yet exist
"""
Expand All @@ -64,7 +66,7 @@ def counter(self, name: str, start: int = 0, stop: int = 65535) -> int:
f"Redefining counter {name} with different start/stop values"
)
result = counter.current
counter.increment()
counter.increment(inc)
self.counters[name] = counter

return result
4 changes: 2 additions & 2 deletions tests/samples/example-srrfioc08/SR-RF-IOC-08.ibek.ioc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ entities:
- type: Hy8401ip.Hy8401ip
name: SlotA
carrier: IPAC4
ip_slot: 0
ip_site_number: 0
vector: Vec0

- type: Hy8401ip.Hy8401ip
name: SlotC
carrier: IPAC4
ip_slot: 2
ip_site_number: 2
vector: Vec1
4 changes: 2 additions & 2 deletions tests/samples/example-srrfioc08/st.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ ioc_registerRecordDeviceDriver pdbbase
ipacAddHy8002 "4, 2"
epicsEnvSet IPAC4 0

# Hy8401ipConfigure CardId IPACid IpSlot InterruptVector InterruptEnable AiType ExternalClock ClockRate Inhibit SampleCount SampleSpacing SampleSize
# IpSlot A=0 B=1 C=2 D=3
# Hy8401ipConfigure CardId IPACid IpSiteNumber InterruptVector InterruptEnable AiType ExternalClock ClockRate Inhibit SampleCount SampleSpacing SampleSize
# IpSlot 0=A 1=B 2=C 3=D
# ClockRate 0=1Hz 1=2Hz 2=5Hz 3=10Hz 4=20Hz 5=50Hz 6=100Hz7=200Hz 8=500Hz 9=1kHz 10=2kHz11=5kHz 12=10kHz 13=20kHz 14=50kHz 15=100kHz
Hy8401ipConfigure 40 $(IPAC4) 0 $(Vec0) 0 0 0 15 0 1 1 0
Hy8401ipConfigure 42 $(IPAC4) 2 $(Vec1) 0 0 0 15 0 1 1 0
Expand Down
34 changes: 8 additions & 26 deletions tests/samples/schemas/all.ibek.support.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,6 @@
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"entity_enabled": {
"type": "boolean",
"default": true
},
"carrier": {
"type": "string",
"description": "IPAC carrier name",
"vscode_ibek_plugin_type": "type_object"
},
"type": {
"type": "string",
"const": "dls_psc_support.Psc",
"default": "dls_psc_support.Psc"
}
},
"required": [
"carrier"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
Expand Down Expand Up @@ -323,6 +300,11 @@
"description": "A name for an interrupt vector variable",
"vscode_ibek_plugin_type": "type_id"
},
"count": {
"type": "integer",
"description": "The number of interrupt vectors to reserve",
"default": 1
},
"type": {
"type": "string",
"const": "epics.InterruptVectorVME",
Expand Down Expand Up @@ -351,7 +333,7 @@
"description": "Carrier Board Identifier",
"vscode_ibek_plugin_type": "type_object"
},
"ip_slot": {
"ip_site_number": {
"type": "integer",
"description": "IP Site Number 0=A, 1=B, 2=C, 3=D"
},
Expand Down Expand Up @@ -388,7 +370,7 @@
"card_id": {
"type": "string",
"description": "Card Identifier",
"default": "{{ carrier.slot }}{{ ip_slot }}"
"default": "{{ carrier.slot }}{{ ip_site_number }}"
},
"type": {
"type": "string",
Expand All @@ -399,7 +381,7 @@
"required": [
"name",
"carrier",
"ip_slot",
"ip_site_number",
"vector"
],
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@
"description": "A name for an interrupt vector variable",
"vscode_ibek_plugin_type": "type_id"
},
"count": {
"type": "integer",
"description": "The number of interrupt vectors to reserve",
"default": 1
},
"type": {
"type": "string",
"const": "epics.InterruptVectorVME",
Expand Down
5 changes: 5 additions & 0 deletions tests/samples/schemas/epics.ibek.support.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@
"description": "A name for an interrupt vector variable",
"vscode_ibek_plugin_type": "type_id"
},
"count": {
"type": "integer",
"description": "The number of interrupt vectors to reserve",
"default": 1
},
"type": {
"type": "string",
"const": "epics.InterruptVectorVME",
Expand Down
6 changes: 3 additions & 3 deletions tests/samples/schemas/ibek.defs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@
},
"header": {
"type": "string",
"description": "commands/comments to appear before the function"
"description": "commands/comments to appear before the function",
"default": ""
},
"once": {
"type": "boolean",
Expand All @@ -269,8 +270,7 @@
},
"required": [
"name",
"args",
"header"
"args"
],
"additionalProperties": false
},
Expand Down