예제 #1
0
static void kaa_device_info_request(void *context
                           , kaa_remote_control_ecf_device_info_request_t *event
                           , kaa_endpoint_id_p source)
{
    (void)context;
    (void)source;

    demo_printf("Device info request received\r\n");
    kaa_remote_control_ecf_device_info_response_t *response = kaa_remote_control_ecf_device_info_response_create();

    response->device_name = kaa_string_copy_create(TARGET_DEVICE_NAME);
    response->model       = kaa_string_copy_create(TARGET_MODEL_NAME);
    response->gpio_status = kaa_list_create();
    for (int i = 0; i < target_gpio_led_get_count(); ++i) {
        gpio_port_t *gpio_led = target_get_gpio_port( i );
        if (gpio_led) {
            kaa_remote_control_ecf_gpio_status_t *gio_status = kaa_remote_control_ecf_gpio_status_create();
            gio_status->id = i;
            gio_status->status = gpio_led->state;
            gio_status->type = kaa_string_copy_create( gpio_led->id );
            kaa_list_push_back(response->gpio_status, (void*)gio_status);
        }
    }
    kaa_error_t err = kaa_event_manager_send_kaa_remote_control_ecf_device_info_response(kaa_client_get_context(kaa_client)->event_manager, response, NULL);

    response->destroy(response); // Destroying event that was successfully sent
    event->destroy(event);
}
예제 #2
0
kaa_error_t kaa_demo_configuration_receiver(void *context,
                                            const kaa_root_configuration_t *configuration) {
    (void) context;
    demo_printf("Received configuration data\n");
    kaa_demo_print_configuration_message(configuration);
    kaa_client_stop(kaa_client);
    return KAA_ERR_NONE;
}
예제 #3
0
void kaa_demo_print_configuration_message(
        const kaa_root_configuration_t *configuration) {
    if (configuration->address_list->type ==
            KAA_CONFIGURATION_UNION_ARRAY_LINK_OR_NULL_BRANCH_0) {
        demo_printf("Configuration body:\n");

        kaa_list_node_t *it = kaa_list_begin(
                (kaa_list_t *) configuration->address_list->data);
        while (it) {
            kaa_configuration_link_t *current_link = kaa_list_get_data(it);
            demo_printf("%s - %s\n", current_link->label->data,
                        current_link->url->data);
            it = kaa_list_next(it);
        }
    } else {
        demo_printf("Configuration body: null\n");
    }
}
예제 #4
0
static void kaa_GPIOToggle_info_request(void *context
                              , kaa_remote_control_ecf_gpio_toggle_request_t *event
                              , kaa_endpoint_id_p source)
{
    (void)context;
    (void)source;

    demo_printf("Toggling GPIO...\r\n");

    target_gpio_led_toggle(event->gpio->id, event->gpio->status);

    event->destroy(event);
}
예제 #5
0
int main(/*int argc, char *argv[]*/) {
    /**
     * Initialise a board
     */
    int ret = target_initialise();
    if (ret < 0) {
        /* If console is failed to initialise, you will not see this message */
        demo_printf("Failed to initialise a target\n");
        return 1;
    }

    demo_printf("Configuration demo started\n");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        demo_printf("Failed create Kaa client\n");
        return 2;
    }

    kaa_configuration_root_receiver_t receiver = {
            NULL,
            &kaa_demo_configuration_receiver
    };

    error_code = kaa_configuration_manager_set_root_receiver(
            kaa_client_get_context(kaa_client)->configuration_manager,
            &receiver);

    if (error_code) {
        demo_printf("Failed to add configuration receiver\n");
        return 3;
    }

    kaa_demo_print_configuration_message(
            kaa_configuration_manager_get_configuration(
                    kaa_client_get_context(kaa_client)->configuration_manager));

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    if(error_code) {
        demo_printf("Failed to start Kaa main loop\n");
        return 4;
    }

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    demo_printf("Configuration demo stopped\n");
    return 0;
}
예제 #6
0
int main(void)
{
	char * p;

#ifdef EMBEDDED
  #pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting 
                                            // SWIs are linked in from the C library 
#ifdef USE_SERIAL_PORT
  init_serial(0, ARM_BAUD_115200);            // initialize serial port A
#endif

#endif




  printf("C Library Example\n");

  demo_printf();
  demo_sprintf();
  demo_float_print();
  demo_malloc();
  
  p=malloc(0x1000);
  printf("p = 0x%08x\n",(int)p);
  p=malloc(0x1000);
  printf("p = 0x%08x\n",(int)p);
  p=malloc(0x1000);
  printf("p = 0x%08x\n",(int)p);
  p=malloc(0x1000);
  printf("p = 0x%08x\n",(int)p);
  
  

  return 0;
}
예제 #7
0
int main(void)
{
    int rc = target_initialize();
    if (rc < 0) {
        return 1;
    }

    target_gpio_led_init();

    demo_printf("GPIO demo started\r\n");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        demo_printf("Failed to create client context: %i\r\n", error_code);
        return 2;
    }

    error_code = kaa_profile_manager_set_endpoint_access_token(kaa_client_get_context(kaa_client)->profile_manager,
        DEMO_ACCESS_TOKEN);

    if (error_code) {
        demo_printf("Failed to set access token: %i\r\n", error_code);
        return 3;
    }

    error_code = kaa_event_manager_set_kaa_remote_control_ecf_device_info_request_listener(kaa_client_get_context(kaa_client)->event_manager,
            kaa_device_info_request,
            NULL);
    if (error_code) {
        demo_printf("Unable to set remote control listener: %i\r\n", error_code);
        return 4;
    }

    error_code = kaa_event_manager_set_kaa_remote_control_ecf_gpio_toggle_request_listener(kaa_client_get_context(kaa_client)->event_manager,
            kaa_GPIOToggle_info_request,
            NULL);
    if (error_code) {
        demo_printf("Unable to set GPIO listener: %i\r\n", error_code);
        return 5;
    }

    demo_printf("ACCESS_TOKEN :%s\r\n", DEMO_ACCESS_TOKEN);

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, kaa_external_process_fn, NULL, 0);
    if (error_code) {
        demo_printf("Unable to start Kaa client: %i\r\n", error_code);
        return 6;
    }

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    demo_printf("GPIO demo stopped\r\n");

    return error_code;
}
예제 #8
0
int main(/*int argc, char *argv[]*/) {
    /**
     * Initialise a board
     */
    int ret = target_initialize();
    if (ret < 0) {
        /* If console is failed to initialise, you will not see this message */
        demo_printf("Failed to initialise a target\r\n");
        return EXIT_FAILURE;
    }

    demo_printf("Configuration demo started\r\n");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        demo_printf("Failed create Kaa client\r\n");
        return EXIT_FAILURE;
    }

    /*
     * Set the handler for configuration updates.
     */
    kaa_configuration_root_receiver_t receiver = {
            NULL,
            &kaa_demo_configuration_receiver
    };

    error_code = kaa_configuration_manager_set_root_receiver(
            kaa_client_get_context(kaa_client)->configuration_manager,
            &receiver);

    if (error_code) {
        demo_printf("Failed to add configuration receiver\r\n");
        return EXIT_FAILURE;
    }

    /*
     * Display default configuration.
     */
    kaa_demo_print_configuration_message(
            kaa_configuration_manager_get_configuration(
                    kaa_client_get_context(kaa_client)->configuration_manager));

    /*
     * Obtain and display endpoint ID (represented by the EP key hash).
     */
    const uint8_t *endpoint_key_hash = NULL;
    size_t endpoint_key_hash_length = 0;

    ext_get_sha1_base64_public(&endpoint_key_hash, &endpoint_key_hash_length);

    printf("Endpoint ID: %.*s\r\n", (int)endpoint_key_hash_length,
            endpoint_key_hash);

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    if(error_code) {
        demo_printf("Failed to start Kaa main loop\r\n");
        return EXIT_FAILURE;
    }

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    return EXIT_SUCCESS;
}
예제 #9
0
void kaa_demo_print_configuration_message(
        const kaa_root_configuration_t *configuration) {
    demo_printf("Sample period is now %d second(s)\r\n", configuration->sample_period);
}