failed approach

This commit is contained in:
2020-11-19 18:24:03 +01:00
parent 349897d878
commit 6c23b00c22
324 changed files with 57839 additions and 11 deletions

View File

@ -0,0 +1,147 @@
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <csp/csp.h>
#include <util/console.h>
#include <power_if.h>
static uint8_t power_if_port = 10;
static uint32_t power_if_timeout = 5000;
static int cmd_power_if_port(struct command_context * ctx) {
if (ctx->argc < 2) {
printf("Current port is %d\n", power_if_port);
return CMD_ERROR_NONE;
}
power_if_port = atoi(ctx->argv[1]);
return CMD_ERROR_NONE;
}
static int cmd_power_if_timeout(struct command_context *ctx) {
if (ctx->argc < 2) {
printf("Current timeout is %"PRIu32"\n", power_if_timeout);
return CMD_ERROR_NONE;
}
if (sscanf(command_args(ctx), "%"SCNu32, &power_if_timeout) != 1)
return CMD_ERROR_SYNTAX;
if (power_if_timeout > 30000) {
printf("Timeout set to high, limited to 30000 ms\n");
power_if_timeout = 30000;
}
printf("Timeout set to %"PRIu32"\n", power_if_timeout);
return CMD_ERROR_NONE;
}
static int cmd_power_if_set_get(struct command_context * ctx) {
power_if_ch_status_t ch_status;
if (ctx->argc < 3) {
return CMD_ERROR_SYNTAX;
}
uint8_t node = atoi(ctx->argv[1]);
memset(&ch_status, 0, sizeof(ch_status));
strncpy(ch_status.name, ctx->argv[2], 7);
ch_status.name[7] = 0;
char * cmd = ctx->argv[0];
if (!strcmp(cmd, "status") && (ctx->argc == 3)) {
if (!p60_power_if_cmd(node, power_if_port, power_if_timeout, POWER_IF_GET, &ch_status)) {
return CMD_ERROR_FAIL;
}
} else {
if (!strcmp(cmd, "on")) {
ch_status.mode = 1;
} else if (!strcmp(cmd, "off")) {
ch_status.mode = 0;
}
ch_status.on_cnt = (ctx->argc > 3) ? atoi(ctx->argv[3]) : 0;
ch_status.off_cnt = (ctx->argc > 4) ? atoi(ctx->argv[4]) : 0;
if (!p60_power_if_cmd(node, power_if_port, power_if_timeout, POWER_IF_SET, &ch_status)) {
return CMD_ERROR_FAIL;
}
}
printf("Node %u, Output channel '%s' (%u) is %s\r\n", node, ch_status.name, ch_status.ch_idx, (ch_status.mode ? "ON": "OFF"));
printf(" ch_idx: %u\r\n", ch_status.ch_idx);
printf(" mode: %u\r\n", ch_status.mode);
printf(" on_cnt: %u\r\n", ch_status.on_cnt);
printf(" off_cnt: %u\r\n", ch_status.off_cnt);
printf(" cur_lu_lim: %u\r\n", ch_status.cur_lu_lim);
printf(" cur_lim: %u\r\n", ch_status.cur_lim);
printf(" voltage: %u\r\n", ch_status.voltage);
printf(" current: %d\r\n", ch_status.current);
printf(" latchup: %u\r\n", ch_status.latchup);
return CMD_ERROR_NONE;
}
static int cmd_power_if_list(struct command_context * ctx) {
if (ctx->argc < 2) {
return CMD_ERROR_SYNTAX;
}
uint8_t node = atoi(ctx->argv[1]);
power_if_cmd_list_response_t ch_list;
if (!p60_power_if_cmd(node, power_if_port, power_if_timeout, POWER_IF_LIST, &ch_list)) {
return CMD_ERROR_FAIL;
}
printf("ch name status\r\n");
for (uint8_t ch = 0; ch < ch_list.count; ch++) {
printf("%2u %-8s %s\r\n", ch_list.list[ch].ch_idx, ch_list.list[ch].name, ch_list.list[ch].mode ? "ON": "OFF");
}
return CMD_ERROR_NONE;
}
command_t power_if_commands[] = {
{
.name = "port",
.help = "Set power interface port (default is 10)",
.usage = "<port>",
.handler = cmd_power_if_port,
},
{
.name = "timeout",
.help = "Set power interface timeout in milliseconds",
.usage = "<timeout>",
.handler = cmd_power_if_timeout,
},
{
.name = "status",
.help = "Get power channel status",
.usage = "<node> <channel>",
.handler = cmd_power_if_set_get,
},
{
.name = "on",
.help = "Turn power channel on",
.usage = "<node> <channel> [<on_cnt> <off_cnt>]",
.handler = cmd_power_if_set_get,
},
{
.name = "off",
.help = "Turn power channel off",
.usage = "<node> <channel> off [<on_cnt> <off_cnt>]",
.handler = cmd_power_if_set_get,
},
{
.name = "list",
.help = "Get list power channels",
.usage = "<node>",
.handler = cmd_power_if_list,
},
};
command_t __root_command power_if_root_command[] = {
{
.name = "power",
.help = "client: NanoPower P60",
.chain = INIT_CHAIN(power_if_commands),
}
};
void cmd_power_if_setup(void) {
command_register(power_if_root_command);
}

View File

