57def main(crate_ip, amcs, cmd):
58
59
60 try:
61 sh.ping(["-c", '1', crate_ip])
62 print(f"[green]uTCA crate {crate_ip} is active[/green]")
63 except sh.ErrorReturnCode as e:
64 print(f"[red]Could not ping uTCA Crate at IP: {crate_ip}[/red]")
65 exit(1)
66
67 crate_subnet = crate_ip.rsplit(".", 1)[0]
68
69 amc_ips = { i: crate_subnet + f".{i + 1}" for i in amcs}
70
71 if cmd=='arping':
72
73 try:
74 r = sh.arping(["-c", '1', crate_ip])
75 print(f"- [green]uTCA crate {crate_ip} responded to arping[/green]")
76 print(r)
77 except sh.ErrorReturnCode as e:
78 print(f"- [red]Could not arping uTCA Crate at IP: {crate_ip}[/red]")
79
80
81 for amc, amc_ip in amc_ips.items():
82 try:
83 r = sh.arping(["-c", '1', amc_ip])
84 print(f"- [green]AMC {amc} ({amc_ip}) responded to arping[/green]")
85 print(r)
86
87 except sh.ErrorReturnCode as e:
88 print(f"- [red]Could not arping AMC {amc} at IP: {amc_ip}[/red]")
89
90
91 nic_ip = crate_subnet+'.129'
92 try:
93 r = sh.arping(["-c", '1', nic_ip])
94 print(f"- [green]NIC data sink {nic_ip} responded to arping[/green]")
95 print(r)
96 except sh.ErrorReturnCode as e:
97 print(f"- [red]Could not arping NIC data at IP: {nic_ip}[/red]")
98
99 else:
100 if cmd:
101 controllers = { amc_ip:tdemodules.AMCController(amc_ip, 54321 + (i + 1)) for i,amc_ip in amc_ips.items() }
102 print(controllers)
103 cmds = Commands(controllers)
104 getattr(cmds, cmd)()
105 else:
106 print("no command was provided.")
107
108 return
109
int main(int argc, char **argv)