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-16 22:06:21 +00:00
committed by Will Xyen
parent 47336855d6
commit a2d396f470
6 changed files with 120 additions and 2 deletions
+16 -1
View File
@@ -18,6 +18,7 @@ struct aciomgr_port_dispatcher {
struct aciodrv_device_ctx *device; struct aciodrv_device_ctx *device;
char path[MAX_PORT_PATH_LENGTH]; char path[MAX_PORT_PATH_LENGTH];
int baud; int baud;
bool has_failure;
}; };
static void _aciomgr_setup_port_dispatcher( static void _aciomgr_setup_port_dispatcher(
@@ -41,6 +42,13 @@ static void _aciomgr_setup_port_dispatcher(
dispatcher->baud = baud; dispatcher->baud = baud;
dispatcher->device = aciodrv_device_open_path(path, 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; 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); _aciomgr_setup_port_dispatcher(entry, path, baud);
done: done:
entry->references++; if (!entry->has_failure) {
entry->references++;
}
LeaveCriticalSection(&mgr_cs); LeaveCriticalSection(&mgr_cs);
if (entry->has_failure) {
return NULL;
}
return entry; return entry;
} }
+2
View File
@@ -4,7 +4,9 @@ dlls += \
libs_eamio-icca := \ libs_eamio-icca := \
aciodrv \ aciodrv \
aciomgr \ aciomgr \
cconfig \
util \ util \
src_eamio-icca := \ src_eamio-icca := \
config-icc.c \
eamio-icca.c \ eamio-icca.c \
+55
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);
}
}
+18
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
+27 -1
View File
@@ -13,6 +13,9 @@
#include "bemanitools/eamio.h" #include "bemanitools/eamio.h"
#include "cconfig/cconfig-main.h"
#include "eamio-icca/config-icc.h"
#include "util/log.h" #include "util/log.h"
#define NUMBER_OF_EMULATED_READERS 2 #define NUMBER_OF_EMULATED_READERS 2
@@ -73,7 +76,30 @@ static bool check_if_icca(int node_id) {
bool eam_io_init( bool eam_io_init(
thread_create_t create, thread_join_t join, thread_destroy_t destroy) 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) { if (acio_manager_ctx == NULL) {
log_warning("Opening acio device on COM1 failed"); log_warning("Opening acio device on COM1 failed");
+2
View File
@@ -15,6 +15,8 @@
*/ */
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
log_to_writer(log_writer_stdout, NULL);
eam_io_set_loggers( eam_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal); log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);