Browse Source

Add submodules and project sceleton

master
Ilja Kartašov 3 years ago
parent
commit
06a69f0edd
  1. 7
      .gitignore
  2. 6
      .gitmodules
  3. 77
      Makefile
  4. 1
      cStuff
  5. 3
      data/arcd.config
  6. 77
      project.mk
  7. 1
      sdk
  8. 37
      src/agent.c
  9. 31
      src/agent.h
  10. 58
      src/config.h
  11. 37
      src/end-points.h
  12. 33
      src/html.c
  13. 26
      src/html.h
  14. 26
      src/log.h
  15. 142
      src/main.c
  16. 155
      src/observer.c
  17. 34
      src/observer.h
  18. 12
      todo.txt

7
.gitignore

@ -0,0 +1,7 @@
build/
*.tar.gz
*.zip
*.rar
*.gz
*.bz2
*.vgcore

6
.gitmodules

@ -0,0 +1,6 @@
[submodule "sdk"]
path = sdk
url = git@lowenware.com:lowenware/aisl-sdk.git
[submodule "cStuff"]
path = cStuff
url = git@lowenware.com:lowenware/cStuff.git

77
Makefile

@ -0,0 +1,77 @@
#
# Makefile
# Ilja Kartašov, 2019-03-02 17:32
#
.POSIX:
# Project directories
SRC_DIR ?= src
SDK_DIR ?= sdk
CSTUFF_DIR ?= cStuff
OUT_DIR ?= ./build
# Project definition
include project.mk
# CFLAGS
CFLAGS := \
$(PROJECT_INCLUDES) \
-std=c99 \
-pedantic \
-Wall \
-Wmissing-prototypes \
-Wstrict-prototypes \
-Wold-style-definition \
-O2 \
-s \
-fvisibility=hidden \
-DVERSION_MAJOR=$(PROJECT_VERSION_MAJOR) \
-DVERSION_MINOR=$(PROJECT_VERSION_MINOR) \
-DVERSION_TWEAK=$(PROJECT_VERSION_TWEAK) \
-DVERSION_LABEL=$(PROJECT_VERSION_LABEL) \
$(PROJECT_CFLAGS) \
$(CFLAGS) \
LDFLAGS := \
$(PROJECT_LIBRARIES) \
$(LDFLAGS) \
$(PROJECT_LDFLAGS) \
SOURCE_LIST := $(wildcard $(PROJECT_SOURCES))
OBJECT_FILES := $(addprefix $(OUT_DIR)/o_, ${SOURCE_LIST:.c=.o})
project: dirs $(OBJECT_FILES)
$(info linking target: $@)
@$(CC) -o $(OUT_DIR)/$(PROJECT_NAME) $(OBJECT_FILES) $(LDFLAGS)
$(info done: $@)
build/o_%.o: %.c
$(info compiling file: $<)
@$(CC) $(CFLAGS) -c $< -o $@
dirs:
$(info preparing: build folders)
@mkdir -p $(OUT_DIR)/o_$(SRC_DIR)
@mkdir -p $(OUT_DIR)/o_$(CSTUFF_DIR)
@mkdir -p $(OUT_DIR)/o_$(SDK_DIR)/components
@mkdir -p $(OUT_DIR)/o_$(SDK_DIR)/mods
clean:
$(info cleaning: build files)
@rm -Rf $(OUT_DIR)
@rm -Rf ./vgcore.*
all: project
default: project
.PHONY: all dirs clean
# vim:ft=make
#

1
cStuff

@ -0,0 +1 @@
Subproject commit 4ba00ca17a6a86a9309fe8426220cc378d8f4579

3
data/arcd.config

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

77
project.mk

