1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2025-02-17 19:19:16 +01:00

eamio-icca: add config to allow port to be set

also fixes issue where no logging would show up in eamiotest
This commit is contained in:
Will Xyen 2021-03-09 23:43:12 -08:00 committed by b775d4b79856d2b538f34c4bd2ef68af9d144fff
parent 089253a537
commit fb3d2ea312
6 changed files with 120 additions and 2 deletions

View File

@ -18,6 +18,7 @@ struct aciomgr_port_dispatcher {
struct aciodrv_device_ctx *device;
char path[MAX_PORT_PATH_LENGTH];
int baud;
bool has_failure;
};
static void _aciomgr_setup_port_dispatcher(
@ -41,6 +42,13 @@ static void _aciomgr_setup_port_dispatcher(
dispatcher->baud = baud;
dispatcher->device = aciodrv_device_open_path(path, baud);
dispatcher->has_failure = false;
if (dispatcher->device == NULL) {
log_info("Opening ACIO device on %s failed", path);
dispatcher->has_failure = true;
}
dispatcher->references = 0;
}
@ -119,9 +127,16 @@ struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud)
_aciomgr_setup_port_dispatcher(entry, path, baud);
done:
entry->references++;
if (!entry->has_failure) {
entry->references++;
}
LeaveCriticalSection(&mgr_cs);
if (entry->has_failure) {
return NULL;
}
return entry;
}

View File

@ -4,7 +4,9 @@ dlls += \
libs_eamio-icca := \
aciodrv \
aciomgr \
cconfig \
util \
src_eamio-icca := \
config-icc.c \
eamio-icca.c \

View File

@ -0,0 +1,55 @@
#include "cconfig/cconfig-util.h"
#include "eamio-icca/config-icc.h"
#include "util/log.h"
#define EAMIO_ICCA_CONFIG_ICC_PORT_KEY "bio2.port"
#define EAMIO_ICCA_CONFIG_ICC_BAUD_KEY "bio2.baud"
#define EAMIO_ICCA_CONFIG_ICC_DEFAULT_PORT_VALUE "COM1"
#define EAMIO_ICCA_CONFIG_ICC_DEFAULT_BAUD_VALUE 57600
void eamio_icca_config_icc_init(struct cconfig *config)
{
cconfig_util_set_str(
config,
EAMIO_ICCA_CONFIG_ICC_PORT_KEY,
EAMIO_ICCA_CONFIG_ICC_DEFAULT_PORT_VALUE,
"ICCA serial port");
cconfig_util_set_int(
config,
EAMIO_ICCA_CONFIG_ICC_BAUD_KEY,
EAMIO_ICCA_CONFIG_ICC_DEFAULT_BAUD_VALUE,
"ICCA bus baudrate (real devices expect 57600)");
}
void eamio_icca_config_icc_get(
struct icc_config *config_icc, struct cconfig *config)
{
if (!cconfig_util_get_str(
config,
EAMIO_ICCA_CONFIG_ICC_PORT_KEY,
config_icc->port,
sizeof(config_icc->port) - 1,
EAMIO_ICCA_CONFIG_ICC_DEFAULT_PORT_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
EAMIO_ICCA_CONFIG_ICC_PORT_KEY,
EAMIO_ICCA_CONFIG_ICC_DEFAULT_PORT_VALUE);
}
if (!cconfig_util_get_int(
config,
EAMIO_ICCA_CONFIG_ICC_BAUD_KEY,
&config_icc->baud,
EAMIO_ICCA_CONFIG_ICC_DEFAULT_BAUD_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
EAMIO_ICCA_CONFIG_ICC_BAUD_KEY,
EAMIO_ICCA_CONFIG_ICC_DEFAULT_BAUD_VALUE);
}
}

View File

@ -0,0 +1,18 @@
#ifndef EAMIO_ICCA_CONFIG_ICC_H
#define EAMIO_ICCA_CONFIG_ICC_H
#include <windows.h>
#include "cconfig/cconfig.h"
struct icc_config {
char port[64];
int32_t baud;
};
void eamio_icca_config_icc_init(struct cconfig *config);
void eamio_icca_config_icc_get(
struct icc_config *config_icc, struct cconfig *config);
#endif

View File

@ -13,6 +13,9 @@
#include "bemanitools/eamio.h"
#include "cconfig/cconfig-main.h"
#include "eamio-icca/config-icc.h"
#include "util/log.h"
#define NUMBER_OF_EMULATED_READERS 2
@ -73,7 +76,30 @@ static bool check_if_icca(int node_id) {
bool eam_io_init(
thread_create_t create, thread_join_t join, thread_destroy_t destroy)
{
acio_manager_ctx = aciomgr_port_init("COM1", 57600);
struct cconfig *config;
struct icc_config config_icc;
config = cconfig_init();
eamio_icca_config_icc_init(config);
if (!cconfig_main_config_init(
config,
"--icc-config",
"eamio-icc.conf",
"--help",
"-h",
"eamio-icca",
CCONFIG_CMD_USAGE_OUT_STDOUT)) {
cconfig_finit(config);
exit(EXIT_FAILURE);
}
eamio_icca_config_icc_get(&config_icc, config);
cconfig_finit(config);
acio_manager_ctx = aciomgr_port_init(config_icc.port, config_icc.baud);
if (acio_manager_ctx == NULL) {
log_warning("Opening acio device on COM1 failed");

View File

@ -15,6 +15,8 @@
*/
int main(int argc, char **argv)
{
log_to_writer(log_writer_stdout, NULL);
eam_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);