mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2026-08-22 08:24:02 -05:00
refact(ddrio-p3io): Support new config api
Summary: Test Plan:
This commit is contained in:
@@ -2,16 +2,17 @@ dlls += ddrio-p3io
|
||||
|
||||
ldflags_ddrio-p3io:= \
|
||||
-lsetupapi \
|
||||
-lws2_32 \
|
||||
|
||||
libs_ddrio-p3io := \
|
||||
core \
|
||||
cconfig \
|
||||
extio \
|
||||
extiodrv \
|
||||
p3io \
|
||||
p3iodrv \
|
||||
util \
|
||||
iface-core \
|
||||
security \
|
||||
|
||||
src_ddrio-p3io := \
|
||||
config.c \
|
||||
|
||||
@@ -1,35 +1,32 @@
|
||||
#include "cconfig/cconfig-util.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "core/config-ext.h"
|
||||
|
||||
#include "ddrio-p3io/config.h"
|
||||
|
||||
#include "iface-core/log.h"
|
||||
|
||||
#define DDRIO_P3IO_CONFIG_EXTIO_PORT_KEY "ddrio.p3io.extio_port"
|
||||
|
||||
#define DDRIO_P3IO_CONFIG_EXTIO_PORT_VALUE "COM1"
|
||||
|
||||
void ddrio_p3io_config_init(struct cconfig *config)
|
||||
static void _ddrio_p3io_config_verify(const ddrio_p3io_config_t *config_ddrio_p3io)
|
||||
{
|
||||
cconfig_util_set_str(
|
||||
config,
|
||||
DDRIO_P3IO_CONFIG_EXTIO_PORT_KEY,
|
||||
DDRIO_P3IO_CONFIG_EXTIO_PORT_VALUE,
|
||||
"COM port the EXTIO is connected to, default COM1");
|
||||
}
|
||||
char *num_part;
|
||||
int num;
|
||||
|
||||
void ddrio_p3io_config_get(
|
||||
struct ddrio_p3io_config *config_ddrio_p3io, struct cconfig *config)
|
||||
{
|
||||
if (!cconfig_util_get_str(
|
||||
config,
|
||||
DDRIO_P3IO_CONFIG_EXTIO_PORT_KEY,
|
||||
config_ddrio_p3io->extio_port,
|
||||
sizeof(config_ddrio_p3io->extio_port) - 1,
|
||||
DDRIO_P3IO_CONFIG_EXTIO_PORT_VALUE)) {
|
||||
log_warning(
|
||||
"Invalid value for key '%s' specified, fallback "
|
||||
"to default '%s'",
|
||||
DDRIO_P3IO_CONFIG_EXTIO_PORT_KEY,
|
||||
DDRIO_P3IO_CONFIG_EXTIO_PORT_VALUE);
|
||||
if (strncmp(config_ddrio_p3io->extio_port, "COM", 3) != 0) {
|
||||
log_fatal("Invalid COM port string: %s", config_ddrio_p3io->extio_port);
|
||||
}
|
||||
|
||||
num_part = ((char*) config_ddrio_p3io->extio_port) + 3;
|
||||
|
||||
num = atoi(num_part);
|
||||
|
||||
if (num < 1 || num > 99) {
|
||||
log_fatal("Invalid COM port number in string: %s", config_ddrio_p3io->extio_port);
|
||||
}
|
||||
}
|
||||
|
||||
void ddrio_p3io_config_get(const bt_core_config_t *config, ddrio_p3io_config_t *config_ddrio_p3io)
|
||||
{
|
||||
bt_core_config_ext_str_get(config, "extio_port", config_ddrio_p3io->extio_port, sizeof(config_ddrio_p3io->extio_port));
|
||||
|
||||
_ddrio_p3io_config_verify(config_ddrio_p3io);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
#ifndef DDRIO_P3IO_CONFIG_H
|
||||
#define DDRIO_P3IO_CONFIG_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "api/core/config.h"
|
||||
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
struct ddrio_p3io_config {
|
||||
typedef struct ddrio_p3io_config {
|
||||
char extio_port[12];
|
||||
};
|
||||
} ddrio_p3io_config_t;
|
||||
|
||||
void ddrio_p3io_config_init(struct cconfig *config);
|
||||
|
||||
void ddrio_p3io_config_get(
|
||||
struct ddrio_p3io_config *config_ddrio_p3io, struct cconfig *config);
|
||||
void ddrio_p3io_config_get(const bt_core_config_t *config, ddrio_p3io_config_t *config_ddrio_p3io);
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,9 @@ LIBRARY ddrio-p3io
|
||||
|
||||
EXPORTS
|
||||
; Bemanitools 6 API
|
||||
bt_module_core_config_api_set
|
||||
bt_module_core_log_api_set
|
||||
bt_module_configure_do
|
||||
bt_module_io_ddr_api_get
|
||||
|
||||
; Direct API
|
||||
|
||||
@@ -6,22 +6,22 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cconfig/cconfig-main.h"
|
||||
|
||||
#include "ddrio-p3io/config.h"
|
||||
|
||||
#include "extiodrv/device.h"
|
||||
#include "extiodrv/extio.h"
|
||||
|
||||
#include "iface-core/config.h"
|
||||
#include "iface-core/log.h"
|
||||
|
||||
#include "p3iodrv/ddr.h"
|
||||
#include "p3iodrv/device.h"
|
||||
|
||||
#include "sdk/module/configure.h"
|
||||
#include "sdk/module/core/log.h"
|
||||
#include "sdk/module/io/ddr.h"
|
||||
|
||||
static struct ddrio_p3io_config _ddr_io_p3io_config;
|
||||
static ddrio_p3io_config_t _ddr_io_p3io_config;
|
||||
static HANDLE _ddr_io_p3io_handle;
|
||||
static HANDLE _ddr_io_extio_handle;
|
||||
|
||||
@@ -249,37 +249,10 @@ static HRESULT _ddr_io_flush_and_reset(HANDLE p3io_handle, HANDLE extio_handle)
|
||||
return hr;
|
||||
}
|
||||
|
||||
static void _ddr_io_config_init(struct ddrio_p3io_config *config_ddrio_p3io)
|
||||
{
|
||||
struct cconfig *config;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
ddrio_p3io_config_init(config);
|
||||
|
||||
if (!cconfig_main_config_init(
|
||||
config,
|
||||
"--ddrio-p3io-config",
|
||||
"ddrio-p3io.conf",
|
||||
"--help",
|
||||
"-h",
|
||||
"ddrio-p3io",
|
||||
CCONFIG_CMD_USAGE_OUT_STDOUT)) {
|
||||
cconfig_finit(config);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ddrio_p3io_config_get(config_ddrio_p3io, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
bool bt_io_ddr_init()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
_ddr_io_config_init(&_ddr_io_p3io_config);
|
||||
|
||||
hr = _ddr_io_p3io_init(&_ddr_io_p3io_handle);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
@@ -420,11 +393,23 @@ void bt_io_ddr_fini(void)
|
||||
}
|
||||
}
|
||||
|
||||
void bt_module_core_config_api_set(const bt_core_config_api_t *api)
|
||||
{
|
||||
bt_core_config_api_set(api);
|
||||
}
|
||||
|
||||
void bt_module_core_log_api_set(const bt_core_log_api_t *api)
|
||||
{
|
||||
bt_core_log_api_set(api);
|
||||
}
|
||||
|
||||
bool bt_module_configure_do(const bt_core_config_t *config)
|
||||
{
|
||||
ddrio_p3io_config_get(config, &_ddr_io_p3io_config);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void bt_module_io_ddr_api_get(bt_io_ddr_api_t *api)
|
||||
{
|
||||
api->version = 1;
|
||||
|
||||
Reference in New Issue
Block a user