@ -0,0 +1,33 @@
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
* NanoCom firmware
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <csp/csp.h>
#include <csp/csp_endian.h>
#include <p60.h>
#include <p60_board.h>
/**
* Setup info about board configuration parameters
*/
const param_table_t p60_config[] = {
{.name = "uid", .addr = P60_BOARD_UID, .type = PARAM_STRING, .size = 16},
{.name = "type", .addr = P60_BOARD_TYPE, .type = PARAM_UINT8, .size = sizeof(uint8_t)},
{.name = "rev", .addr = P60_BOARD_REV, .type = PARAM_UINT8, .size = sizeof(uint8_t)},
{.name = "csp_addr", .addr = P60_BOARD_CSP_ADDR, .type = PARAM_UINT8, .size = sizeof(uint8_t)},
{.name = "i2c_addr", .addr = P60_BOARD_I2C_ADDR, .type = PARAM_UINT8, .size = sizeof(uint8_t)},
{.name = "i2c_speed", .addr = P60_BOARD_I2C_SPEED_KHZ, .type = PARAM_UINT16, .size = sizeof(uint16_t)},
{.name = "can_speed", .addr = P60_BOARD_CAN_SPEED_KHZ, .type = PARAM_UINT16, .size = sizeof(uint16_t)},
{.name = "kiss_en", .addr = P60_BOARD_KISS_ENABLE, .type = PARAM_UINT8, .size = sizeof(uint8_t)},
{.name = "rs422_mode", .addr = P60_BOARD_RS422_MODE, .type = PARAM_UINT8, .size = sizeof(uint8_t)},
{.name = "rs422_speed", .addr = P60_BOARD_RS422_SPEED_KHZ, .type = PARAM_UINT32, .size = sizeof(uint32_t)},
{.name = "csp_rtable", .addr = P60_BOARD_RTABLE_STR, .type = PARAM_STRING, .size = P60_BOARD_RTABLE_STR_SIZE},
};
const int p60_config_count = sizeof(p60_config) / sizeof(p60_config[0]);

View File

@ -0,0 +1,91 @@
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
* NanoPower firmware
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <csp/csp.h>
#include <csp/csp_endian.h>
#include <power_if.h>
uint8_t p60_power_if_get_ch_idx(char * ch_name, uint8_t * ch_no, uint8_t ch_no_max) {
uint8_t result = 1;
uint8_t len = strlen(ch_name);
for (int i = 0; i < len; i++) {
if (!isdigit(ch_name[i])) {
result = 0;
break;
}
}
if (result) {
*ch_no = atoi(ch_name);
if (*ch_no >= ch_no_max) {
result = 0;
}
}
return result;
}
int p60_power_if_cmd(uint8_t node, uint8_t port, uint32_t timeout, uint8_t cmd, void * ch_status_p) {
power_if_cmd_request_t req;
if ((cmd == POWER_IF_SET) || (cmd == POWER_IF_GET)) {
power_if_cmd_response_t resp;
power_if_ch_status_t * ch_status = (power_if_ch_status_t *)ch_status_p;
if (cmd == POWER_IF_SET) {
req.cmd = POWER_IF_SET;
req.ch_status.mode = ch_status->mode;
req.ch_status.on_cnt = csp_hton16(ch_status->on_cnt);
req.ch_status.off_cnt = csp_hton16(ch_status->off_cnt);
} else {
req.cmd = POWER_IF_GET;
req.ch_status.mode = 0;
req.ch_status.on_cnt = 0;
req.ch_status.off_cnt = 0;
}
ch_status->name[POWER_IF_NAME_LEN - 1] = 0;
strcpy(req.ch_status.name, ch_status->name);
if (csp_transaction(CSP_PRIO_HIGH, node, port, timeout, &req, sizeof(power_if_cmd_request_t), &resp, sizeof(power_if_cmd_response_t))) {
if ((resp.cmd == POWER_IF_SET) || (resp.cmd == POWER_IF_GET)) {
if (resp.status == POWER_IF_STATUS_OK) {
ch_status->ch_idx = resp.ch_status.ch_idx;
ch_status->mode = resp.ch_status.mode;
ch_status->on_cnt = csp_ntoh16(resp.ch_status.on_cnt);
ch_status->off_cnt = csp_ntoh16(resp.ch_status.off_cnt);
ch_status->cur_lu_lim = csp_ntoh16(resp.ch_status.cur_lu_lim);
ch_status->cur_lim = csp_ntoh16(resp.ch_status.cur_lim);
ch_status->voltage = csp_ntoh16(resp.ch_status.voltage);
ch_status->current = csp_ntoh16(resp.ch_status.current);
ch_status->latchup = csp_ntoh16(resp.ch_status.latchup);
strncpy(ch_status->name, resp.ch_status.name, POWER_IF_NAME_LEN - 1);
/* Ensure zero termination*/
ch_status->name[POWER_IF_NAME_LEN - 1] = 0;
return 1;
}
}
}
} else if (cmd == POWER_IF_LIST) {
power_if_cmd_list_response_t * ch_list = (power_if_cmd_list_response_t *)ch_status_p;
req.cmd = POWER_IF_LIST;
req.ch_status.mode = 0;
req.ch_status.on_cnt = 0;
req.ch_status.off_cnt = 0;
req.ch_status.name[0] = 0;
if (csp_transaction(CSP_PRIO_HIGH, node, port, timeout, &req, sizeof(power_if_cmd_request_t), ch_list, sizeof(power_if_cmd_list_response_t))) {
if ((ch_list->cmd == POWER_IF_LIST) && (ch_list->status == POWER_IF_STATUS_OK)) {
return 1;
}
}
}
return 0;
}