29 raw_gpio_cmd = b
'\x01'
31 cmd = raw_gpio_cmd+struct.pack(
"B", port)+mode
34 result = ipmi_connection.raw_command(0x00, 0x30, cmd)
37 cmd_result.append(char)
40 port_directions_flag=0b0
41 for i
in range(4,0,-1):
42 port_directions_flag = (port_directions_flag << 8) | cmd_result[i]
46 for i
in range(8,4,-1):
47 port_states_flag = (port_states_flag << 8) | cmd_result[i]
50 portTable.set_deco(Texttable.VLINES | Texttable.BORDER | Texttable.HEADER)
51 portTable.set_cols_align([
"l",
"l",
"l"])
52 portTable.set_chars([
'-',
'|',
'+',
'-'])
53 portTable.header( [
'Pin',
'Direction',
'State'] )
57 pin_dir_colour =
'yellow'
58 if port_directions_flag & (0x1 << i):
60 pin_dir_colour =
'green'
63 pin_state_colour =
'blue'
64 if port_states_flag & (0x1 << i):
66 pin_state_colour =
'red'
68 portTable.add_row( [i, style(pin_dir, fg=pin_dir_colour), style(pin_state, fg=pin_state_colour)] )
70 print(
"Port {} pins".format(port))
71 return portTable.draw()
78 if mode < 1
or mode > 2:
79 raise click.ClickException(
"Valid configuring modes are 1 or 2")
81 raw_gpio_cmd = b
'\x01'
82 cmd = raw_gpio_cmd + struct.pack(
"B", port) + struct.pack(
"B", mode) + struct.pack(
"B", pin)
84 if mode==2
and value >= 0:
85 cmd = cmd+struct.pack(
"B", value)
90 if cmd_attempts > max_attempts:
91 raise click.ClickException(
"Failed to configure port {} pin {} after {} attempts".format(hex(port), hex(pin), max_attempts))
93 result = ipmi_connection.raw_command(0x00, 0x30, cmd)
95 cmd_result.append(char)
96 if cmd_result[1] == 0
and mode == 0x1:
98 elif cmd_result[1] == 1
and mode == 0x2:
102 if cmd_result[2] == value:
105 echo (
"error configured pin state {}, does not match requested {}".format(cmd_result[2], value))