Beispiel #1
0
void test_profile_sync_get_size(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;
    kaa_profile_t *profile = kaa_profile_basic_endpoint_profile_test_create();
    profile->profile_body = kaa_string_copy_create("dummy");

    size_t serialized_profile_size = profile->get_size(profile);
    char *serialized_profile = (char *) KAA_MALLOC(serialized_profile_size * sizeof(char));
    avro_writer_t writer = avro_writer_memory(serialized_profile, serialized_profile_size);
    profile->serialize(writer, profile);

    size_t expected_size = KAA_EXTENSION_HEADER_SIZE
                         + sizeof(uint32_t)  // profile size
                         + kaa_aligned_size_get(serialized_profile_size);

    size_t profile_sync_size = 0;

    error_code = kaa_profile_manager_update_profile(profile_manager, profile);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    status->is_registered = true;

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    status->is_registered = false;

    expected_size += sizeof(uint32_t)
                   + TEST_PUB_KEY_SIZE;

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    const char *access_token = "access token";
    error_code = kaa_profile_manager_set_endpoint_access_token(profile_manager, access_token);

    expected_size += sizeof(uint32_t)
                   + strlen(access_token);

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    avro_writer_free(writer);
    KAA_FREE(serialized_profile);
    profile->destroy(profile);

    KAA_TRACE_OUT(logger);
}
Beispiel #2
0
void test_profile_update(void)
{
    KAA_TRACE_IN(logger);

    kaa_profile_t *profile1 = kaa_profile_basic_endpoint_profile_test_create();
    profile1->profile_body = kaa_string_copy_create("dummy");
    kaa_error_t error = kaa_profile_manager_update_profile(profile_manager, profile1);
    ASSERT_EQUAL(error, KAA_ERR_NONE);

    bool need_resync = false;
    error = kaa_profile_need_profile_resync(profile_manager, &need_resync);
    ASSERT_EQUAL(error, KAA_ERR_NONE);
    ASSERT_TRUE(need_resync);

    error = kaa_profile_manager_update_profile(profile_manager, profile1);
    ASSERT_EQUAL(error, KAA_ERR_NONE);

    error = kaa_profile_need_profile_resync(profile_manager, &need_resync);
    ASSERT_EQUAL(error, KAA_ERR_NONE);
    ASSERT_FALSE(need_resync);

    profile1->destroy(profile1);

    kaa_profile_t *profile2 = kaa_profile_basic_endpoint_profile_test_create();
    profile2->profile_body = kaa_string_copy_create("new_dummy");
    error = kaa_profile_manager_update_profile(profile_manager, profile2);
    ASSERT_EQUAL(error, KAA_ERR_NONE);

    error = kaa_profile_need_profile_resync(profile_manager, &need_resync);
    ASSERT_EQUAL(error, KAA_ERR_NONE);
    ASSERT_TRUE(need_resync);

    profile2->destroy(profile2);

    KAA_TRACE_OUT(logger);
}
Beispiel #3
0
void test_profile_is_set(void)
{
    KAA_TRACE_IN(logger);

#if KAA_PROFILE_SCHEMA_VERSION > 0
    ASSERT_FALSE(kaa_profile_manager_is_profile_set(profile_manager));
    kaa_profile_t *profile = kaa_profile_basic_endpoint_profile_test_create();
    profile->profile_body = kaa_string_copy_create("test");
    kaa_error_t error = kaa_profile_manager_update_profile(profile_manager, profile);
    profile->destroy(profile);
    ASSERT_EQUAL(error, KAA_ERR_NONE);
    ASSERT_TRUE(kaa_profile_manager_is_profile_set(profile_manager));
#else
    ASSERT_TRUE(kaa_profile_manager_is_profile_set(profile_manager));
#endif

    KAA_TRACE_OUT(logger);
}
Beispiel #4
0
int main(int argc, char *argv[])
{   
    if (argc != 5) {
        printf("Please, input + or - for audio, video and vibro supporting and directory for key storage. (Need 4 arguments)\n");
        exit(1);
    }
    
    mkdir(argv[4], 0777);
    chdir(argv[4]);

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        printf("Failed create Kaa client, error code %d\n", error_code);
        return EXIT_FAILURE;
    }
    
    kaa_profile_t *profile = kaa_profile_pager_client_profile_create();
    if (!profile) {
        printf("Failed to create profile\n");
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }
    
    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);

    if (access(KAA_CONFIGURATION_STORAGE, F_OK) != -1) {
        printf("Waiting for new configuration for\n");
        printf("Endpoint ID %.*s\n", (int)endpoint_key_hash_length, endpoint_key_hash);
    }

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


    profile->audio_support = set_client_parameter(argv[1]);
    profile->video_support = set_client_parameter(argv[2]);
    profile->vibro_support = set_client_parameter(argv[3]);

    printf("Profiling body (have audio-, video-, vibro-support):\n");
    printf("%s - %s - %s\n", profile->audio_support ? "true" : "false",
        profile->video_support ? "true" : "false",
        profile->vibro_support ? "true" : "false");

    error_code = kaa_profile_manager_update_profile(kaa_client_get_context(kaa_client)->profile_manager, profile);
    if (error_code) {
        printf("Failed to update profile, error code %d", error_code);
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }

    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) {
        printf("Failed to add configuration receiver\n");
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }
    printf("Default configuration:\n");
    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) {
        printf("Failed to start Kaa main loop, error code %d\n", error_code);
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }
    
    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    return EXIT_SUCCESS;
}
Beispiel #5
0
void test_profile_sync_serialize(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    kaa_platform_message_writer_t *manual_writer;
    kaa_platform_message_writer_t *auto_writer;

    const char *access_token = "access token";
    const size_t access_token_size = strlen(access_token);
    kaa_profile_t *profile = kaa_profile_basic_endpoint_profile_test_create();
    profile->profile_body = kaa_string_copy_create("dummy");
    size_t serialized_profile_size = profile->get_size(profile);
    char *serialized_profile = (char *) KAA_MALLOC(serialized_profile_size * sizeof(char));
    avro_writer_t avro_writer = avro_writer_memory(serialized_profile, serialized_profile_size);

    profile->serialize(avro_writer, profile);

    error_code = kaa_profile_manager_update_profile(profile_manager, profile);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    status->is_registered = false;
    error_code = kaa_profile_manager_set_endpoint_access_token(profile_manager, access_token);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t profile_sync_size;
    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    char buffer[profile_sync_size];
    error_code = kaa_platform_message_writer_create(&manual_writer, buffer, profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    uint32_t network_order_32;

    error_code = kaa_platform_message_write_extension_header(manual_writer
                                                           , KAA_PROFILE_EXTENSION_TYPE
                                                           , 0
                                                           , profile_sync_size - KAA_EXTENSION_HEADER_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    bool need_resync = true;
    ASSERT_EQUAL(kaa_profile_need_profile_resync(profile_manager, &need_resync), KAA_ERR_NONE);

    network_order_32 = KAA_HTONL(0);
    if (need_resync)
        network_order_32 = KAA_HTONL(serialized_profile_size);
    error_code = kaa_platform_message_write(manual_writer, &network_order_32, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    if (need_resync) {
        error_code = kaa_platform_message_write_aligned(manual_writer, serialized_profile, serialized_profile_size);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    }

    network_order_32 = KAA_HTONS(TEST_PUB_KEY_SIZE) << 16 | PUB_KEY_VALUE;
    error_code = kaa_platform_message_write(manual_writer, &network_order_32, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_platform_message_write_aligned(manual_writer, test_ep_key, TEST_PUB_KEY_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    network_order_32 = KAA_HTONS(access_token_size) << 16 | ACCESS_TOKEN_VALUE;
    error_code = kaa_platform_message_write(manual_writer, &network_order_32, sizeof(uint32_t));
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_platform_message_write_aligned(manual_writer, access_token, access_token_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    char buffer2[profile_sync_size];
    error_code = kaa_platform_message_writer_create(&auto_writer, buffer2, profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_profile_request_serialize(profile_manager, auto_writer);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = (memcmp(buffer, buffer2, profile_sync_size) == 0 ? KAA_ERR_NONE : KAA_ERR_BADDATA);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    KAA_FREE(serialized_profile);
    avro_writer_free(avro_writer);
    profile->destroy(profile);
    kaa_platform_message_writer_destroy(auto_writer);
    kaa_platform_message_writer_destroy(manual_writer);

    KAA_TRACE_OUT(logger);
}
Beispiel #6
0
static void APP_main()
{
   ip_connected = false;
   kaa_started = false;

   kaa_error_t kaa_error = KAA_ERR_NONE;
   { //Used to limit kaa_props visibility, it creates on stack and release once is used
       kaa_client_props_t kaa_props;
       kaa_props.max_update_time = 2;
       kaa_error = kaa_client_create(&kaa_client, &kaa_props);
       if (kaa_error) {
           sndc_printf("Error %d initializing Kaa client \n",kaa_error);
           return;
       }
   }

   kaa_list_t *zones = kaa_list_create();
   int i = 0;
   for(; i < LIGHT_ZONES_COUNT; ++i) {
       sndc_io_setMode(light_zones[i], IO_MODE_OUTPUT);
       sndc_io_write(light_zones[i], LIGHT_OFF);
       int32_t *zone_id = (int32_t *) KAA_MALLOC(sizeof(int32_t));
       *zone_id = i;
       kaa_list_push_front(zones, zone_id);
   }
   kaa_profile_street_lights_profile_t *profile = kaa_profile_street_lights_profile_create();
   profile->light_zones = zones;
   kaa_profile_manager_update_profile(kaa_client_get_context(kaa_client)->profile_manager, profile);
   profile->destroy(profile);

   /**
    * Configuration example, below is how to configure and read default configuration values
    */
   kaa_configuration_root_receiver_t receiver = { NULL, &kaa_on_configuration_updated };
   kaa_error = kaa_configuration_manager_set_root_receiver(kaa_client_get_context(kaa_client)->configuration_manager, &receiver);
   sndc_printf("Configuration setting done. %d\n", kaa_error);
   //sndc_thrd_delay(TRACE_DELAY * SNDC_MILLISECOND);
   const kaa_root_configuration_t *root_config = kaa_configuration_manager_get_configuration(kaa_client_get_context(kaa_client)->configuration_manager);
   kaa_on_configuration_updated(NULL, root_config);

   //set SW2 button as key input
   //sndc_io_ctrl(BUTTON,
   //             IO_PIN_FUNC_PULL_UP,
   //             IO_PIN_DRIVE_DEFAULT,
   //             IO_PIN_SLEW_RATE_DEFAULT);
   //sndc_io_setMode(BUTTON, IO_MODE_KEY);

   //sndc_device_config = sndc_config_get();

   /* clean all profiles */
   //sndc_profile_eraseAll();
   //sndc_printf("Press SW2 to start test. \n");

   start_client();

   //infinite thread loop, button press is monitored by system events
   while(1)
   {

      if (ip_connected && !kaa_started) {
          kaa_client_start(kaa_client, NULL, NULL, 0);
          kaa_started = true;
      }
      //thread sleep for 500 ms
      sndc_thrd_delay(500 * SNDC_MILLISECOND);
   }
}