Browse Source

Add and debug config module, surgard prototype

master
Ilja Kartašov 2 years ago
parent
commit
3f836d2ded
10 changed files with 99 additions and 7 deletions
  1. +1
    -1
      .gitignore
  2. +1
    -1
      cStuff
  3. +1
    -1
      data/arcd.config
  4. +3
    -0
      project.mk
  5. +5
    -4
      src/agent.c
  6. +34
    -0
      src/config.c
  7. +4
    -0
      src/config.h
  8. +3
    -0
      src/main.c
  9. +25
    -0
      src/surgard.c
  10. +22
    -0
      src/surgard.h

+ 1
- 1
.gitignore View File

@@ -4,4 +4,4 @@ build/
*.rar
*.gz
*.bz2
*.vgcore
vgcore.*

+ 1
- 1
cStuff

@@ -1 +1 @@
Subproject commit 17ce2c5753c5512f7acf5aac0d15b9587be79b7f
Subproject commit 2f5c10cf5dc8f351b08936d6136e52b4b1784c82

+ 1
- 1
data/arcd.config View File

@@ -1,3 +1,3 @@
agent:
surgard-1 = surgard-serial:///dev/ttyUSB0/?speed=9600
jaga-1 = surgard:///dev/ttyUSB0/?speed=9600
osm-1 = osm://127.0.0.1/

+ 3
- 0
project.mk View File

@@ -25,13 +25,16 @@ PROJECT_VERSION_LABEL = 0

PROJECT_SOURCES := \
$(SRC_DIR)/main.c \
$(SRC_DIR)/config.c \
$(SRC_DIR)/observer.c \
$(SRC_DIR)/agent.c \
$(SRC_DIR)/surgard.c \
\
$(CSTUFF_DIR)/log.c \
$(CSTUFF_DIR)/string.c \
$(CSTUFF_DIR)/list.c \
$(CSTUFF_DIR)/file.c \
$(CSTUFF_DIR)/config.c \
\
$(SDK_DIR)/components/query.c \
$(SDK_DIR)/components/quick.c \


+ 5
- 4
src/agent.c View File

@@ -13,6 +13,7 @@
* @see https://lowenware.com/
*/

#include "surgard.h"
#include "agent.h"


@@ -33,11 +34,11 @@ agent_release(void)
int
agent_run_cycle(void)
{
int result = 0, rc;
int result = 1, rc;

if ((rc = surgard_run_cycle())) {
if (!(rc = surgard_run_cycle())) {
result = rc;
}
:
return 1;
return result;
}

+ 34
- 0
src/config.c View File

@@ -14,11 +14,45 @@
*/

#include <cStuff/config.h>
#include "log.h"
#include "config.h"


static int
config_callback(struct cstuff_config *cfg, void *u_ptr)
{
switch(cfg->evt) {
case CSTUFF_CONFIG_NODE:
LOG_STATE("node: %s(%d)", cfg->data.node.name, cfg->data.node.name_len);
return 0;
case CSTUFF_CONFIG_PAIR:
LOG_STATE("node: %s(%d)->%s(%d)", cfg->data.pair.key,
cfg->data.pair.key_len, cfg->data.pair.val,
cfg->data.pair.val_len);
return 0;
case CSTUFF_CONFIG_ERROR:
LOG_ERROR("config error at line %d:%d - %s", cfg->line_num,
cfg->data.error.char_num, cfg->data.error.err_txt);
break;
default:
LOG_ERROR("event unknown: %d", cfg->evt);
}
(void) u_ptr;
return -1;
}


int
config_read(void)
{
const char cfg_file[] = ARC_CONFIG_FILE;

if (!cstuff_config_parse(cfg_file, config_callback, NULL)) {
return 0;
}
LOG_ERROR("configuration failed");

return -1;
}


+ 4
- 0
src/config.h View File

@@ -16,6 +16,10 @@
#ifndef CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA
#define CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA

#ifndef ARC_CONFIG_FILE
#define ARC_CONFIG_FILE "data/arcd.config"
#endif

/** Default HTTP server port */
#ifndef CONFIG_HTTP_PORT
#define CONFIG_HTTP_PORT 8080


+ 3
- 0
src/main.c View File

@@ -106,6 +106,9 @@ main(int argc, char **argv)

LOG_STATE("working directory: `%s`", getcwd(cwd, sizeof(cwd)));

if (config_read())
return -1;

/* Initialize instance */
if ((aisl = aisl_new(&m_cfg)) != NULL) {
if (observer_init() == 0) {


+ 25
- 0
src/surgard.c View File

@@ -0,0 +1,25 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/

/**
* @file surgard.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/

#include "surgard.h"


int
surgard_run_cycle(void)
{
return 1;
}



+ 22
- 0
src/surgard.h View File

@@ -0,0 +1,22 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/

/**
* @file surgard.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/

#ifndef SURGARD_H_0C382373_4757_4FC1_A2DE_991F9D71CDBC
#define SURGARD_H_0C382373_4757_4FC1_A2DE_991F9D71CDBC

int
surgard_run_cycle(void);

#endif /* !SURGARD_H */

Loading…
Cancel
Save