#ifndef STATION_H_ #define STATION_H_ /* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file station.h * \brief The station structures for fulminata. * \ingroup host * * This file descibe the content of station structure used by fulminata station * * \todo */ #include #include "maximus/common/types/system_types.h" #include "host/fwd.h" #include "host/sci.h" #include "host/netclock.h" #include "host/fcall.h" #define STATION_PIPE_PATH "/tmp" #define STATION_PIPE_PREFIX "station" #define STATION_MAX_LOG_SIZE 4096 #define TICK_PERIOD_NS 40 /** period of a tick in nanosecond */ #define TICK_HZ 25000000 /** frequence of tick (tick number per second) */ #ifndef MAXPATHLEN #define MAXPATHLEN 256 #endif struct sci_ctx; struct netclock_ctx; struct fcall_ctx; struct probe_ctx; struct netclock_callback_t; typedef enum { STATION_STATUS_INIT = 0, STATION_STATUS_RUNNING, STATION_STATUS_IDLE, STATION_STATUS_ERROR, STATION_STATUS_NB } station_status_t; typedef enum { STATION_LOG_NONE, STATION_LOG_ERROR, STATION_LOG_WARNING, STATION_LOG_NOTICE, STATION_LOG_INFO, STATION_LOG_DEBUG, STATION_LOG_NB } station_log_level_t; #define STATION_LOGTYPE_STATION 0x00000001 #define STATION_LOGTYPE_NETCLOCK 0x00000002 #define STATION_LOGTYPE_FCALL 0x00000004 #define STATION_LOGTYPE_SCI 0x00000008 #define STATION_LOGTYPE_PROBE 0x00000010 #define STATION_LOGTYPE_MISC 0x00000020 #define STATION_LOGTYPE_PHY 0x00000040 #define STATION_LOGTYPE_ALL 0xffffffff /** station context structure to manage a station process */ struct station_ctx { station_status_t status; /** init status of station */ pid_t id; /** station identifier (pid process) */ struct sci_ctx *sci; struct netclock_ctx *netclock; struct fcall_ctx *fcall; struct probe_ctx *probe; tick_t current_tick_tck; /** current global clock tick got from sci msg */ int pipe_in_fd; /** file descriptor for messaging input pipe */ char pipe_in_name[MAXPATHLEN]; /** filename of messaging input file */ int pipe_out_fd; /** file descriptor for messaging output pipe */ char pipe_out_name[MAXPATHLEN]; /** filename of messaging output pipe */ int pipe_log_fd; /** output pipe file desc to send debug data */ char pipe_log_name[MAXPATHLEN]; /** output pipe filename to send debug data */ station_log_level_t log_level; unsigned long log_mask; struct netclock_callback *ecos_tick_cb; int is_unit_test; }; //BEGIN_DECLS extern station_ctx_t my_station; /** * station creation, issued from the fulminata process creation. * \return the new created station context, NULL if problem with errno generated by open() call */ station_ctx_t *station_new(void); /** * station destruction with memory freeing. * \param station station context to destroy */ void station_free(station_ctx_t *station); /** * station context initialization, with pipe opening * \param station pointer to station context to initialize * \return 0 if ok, -1 if failed with errno= * - EINVAL if station is NULL * - all errno generated by open() call */ int station_init(station_ctx_t *station); /** * station context to clean and reset, with pipe closing * \param station pointer to station context to stop */ void station_down(station_ctx_t *station); /** * station is into idle state; it sends a sci 'idle' message and waits for sci message reception * \param station the current station context * \return 0 when message has been received and process
* -1 if an error happened with errno=
* */ int station_idle(station_ctx_t *station); /** * schedule an eCos tick event (every 10ms) * \param station pointer to station context * \param tick tick for event scheduling * \return 0 if ok, -1 if failed with errno= * - 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) { return ((station->pipe_in_fd >= 0) && (station->pipe_out_fd >= 0)); } /** * set the station log level * \param station pointer to station context * \param level new log level * \return 0 if ok, -1 if failed with errno= * - EINVAL if station is NULL or level is out of range */ int station_log_set_level(station_ctx_t *station, station_log_level_t level); /** * set the station log mask * \param station pointer to station context * \param mask new log mask */ extern inline void station_log_set_mask(station_ctx_t *station, unsigned long mask) { station->log_mask = mask; } /** * get the station log mask * \param station pointer to station context * \return the current log mask */ extern inline unsigned long station_log_get_mask(station_ctx_t *station) { return station->log_mask; } /** * 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 ... 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, ...); //END_DECLS #endif /*STATION_H_*/