mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
changed documentation style for single lines
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@62 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
d3723022ac
commit
1635e5b192
8 changed files with 65 additions and 58 deletions
|
@ -13,27 +13,25 @@
|
|||
struct node;
|
||||
struct path;
|
||||
|
||||
/// Global configuration
|
||||
/** Global configuration */
|
||||
struct config {
|
||||
/// Name of this node
|
||||
/** Name of this node */
|
||||
const char *name;
|
||||
/// Configuration filename
|
||||
/** Configuration filename */
|
||||
const char *filename;
|
||||
/// Verbosity level
|
||||
int debug;
|
||||
/// Task priority (lower is better)
|
||||
/** Task priority (lower is better) */
|
||||
int priority;
|
||||
/// Core affinity of this task
|
||||
/** Core affinity of this task */
|
||||
int affinity;
|
||||
/// Protocol version of UDP packages
|
||||
/** Protocol version of UDP packages */
|
||||
int protocol;
|
||||
/// Number of parsed paths
|
||||
int path_count;
|
||||
/// Number of parsed nodes
|
||||
int node_count;
|
||||
|
||||
/// libconfig object
|
||||
config_t obj;
|
||||
/** A libconfig object pointing to the root of the config file */
|
||||
config_setting_t *cfg;
|
||||
|
||||
/// Array of nodes
|
||||
struct node *nodes;
|
||||
|
@ -45,6 +43,9 @@ struct config {
|
|||
*
|
||||
* @param c A libconfig object
|
||||
* @param g The global configuration structure (also contains the config filename)
|
||||
* @return
|
||||
* - 0 on success
|
||||
* - otherwise an error occured
|
||||
*/
|
||||
int config_parse(config_t *c, struct config *g);
|
||||
|
||||
|
|
|
@ -10,19 +10,19 @@
|
|||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
/// The version number of the s2ss server
|
||||
/** The version number of the s2ss server */
|
||||
#define VERSION __GIT_TAG__ "-" __GIT_REV__
|
||||
|
||||
/// Maximum number of double values in a struct msg
|
||||
/** Maximum number of double values in a struct msg */
|
||||
#define MAX_VALUES 6
|
||||
|
||||
/// Maximum number of registrable hook functions per path
|
||||
/** Maximum number of registrable hook functions per path */
|
||||
#define MAX_HOOKS 5
|
||||
|
||||
/// Size of the stack which gets prefaulted during initialization
|
||||
/** Size of the stack which gets prefaulted during initialization */
|
||||
#define MAX_SAFE_STACK (16*1024) /* 16 KiB */
|
||||
|
||||
/// Socket priority
|
||||
/** Socket priority */
|
||||
#define SOCKET_PRIO 7
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
*/
|
||||
struct msg
|
||||
{
|
||||
/// Sender device ID
|
||||
/** Sender device ID */
|
||||
uint16_t device;
|
||||
/// Message ID
|
||||
/** Message ID */
|
||||
uint32_t sequence;
|
||||
/// Message length (data only)
|
||||
/** Message length (data only) */
|
||||
uint16_t length;
|
||||
/// Message data
|
||||
/** Message data */
|
||||
double data[MAX_VALUES];
|
||||
} __attribute__((packed));
|
||||
#elif PROTOCOL == 1
|
||||
|
@ -41,21 +41,21 @@ struct msg
|
|||
{
|
||||
struct
|
||||
{
|
||||
/// Protocol version
|
||||
/** Protocol version */
|
||||
unsigned version : 4;
|
||||
/// Header length
|
||||
/** Header length */
|
||||
unsigned hdr_len : 4;
|
||||
/// Message flags
|
||||
/** Message flags */
|
||||
uint8_t flags;
|
||||
/// Sender device ID
|
||||
/** Sender device ID */
|
||||
uint16_t dev_id;
|
||||
/// Message ID
|
||||
/** Message ID */
|
||||
uint32_t sequence;
|
||||
/// Message length (data only)
|
||||
/** Message length (data only) */
|
||||
uint16_t data_len;
|
||||
/// Digital signature for authentication
|
||||
/** Digital signature for authentication */
|
||||
uint32_t signature;
|
||||
/// Timestamp in uS since unix epoch
|
||||
/** Timestamp in uS since unix epoch */
|
||||
uint64_t timestamp
|
||||
} header;
|
||||
union
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
/** The type of a node.
|
||||
*
|
||||
|
@ -37,26 +38,29 @@ enum node_type
|
|||
*/
|
||||
struct node
|
||||
{
|
||||
/// The socket descriptor
|
||||
/** The socket descriptor */
|
||||
int sd;
|
||||
|
||||
/// The type of this node
|
||||
/** The type of this node */
|
||||
enum node_type type;
|
||||
|
||||
/// Local address of the socket
|
||||
/** Local address of the socket */
|
||||
struct sockaddr_in local;
|
||||
/// Remote address of the socket
|
||||
/** Remote address of the socket */
|
||||
struct sockaddr_in remote;
|
||||
|
||||
/// Name of the local interface
|
||||
/** Name of the local interface */
|
||||
const char *ifname;
|
||||
/// Index of the local interface
|
||||
/** Index of the local interface */
|
||||
int ifindex;
|
||||
/// Socket Mark
|
||||
int mark;
|
||||
|
||||
/// A short identifier of the node
|
||||
/** A short identifier of the node */
|
||||
const char *name;
|
||||
|
||||
/** A pointer to the libconfig object which instantiated this node */
|
||||
config_setting_t *cfg;
|
||||
};
|
||||
|
||||
/** Create a new node.
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define _PATH_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "node.h"
|
||||
|
@ -20,9 +21,9 @@
|
|||
*/
|
||||
struct path
|
||||
{
|
||||
/// Pointer to the incoming node
|
||||
/** Pointer to the incoming node */
|
||||
struct node *in;
|
||||
/// Pointer to the outgoing node
|
||||
/** Pointer to the outgoing node */
|
||||
struct node *out;
|
||||
|
||||
/** If non NULL this function is called for every received message.
|
||||
|
@ -32,20 +33,19 @@ struct path
|
|||
*/
|
||||
int (*hook)(struct msg *m);
|
||||
|
||||
/// Counter for received messages
|
||||
/** Counter for received messages */
|
||||
unsigned int received;
|
||||
|
||||
/// Counter for messages which arrived reordered
|
||||
/** Counter for messages which arrived reordered */
|
||||
unsigned int delayed;
|
||||
|
||||
/// Counter for messages which arrived multiple times
|
||||
/** Counter for messages which arrived multiple times */
|
||||
unsigned int duplicated;
|
||||
|
||||
/// Last known message number
|
||||
/** Last known message number */
|
||||
unsigned int sequence;
|
||||
|
||||
/// The thread for this path
|
||||
/** The thread for this path */
|
||||
pthread_t tid;
|
||||
/** A pointer to the libconfig object which instantiated this path */
|
||||
config_setting_t *cfg;
|
||||
};
|
||||
|
||||
/** Setup a new path.
|
||||
|
|
|
@ -17,7 +17,7 @@ struct config;
|
|||
struct sockaddr_in;
|
||||
struct sockaddr;
|
||||
|
||||
/// The log level which is passed as first argument to print()
|
||||
/** The log level which is passed as first argument to print() */
|
||||
enum log_level
|
||||
{
|
||||
DEBUG,
|
||||
|
@ -69,7 +69,7 @@ void init_realtime(struct config *g);
|
|||
*/
|
||||
int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b);
|
||||
|
||||
/// Check assertion and exit if failed.
|
||||
/** Check assertion and exit if failed. */
|
||||
#define assert(exp) do { \
|
||||
if (!(exp)) { \
|
||||
print(ERROR, "Assertion failed: '%s' in %s, %s:%d", \
|
||||
|
@ -77,36 +77,36 @@ int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b);
|
|||
exit(EXIT_FAILURE); \
|
||||
} } while (0)
|
||||
|
||||
/// Printf alike debug message with level.
|
||||
/** Printf alike debug message with level. */
|
||||
#define debug(lvl, msg, ...) do { \
|
||||
if (lvl <= V) \
|
||||
print(DEBUG, msg, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/// Printf alike info message.
|
||||
/** Printf alike info message. */
|
||||
#define info(msg, ...) do { \
|
||||
print(INFO, msg, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/// Printf alike warning message.
|
||||
/** Printf alike warning message. */
|
||||
#define warn(msg, ...) do { \
|
||||
print(WARN, msg, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
/// Print error and exit.
|
||||
/** Print error and exit. */
|
||||
#define error(msg, ...) do { \
|
||||
print(ERROR, msg, ##__VA_ARGS__); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
|
||||
/// Print error and strerror(errno).
|
||||
/** Print error and strerror(errno). */
|
||||
#define perror(msg, ...) do { \
|
||||
print(ERROR, msg ": %s", ##__VA_ARGS__, \
|
||||
strerror(errno)); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
|
||||
/// Print configuration error and exit.
|
||||
/** Print configuration error and exit. */
|
||||
#define cerror(c, msg, ...) do { \
|
||||
print(ERROR, msg " in %s:%u", ##__VA_ARGS__, \
|
||||
config_setting_source_file(c), \
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Configuration parser
|
||||
*
|
||||
* @author Steffen Vogel <steffen.vogel@rwth-aachen.de>
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
*/
|
||||
|
||||
|
@ -76,6 +76,8 @@ int config_parse_global(config_setting_t *c, struct config *g)
|
|||
config_setting_lookup_int(c, "priority", &g->priority);
|
||||
config_setting_lookup_int(c, "protocol", &g->protocol);
|
||||
|
||||
g->cfg = c;
|
||||
|
||||
return CONFIG_TRUE;
|
||||
}
|
||||
|
||||
|
@ -112,6 +114,7 @@ int config_parse_path(config_setting_t *c, struct config *g)
|
|||
if (path_create(&g->paths[g->path_count], in, out))
|
||||
cerror(c, "Failed to parse path");
|
||||
|
||||
g->cfg = c;
|
||||
g->path_count++;
|
||||
|
||||
if (reverse) {
|
||||
|
@ -132,8 +135,7 @@ int config_parse_node(config_setting_t *c, struct config *g)
|
|||
const char *remote_str = NULL;
|
||||
const char *local_str = NULL;
|
||||
|
||||
struct sockaddr_in local;
|
||||
struct sockaddr_in remote;
|
||||
struct sockaddr_in local, remote;
|
||||
enum node_type type;
|
||||
|
||||
/* Optional settings */
|
||||
|
@ -168,5 +170,6 @@ int config_parse_node(config_setting_t *c, struct config *g)
|
|||
if (node_create(&g->nodes[g->node_count], name, type, local, remote))
|
||||
cerror(c, "Failed to parse node");
|
||||
|
||||
g->cfg = c;
|
||||
g->node_count++;
|
||||
}
|
||||
|
|
|
@ -20,9 +20,8 @@
|
|||
#include "path.h"
|
||||
#include "node.h"
|
||||
|
||||
/// Global default settings
|
||||
struct config config = {
|
||||
.debug = 0,
|
||||
/** Default settings */
|
||||
static struct config config = {
|
||||
.priority = 0,
|
||||
.affinity = 0xC0,
|
||||
.protocol = 0
|
||||
|
|
Loading…
Add table
Reference in a new issue