Beispiel #1
0
int main( int argc, const char* argv[] )
{
    if( argc < 5 )
    {
        print_usage();
        exit( 0 );
    }

    // create the xi library context
    xi_context_t* xi_context
        = xi_create_context(
                  XI_HTTP, argv[ 1 ]
                , atoi( argv[ 2 ] ) );

    // check if everything works
    if( xi_context == 0 )
    {
        return -1;
    }

    xi_datapoint_t datapoint;
    xi_set_value_i32( &datapoint, atoi( argv[ 4 ] ) );

    { // get actual timestamp
        time_t timer = 0;
        time( &timer );
        datapoint.timestamp.timestamp = timer;
    }

    xi_datastream_create( xi_context
            , atoi( argv[ 2 ] ), argv[ 3 ]
            , &datapoint.value );

    // destroy the context cause we don't need it anymore
    xi_delete_context( xi_context );

    return 0;
}
Beispiel #2
0
void test_datapoint_value_setters_and_getters(void* data)
{
    (void)(data);

    void * ret;

    xi_datapoint_t dp;

    ret = xi_set_value_i32( &dp, 320 );

    tt_assert( ret != 0 );

    tt_assert( xi_get_value_i32( &dp ) == 320 );

    tt_assert( xi_get_value_type( &dp ) == XI_VALUE_TYPE_I32 );

    tt_assert( xi_value_pointer_i32( &dp ) != 0 &&
               xi_value_pointer_f32( &dp ) == 0 &&
               xi_value_pointer_str( &dp ) == 0 );

    ret = xi_set_value_f32( &dp, (320.0/10) );

    tt_assert( ret != 0 );

    tt_assert( xi_get_value_f32( &dp ) == (320.0/10) );

    tt_assert( xi_get_value_type( &dp ) == XI_VALUE_TYPE_F32 );

    tt_assert( xi_value_pointer_i32( &dp ) == 0 &&
               xi_value_pointer_f32( &dp ) != 0 &&
               xi_value_pointer_str( &dp ) == 0 );

    ret = xi_set_value_str( &dp, "Let's test everything!" );

    tt_assert( ret != 0 );

    char s[XI_VALUE_STRING_MAX_SIZE+100];
    for (size_t i = 0; i < sizeof(s); i++) {
        s[i] = 'a';
    }

    ret = xi_set_value_str( &dp, s );

    tt_assert( ret != 0 )

    tt_assert( xi_get_value_type( &dp ) == XI_VALUE_TYPE_STR );

    tt_assert( xi_value_pointer_i32( &dp ) == 0 &&
               xi_value_pointer_f32( &dp ) == 0 &&
               xi_value_pointer_str( &dp ) != 0 );

    char * x = xi_value_pointer_str( &dp );

    tt_assert( strlen(s) > strlen(x) );
    tt_assert( strlen(x) == XI_VALUE_STRING_MAX_SIZE-1 );

    s[XI_VALUE_STRING_MAX_SIZE-5] = '\0';

    ret = xi_set_value_str( &dp, s );

    tt_assert( ret != 0 );

    tt_assert( strlen(s) == strlen(x) );
    tt_assert( strlen(x) == XI_VALUE_STRING_MAX_SIZE-5 );

end:
    ;
}
int main( int argc, const char* argv[] )
{
#ifdef XI_NOB_ENABLED
    XI_UNUSED( argc );
    XI_UNUSED( argv );
#else
    if( argc < REQUIRED_ARGS )
    {
        print_usage();
        exit( 0 );
    }

    // create the xi library context
    xi_context_t* xi_context
        = xi_create_context(
                  XI_HTTP, argv[ 1 ]
                , atoi( argv[ 2 ] ) );

    // check if everything works
    if( xi_context == 0 )
    {
        return -1;
    }

    // remember the count for pairs
    size_t pairs_count = ( argc - REQUIRED_ARGS ) / 2;

    // create feed
    xi_feed_t f;
    memset( &f, 0, sizeof( xi_feed_t ) );

    // set datastream count
    f.feed_id           = atoi( argv[ 2 ] );
    f.datastream_count  = pairs_count;

    // for each pair
    for( size_t i = 0; i < pairs_count; i++ )
    {
        // get the datastream pointer
        xi_datastream_t* d = &f.datastreams[ i ];

        // set the datapoint count
        d->datapoint_count   = 1;

        int size = sizeof( d->datastream_id );
        int s = xi_str_copy_untiln( d->datastream_id, size
            , argv[ REQUIRED_ARGS + ( i * 2 ) ], '\0' );

        if( s >= size )
        {
            printf( "datastream id too long: %s\n", argv[ REQUIRED_ARGS + ( i * 2 ) ] );
        }

        // get the datpoint counter
        xi_datapoint_t* p = &d->datapoints[ 0 ];

        // set the datapoint
        xi_set_value_i32( p, atoi( argv[ REQUIRED_ARGS + ( i  * 2 ) + 1 ] ) );
    }

    for( int i = 0; i < 20; ++i )
    {
        xi_feed_update( xi_context, &f );
    }

    // destroy the context cause we don't need it anymore
    xi_delete_context( xi_context );
#endif
    return 0;
}