2

In the startup method of my agent I get the agent ID of the physical agent as:
phy = agentForService(Services.PHYSICAL)

Then I have tried different ways to set the powerLevel but usually something like:
phy.send(new ParameterReq().set(PhysicalChannelParam.powerLevel, -20))
phy.send(new ParameterReq().set(PhysicalChannelParam.powerLevel, [-20 -20 -20])) phy.set(PhysicalChannelParam.powerLevel, [-20 -20 -20]

Neither of them works.
I guess this is because there are multiple physical channels (CONTROL, DATA).
How do I specify which channel type to change the power level of?

EDIT:
A solution was to apparently to change the parameter directly:
control_channel = phy[1]
control_channel.powerLevel = -20
However, this feels like violating the basic ideas behind Fjåge.

moerot
  • 131
  • 5

1 Answers1

2

The phy[1].powerLevel = -20 syntax is just a syntactic sugar for roughly this:

def phy = agentForService(Services.PHYSICAL)
def req = new ParameterReq(phy)
req.setIndex(1)
req.set(PhysicalChannelParam.powerLevel, -20)
def rsp = request(req, 1000)
assert rsp?.get(PhysicalChannelParam.powerLevel) == -20

The req.setIndex(1) was the magic ingredient you were missing.

Also see: ParameterReq API docs.

Mandar Chitre
  • 2,110
  • 6
  • 14
  • 2
    Ah, now I understand what the indexing of the ParameterReq referred to. Cheers :) I was a bit surprised that the sugar-way worked inside any agent. Thought it was a feature of the shell agent. – moerot Nov 26 '20 at 10:40
  • It is a feature of `AgentID` provided in Groovy, and so it works in all Groovy agents in UnetStack, and is implemented under-the-hood using `ParameterReq` messages. If you're writing a Java agent, there are `UnetAgent` utility methods `get()` and `set()` that can be used instead of the Groovy indexing syntax. – Mandar Chitre Nov 27 '20 at 01:43