summaryrefslogtreecommitdiff
path: root/cesar/cp/station/src/station_apivs.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/station/src/station_apivs.c')
-rw-r--r--cesar/cp/station/src/station_apivs.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/cesar/cp/station/src/station_apivs.c b/cesar/cp/station/src/station_apivs.c
new file mode 100644
index 0000000000..3a4df197da
--- /dev/null
+++ b/cesar/cp/station/src/station_apivs.c
@@ -0,0 +1,148 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/station/src/station_apivs.c
+ * \brief here are all the functions to control the visual state fsm
+ * \ingroup cp_station
+ */
+
+
+#include "common/std.h"
+
+#include "cp/beacon/inc/bentry.h"
+#include "cp/beacon/inc/beacons_ctx.h"
+#include "cp/beacon/forward.h"
+#include "cp/beacon/inc/beacons_work.h"
+
+#include "cp/station/inc/station_apivs.h"
+
+
+
+// Define SEM_CONTEXT storage
+static SEM_CONTEXT *pSEMContext;
+
+
+void
+cp_station_init_fsm(void)
+{
+ // Define completion code storage
+ unsigned char cc;
+
+ //printf("%s\n", __FUNCTION__);
+ // Initialize the VS System.
+ if ((cc = SMP_Connect(&pSEMContext, &main_fsm)) != SES_OKAY)
+ dbg_assert(0); // error handling
+ // Initialize all needed data
+ main_fsmSMP_InitAll(&pSEMContext);
+ // send the reset event to the fsm
+ if(cp_station_add_event(SE_RESET, NULL) != EV_OK) dbg_assert(0);
+}
+
+
+
+void
+cp_station_process_fsm_event(void)
+{
+ msg_ctx_t *msg_ctx;
+ event_t event;
+ // Define completion code storage
+ unsigned char cc;
+ // Define action expression variable.
+ SEM_ACTION_EXPRESSION_TYPE actionExpressNo;
+
+ dbg_assert(pSEMContext);
+ //printf("%s\n", __FUNCTION__);
+ // get the event from the handler
+ while(cp_station_get_event(&event) != EV_QUEUE_EMPTY)
+ {
+ //printf("event type : 0x%x\n", event.event_type);
+ // Deduct the event
+ if ((cc = main_fsmSMP_Deduct(pSEMContext, event.event_type, event.mme_address)) != SES_OKAY)
+ dbg_assert(0); // error handling
+ // Get resulting action expressions and execute them.
+ while ((cc = SMP_GetOutput(pSEMContext, &actionExpressNo)) == SES_FOUND)
+ {
+ //printf("SMP_GetOutput : context %i, mainVSaction %i, actionexpressno %i\n", pSEMContext, MainVSAction , actionExpressNo);
+ SMP_TableAction(pSEMContext, MainVSAction , actionExpressNo);
+ }
+ if (cc != SES_OKAY)
+ dbg_assert(0); // error handling
+ // Change the next state vector.
+ if ((cc = SMP_NextState(pSEMContext)) != SES_OKAY)
+ dbg_assert(0); // error handling
+ // finaly, free the message buffer (if ir exist)
+ if(event.mme_address)
+ {
+ msg_ctx = (msg_ctx_t *)event.mme_address;
+ //dbg_assert ( !msg_check_wrong_mme_const_values (event.mme_address));
+ dbg_assert ( !msg_check_wrong_mme_const_values ((msg_mme_t *)msg_ctx->buffer));
+#if 0
+ interf_release_buf(event.mme_address);
+#else
+ /* TODO : (re)faire le (bon) release ici ? ... */
+#endif
+ }
+ }
+}
+
+
+// this function is for test purpose only
+void
+cp_station_test_fsm(void)
+{
+/* msg_mme_t *msg;
+ msg_param_t msg_param;
+
+ msg = msg_sending_common_part("ABCEFG", &msg_param);
+
+
+ printf("start of fsm test\n");
+ // send the reset event to the fsm
+ if(sta_add_event(SE_RESET, NULL) != EV_OK) dbg_assert(0);
+ station_process_fsm_event();
+ station_print_fsm_states();
+ // send the USTA event to the fsm
+ if(sta_add_event(TO_USTA, NULL) != EV_OK) dbg_assert(0);
+ station_process_fsm_event();
+ station_print_fsm_states();
+ // set the fsm to UCCO
+ if(sta_add_event(BEACON_TIMER_EXPIRES, NULL) != EV_OK) dbg_assert(0);
+ station_process_fsm_event();
+ station_print_fsm_states();
+ // go to associated sta state
+ if(sta_add_event(SE_RESET, NULL) != EV_OK) dbg_assert(0);
+ if(sta_add_event(TO_STA, msg) != EV_OK) dbg_assert(0);
+ station_process_fsm_event();
+ station_print_fsm_states();
+ // go to CCO
+ if(sta_add_event(BECOME_BACKUP_CCO, NULL) != EV_OK) dbg_assert(0);
+ if(sta_add_event(BEACON_TIMER_EXPIRES, NULL) != EV_OK) dbg_assert(0);
+ station_process_fsm_event();
+ station_print_fsm_states();
+ */
+}
+
+
+// this function is for test purpose only
+void
+cp_station_print_fsm_states(void)
+{
+ SEM_STATE_MACHINE_TYPE i;
+ SEM_STATE_TYPE StateNo = STATE_UNDEFINED;
+
+ for (i = 0 ; i < VS_NOF_STATE_MACHINES ; i++)
+ {
+ if (SMP_State (pSEMContext, i, &StateNo) != SES_FOUND)
+ printf ("\nState machine is in undefined state\n");
+ else
+ printf ("%2d ; ", StateNo);
+ }
+ printf("\n");
+}
+
+