123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
-
-
- #include <unistd.h>
- #include <iostream>
- #include "nrf8001.h"
- #include "nrf8001-broadcast.h"
- #include <lib_aci.h>
- #include <aci_setup.h>
- #include <signal.h>
-
- #ifdef SERVICES_PIPE_TYPE_MAPPING_CONTENT
- static services_pipe_type_mapping_t
- services_pipe_type_mapping[NUMBER_OF_PIPES] = SERVICES_PIPE_TYPE_MAPPING_CONTENT;
- #else
- #define NUMBER_OF_PIPES 0
- static services_pipe_type_mapping_t * services_pipe_type_mapping = NULL;
- #endif
-
-
- static hal_aci_data_t setup_msgs[NB_SETUP_MESSAGES] = SETUP_MESSAGES_CONTENT;
-
-
- static struct aci_state_t aci_state;
-
-
- static hal_aci_evt_t aci_data;
-
- void
- sig_handler(int signo)
- {
- printf("got signal\n");
- if (signo == SIGINT) {
- printf("exiting application\n");
- }
- }
-
- void
- init_aci_setup () {
-
-
- if (NULL != services_pipe_type_mapping) {
- aci_state.aci_setup_info.services_pipe_type_mapping = &services_pipe_type_mapping[0];
- } else {
- aci_state.aci_setup_info.services_pipe_type_mapping = NULL;
- }
-
- aci_state.aci_setup_info.number_of_pipes = NUMBER_OF_PIPES;
- aci_state.aci_setup_info.setup_msgs = setup_msgs;
- aci_state.aci_setup_info.num_setup_msgs = NB_SETUP_MESSAGES;
- }
-
- int
- main(int argc, char **argv)
- {
-
-
- init_aci_setup ();
- init_local_interfaces (&aci_state, 10, 8, 4);
-
- while (1) {
- static bool setup_required = false;
- if (lib_aci_event_get (&aci_state, &aci_data)) {
- aci_evt_t * aci_evt;
- aci_evt = &aci_data.evt;
-
- switch(aci_evt->evt_opcode) {
-
-
- case ACI_EVT_DEVICE_STARTED: {
- aci_state.data_credit_available = aci_evt->params.device_started.credit_available;
- switch(aci_evt->params.device_started.device_mode) {
- case ACI_DEVICE_SETUP:
-
-
- printf ("Evt Device Started: Setup\n");
- setup_required = true;
- break;
-
- case ACI_DEVICE_STANDBY:
- printf ("Evt Device Started: Standby\n");
- lib_aci_broadcast(10, 0x0100 );
- printf ("Broadcasting started\n");
- break;
- }
- }
- break;
-
- case ACI_EVT_CMD_RSP:
- if (ACI_STATUS_SUCCESS != aci_evt->params.cmd_rsp.cmd_status) {
- printf ("ACI_EVT_CMD_RSP\n");
- while (1);
- }
- break;
-
- case ACI_EVT_CONNECTED:
- printf ("ACI_EVT_CONNECTED\n");
- break;
-
- case ACI_EVT_PIPE_STATUS:
- printf ("ACI_EVT_PIPE_STATUS\n");
- break;
-
- case ACI_EVT_DISCONNECTED:
- if (ACI_STATUS_ERROR_ADVT_TIMEOUT == aci_evt->params.disconnected.aci_status) {
- printf ("Broadcasting timed out\n");
- } else {
- printf ("Evt Disconnected. Link Loss\n");
- }
- break;
-
- case ACI_EVT_DATA_RECEIVED:
- printf ("ACI_EVT_DATA_RECEIVED\n");
- break;
-
- case ACI_EVT_HW_ERROR:
- printf ("ACI_EVT_HW_ERROR\n");
- break;
- }
- }
-
- if (setup_required) {
- if (SETUP_SUCCESS == do_aci_setup(&aci_state)) {
- setup_required = false;
- }
- }
- usleep (100);
- }
-
- close_local_interfaces (&aci_state);
-
-
-
- std::cout << "exiting application" << std::endl;
-
- return 0;
- }
|