1""" Helper functions for RapidCode Python samples.
2"""
3
4from _imports import RapidCode, RAPIDCODE_DIR, constants, platform
5
6def get_creation_parameters():
7
8
9 creation_params: RapidCode.CreationParameters = RapidCode.CreationParameters()
10 creation_params.RmpPath = RAPIDCODE_DIR
11 creation_params.NicPrimary = constants.RMP_NIC_PRIMARY
12
13 if platform.system() == "Windows":
14 creation_params.NodeName = constants.RMP_NODE_NAME
15 elif platform.system() == "Linux":
16 creation_params.CpuAffinity = constants.RMP_CPU_AFFINITY
17 else:
18 raise Exception("Unsupported platform")
19
20 return creation_params
21
22def check_errors(rsi_object):
23
24
25
26 error_string_builder = ""
27 i = rsi_object.ErrorLogCountGet()
28 while rsi_object.ErrorLogCountGet() > 0:
29 error:RapidCode.RsiError = rsi_object.ErrorLogGet()
30 error_type = "WARNING" if error.isWarning else "ERROR"
31 error_string_builder += f"{error_type}: {error.text}\n"
32 if len(error_string_builder) > 0:
33 print(error_string_builder)
34 if "ERROR" in error_string_builder:
35 raise Exception(error_string_builder)
36 return "ERROR" in error_string_builder, error_string_builder
37
38def start_the_network(controller):
39
40
41
42 if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
43 print("Starting Network..")
44 controller.NetworkStart()
45
46 if controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
47 messages_to_read = controller.NetworkLogMessageCountGet()
48
49 for i in range(messages_to_read):
50 print(controller.NetworkLogMessageGet(i))
51 print("Expected OPERATIONAL state but the network did not get there.")
52
53 else:
54 print("Network Started")