Esempio n. 1
0
void test_helpers_copy_until( void* data )
{
    (void)(data);

    const int buffer_size         = 64;
    const int buffer_size_small     = 2;

    // simple test
    {
        const char src[] = "test of some string";

        char dst[ buffer_size ];
        memset( dst, 0, sizeof( dst ) );

        int s = xi_str_copy_untiln( dst, buffer_size, src, ' ' );

        tt_assert( strcmp( dst, "test" ) == 0 );
        tt_assert( s == 4 );
    }

    // test not found
    {
        const char src[] = "test of some string";

        char dst[ buffer_size ];
        memset( dst, 0, sizeof( dst ) );

        int s = xi_str_copy_untiln( dst, buffer_size, src, '0' );

        tt_assert( strcmp( dst, "test of some string" ) == 0 );
        tt_assert( s == sizeof( src ) - 1 );
    }

    // test capacity exceeded
    {
        const char src[] = "test of some string";

        char dst[ buffer_size_small ];
        memset( dst, 0, sizeof( dst ) );

        int s = xi_str_copy_untiln( dst, buffer_size_small, src, '0' );

        tt_assert( strcmp( dst, "t" ) == 0 );
        tt_assert( s == buffer_size_small - 1 );
    }

end:
    ;
}
Esempio n. 2
0
int main()
{
   // Create the Xively context
   xi_context_t* xi_context = xi_create_context(XI_HTTP, DEVICE_KEY, FEED_ID);
   if(xi_context==NULL){
      perror("XIVELY: Problem in creating the context");
      return 1;
   }
   // Create the feed and clear its contents
   xi_feed_t feed;
   memset(&feed, 0, sizeof(xi_feed_t));
   // Set the properties of the feed (id, number of streams and datstream)
   feed.feed_id           = FEED_ID;
   feed.datastream_count  = 1;  //only sending a single stream, datastream 0
   // Get a reference to the datastream
   xi_datastream_t* data  = &feed.datastreams[0];
   // Only going to send a single data point in the stream
   data->datapoint_count = 1;
   // Set up the data stream identifier "tempSensor"
   int size = sizeof(data->datastream_id);
   xi_str_copy_untiln(data->datastream_id, size, "tempSensor", '\0' );
   // Set up the data point and setting a floating point value
   xi_datapoint_t* point = &data->datapoints[0];
   xi_set_value_f32(point, getTemperature(readAnalog(0)));
   // Update the feed
   xi_feed_update(xi_context, &feed);
   xi_delete_context(xi_context);
   return 0;
}
Esempio n. 3
0
xi_datapoint_t* xi_set_value_str( xi_datapoint_t* p, const char* value )
{
    // PRECONDITION
    assert( p != 0 );

    int s = xi_str_copy_untiln( p->value.str_value
        , XI_VALUE_STRING_MAX_SIZE, value, '\0' );

    XI_CHECK_SIZE( s, XI_VALUE_STRING_MAX_SIZE, XI_DATAPOINT_VALUE_BUFFER_OVERFLOW );

    p->value_type = XI_VALUE_TYPE_STR;

    return p;

err_handling:
    return 0;
}
Esempio n. 4
0
int main( int argc, const char* argv[] )
{

    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 datapoints_count = argc - REQUIRED_ARGS;

    // 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  = datapoints_count;

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

        // set the datastream id
        int size = sizeof( d->datastream_id );
        int s = xi_str_copy_untiln( d->datastream_id, size
            , argv[ REQUIRED_ARGS + i ], '\0' );

        if( s >= size )
        {
            perror( "datastream name too long " );
        }
    }

    xi_feed_get( xi_context, &f );

    for( size_t i = 0; i < f.datastream_count; ++i )
    {
        xi_datastream_t* d = &f.datastreams[ i ];
        printf( "datasream_id: %s ", d->datastream_id );

        for( size_t j = 0; j < d->datapoint_count; ++j )
        {
            xi_datapoint_t* p = &d->datapoints[ j ];
            print_datapoint( p );
        }
    }

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

    return 0;
}
Esempio n. 5
0
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;
}