@ -0,0 +1,77 @@
#
# config.mk
# Löwenware Makefile Config, 2019-03-02 17:35
#
PREFIX = /usr/
PKG_CONFIG = pkg-config
PROJECT_NAME = arcd
# Version
PROJECT_VERSION_MAJOR = 1
PROJECT_VERSION_MINOR = 0
PROJECT_VERSION_TWEAK = 0
PROJECT_VERSION_LABEL = 0
# Override default paths
#SRC_DIR = src
#SDK_DIR = sdk
#OUT_DIR = ./build
# Source files
PROJECT_SOURCES := \
$(SRC_DIR)/main.c \
$(SRC_DIR)/observer.c \
$(SRC_DIR)/agent.c \
\
$(CSTUFF_DIR)/log.c \
$(CSTUFF_DIR)/string.c \
$(CSTUFF_DIR)/list.c \
$(CSTUFF_DIR)/file.c \
\
$(SDK_DIR)/components/query.c \
$(SDK_DIR)/components/quick.c \
$(SDK_DIR)/components/validate.c \
$(SDK_DIR)/components/mail.c \
$(SDK_DIR)/components/log.c \
$(SDK_DIR)/components/todo.c \
\
$(SDK_DIR)/mods/context.c \
$(SDK_DIR)/mods/module.c \
# includes
PROJECT_INCLUDES = \
-I./ \
-I./$(SDK_DIR) \
`$(PKG_CONFIG) --cflags libaisl` \
`$(PKG_CONFIG) --cflags libcurl` \
`$(PKG_CONFIG) --cflags uuid` \
# libraries
PROJECT_LIBRARIES = \
`$(PKG_CONFIG) --libs libaisl` \
`$(PKG_CONFIG) --libs libcurl` \
`$(PKG_CONFIG) --libs uuid` \
-lpthread \
# compilation macro options:
# flags
PROJECT_CFLAGS = -D_POSIX_C_SOURCE=200809L
PROJECT_CFLAGS += -D_ISOC99_SOURCE
PROJECT_CFLAGS += -D_XOPEN_SOURCE=500
PROJECT_CFLAGS += -D_GNU_SOURCE
# PROJECT_CFLAGS += -DDEBUG
# PROJECT_LDFLAGS = -L
# vim:ft=make
#

1
sdk

@ -0,0 +1 @@
Subproject commit e00ffe6f708f1460ca1d2b00d94c739ebb2cb184

37
src/agent.c

@ -0,0 +1,37 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file agent.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#include "agent.h"
int
agent_init(void)
{
return 0;
}
void
agent_release(void)
{
}
int
agent_run_cycle(void)
{
return 1;
}

31
src/agent.h

@ -0,0 +1,31 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file agent.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#ifndef AGENT_H_D0CDB429_AC49_4BC6_83FA_9163404D387E
#define AGENT_H_D0CDB429_AC49_4BC6_83FA_9163404D387E
int
agent_init(void);
void
agent_release(void);
int
agent_run_cycle(void);
#endif /* !AGENT_H */

58
src/config.h

@ -0,0 +1,58 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file config.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#ifndef CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA
#define CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA
/** Default HTTP server port */
#ifndef CONFIG_HTTP_PORT
#define CONFIG_HTTP_PORT 8080
#endif
#ifndef CONFIG_LOG_TARGET
#define CONFIG_LOG_TARGET "output.log"
#endif
#ifndef CONFIG_SMTP_SERVER
#define CONFIG_SMTP_SERVER "mx.lowenware.com"
#endif
#ifndef CONFIG_SMTP_PORT
#define CONFIG_SMTP_PORT 465
#endif
#ifndef CONFIG_SMTP_USER
#define CONFIG_SMTP_USER "robot@lowenware.com"
#endif
#ifndef CONFIG_SMTP_PASS
#define CONFIG_SMTP_PASS "3HFzxiQYY9QJ6LN3" /* +){xA8}(mNF43B(~" */
#endif
#ifndef CONFIG_MAIL_FROM
#define CONFIG_MAIL_FROM CONFIG_SMTP_USER
#endif
#ifndef CONFIG_MAIL_TO
#define CONFIG_MAIL_TO "ik@lowenware.com"
#endif
#ifndef CONFIG_MAIL_SUBJECT
#define CONFIG_MAIL_SUBJECT "Feedback from website"
#endif
#endif /* !CONFIG_H */

37
src/end-points.h

@ -0,0 +1,37 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file end-points.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief Header-file only module with end-points URI macroses
*
* @see https://lowenware.com/
*/
#ifndef END_POINTS_H_406472C7_FC75_41D5_8988_AA12455597EC
#define END_POINTS_H_406472C7_FC75_41D5_8988_AA12455597EC
#define ROOT_URI "/"
#define HOOK_URI "/hook/"
#define BLOG_URI "/blog/"
#define TODO_URI "/todo/"
/* Pages */
/* Blog */
/* Static */
/* ToDo */
#define TODO_END_POINT TODO_URI
/* Hooks */
#define FEEDBACK_END_POINT HOOK_URI "feedback/"
#endif /* !END_POINTS_H */

33
src/html.c

@ -0,0 +1,33 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file html.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#include "html.h"
typedef enum {
HTML_HEADER = 0,
HTML_MENU = 20,
HTML_FOOTER = 100
} HtmlSequence;
const struct html html[] = {
{7, 0, 0, "<html>\n"}
, {7, 1, 0, "<head>\n"}
, {7, 2, 0, "<title>"},
, {9, 2, 0, "</title>\n"},
, {8, 1, 0, "</head>\n"},
};

26
src/html.h

