failed approach
This commit is contained in:
48
gomspace/libp60_client/include/p60.h
Normal file
48
gomspace/libp60_client/include/p60.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef _P60_H_
|
||||
#define _P60_H_
|
||||
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
|
||||
|
||||
#define P60_PORT_RPARAM 7
|
||||
#define P60_PORT_GNDWDT_RESET 9
|
||||
#define P60_PORT_CMDCONTROL 10
|
||||
#define P60_PORT_GSSB_SERVICE 15
|
||||
#define P60_PORT_GSCRIPT 22
|
||||
|
||||
/** FRAM MEMORY MAP */
|
||||
#define P60_FRAM_BOARD 0x0000
|
||||
|
||||
/** FRAM FILENAMES */
|
||||
#define P60_FNO_BOARD 0
|
||||
#define P60_FNO_BOARD_DFL 4
|
||||
|
||||
#define P60_FRAM_WP_BEGIN (0x1000)
|
||||
#define P60_FRAM_WP_END (0x1C00 - 1)
|
||||
|
||||
/** GND WD FRAM ADDR **/
|
||||
#define P60_FRAM_GNDWDT 0x1F00
|
||||
|
||||
/** PARAM INDEX MAP */
|
||||
#define P60_BOARD_PARAM 0
|
||||
|
||||
#define DEVICE_FM24CL64B 0
|
||||
|
||||
typedef enum {
|
||||
UNKNOWN_RST = 0,
|
||||
GND_WDT_RST,
|
||||
I2C_WDT_RST,
|
||||
CAN_WDT_RST,
|
||||
EXT_HARD_RST,
|
||||
EXT_SOFT_RST,
|
||||
} p60_reset_cause_t;
|
||||
|
||||
extern const uint8_t board_fallback_type;
|
||||
extern const uint8_t csp_fallback_addr;
|
||||
extern const uint8_t board_rs422_mode;
|
||||
|
||||
extern void module_init_early(void);
|
||||
extern void module_init(void);
|
||||
extern void wdt_gnd_clear(void);
|
||||
extern uint16_t command_control(uint8_t *packet, uint16_t length);
|
||||
extern void module_task(void * pvParameters);
|
||||
|
||||
#endif /* _P60_H_ */
|
35
gomspace/libp60_client/include/p60_board.h
Normal file
35
gomspace/libp60_client/include/p60_board.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
|
||||
/**
|
||||
* NanoCom firmware
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef P60_PARAM_H_
|
||||
#define P60_PARAM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <param/param_types.h>
|
||||
|
||||
/**
|
||||
* Define memory space
|
||||
*/
|
||||
#define P60_BOARD_UID 0x00
|
||||
#define P60_BOARD_TYPE 0x10
|
||||
#define P60_BOARD_REV 0x11
|
||||
#define P60_BOARD_CSP_ADDR 0x12
|
||||
#define P60_BOARD_I2C_ADDR 0x13
|
||||
#define P60_BOARD_I2C_SPEED_KHZ 0x14
|
||||
#define P60_BOARD_CAN_SPEED_KHZ 0x16
|
||||
#define P60_BOARD_KISS_ENABLE 0x18
|
||||
#define P60_BOARD_RS422_MODE 0x19
|
||||
#define P60_BOARD_RS422_SPEED_KHZ 0x1C
|
||||
#define P60_BOARD_RTABLE_STR 0x20 //! This one is 0x60 = 96 bytes
|
||||
#define P60_BOARD_RTABLE_STR_SIZE 0x60
|
||||
|
||||
/** Define the memory size */
|
||||
#define P60_BOARD_PARAM_SIZE 0x80
|
||||
|
||||
extern const param_table_t p60_config[];
|
||||
extern const int p60_config_count;
|
||||
|
||||
#endif /* P60_PARAM_H_ */
|
62
gomspace/libp60_client/include/power_if.h
Normal file
62
gomspace/libp60_client/include/power_if.h
Normal file
@ -0,0 +1,62 @@
|
||||
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
|
||||
/**
|
||||
* NanoPower firmware
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef POWER_IF_H_
|
||||
#define POWER_IF_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define POWER_IF_SET 1
|
||||
#define POWER_IF_GET 2
|
||||
#define POWER_IF_LIST 3
|
||||
|
||||
#define POWER_IF_STATUS_OK 0
|
||||
#define POWER_IF_STATUS_ERROR 1
|
||||
|
||||
#define POWER_IF_NAME_LEN 8
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t ch_idx;
|
||||
uint8_t mode;
|
||||
uint16_t on_cnt;
|
||||
uint16_t off_cnt;
|
||||
uint16_t cur_lu_lim;
|
||||
uint16_t cur_lim;
|
||||
uint16_t voltage;
|
||||
int16_t current;
|
||||
uint16_t latchup;
|
||||
char name[POWER_IF_NAME_LEN];
|
||||
} power_if_ch_status_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t ch_idx;
|
||||
uint8_t mode;
|
||||
char name[8];
|
||||
} power_if_list_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t cmd;
|
||||
uint8_t status;
|
||||
power_if_ch_status_t ch_status;
|
||||
} power_if_cmd_request_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t cmd;
|
||||
uint8_t status;
|
||||
power_if_ch_status_t ch_status;
|
||||
} power_if_cmd_response_t;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t cmd;
|
||||
uint8_t status;
|
||||
uint8_t count;
|
||||
power_if_list_t list[16];
|
||||
} power_if_cmd_list_response_t;
|
||||
|
||||
int p60_power_if_cmd(uint8_t node, uint8_t port, uint32_t timeout, uint8_t cmd, void * ch_status_p);
|
||||
uint8_t p60_power_if_get_ch_idx(char * ch_name, uint8_t * ch_no, uint8_t ch_no_max);
|
||||
|
||||
#endif /* POWER_IF_H_ */
|
147
gomspace/libp60_client/src/cmd/power_if_cmd.c
Normal file
147
gomspace/libp60_client/src/cmd/power_if_cmd.c
Normal 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);
|
||||
}
|
33
gomspace/libp60_client/src/p60_client.c
Normal file
33
gomspace/libp60_client/src/p60_client.c
Normal 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]);
|
91
gomspace/libp60_client/src/power_if.c
Normal file
91
gomspace/libp60_client/src/power_if.c
Normal 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;
|
||||
}
|
28
gomspace/libp60_client/wscript
Normal file
28
gomspace/libp60_client/wscript
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# Copyright (c) 2013-2018 GomSpace A/S. All rights reserved.
|
||||
|
||||
APPNAME = 'p60_client'
|
||||
|
||||
|
||||
def options(ctx):
|
||||
gr = ctx.add_option_group('NanoPower-P60 library client options')
|
||||
gr.add_option('--disable-libp60-cmd', action='store_true', help='Disable client cmd code for NanoPower-P60 library')
|
||||
|
||||
|
||||
def configure(ctx):
|
||||
ctx.env.append_unique('FILES_LIBP60_CLIENT', ['src/*.c'])
|
||||
if not ctx.options.disable_libp60_cmd:
|
||||
ctx.env.append_unique('FILES_LIBP60_CLIENT', ['src/cmd/*.c'])
|
||||
|
||||
|
||||
def build(ctx):
|
||||
public_include = APPNAME + '_h'
|
||||
ctx(export_includes=['include'], name=public_include)
|
||||
ctx.objects(source=ctx.path.ant_glob(ctx.env.FILES_LIBP60_CLIENT),
|
||||
target=APPNAME,
|
||||
use=['csp', 'gosh', 'param', 'param_client', 'util', public_include])
|
||||
|
||||
|
||||
def gs_dist(ctx):
|
||||
ctx.add_default_files(source_module=True)
|
Reference in New Issue
Block a user