summaryrefslogtreecommitdiff
path: root/cesar/host
diff options
context:
space:
mode:
authorThierry Carré2013-02-14 15:50:01 +0100
committerThierry Carré2013-02-22 16:43:24 +0100
commitbb3903a3a3a000b4199dcc3d3cb47083f09864fe (patch)
tree596d92663bf06659d1e25365e677bb0f0904e072 /cesar/host
parent244cfaa27e26465531c4efa652117f328cfb9d12 (diff)
cesar/host/station: remove space on eol and re-formating through vim
Diffstat (limited to 'cesar/host')
-rw-r--r--cesar/host/station/src/station.c236
-rw-r--r--cesar/host/station/station.h22
2 files changed, 129 insertions, 129 deletions
diff --git a/cesar/host/station/src/station.c b/cesar/host/station/src/station.c
index 5659c31510..f62336506b 100644
--- a/cesar/host/station/src/station.c
+++ b/cesar/host/station/src/station.c
@@ -5,7 +5,7 @@
* <<<Licence>>>
*
* }}} */
-
+
/**
* \file station.c
* \brief The station management functions
@@ -13,7 +13,7 @@
*
* This file provide station management functions
*
- * \todo
+ * \todo
*/
#include "common/std.h"
@@ -45,7 +45,7 @@ static fcall_ctx_t _my_fcall;
static probe_ctx_t _my_probe;
static system_ctx_t _my_system;
static netclock_callback_t _ecos_tick_cb;
-
+
/**
* fill buffer with the in/out pipe name for sci msg communication
* \param suffix pipe name suffix; normaly "in" or "out"
@@ -71,16 +71,16 @@ static netclock_callback_t _ecos_tick_cb;
int station_init(station_ctx_t *station)
{
#ifdef STATION_SOCK
- int sock_server_fd;
+ int sock_server_fd;
#endif /* STATION_SOCK */
-
+
DBG_ASSERT(station);
if(station == NULL)
{
errno = EINVAL;
return -1;
}
-
+
memset(station, '\0', sizeof(station_ctx_t));
#ifdef STATION_SOCK
station->sock_fd = -1;
@@ -94,7 +94,7 @@ int station_init(station_ctx_t *station)
/* get station id */
station->id = getpid();
-
+
/* set variables */
station->log_level = STATION_LOG_WARNING;
@@ -109,18 +109,18 @@ int station_init(station_ctx_t *station)
#endif
// reset errno generated by the 'unlink() function'
errno = 0;
-
+
/* open log */
if(mknod(station->pipe_log_name, 0770 | S_IFIFO, 0) < 0)
- goto failed;
+ goto failed;
if((station->pipe_log_fd = open(station->pipe_log_name, O_RDWR | O_NONBLOCK, S_IRWXU | S_IRWXG)) < 0)
goto failed;
-
+
#ifdef STATION_SOCK
/* build sock name */
sprintf(station->sock_name, "%s/%s_sock_%d", STATION_SOCK_PATH, STATION_SOCK_PREFIX, station->id);
unlink(station->sock_name);
-
+
/* create socket */
#ifdef UNIT_TEST
int sock_fd[2];
@@ -131,72 +131,72 @@ int station_init(station_ctx_t *station)
if((sock_server_fd = socket (PF_UNIX, SOCK_STREAM, 0)) < 0)
{
station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: failed to create socket (errno=%d)",
- __FUNCTION__, errno);
+ "%s: failed to create socket (errno=%d)",
+ __FUNCTION__, errno);
goto failed;
}
/* extend send buffer size */
{
- int bufsize = STATION_MAX_SOCK_BUFFER_SIZE;
- if(setsockopt (sock_server_fd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize)) < 0)
- {
+ int bufsize = STATION_MAX_SOCK_BUFFER_SIZE;
+ if(setsockopt (sock_server_fd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize)) < 0)
+ {
station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: failed to set buffer size to %d bytes (errno=%d)",
- __FUNCTION__, bufsize, errno);
+ "%s: failed to set buffer size to %d bytes (errno=%d)",
+ __FUNCTION__, bufsize, errno);
goto failed;
}
}
-
+
/* bind the socket */
{
- struct sockaddr_un sockaddr;
- sockaddr.sun_family = AF_UNIX;
- strcpy (sockaddr.sun_path, station->sock_name);
- if((bind (sock_server_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) < 0)
- {
+ struct sockaddr_un sockaddr;
+ sockaddr.sun_family = AF_UNIX;
+ strcpy (sockaddr.sun_path, station->sock_name);
+ if((bind (sock_server_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr))) < 0)
+ {
station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: bind to '%s' failed (errno=%d)",
- __FUNCTION__, station->sock_name, errno);
+ "%s: bind to '%s' failed (errno=%d)",
+ __FUNCTION__, station->sock_name, errno);
goto failed;
- }
+ }
}
#endif /* UNIT_TEST */
-#else /* STATION_SOCK */
+#else /* STATION_SOCK */
/* open in pipe */
if(mknod(station->pipe_in_name, 0770 | S_IFIFO, 0) < 0)
{
station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: failed to create fifo '%s' (errno=%d)",
- __FUNCTION__, station->pipe_in_name, errno);
+ "%s: failed to create fifo '%s' (errno=%d)",
+ __FUNCTION__, station->pipe_in_name, errno);
goto failed;
}
if((station->pipe_in_fd = open(station->pipe_in_name, O_RDWR, S_IRWXU | S_IRWXG)) < 0)
{
station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: failed to open fifo '%s' (errno=%d)",
- __FUNCTION__, station->pipe_in_name, errno);
+ "%s: failed to open fifo '%s' (errno=%d)",
+ __FUNCTION__, station->pipe_in_name, errno);
goto failed;
}
-
+
/* open out pipe */
if(mknod(station->pipe_out_name, 0770 | S_IFIFO, 0) < 0)
{
- station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: failed to create fifo '%s' (errno=%d)",
- __FUNCTION__, station->pipe_out_name, errno);
+ station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
+ "%s: failed to create fifo '%s' (errno=%d)",
+ __FUNCTION__, station->pipe_out_name, errno);
goto failed;
}
if((station->pipe_out_fd = open(station->pipe_out_name, O_RDWR, S_IRWXU | S_IRWXG)) < 0)
{
- station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: failed to open fifo '%s' (errno=%d)",
- __FUNCTION__, station->pipe_out_name, errno);
+ station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
+ "%s: failed to open fifo '%s' (errno=%d)",
+ __FUNCTION__, station->pipe_out_name, errno);
goto failed;
}
#endif /* STATION_SOCK */
-
+
/* init all contexts */
station->sci = &_my_sci;
sci_init(station->sci, station);
@@ -210,42 +210,42 @@ int station_init(station_ctx_t *station)
system_init(station->system, station->sci);
station->ecos_tick_cb = &_ecos_tick_cb;
station->status = STATION_STATUS_RUNNING;
-
+
/* init the random generator */
srand(station->id);
-
+
#if (defined STATION_SOCK) && !defined(UNIT_TEST)
/* listen and accept connection */
listen(sock_server_fd, 1);
- if((station->sock_fd = accept(sock_server_fd, NULL, NULL)) < 0)
+ if((station->sock_fd = accept(sock_server_fd, NULL, NULL)) < 0)
{
station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
- "%s: accept failed (errno=%d)",
- __FUNCTION__, errno);
+ "%s: accept failed (errno=%d)",
+ __FUNCTION__, errno);
goto failed;
}
close(sock_server_fd);
#endif /* STATION_SOCK && !UNIT_TEST */
-
+
return 0;
-
+
failed:
- if(station->pipe_log_fd >= 0)
- close(station->pipe_log_fd);
+ if(station->pipe_log_fd >= 0)
+ close(station->pipe_log_fd);
unlink(station->pipe_log_name);
station->pipe_log_fd = -1;
-#ifdef STATION_SOCK
- if(station->sock_fd >= 0)
- close(station->sock_fd);
- if(station->sock_pair_fd >= 0)
- close(station->sock_pair_fd);
- if(sock_server_fd >= 0)
- close(sock_server_fd);
+#ifdef STATION_SOCK
+ if(station->sock_fd >= 0)
+ close(station->sock_fd);
+ if(station->sock_pair_fd >= 0)
+ close(station->sock_pair_fd);
+ if(sock_server_fd >= 0)
+ close(sock_server_fd);
unlink(station->sock_name);
station->sock_fd = -1;
station->sock_pair_fd = -1;
#else /* STATION_SOCK */
- if(station->pipe_out_fd >= 0)
+ if(station->pipe_out_fd >= 0)
close(station->pipe_out_fd);
if(station->pipe_in_fd >= 0)
close(station->pipe_in_fd);
@@ -256,7 +256,7 @@ failed:
#endif /* STATION_SOCK */
station->status = STATION_STATUS_ERROR;
return -1;
-}
+}
/**
* station context to clean and reset, with pipe closing
@@ -265,18 +265,18 @@ failed:
void station_down(station_ctx_t *station)
{
if((station == NULL)
- || (station->status == STATION_STATUS_INIT))
+ || (station->status == STATION_STATUS_INIT))
return;
#ifdef STATION_SOCK
- if(station->sock_fd >= 0)
- close(station->sock_fd);
- if(station->sock_pair_fd >= 0)
- close(station->sock_pair_fd);
+ if(station->sock_fd >= 0)
+ close(station->sock_fd);
+ if(station->sock_pair_fd >= 0)
+ close(station->sock_pair_fd);
unlink(station->sock_name);
station->sock_fd = -1;
station->sock_pair_fd = -1;
-#else /* STATION_SOCK */
+#else /* STATION_SOCK */
if(station->pipe_out_fd >= 0)
close(station->pipe_out_fd);
if(station->pipe_in_fd >= 0)
@@ -291,7 +291,7 @@ void station_down(station_ctx_t *station)
unlink(station->pipe_log_name);
station->pipe_log_fd = -1;
return;
-}
+}
/**
* station is into idle state; it sends a sci 'idle' message and waits for sci message reception
@@ -308,23 +308,23 @@ int station_idle(station_ctx_t *station)
fd_set read_fds;
struct timeval timeout;
int sel;
-
+
DBG_ASSERT(station);
DBG_ASSERT(station->status != STATION_STATUS_INIT);
if((station == NULL)
- || (station->status == STATION_STATUS_INIT))
+ || (station->status == STATION_STATUS_INIT))
//|| !station_is_initialized(station))
{
errno = EINVAL;
return -1;
}
-
+
if(station->status == STATION_STATUS_RUNNING)
{
/* init msg */
if(sci_msg_init(&msg, buffer, 64) < 0)
return -1;
-
+
/* fill system header */
if (0 > sci_msg_push (&msg, sizeof (station_msg_hdr_t)))
return -1;
@@ -332,7 +332,7 @@ int station_idle(station_ctx_t *station)
msg.hdr.station->version = SYSTEM_VERSION;
msg.hdr.station->type = SYSTEM_TYPE_IDLE;
msg.hdr.station->flags = 0;
-
+
/* fill sci header and send msg */
if(sci_fill_hdr(station->sci, &msg, SCI_MSG_TYPE_SYSTEM, 0) < 0)
return -1;
@@ -341,19 +341,19 @@ int station_idle(station_ctx_t *station)
station_log(station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION, "%s failed to send system idle (errno=%d)", __FUNCTION__, errno);
return -1;
}
- station->status = STATION_STATUS_IDLE;
+ station->status = STATION_STATUS_IDLE;
}
-
+
/* don't wait for next message with unit tests */
#ifdef UNIT_TEST
return 0;
#endif
-
+
/* vait for next message with 1 second timeout */
FD_ZERO(&read_fds);
-#ifdef STATION_SOCK
+#ifdef STATION_SOCK
FD_SET(station->sock_fd, &read_fds);
-#else /* STATION_SOCK */
+#else /* STATION_SOCK */
FD_SET(station->pipe_in_fd, &read_fds);
#endif /* STATION_SOCK */
timeout.tv_sec = 1;
@@ -365,8 +365,8 @@ int station_idle(station_ctx_t *station)
return -1;
}
else if(sel > 0)
- {
- station->status = STATION_STATUS_RUNNING;
+ {
+ station->status = STATION_STATUS_RUNNING;
return sci_recv(station->sci);
}
else
@@ -382,11 +382,11 @@ static void _ecos_set_itimer_cb(void *data)
uint32_t *isr;
#ifndef UNIT_TEST
station_log(&my_station, STATION_LOG_DEBUG, STATION_LOGTYPE_STATION, "%s", __FUNCTION__);
-#endif /* UNIT_TEST */
- isr = (uint32_t *)data;
+#endif /* UNIT_TEST */
+ isr = (uint32_t *)data;
*isr |= (1 << CYGNUM_HAL_INTERRUPT_RTC);
return;
-}
+}
/**
* schedule an eCos tick event (every 10ms)
@@ -401,21 +401,21 @@ int station_ecos_set_itimer(station_ctx_t *station, tick_t tick)
DBG_ASSERT(station);
DBG_ASSERT(station->status != STATION_STATUS_INIT);
if((station == NULL)
- || (station->status == STATION_STATUS_INIT))
+ || (station->status == STATION_STATUS_INIT))
{
errno = EINVAL;
return -1;
}
-
- return netclock_schedule(station->netclock,
- station->ecos_tick_cb,
- NETWORK_CLOCK_TYPE_STATION,
- tick,
- _ecos_set_itimer_cb,
- (void *)&maximus_pending_isrs,
- &id);
-}
-
+
+ return netclock_schedule(station->netclock,
+ station->ecos_tick_cb,
+ NETWORK_CLOCK_TYPE_STATION,
+ tick,
+ _ecos_set_itimer_cb,
+ (void *)&maximus_pending_isrs,
+ &id);
+}
+
/**
* set the station log level
* \param station pointer to station context
@@ -430,14 +430,14 @@ int station_log_set_level(station_ctx_t *station, station_log_level_t level)
DBG_ASSERT(level > STATION_LOG_NONE);
DBG_ASSERT(level < STATION_LOG_NB);
if((station == NULL)
- || (station->status == STATION_STATUS_INIT)
- || (level <= STATION_LOG_NONE)
- || (level >= STATION_LOG_NB))
+ || (station->status == STATION_STATUS_INIT)
+ || (level <= STATION_LOG_NONE)
+ || (level >= STATION_LOG_NB))
{
errno = EINVAL;
return -1;
}
-
+
station->log_level = level;
return 0;
}
@@ -446,53 +446,53 @@ int station_log_set_level(station_ctx_t *station, station_log_level_t level)
* send message to station log system
* \param station pointer to station context
* \param level level of log message
- * \param format string structure describing the data log format
+ * \param format string structure describing the data log format
* \param ... suite of parameters to fit the format
*/
- void station_log(station_ctx_t *station,
- station_log_level_t level,
- unsigned long type,
- const char *format,
- ...)
+void station_log(station_ctx_t *station,
+ station_log_level_t level,
+ unsigned long type,
+ const char *format,
+ ...)
{
va_list va_args;
int hdr_len, ret = 0;
static char buffer[STATION_BUFFER_SIZE];
if((station == NULL)
- || (station->status == STATION_STATUS_INIT)
- || (format == NULL)
- || (station->system == NULL))
+ || (station->status == STATION_STATUS_INIT)
+ || (format == NULL)
+ || (station->system == NULL))
return;
- if ((level <= STATION_LOG_NONE)
+ if ((level <= STATION_LOG_NONE)
|| (level > station->log_level))
return;
-
+
if (station->pipe_log_fd < 0)
return;
-
+
if(type == 0)
type = STATION_LOGTYPE_ALL;
-
+
if(!(station->log_mask & type))
return;
-
+
/* build header and send it */
if(strlen(station->system->station_name) == 0)
{
sprintf(buffer, "sta(%d) %Lu: ",
- station->id,
- station->current_tick_tck
- );
+ station->id,
+ station->current_tick_tck
+ );
}
else
{
sprintf(buffer, "== %s ==(%d) %Lu: ",
- station->system->station_name,
- station->id,
- station->current_tick_tck
- );
+ station->system->station_name,
+ station->id,
+ station->current_tick_tck
+ );
}
if(level >= STATION_LOG_DEBUG)
{
@@ -500,7 +500,7 @@ int station_log_set_level(station_ctx_t *station, station_log_level_t level)
}
hdr_len = strlen(buffer);
write(station->pipe_log_fd, buffer, hdr_len);
-
+
/* build body and send it */
buffer[STATION_BUFFER_SIZE - 1] = '\0';
va_start(va_args, format);
@@ -514,4 +514,4 @@ int station_log_set_level(station_ctx_t *station, station_log_level_t level)
write(station->pipe_log_fd, "\n", 1);
return;
-}
+}
diff --git a/cesar/host/station/station.h b/cesar/host/station/station.h
index 774caf8c2e..8c6fd11c3e 100644
--- a/cesar/host/station/station.h
+++ b/cesar/host/station/station.h
@@ -8,15 +8,15 @@
* <<<Licence>>>
*
* }}} */
-
- /**
+
+/**
* \file station.h
* \brief The station structures for fulminata.
* \ingroup host
*
* This file descibe the content of station structure used by fulminata station
*
- * \todo
+ * \todo
*/
#include <sys/types.h>
@@ -160,7 +160,7 @@ int station_idle(station_ctx_t *station);
* - EINVAL if station id NULL or if wanted tick is to old
*/
int station_ecos_set_itimer(station_ctx_t *station, tick_t tick);
-
+
static inline int station_is_initialized(station_ctx_t *station)
{
#ifdef STATION_SOCK
@@ -203,15 +203,15 @@ extern inline unsigned long station_log_get_mask(station_ctx_t *station)
* send message to station log system
* \param station pointer to station context
* \param level level of log message
- * \param format string structure describing the data log format
+ * \param format string structure describing the data log format
* \param ... suite of parameters to fit the format
*/
-void station_log(station_ctx_t *station,
- station_log_level_t level,
- unsigned long type,
- const char *format,
- ...);
-
+void station_log(station_ctx_t *station,
+ station_log_level_t level,
+ unsigned long type,
+ const char *format,
+ ...);
+
//END_DECLS
#endif /*STATION_H_*/