@ -0,0 +1,26 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file html.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#ifndef HTML_H_43FF7C60_6224_40DF_B3C6_6E4E18350871
#define HTML_H_43FF7C60_6224_40DF_B3C6_6E4E18350871
struct html {
uint32_t size;
uint16_t offset;
uint16_t reserve;
const char *data;
};
#endif /* !HTML_H */

26
src/log.h

@ -0,0 +1,26 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file log.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief
*
* @see https://lowenware.com/
*/
#ifndef LOG_H_33B3B660_C0F7_455F_A17D_AB4FD0C0FD2C
#define LOG_H_33B3B660_C0F7_455F_A17D_AB4FD0C0FD2C
#include <components/log.h>
#define LOG_DEBUG(...) AX_LOG_DEBUG(__VA_ARGS__)
#define LOG_STATE(...) AX_LOG_STATE(__VA_ARGS__)
#define LOG_ALERT(...) AX_LOG_ALERT(__VA_ARGS__)
#define LOG_ERROR(...) AX_LOG_ERROR(__VA_ARGS__)
#endif /* !LOG_H */

142
src/main.c

@ -0,0 +1,142 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file main.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief Lowenware.com backend main source code file
*
* @see https://lowenware.com/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <locale.h>
/* Include library meta header */
#include <aisl/aisl.h>
#include "log.h"
#include "config.h"
#include "observer.h"
#include "agent.h"
static const struct aisl_cfg_srv m_srv[] = {{
.host = "0.0.0.0",
.port = CONFIG_HTTP_PORT,
.secure = false
}};
static const struct aisl_cfg m_cfg = {
AISL_CFG_DEFAULTS
, .srv = m_srv
, .srv_cnt = sizeof (m_srv) / sizeof (m_srv[0])
, .ssl = NULL
, .ssl_cnt = 0
, .callback = observer_on_aisl_event
};
static int
process_args(int argc, char **argv)
{
int i;
char c = 0;
for (i = 1; i < argc; i++) {
switch (c) {
case 'd':
if (chdir(argv[i]) != 0) {
LOG_ERROR("Failed to set working directory `%s`: %s", argv[i],
strerror(errno));
return -1;
}
break;
default:
if (strcmp(argv[i], "-d") == 0) {
c = 'd';
} else if (strcmp(argv[i], "-h") == 0) {
printf("arcd %d.%d.%d\n\n", VERSION_MAJOR, VERSION_MINOR, VERSION_TWEAK);
printf("USAGE: arcd [ARGUMENTS]\n");
printf("ARGUMENTS:\n");
printf("\t-h - show this information\n");
printf("\t-d :dir - set custom working directory\n");
printf("\n");
exit(0);
}
continue;
}
c = 0;
}
if (c) {
LOG_ERROR("No value for -%c argument", c);
return -1;
}
return 0;
}
int
main(int argc, char **argv)
{
AislInstance aisl; /**< AISL instance pointer */
char cwd[64];
AX_LOG_INIT(CSTUFF_LOG_ALL);
if (!setlocale(LC_ALL, "C")) {
LOG_ERROR("Failed to set C locale");
return -1;
}
if (process_args(argc, argv)) {
return -1;
}
LOG_STATE("working directory: `%s`", getcwd(cwd, sizeof(cwd)));
/* Initialize instance */
if ((aisl = aisl_new(&m_cfg)) != NULL) {
if (observer_init() == 0) {
if (agent_init() == 0) {
/* launch application loop */
fprintf(stdout, "Entering main loop");
for(;;) {
int rc, do_sleep = 1;
if ((rc = aisl_run_cycle(aisl)) == AISL_SUCCESS)
do_sleep = 0;
if ((rc = agent_run_cycle()) == 0)
do_sleep = 0;
if (!do_sleep)
continue;
aisl_sleep(aisl, 500);
}
agent_release();
}
observer_release();
}
aisl_free(aisl);
} else {
fprintf(stderr, "Failed to initialize AISL");
}
AX_LOG_RELEASE();
return 0;
}

155
src/observer.c

