4app = typer.Typer(help=
"DaaS-IoT Python CLI")
11 Gestore eventi per il nodo DaaS-IoT.
12 Tutti i metodi definiti in IDaasApiEvent sono implementati qui
13 e stampano le informazioni ricevute.
20 print(f
"[EVENT] DIN accepted: {din}")
23 print(f
"[EVENT] DDO available from DIN {din} (size={payload_size}, typeset={typeset})")
25 print(
"[ERROR] No node reference set in handler.")
29 if err == pydaasiot.daas_error_t.ERROR_NONE
and ddo:
30 data = ddo.getPayloadAsBinary()
31 print(f
"[PULL] Pulled data: {data}")
33 print(f
"[PULL] Pull failed with error {err}")
36 print(f
"[EVENT] FRISBEE from DIN {din}")
39 print(f
"[EVENT] Node state received for DIN {din}")
42 print(f
"[EVENT] ATS sync completed for DIN {din}")
45 print(f
"[EVENT] Frisbee dperf completed for DIN {din} "
46 f
"(packets_sent={packets_sent}, block_size={block_size})")
50def init(sid: int, din: int, config: str = typer.Option(
"config.json", help=
"Path to config file")):
52 Initialize a DaaS-IoT node with given SID and DIN.
56 node = pydaasiot.DaasWrapper(config, handler)
59 typer.echo(f
"Node initialized SID={sid} DIN={din}")
64 Enable a driver on the node.
67 enable-driver _LINK_INET4 127.0.0.1:2222
71 typer.echo(
"Node not initialized")
73 link_enum = getattr(pydaasiot.link_t, link)
74 node.enableDriver(link_enum, uri)
75 typer.echo(f
"Driver enabled: {link} at {uri}")
78def map(din: int, link: str, uri: str):
80 Map a remote node in the DaaS network.
84 typer.echo(
"Node not initialized")
86 link_enum = getattr(pydaasiot.link_t, link)
87 node.map(din, link_enum, uri)
88 typer.echo(f
"Mapped remote node DIN={din} at {uri}")
91def perform(mode: str = typer.Option(
"PERFORM_CORE_THREAD", help=
"Execution mode")):
93 Start the internal processing loop.
97 typer.echo(
"Node not initialized")
99 mode_enum = getattr(pydaasiot.performs_mode_t, mode)
100 node.doPerform(mode_enum)
101 typer.echo(f
"doPerform started with mode {mode}")
104def push(din: int, message: str):
106 Push a text message to a remote node.
110 typer.echo(
"Node not initialized")
112 ddo = pydaasiot.DDO()
115 ddo.allocatePayload(len(message))
116 ddo.appendPayloadData(message.encode())
117 err = node.push(din, ddo)
118 typer.echo(f
"Push result: {err}")
123 Pull messages manually from a remote node.
127 typer.echo(
"Node not initialized")
129 err, ddo = node.pull(din)
130 if err == pydaasiot.daas_error_t.ERROR_NONE
and ddo:
131 typer.echo(f
"Pulled data: {ddo.getPayloadAsBinary()}")
133 typer.echo(f
"Pull failed: {err}")
135if __name__ ==
"__main__":
ddoReceivedEvent(self, int payload_size, int typeset, int din)
dinAcceptedEvent(self, int din)
nodeStateReceivedEvent(self, int din)
frisbeeReceivedEvent(self, int din)
atsSyncCompleted(self, int din)
__init__(self, node_ref=None)
frisbeeDperfCompleted(self, int din, int packets_sent, int block_size)
push(int din, str message)
init(int sid, int din, str config=typer.Option("config.json", help="Path to config file"))
perform(str mode=typer.Option("PERFORM_CORE_THREAD", help="Execution mode"))
map(int din, str link, str uri)
enable_driver(str link, str uri)