summaryrefslogtreecommitdiff
path: root/host/src/station.c
diff options
context:
space:
mode:
Diffstat (limited to 'host/src/station.c')
-rw-r--r--host/src/station.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/host/src/station.c b/host/src/station.c
index 45514fab25..9b38f40488 100644
--- a/host/src/station.c
+++ b/host/src/station.c
@@ -134,7 +134,7 @@ int station_init(station_ctx_t *station)
station->probe = &_my_probe;
//probe_init(station->probe, station);
station->ecos_tick_cb = &_ecos_tick_cb;
- station->status = STATION_STATUS_OK;
+ station->status = STATION_STATUS_RUNNING;
#ifndef UNIT_TEST
/* first call for tick */
@@ -167,7 +167,7 @@ failed:
void station_down(station_ctx_t *station)
{
if((station == NULL)
- || (station->status != STATION_STATUS_OK))
+ || (station->status != STATION_STATUS_INIT))
return;
if(station->pipe_out_fd >= 0)
@@ -202,31 +202,35 @@ int station_idle(station_ctx_t *station)
int sel;
if((station == NULL)
- || (station->status != STATION_STATUS_OK))
+ || (station->status == STATION_STATUS_INIT))
//|| !station_is_initialized(station))
{
errno = EINVAL;
return -1;
}
- /* init msg */
- sci_msg_init(&msg, buffer, 64);
+ if(station->status == STATION_STATUS_RUNNING)
+ {
+ /* init msg */
+ sci_msg_init(&msg, buffer, 64);
- /* fill system header */
- sci_msg_push(&msg, sizeof(station_msg_hdr_t));
- msg.hdr.station = (station_msg_hdr_t *)msg.data_begin;
- msg.hdr.station->version = SYSTEM_VERSION;
- msg.hdr.station->type = SYSTEM_TYPE_IDLE;
- msg.hdr.station->flags = 0;
+ /* fill system header */
+ sci_msg_push(&msg, sizeof(station_msg_hdr_t));
+ msg.hdr.station = (station_msg_hdr_t *)msg.data_begin;
+ msg.hdr.station->version = SYSTEM_VERSION;
+ msg.hdr.station->type = SYSTEM_TYPE_IDLE;
+ msg.hdr.station->flags = 0;
- /* fill sci header and send msg */
- sci_fill_hdr(station->sci, &msg, SCI_MSG_TYPE_SYSTEM, 0);
- if(sci_send(station->sci, &msg) < 0)
- {
- station_log(station, STATION_LOG_WARNING, "%s failed to send system idle (errno=%d)", __FUNCTION__, errno);
- return -1;
+ /* fill sci header and send msg */
+ sci_fill_hdr(station->sci, &msg, SCI_MSG_TYPE_SYSTEM, 0);
+ if(sci_send(station->sci, &msg) < 0)
+ {
+ station_log(station, STATION_LOG_WARNING, "%s failed to send system idle (errno=%d)", __FUNCTION__, errno);
+ return -1;
+ }
+ station->status = STATION_STATUS_IDLE;
}
-
+
/* don't wait for next message with unit tests */
if(station->is_unit_test)
return 0;
@@ -244,6 +248,7 @@ int station_idle(station_ctx_t *station)
}
else if(sel > 0)
{
+ station->status = STATION_STATUS_RUNNING;
return sci_recv(station->sci);
}
else
@@ -272,7 +277,7 @@ static void _ecos_set_itimer_cb(void *data)
int station_ecos_set_itimer(station_ctx_t *station, tick_t tick)
{
if((station == NULL)
- || (station->status != STATION_STATUS_OK))
+ || (station->status == STATION_STATUS_INIT))
{
errno = EINVAL;
return -1;
@@ -296,7 +301,7 @@ int station_ecos_set_itimer(station_ctx_t *station, tick_t tick)
int station_log_set_level(station_ctx_t *station, station_log_level_t level)
{
if((station == NULL)
- || (station->status != STATION_STATUS_OK)
+ || (station->status == STATION_STATUS_INIT)
|| (level <= STATION_LOG_NONE)
|| (level >= STATION_LOG_NB))
{
@@ -325,7 +330,7 @@ int station_log_set_level(station_ctx_t *station, station_log_level_t level)
static char buffer[STATION_MAX_LOG_SIZE];
if((station == NULL)
- || (station->status != STATION_STATUS_OK)
+ || (station->status == STATION_STATUS_INIT)
|| (format == NULL))
return;