Beispiel #1
0
void main (void)
{
  SPIRIT_INIT();
  while (1)
  {
    if (Spirit_data == Spirit_waiting_window)            // check if there is data ready to be sent
    {
      if(SysyTickCnt > ((endpoint_address * 100) + 50))  // check if window for sending
        {
          send_to_Base_Station();                       // sending to Base Station
        }
    }
    
    if(command_pending == 1)
    {
      apply_command();
    }
      
    IWDG_ReloadCounter();          //przeladowanie IWDG    
 //   SdkEvalLedToggle(LED_GREEN);
      
    if (App == App_connected)
    {
      daas_manage();
    }else
    {
      app_connect();
    }
   }
}  // End of main()
Beispiel #2
0
/**
 ****************************************************************************************
 * @brief Handles GAPM command completion events.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int gap_cmp_evt_handler(ke_msg_id_t msgid,
                        struct gapm_cmp_evt *param,
                        ke_task_id_t dest_id,
                        ke_task_id_t src_id)
{
    if (param->status ==  CO_ERROR_NO_ERROR)
    {
        if(param->operation == GAPM_RESET)
        {
            gapm_reset_cmd_completed = TRUE;
            app_set_mode(); // initialize 
        }
        else if(param->operation == GAPM_SET_DEV_CONFIG)
        {
            // start scanning for target device
            printf("Scanning... \n");
            app_env.state = APP_SCAN;            
            app_inq();
        }
    }
    else
    {
        if(param->operation == GAPM_SCAN_ACTIVE || param->operation == GAPM_SCAN_PASSIVE)
        {
            // scan operation has completed
            app_env.state = APP_IDLE; 

            // check if the target device was found
            if (app_env.target_idx != -1)
            {
                // connect to the target
                printf("Connecting to target device...\n");
                app_connect(app_env.target_idx);
            }
            else
            {
                if ( app_env.scan_attempts_made < MAX_SCANNING_ATTEMPTS )
                {
                    // do next scan attempt
                    printf("Scanning...\n");
                    app_env.state = APP_SCAN;
                    app_inq();
                }
                else
                {
                    // no more scan attempts -> exit application
                    printf("Target device was not found. \n");
                    app_exit();
                }
            }

        }
    }

    return (KE_MSG_CONSUMED);
}
Beispiel #3
0
/**
 ****************************************************************************************
 * @brief Handles GAP manager command complete events.
 *
 * @param[in] msgid     Id of the message received.
 * @param[in] param     Pointer to the parameters of the message.
 * @param[in] dest_id   ID of the receiving task instance (TASK_GAP).
 * @param[in] src_id    ID of the sending task instance.
 *
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
int gapm_cmp_evt_handler(ke_msg_id_t const msgid,
                                struct gapm_cmp_evt const *param,
                                ke_task_id_t const dest_id,
                                ke_task_id_t const src_id)
{	
    switch(param->operation)
    {
        // reset completed
        case GAPM_RESET:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {

                // set device configuration
                struct gapm_set_dev_config_cmd* cmd = KE_MSG_ALLOC(GAPM_SET_DEV_CONFIG_CMD,
                        TASK_GAPM, TASK_APP, gapm_set_dev_config_cmd);

                app_configuration_func(dest_id, cmd);

                ke_msg_send(cmd);
            }
        }
        break;

        // device configuration updated
        case GAPM_SET_DEV_CONFIG:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
            else
            {
              app_set_dev_config_complete_func();
            }
        }
        break;

        // Advertising finished
        case GAPM_ADV_UNDIRECT:
        {
            app_adv_undirect_complete(param->status);
        }
        break;
        
        // Directed advertising finished
        case GAPM_ADV_DIRECT:
        {
            app_adv_direct_complete(param->status);  
        }
        break;
				
        case GAPM_SCAN_PASSIVE:
		case GAPM_SCAN_ACTIVE:
        {
            if (param->status == GAP_ERR_CANCELED)
            {
                app_connect();
            }						
            else 
            {
                app_scanning();
            }
        }				
        break;
        /* end */
				
        case GAPM_CANCEL:
        {
            if(param->status != GAP_ERR_NO_ERROR)
            {
                ASSERT_ERR(0); // unexpected error
            }
        }
		case GAPM_CONNECTION_DIRECT:
            if (param->status == GAP_ERR_CANCELED)
            {
				app_connect_failed_func();
            }
				break;
        default:
        {
            ASSERT_ERR(0); // unexpected error
        }
        break;
    }
		
    return (KE_MSG_CONSUMED);
}