@ -0,0 +1,155 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file observer.c
* @author Ilja Kartašov <ik@lowenware.com>
* @brief AISL event observer source code file
*
* @see https://lowenware.com/
*/
#include <string.h>
/* modules */
#include <mods/module.h>
/* commons */
#include "config.h"
#include "end-points.h"
#include "log.h"
#include "observer.h"
/* static struct ax_feedback m_feedback = {0}; */
AislStatus
observer_init(void)
{
AislStatus result = AISL_SUCCESS;
/* struct ax_feedback_cfg feedback_cfg; */
/*
memset(&feedback_cfg, 0, sizeof(struct ax_feedback_cfg));
feedback_cfg.end_point = FEEDBACK_END_POINT;
feedback_cfg.smtp.host = CONFIG_SMTP_SERVER;
feedback_cfg.smtp.user = CONFIG_SMTP_USER;
feedback_cfg.smtp.pass = CONFIG_SMTP_PASS;
feedback_cfg.smtp.port = CONFIG_SMTP_PORT;
feedback_cfg.mail_from = CONFIG_MAIL_FROM;
feedback_cfg.mail_to = CONFIG_MAIL_TO;
feedback_cfg.mail_subject = CONFIG_MAIL_SUBJECT;
feedback_cfg.name_email = "email";
feedback_cfg.name_msg = "msg";
if ((result = ax_feedback_init(&m_feedback, &feedback_cfg)) != 0)
return result;
*/
return result;
}
void
observer_release(void)
{
/* ax_feedback_release(&m_feedback); */
}
static void
observer_on_stream_event(const struct aisl_evt *evt)
{
AxModule mods[] = { /* AX_MODULE(&m_feedback) */ NULL };
int i, c = sizeof (mods) / sizeof (mods[0]);
for (i = 0; i < c; i++) {
/* TODO: remove !!!! */
if (!mods[i])
continue;
AislStatus status = ax_module_on_event(mods[i], evt);
switch(status) {
case AISL_IDLE:
continue;
case AISL_SUCCESS:
return;
default:
LOG_ALERT("Module error: %s", aisl_status_to_string(status));
return;
}
}
}
static void
observer_on_server_event(const struct aisl_evt *evt)
{
struct sockaddr_in srv_addr;
AislServer srv = (AislServer) evt->source;
AislStatus status = evt->status;
aisl_server_get_address(srv, &srv_addr);
LOG_STATE("HTTP%s server %s:%d: %s", (aisl_server_get_ssl(srv) ? "s" : ""),
inet_ntoa(srv_addr.sin_addr), ntohs(srv_addr.sin_port),
(status ? aisl_status_to_string(status) : "ready"));
}
static void
observer_on_client_event(const struct aisl_evt *evt, const char *msg)
{
struct sockaddr_in cli_addr;
AislClient cli = (AislClient) evt->source;
aisl_client_get_address(cli, &cli_addr);
if (evt->status == AISL_IDLE)
msg = "timeout";
LOG_STATE( "HTTP%s client %s:%d: %s",
(aisl_client_is_secure(cli) ? "s" : ""),
inet_ntoa(cli_addr.sin_addr),
ntohs(cli_addr.sin_port),
msg
);
}
void
observer_on_aisl_event(const struct aisl_evt *evt, void *p_ctx)
{
switch(evt->code) {
case AISL_EVENT_SERVER_READY:
case AISL_EVENT_SERVER_ERROR:
observer_on_server_event(evt);
break;
case AISL_EVENT_CLIENT_CONNECT:
observer_on_client_event(evt, "connected");
break;
case AISL_EVENT_CLIENT_DISCONNECT:
observer_on_client_event(evt, "disconnected");
break;
case AISL_EVENT_STREAM_OPEN:
case AISL_EVENT_STREAM_HEADER:
case AISL_EVENT_STREAM_INPUT:
case AISL_EVENT_STREAM_REQUEST:
case AISL_EVENT_STREAM_OUTPUT:
case AISL_EVENT_STREAM_CLOSE:
case AISL_EVENT_STREAM_ERROR:
observer_on_stream_event(evt);
break;
}
}

34
src/observer.h

@ -0,0 +1,34 @@
/******************************************************************************
*
* Copyright (c) 2017-2019 by Löwenware Ltd
* Please, refer LICENSE file for legal information
*
******************************************************************************/
/**
* @file observer.h
* @author Ilja Kartašov <ik@lowenware.com>
* @brief AISL event observer header file
*
* @see https://lowenware.com/
*/
#ifndef OBSERVER_H_C0DE24F7_EC8D_4C89_B253_15F0BB5BF7B5
#define OBSERVER_H_C0DE24F7_EC8D_4C89_B253_15F0BB5BF7B5
#include <aisl/aisl.h>
AislStatus
observer_init(void);
void
observer_release(void);
void
observer_on_aisl_event(const struct aisl_evt *evt, void *p_ctx);
#endif /* !OBSERVER_H */

12
todo.txt

@ -0,0 +1,12 @@
Port templight to SDK
Implement authentication UI
Implement authentication modules in SDK
Implement serial surgard receiver
Implement EBS OSM receiver
Define device file format
Implement device logs
Implement ARC journal
Implement device cards
Implement routes
x Create project repository
Loading…
Cancel
Save