Skip to content

Commit

Permalink
tek-poe: rtl: siwtch from 8-port to 4-port status query
Browse files Browse the repository at this point in the history
The 8-port status command seems, once again, to be specific to
engenius devices. Out of about 30 query packets, the 8-port command
optimizes out one packet, and is specific to one vendor. That's genius!
  • Loading branch information
mrnuke committed Sep 13, 2024
1 parent 4dcaf5a commit 3e5071a
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions src/dialect_rtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,44 @@ static int rtl_reply_power_stats(struct mcu_state *ctx, uint8_t *reply)
return 0;
}

static int rtl_cmd_4_port_group_status(uint8_t start_port)
{
uint8_t cmd[] = { 0x43, 0x00, start_port / 4};

return poe_cmd_queue(cmd, sizeof(cmd));
}

static int rtl_reply_4_port_group_status(struct mcu_state *mcu, uint8_t *reply)
{

int i, port, pstate;

const char *status[] = {
[0] = "Disabled",
[1] = "Searching",
[2] = "Delivering power",
[4] = "Fault",
[5] = "Other fault",
[6] = "Requesting power",
};

port = reply[2] * 4;
for (i = 3; i < 11; i += 2, port++) {
pstate = reply[i];

if (port == 0xff) {
continue;
} else if (port >= MAX_PORT) {
ULOG_WARN("Invalid port status packet (port=%d)\n", port);
return -1;
}

mcu->ports[port].status = GET_STR(pstate & 0xf, status);
}

return 0;
}

static int rtl_cmd_port_power_stats(uint8_t port)
{
uint8_t cmd[] = { 0x44, 0x00, port};
Expand Down Expand Up @@ -226,43 +264,6 @@ static int rtl_reply_port_ext_config(struct mcu_state *mcu, uint8_t *reply)
return 0;
}

static int rtl_cmd_8_port_status(void)
{
uint8_t cmd[] = { 0x50, 0x00, 0x00 };

return poe_cmd_queue(cmd, sizeof(cmd));
}

static int rtl_reply_8_port_status(struct mcu_state *mcu, uint8_t *reply)
{
int i, port, pstate, start_idx = reply[2];

const char *status[] = {
[0] = "Disabled",
[1] = "Searching",
[2] = "Delivering power",
[4] = "Fault",
[5] = "Other fault",
[6] = "Requesting power",
};

for (i = 3; i < 11; i++) {
port = start_idx + i - 3;
pstate = reply[i];

if (port == 0xff) {
continue;
} else if (port >= MAX_PORT) {
ULOG_WARN("Invalid port status packet (port=%d)\n", port);
return -1;
}

mcu->ports[port].status = GET_STR(pstate & 0xf, status);
}

return 0;
}

static int rtl_reply_4_port(struct mcu_state *mcu, uint8_t *reply)
{
uint8_t port, ret;
Expand Down Expand Up @@ -293,10 +294,10 @@ static poe_reply_handler reply_handler[] = {
[0x15] = rtl_reply_4_port,
[0x40] = rtl_reply_status,
[0x41] = rtl_reply_power_stats,
[0x43] = rtl_reply_4_port_group_status,
[0x44] = rtl_reply_port_power_stats,
[0x48] = rtl_reply_port_config,
[0x49] = rtl_reply_port_ext_config,
[0x50] = rtl_reply_8_port_status,
};

static int poe_default_reply_handler(uint8_t *reply)
Expand Down Expand Up @@ -430,7 +431,9 @@ static int rtl_poll(struct mcu *mcu, const struct config *config)
size_t i;

rtl_cmd_power_stats();
rtl_cmd_8_port_status();

for (i = 0; i < config->port_count; i += 4)
rtl_cmd_4_port_group_status(i);

for (i = 0; i < config->port_count; i++) {
rtl_cmd_port_config(i);
Expand Down

0 comments on commit 3e5071a

Please sign in to comment.