Add and debug config module, surgard prototype
This commit is contained in:
		
							parent
							
								
									24672363c4
								
							
						
					
					
						commit
						3f836d2ded
					
				|  | @ -4,4 +4,4 @@ build/ | ||||||
| *.rar | *.rar | ||||||
| *.gz | *.gz | ||||||
| *.bz2 | *.bz2 | ||||||
| *.vgcore | vgcore.* | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								cStuff
								
								
								
								
							
							
								
								
								
								
								
								
							
						
						
									
										2
									
								
								cStuff
								
								
								
								
							|  | @ -1 +1 @@ | ||||||
| Subproject commit 17ce2c5753c5512f7acf5aac0d15b9587be79b7f | Subproject commit 2f5c10cf5dc8f351b08936d6136e52b4b1784c82 | ||||||
|  | @ -1,3 +1,3 @@ | ||||||
| agent: | agent: | ||||||
| 	surgard-1 = surgard-serial:///dev/ttyUSB0/?speed=9600 | 	jaga-1 = surgard:///dev/ttyUSB0/?speed=9600 | ||||||
| 	osm-1 = osm://127.0.0.1/ | 	osm-1 = osm://127.0.0.1/ | ||||||
|  |  | ||||||
|  | @ -25,13 +25,16 @@ PROJECT_VERSION_LABEL = 0 | ||||||
| 
 | 
 | ||||||
| PROJECT_SOURCES := \
 | PROJECT_SOURCES := \
 | ||||||
|   $(SRC_DIR)/main.c \
 |   $(SRC_DIR)/main.c \
 | ||||||
|  |   $(SRC_DIR)/config.c \
 | ||||||
|   $(SRC_DIR)/observer.c \
 |   $(SRC_DIR)/observer.c \
 | ||||||
|   $(SRC_DIR)/agent.c \
 |   $(SRC_DIR)/agent.c \
 | ||||||
|  |   $(SRC_DIR)/surgard.c \
 | ||||||
|   \
 |   \
 | ||||||
|   $(CSTUFF_DIR)/log.c \
 |   $(CSTUFF_DIR)/log.c \
 | ||||||
|   $(CSTUFF_DIR)/string.c \
 |   $(CSTUFF_DIR)/string.c \
 | ||||||
|   $(CSTUFF_DIR)/list.c \
 |   $(CSTUFF_DIR)/list.c \
 | ||||||
|   $(CSTUFF_DIR)/file.c \
 |   $(CSTUFF_DIR)/file.c \
 | ||||||
|  |   $(CSTUFF_DIR)/config.c \
 | ||||||
|   \
 |   \
 | ||||||
|   $(SDK_DIR)/components/query.c \
 |   $(SDK_DIR)/components/query.c \
 | ||||||
|   $(SDK_DIR)/components/quick.c \
 |   $(SDK_DIR)/components/quick.c \
 | ||||||
|  |  | ||||||
|  | @ -13,6 +13,7 @@ | ||||||
|  * @see https://lowenware.com/
 |  * @see https://lowenware.com/
 | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | #include "surgard.h" | ||||||
| #include "agent.h" | #include "agent.h" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -33,11 +34,11 @@ agent_release(void) | ||||||
| int | int | ||||||
| agent_run_cycle(void) | agent_run_cycle(void) | ||||||
| { | { | ||||||
| 	int result = 0, rc; | 	int result = 1, rc; | ||||||
| 
 | 
 | ||||||
| 	if ((rc = surgard_run_cycle())) { | 	if (!(rc = surgard_run_cycle())) { | ||||||
| 		result = rc; | 		result = rc; | ||||||
| 	} | 	} | ||||||
| : | 
 | ||||||
| 	return 1; | 	return result; | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										34
									
								
								src/config.c
								
								
								
								
							
							
						
						
									
										34
									
								
								src/config.c
								
								
								
								
							|  | @ -14,11 +14,45 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <cStuff/config.h> | #include <cStuff/config.h> | ||||||
|  | #include "log.h" | ||||||
| #include "config.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 | int | ||||||
| config_read(void) | 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; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -16,6 +16,10 @@ | ||||||
| #ifndef CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA | #ifndef CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA | ||||||
| #define 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 */ | /** Default HTTP server port */ | ||||||
| #ifndef CONFIG_HTTP_PORT | #ifndef CONFIG_HTTP_PORT | ||||||
| #define CONFIG_HTTP_PORT 8080 | #define CONFIG_HTTP_PORT 8080 | ||||||
|  |  | ||||||
|  | @ -106,6 +106,9 @@ main(int argc, char **argv) | ||||||
| 
 | 
 | ||||||
| 	LOG_STATE("working directory: `%s`", getcwd(cwd, sizeof(cwd))); | 	LOG_STATE("working directory: `%s`", getcwd(cwd, sizeof(cwd))); | ||||||
| 
 | 
 | ||||||
|  | 	if (config_read()) | ||||||
|  | 		return -1; | ||||||
|  | 
 | ||||||
| 	/* Initialize instance */ | 	/* Initialize instance */ | ||||||
| 	if ((aisl = aisl_new(&m_cfg)) != NULL) { | 	if ((aisl = aisl_new(&m_cfg)) != NULL) { | ||||||
| 		if (observer_init() == 0) { | 		if (observer_init() == 0) { | ||||||
|  |  | ||||||
|  | @ -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; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @ -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…
	
		Reference in New Issue