Esempio n. 1
0
int OSC_Base::parseData(osc_message* message) {
  int offset = message->header.offset_to_data<<2;
  const char* buffer = message->header.path;
  
  message->data_count = message->typetag_length-1;
  message->data = (data_holder_type*)local_rx_malloc(sizeof(data_holder_type)*message->data_count);
  
  // make sure the holder is null
  memset(message->data, 0x00, sizeof(data_holder_type)*message->data_count);
  
  for (int i = 0; i < message->data_count; i++) {
    switch(message->typetag[i+1]) {
    case 'c': message->data[i].type = TYPE_CHARACTER;  offset += load_32bit(&buffer[offset], &message->data[i]); break;
    case 'f': message->data[i].type = TYPE_FLOAT;      offset += load_32bit(&buffer[offset], &message->data[i]); break;
    case 'i': message->data[i].type = TYPE_INTEGER;    offset += load_32bit(&buffer[offset], &message->data[i]); break;
    case 'r': message->data[i].type = TYPE_COLOR;      offset += load_32bit(&buffer[offset], &message->data[i]); break;
    case 't': message->data[i].type = TYPE_TIMETAG;    offset += load_64bit(&buffer[offset], &message->data[i]); break;
    case 'h': message->data[i].type = TYPE_LONG;       offset += load_64bit(&buffer[offset], &message->data[i]); break;
    case 'd': message->data[i].type = TYPE_DOUBLE;     offset += load_64bit(&buffer[offset], &message->data[i]); break;
    case 'F': message->data[i].type = TYPE_FALSE;      message->data[i].value_uint32 = 0; break; 
    case 'N': message->data[i].type = TYPE_NONE;       message->data[i].value_uint32 = 0; break;
    case 'I': message->data[i].type = TYPE_IMPULSE;    message->data[i].value_uint32 = 1; break;
    case 'T': message->data[i].type = TYPE_TRUE;       message->data[i].value_uint32 = 1; break;
    case 's': message->data[i].type = TYPE_STRING;     offset += load_string(&buffer[offset], &message->data[i]); break;
    case 'b': message->data[i].type = TYPE_BLOB;       offset += load_blob(&buffer[offset], &message->data[i]); break;
    case 'B': message->data[i].type = TYPE_ADVBLOB;    offset += load_blob(&buffer[offset], &message->data[i]); break;
    }
  }
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	void *fdt1, *fdt2;
	uint32_t cpuid1, cpuid2;

	test_init(argc, argv);
	if ((argc != 3)
	    && ((argc != 4) || !streq(argv[1], "-n")))
		CONFIG("Usage: %s [-n] <dtb file> <dtb file>", argv[0]);
	if (argc == 4)
		notequal = 1;

	fdt1 = load_blob(argv[argc-2]);
	fdt2 = load_blob(argv[argc-1]);

	compare_mem_rsv(fdt1, fdt2);
	compare_structure(fdt1, fdt2);

	cpuid1 = fdt_boot_cpuid_phys(fdt1);
	cpuid2 = fdt_boot_cpuid_phys(fdt2);
	if (cpuid1 != cpuid2)
		MISMATCH("boot_cpuid_phys mismatch 0x%x != 0x%x",
			 cpuid1, cpuid2);

	MATCH();
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    void *fdt;

    if (argc != 2)
        CONFIG("Usage: %s <dtb file>\n", argv[0]);

    test_init(argc, argv);
    fdt = load_blob(argv[1]);

    check_expected_failure(fdt, "/", "#address-cells");
    check_expected_failure(fdt, "/", "#size-cells");

    check_string_count(fdt, "/", "compatible", 1);
    check_string_count(fdt, "/device", "compatible", 2);
    check_string_count(fdt, "/device", "big-endian", 0);

    check_string_index(fdt, "/", "compatible", "test-strings", 0);
    check_string_index(fdt, "/device", "compatible", "foo", 0);
    check_string_index(fdt, "/device", "compatible", "bar", 1);
    check_string_index(fdt, "/device", "big-endian", "baz", -1);

    check_string(fdt, "/", "compatible", 0, "test-strings");
    check_string(fdt, "/device", "compatible", 0, "foo");
    check_string(fdt, "/device", "compatible", 1, "bar");

    PASS();
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
	void *fdt1, *fdt2;
	uint32_t cpuid1, cpuid2;
	char **args;
	int argsleft;

	test_init(argc, argv);

	args = &argv[1];
	argsleft = argc - 1;

	while (argsleft > 2) {
		if (streq(args[0], "-n"))
			notequal = 1;
		else if (streq(args[0], "-m"))
			ignore_memrsv = 1;
		else
			badargs(argv);
		args++;
		argsleft--;
	}
	if (argsleft != 2)
		badargs(argv);

	fdt1 = load_blob(args[0]);
	fdt2 = load_blob(args[1]);

	if (!ignore_memrsv)
		compare_mem_rsv(fdt1, fdt2);
	compare_node(fdt1, 0, fdt2, 0);

	cpuid1 = fdt_boot_cpuid_phys(fdt1);
	cpuid2 = fdt_boot_cpuid_phys(fdt2);
	if (cpuid1 != cpuid2)
		MISMATCH("boot_cpuid_phys mismatch 0x%x != 0x%x",
		     cpuid1, cpuid2);

	MATCH();
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
	void *fdt;
	uint32_t cpuid;

	test_init(argc, argv);

	if (argc != 3)
		CONFIG("Usage: %s <dtb file> <cpuid>", argv[0]);

	fdt = load_blob(argv[1]);
	cpuid = strtoul(argv[2], NULL, 0);

	if (fdt_boot_cpuid_phys(fdt) != cpuid)
		FAIL("Incorrect boot_cpuid_phys (0x%x instead of 0x%x)",
		     fdt_boot_cpuid_phys(fdt), cpuid);

	PASS();
}
Esempio n. 6
0
int main (int argc, char *argv[])
{
    int ret;
    sqlite3 *handle;
    char *err_msg = NULL;
    char **results;
    int rows;
    int columns;
    unsigned char *blob;
    int blob_len;
    char *hexBlob;
    unsigned char *xml;
    int len;
    char *sql;
    void *cache = spatialite_alloc_connection();

    if (argc > 1 || argv[0] == NULL)
	argc = 1;		/* silencing stupid compiler warnings */

    ret = sqlite3_open_v2 (":memory:", &handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "cannot open in-memory db: %s\n", sqlite3_errmsg (handle));
	sqlite3_close(handle);
	return -1;
    }

    spatialite_init_ex (handle, cache, 0);

    ret = sqlite3_exec (handle, "SELECT InitSpatialMetadata(1, 'WGS84')", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
	fprintf(stderr, "Unexpected InitSpatialMetadata result: %i, (%s)\n", ret, err_msg);
	sqlite3_free (err_msg);
	return -2;
    }

#ifdef ENABLE_LIBXML2	/* only if LIBXML2 is supported */

    ret = sqlite3_get_table (handle, "SELECT CreateStylingTables(1)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error CreateStylingTables: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -3;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -4;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #0 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -5;
    }
    sqlite3_free_table(results);

    blob = load_blob("empty.png", &blob_len);
    if (blob == NULL) 
        return -6;
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -7;
    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-A', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #1: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -8;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -9;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #1 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -10;
    }
    sqlite3_free_table(results);

    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-A', x%Q, 'title', 'abstract', 'file_name')", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    free(hexBlob);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #2: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -11;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -12;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #2 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -13;
    }
    sqlite3_free_table(results);

    xml = load_xml("thunderstorm_mild.svg", &len);
    if (xml == NULL) 
        return -14;
    gaiaXmlToBlob (cache, xml, len, 1, NULL, &blob, &blob_len, NULL, NULL); 
    free(xml);
    if (blob == NULL) {
        fprintf (stderr, "this is not a well-formed XML !!!\n");
        return -15;
    }
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -16;
    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-B', x%Q, 'title', 'abstract', 'file_name')", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #3: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -17;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -18;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #3 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -19;
    }
    sqlite3_free_table(results);

    sql = sqlite3_mprintf("SELECT RegisterExternalGraphic('url-B', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    free(hexBlob);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterExternalGraphic #4: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -20;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -21;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #4 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -22;
    }
    sqlite3_free_table(results);

    ret = sqlite3_exec (handle, "CREATE TABLE table1 (id INTEGER PRIMARY KEY AUTOINCREMENT)", NULL, NULL, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error Create Table table1: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -23;
    }
    ret = sqlite3_get_table (handle, "SELECT AddGeometryColumn('table1', 'geom', 4326, 'POINT', 'XY')", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error AddGeometryColumn: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -24;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -25;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #5 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -26;
    }
    sqlite3_free_table(results);

    xml = load_xml("stazioni_se.xml", &len);
    if (xml == NULL) 
        return -27;
    gaiaXmlToBlob (cache, xml, len, 1, NULL, &blob, &blob_len, NULL, NULL); 
    free(xml);
    if (blob == NULL) {
        fprintf (stderr, "this is not a well-formed XML !!!\n");
        return -28;
    }
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -29;
    sql = sqlite3_mprintf("SELECT RegisterVectorStyledLayer('table1', 'geom', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterVectorStyledLayer #6: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -30;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -31;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #6 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -32;
    }
    sqlite3_free_table(results);
    
    sql = sqlite3_mprintf("SELECT RegisterVectorStyledLayer('table1', 'geom', 0, x%Q)", hexBlob);
    free(hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterVectorStyledLayer #7: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -33;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -34;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #7 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -35;
    }
    sqlite3_free_table(results);

    xml = load_xml("raster_se.xml", &len);
    if (xml == NULL) 
        return -36;
    gaiaXmlToBlob (cache, xml, len, 1, NULL, &blob, &blob_len, NULL, NULL); 
    free(xml);
    if (blob == NULL) {
        fprintf (stderr, "this is not a well-formed XML !!!\n");
        return -37;
    }
    hexBlob = build_hex_blob(blob, blob_len);
    free(blob);
    if (hexBlob == NULL)
        return -38;
    sql = sqlite3_mprintf("SELECT RegisterRasterStyledLayer('srtm', x%Q)", hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterRasterStyledLayer #8: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -39;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -40;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #8 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -41;
    }
    sqlite3_free_table(results);
    
    sql = sqlite3_mprintf("SELECT RegisterRasterStyledLayer('srtm', 0, x%Q)", hexBlob);
    free(hexBlob);
    ret = sqlite3_get_table (handle, sql, &results, &rows, &columns, &err_msg);
    sqlite3_free(sql);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterRasterStyledLayer #9: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -42;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -43;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #9 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -44;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'srtm', 0)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #10: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -45;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -46;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #10 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -47;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'table1', 'geom', 0)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #11: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -48;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -49;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #12 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -50;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'srtm', 0, 4)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #13: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -51;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -52;
    }
    if (strcmp(results[1 * columns + 0], "0") != 0)
    {
	fprintf (stderr, "Unexpected #13 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -53;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT RegisterStyledGroup('group', 'table1', 'geom', 0, 1)", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #14: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -54;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -55;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #14 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -56;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT SetStyledGroupInfos('group', 'title', 'abstract')", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #15: %s\n", err_msg);
      sqlite3_free (err_msg);
      return -57;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -58;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #15 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -59;
    }
    sqlite3_free_table(results);
    
    ret = sqlite3_get_table (handle, "SELECT SetStyledGroupInfos('group-bis', 'title', 'abstract')", &results, &rows, &columns, &err_msg);
    if (ret != SQLITE_OK) {
      fprintf (stderr, "Error RegisterStyledGroup #16: %s\n", err_msg);
      sqlite3_free (err_msg);
      return 60;
    }
    if ((rows != 1) || (columns != 1))
    {
	sqlite3_free_table(results);
	fprintf (stderr, "Unexpected row / column count: %i x %i\n", rows, columns);
	return -61;
    }
    if (strcmp(results[1 * columns + 0], "1") != 0)
    {
	fprintf (stderr, "Unexpected #16 result (got %s, expected 1)", results[1 * columns + 0]);
	sqlite3_free_table(results);
	return -62;
    }
    sqlite3_free_table(results);


#endif
    
    ret = sqlite3_close (handle);
    if (ret != SQLITE_OK) {
        fprintf (stderr, "sqlite3_close() error: %s\n", sqlite3_errmsg (handle));
	return -57;
    }
        
    spatialite_cleanup_ex (cache);

#ifdef ENABLE_LIBXML2	/* only if LIBXML2 is supported */
    xmlCleanupParser();
#endif
    
    return 0;
}
Esempio n. 7
0
static II_VOID
load_columns
(
    IIAPI_STMTHNDL	*stmtHndl,
    IIAPI_GETCOLPARM	*getColParm,
    IIAPI_MSG_BUFF	*msgBuff
)
{
    IIAPI_DESCRIPTOR	*descr;
    IIAPI_DATAVALUE	*value;
    i4			length;
    u_i2		len;
    bool		done;

    IIAPI_TRACE( IIAPI_TR_VERBOSE )
	( "IIapi_loadColumns: %d columns starting with %d, %d total columns\n",
	  (II_LONG)stmtHndl->sh_colFetch, 
	  (II_LONG)stmtHndl->sh_colIndex, 
	  (II_LONG)stmtHndl->sh_colCount );

    descr = &stmtHndl->sh_colDescriptor[ stmtHndl->sh_colIndex ];
    value = &getColParm->gc_columnData[ (getColParm->gc_rowsReturned * 
					 getColParm->gc_columnCount) +
					 getColParm->gc_columnCount -
					 stmtHndl->sh_colFetch ];

    /*
    ** Process columns until all done or input buffer exhausted.
    */
    for( ; stmtHndl->sh_colFetch; 
	 stmtHndl->sh_colFetch--, stmtHndl->sh_colIndex++, descr++, value++ )
    {
	/*
	** Clear column info at start of row.  The more segments
	** flag must not be set otherwise the first column is a
	** LOB which has already been partially processed.  There
	** must also be at least some data available for the first
	** column, otherwise we may be clearing the info when the
	** last row has already been received.
	*/
	if ( 
	     stmtHndl->sh_colIndex == 0  &&
	     ! (stmtHndl->sh_flags & IIAPI_SH_MORE_SEGMENTS)  &&
	     msgBuff->length > 0 
	   )
	{
	    i2 i;

	    for( i = 0; i < stmtHndl->sh_colCount; i++ )
	        stmtHndl->sh_colInfo[ i ].ci_flags = 0;
	}

	/*
	** Blobs are broken into segments of variable lengths
	** and require special handling to load segments using 
	** internal data value info.
	*/
	if ( IIapi_isBLOB( descr->ds_dataType ) )
	    done = load_blob( stmtHndl, getColParm, descr, msgBuff, value );
	else
	    done = cnvtGDV2DataValue( stmtHndl, descr, msgBuff, value, 
		(stmtHndl->sh_flags & IIAPI_SH_COMP_VARCHAR) ? TRUE : FALSE );

	if ( ! done )  break;	/* Need more data for current column */

	stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_flags |=
								IIAPI_CI_AVAIL;

	IIAPI_TRACE( IIAPI_TR_VERBOSE )
	    ( "IIapi_loadColumns: loaded data for column %d\n",
	      (II_LONG)stmtHndl->sh_colIndex );
    }

    return;
}
Esempio n. 8
0
receive_return_type OSC_Base::_Receive(const char *buffer, size_t len, OSC_Base *origin) {
  osc_message message;
  osc_on_message_args args;
  int offset;
  data_holder_type temp_data;
  args.message = &message;
  args.interface = this;

  //Serial.println("OSC _Receive - called");
  //Serial.printf("OSC _Receive - head: 0x%08X\r\n", ps.head);

  if (len < 8) goto error_incomplete;

  message.origin = origin;

  message.header.path = buffer;
  for (message.header.path_length = 0; message.header.path[message.header.path_length] && message.header.path_length < len; message.header.path_length++);
  offset = (message.header.path_length+4) & (~3);
  if (message.header.path_length >= len || offset >= len) goto error_incomplete;

  //Serial.println("OSC _Receive - sanity checks");
  
  if (message.header.path[0] == '#') {
    //Serial.println("OSC _Receive - #bundle");
    // handle special # code messages - bundle
    if (stringCompareWNull(message.header.path, "#bundle")) {
      data_holder_type timetag;
      message.typetag = (const char*) NULL;
      message.typetag_length = 0;
      
      if (len < 20) goto error_incomplete;

      timetag.raw_header = 0;
      timetag.type = TYPE_TIMETAG;
      offset += load_64bit(&buffer[offset], &timetag);
        
      temp_data.type = TYPE_MESSAGE;
      temp_data.is_array = 1;
      offset += load_blob(&buffer[offset], &temp_data);

      if (offset >= len) goto error_incomplete;
      
      // TODO: finish this to actually handle bundles properly
      return BUNDLE_RECEIVED;
    }
    
    return ERROR_PARSE;
  }
  else {
    //Serial.println("OSC _Receive - message");
    // data handling will take place on a 'parseMessage' call, right now we just need to find the limits of the message
    message.typetag = &buffer[offset];
    for (message.typetag_length = 0; message.typetag[message.typetag_length]; message.typetag_length++);
    offset += (message.typetag_length+4) & (~3);

    //Serial.printf("OSC _Receive - path and typetag; Offset: %d, Path: %d, Typetag: %d\r\n", offset, message.header.path_length, message.typetag_length);
    
    message.header.offset_to_data = offset >> 2;
    message.data_count = message.typetag_length-1;
    
    for (int i = 0; i < message.data_count; i++) {
      switch(message.typetag[i+1]) {
      case 'c': // TYPE_CHARACTER;  offset += load_32bit(&buffer[offset], &message.data[i]); break;
      case 'f': // TYPE_FLOAT;      offset += load_32bit(&buffer[offset], &message.data[i]); break;
      case 'i': // TYPE_INTEGER;    offset += load_32bit(&buffer[offset], &message.data[i]); break;
      case 'r': // TYPE_COLOR;      offset += load_32bit(&buffer[offset], &message.data[i]); break;
        offset += 4;
        //Serial.printf("OSC _Receive - 32bit value; Offset: %d\r\n", offset);
        break;
      case 't': // TYPE_TIMETAG;    offset += load_64bit(&buffer[offset], &message.data[i]); break;
      case 'h': // TYPE_LONG;       offset += load_64bit(&buffer[offset], &message.data[i]); break;
      case 'd': // TYPE_DOUBLE;     offset += load_64bit(&buffer[offset], &message.data[i]); break;
        offset += 8;
        //Serial.printf("OSC _Receive - 64bit value; Offset: %d\r\n", offset);
        break;
      case 'F': // TYPE_FALSE;      message.data[i].value_uint32 = 0; break; 
      case 'N': // TYPE_NONE;       message.data[i].value_uint32 = 0; break;
      case 'I': // TYPE_IMPULSE;    message.data[i].value_uint32 = 1; break;
      case 'T': // TYPE_TRUE;       message.data[i].value_uint32 = 1; break;
        break;
      case 's': // TYPE_STRING;     offset += load_string(&buffer[offset], &message.data[i]); break;
        offset += load_string(&buffer[offset], &temp_data);
        //Serial.printf("OSC _Receive - string; Offset: %d\r\n", offset);
        break;
      case 'b': // TYPE_BLOB;       offset += load_blob(&buffer[offset], &message.data[i]); break;
        offset += load_blob(&buffer[offset], &temp_data);
        //Serial.printf("OSC _Receive - blob; Offset: %d\r\n", offset);
        break;
      case 'B': // TYPE_ADVBLOB;    offset += load_advblob(&buffer[offset], &message.data[i]); break;
        offset += load_blob(&buffer[offset], &temp_data);
        //Serial.printf("OSC _Receive - advblob; Offset: %d\r\n", offset);
        break;
      }
      if (offset > len) goto error_incomplete;
    }
    //Serial.println("OSC _Receive - data measured");
    message.header.length = offset;
    // -------------- handle message
    //Serial.printf("OSC _Receive - Addresses for Pathsearch: 0x%08X 0x%08X 0x%08X\r\n", &ps, message.header.path, &args);
    //Serial.printf("OSC _Receive - head: 0x%08X\r\n", ps.head);
    //Serial.printf("OSC _Receive - matches: %d\r\n", pathSearch(&ps, message.header.path, (void*)&args));
    pathSearch(&ps, message.header.path, (void*)&args);
    //Serial.println("OSC _Receive - pathsearch done");
    // -----------------------------
    //Serial.println("OSC _Receive - finished");
    return MESSAGE_RECEIVED;
  }

  // One of the only times I'll ever use gotos
  // This makes sure the allocated space, if any, is freed before exiting
 error_incomplete:
    Serial.printf("OSC _Receive - Error: Incomplete - offset: %d  len: %d\r\n", offset, len);
    return ERROR_INCOMPLETE;
 error_parse:
    Serial.println("OSC _Receive - Error: Parse");
    return ERROR_PARSE;
}
int main(int argc, char** argv)
{
    //reading data values 
    int fd;
    int ctr_numhits=0;
    int num_records=0;
    ssize_t numbytes;
    int compare = 1;
    off_t offset = 0;
    char error_buf[ERROR_BUF_SIZE];
    int headersize=DR_HEAER_SIZE;
    int next_buffer_size=1;
    int datasize=next_buffer_size;
    char *header = (char *) malloc(DR_HEAER_SIZE);
    char *data = (char *) malloc(MAX_DATA_SIZE);

    //plotting variables
    int maxbin = 0;
    int maxvalue = 0;
    int xmax = (int) BINS;

    //data values
    int finebin = 0 ;
    int bytesread = 1;
    int value;
    int pfb_bin = 0;
    int fft_bin = 0;
    int fft_bin_loc= 0;
    int over_thresh = 0;
    int blank = 0;
    int event = 0;
    unsigned int pfb_fft_power = 0;
    unsigned int fields;
    long int i = 0;
    int j = 0;
    int k = 0;
    int ctr = 0;
    int counter=0;
    int beamnum = 0;
    double fstep,fscoarse = 0.0;
    double rfmin,rfctr = 0.0;
    double freq_fft_bin = 0.0;
    double bary_freq = 0.0;
    char rawfile[] = "largefile_MMMDDYYYY_HHMM";
    int gooddata=1;
    int goodfreq=1;

    long int fileposition=0;   //position in input file
    long int filesize;   //position in input file

    FILE *fout;
    //create buffers
    struct spectral_data spectra;

    struct data_vals *data_ptr;
    data_ptr = (struct data_vals *)data;

    //create header structure
    struct setidata frame;

    // create time structure
    tm hittime;
    double spec_time;

    // create SQL structures
    unsigned long int specid;
    //strcpy(def_password, argv[2]);
    char sqlquery[1024];
    char hitquery[1024];

    // file variables
    FILE *datatext;


    // connect to mySQL database
    dbconnect();

#ifdef GRACE
    // Initialize grace plotting windows
    grace_init();
//    grace_open_deux(8192);
//    grace_init_deux(maxbin,maxvalue,xmax);
#endif

    //check for error opening file
    fd = open(argv[1], O_RDONLY);

    if(fd==-1)
    {
        snprintf(error_buf, ERROR_BUF_SIZE, "Error opening file %s", argv[1]);
        perror(error_buf);
        return 0;
    }

    //if we can't find a header, nothing to be done
    if(find_first_header(fd)==-1) return 0;

    //read header
    //make sure we are reading as much data as expected, otherwise might be at eof
    while(headersize==DR_HEAER_SIZE && datasize==next_buffer_size)
    {
        k = k+1;
	//reset dataflag to "good"
	gooddata=1;

	// read in the header data
        headersize = read(fd, (void *) header, DR_HEAER_SIZE);
	fileposition+=headersize;

//        int iii=0;
//        for(iii=0; iii<DR_HEAER_SIZE; iii++)
//            printf("%c", header[iii]);

	//get the size of spectra and parse header values
        next_buffer_size = read_header(header);

        read_header_data(header, &frame);

	//Read in data
        datasize = read(fd, (void *) data, next_buffer_size);
	fileposition+=datasize;

//        printf("Buffersize, datasize: %d %d\n", next_buffer_size, datasize);
//	int iii=0;
//	printf("Printing data header\n");
//	for(iii=0; iii<datasize; iii++)
//		printf("%c", data[iii]);

	//Parse data header
        beamnum = read_beam(data, datasize);
        read_data_header(data, &frame);

	//Convert to RA and Dec
        scramAzZatoRaDec(frame.agc_systime, frame.agc_time, frame.agc_az, frame.agc_za, 
                frame.alfashm_alfamotorposition, beamnum/2, 0, &frame.ra, &frame.dec,  &hittime);

	get_filename(argv[1], rawfile);
//	printf("%s\n", rawfile);

	//Calculate MJD
	spec_time = time2mjd(frame.agc_systime, frame.agc_time);

        // creates query to config table
        // set digital_lo and board to be constants, because we figured we knew
        // what they were and that they weren't changing
        char bid[] = "B2";
        sprintf(sqlquery, "INSERT INTO config (thrscale, thrlimit, fftshift, pfbshift, beamnum, obstime, ra, decl, digital_lo, board, AGC_SysTime, AGC_Time, AGC_Az, AGC_Za, AlfaFirstBias, AlfaSecondBias, AlfaMotorPosition, IF1_rfFreq, synI_freqHz, IF1_synI_ampDB, IF1_if1FrqMHz, IF1_alfaFb, TT_TurretEncoder, TT_TurretDegrees, rawfile) VALUES (%ld, %ld, %ld, %ld, %d, %lf, %lf, %lf, %ld, '%s', %ld, %ld, %lf, %lf, %ld, %ld, %lf, %9.1lf, %9.1lf, %ld, %lf, %ld, %ld, %lf, '%s')", 
                frame.thrscale, frame.thrlimit, frame.fft_shift, frame.pfb_shift,
                beamnum, (double) ((int) spec_time), frame.ra, frame.dec, 200000000, bid, frame.agc_systime, frame.agc_time, 
                frame.agc_az, frame.agc_za, frame.alfashm_alfafirstbias, frame.alfashm_alfasecondbias, 
                frame.alfashm_alfamotorposition, frame.if1_rffreq, frame.if1_syni_freqhz_0, frame.if1_syni_ampdb_0, 
                frame.if1_if1frqmhz, frame.if1_alfafb, frame.tt_turretencoder, frame.tt_turretdegrees, rawfile);

#ifndef DEBUG
        // insert header data into serendipvv config table
        if (mysql_query(conn, sqlquery)) {
            fprintf(stderr, "Error inserting data into sql database... \n");
            exiterr(3);
        }

        // saves specid to be inserted at index in other sql tables
        if ((res = mysql_store_result(conn))==0 && mysql_field_count(conn)==0 && mysql_insert_id(conn)!=0) {
            specid = (unsigned long int) mysql_insert_id(conn);
        }
#endif

#ifdef DEBUG
	printf("%s\n", sqlquery);
	printf("Spec id: %d\n", specid);
#endif
        //doesn't do any bounds checking yet...
        spectra.numhits = read_data(data, datasize) - 4096;

	//printf("size of spectra %d\n",spectra.numhits);
	//header,data
	data_ptr = (struct data_vals *) (data+SETI_HEADER_SIZE_IN_BYTES);

    //======================== TEST FILE DATA DUMP ================

    /*
        FILE *datafile;
        char dataf[100];
        sprintf(dataf,"datafiles/datafile%d.dat",counter);
        datafile = fopen(dataf,"wb");
        fwrite(data,spectra.numhits,1,(FILE *)datafile);
        fflush(datafile);
        fclose(datafile);  
    */

		
    //==============================================

        num_records = read_data(data,datasize);
	ctr_numhits=0;

        //create file spectraldata and print file header
/*        char filename[BUFSIZ];
        sprintf(filename, "spectraldata%d", beamnum);
        datatext = fopen(filename,"w");
        fprintf(datatext, "specnum,beamnum,coarsebin,coarsepower,hitpower,fftbin\n");
*/
        //Calc values for freq_topo calc
        //Freq chan resolution
        fstep = 200000000.0/134217728;
        fscoarse = 200000000.0/4096;
	//Center of the BEE2 bandpass
        rfctr = frame.if1_rffreq - 50000000.0;
	//Right edge of the last bin is the lowest freq
	//because the RF band is flipped in the IF
//	rfmin=rfctr-0.5*fscoarse;
        rfmin=rfctr+0.5*fscoarse;

	//Check to see if there are too many hits
	if(num_records>0.9*frame.thrlimit*4096) {
	    gooddata=0;
	    fprintf(stderr, "Data bad...more than %5.0lf hits.\n",  0.9*frame.thrlimit*4096);
	}

//****OPEN FILE TO WRITE HITS TO
        fout=fopen("hits_list.txt", "w");
//============================
//         LOOP OVER HITS
//=============================
	for(i=0;i< num_records ;i++)
	{
	    goodfreq=1;
	    fields = ntohl(data_ptr->raw_data);
	    fft_bin = slice(fields,15,0);
	    pfb_bin = slice(fields,12,15);
	    over_thresh = slice(fields,1,27);
	    blank = slice(fields,3,28);
	    event = slice(fields,1,31);
	    
	    pfb_fft_power = ntohl(data_ptr->overflow_cntr); //32.0
//	    pfb_fft_power = data_ptr->overflow_cntr; //32.0

	    //Rearrange the bins
	    //1) Reorder the FFT output order
	    //2) Reverse bins due to RF/IF flip
            pfb_bin = (pfb_bin + 2048) % 4096;
//	    pfb_bin = 4096 - pfb_bin;
	    pfb_bin = 4095 - pfb_bin;
	    fft_bin = (fft_bin + 16384) % 32768;
//	    fft_bin = 32768 - fft_bin;
	    fft_bin = 32767 - fft_bin;
            fft_bin_loc = fft_bin;
            fft_bin+=pfb_bin*32768;

	    freq_fft_bin =  rfmin + fstep*fft_bin;

	    //Check that the freq of the hit falls within the valid ranges
	    if(frame.if1_alfafb==1){
	        if(freq_fft_bin < NBF_FREQ_LO || freq_fft_bin > NBF_FREQ_HI)  goodfreq=0;
	    }
	    else if(frame.if1_alfafb==0){
                if(freq_fft_bin < ALFA_FREQ_LO || freq_fft_bin > ALFA_FREQ_HI)  goodfreq=0;
	    }
           
            value = (int) (pfb_fft_power);
            //printf("%d %d %d %d %d %d\n", pfb_bin, fft_bin, pfb_fft_power, blank, event, over_thresh);

	    if(value < 1)
	    {
                value = 1;
	    }

	    if(value > maxvalue)
	    {
                maxvalue = value;
                maxbin = fft_bin;
	    }

	   //populate coarse bin power
	    if(fft_bin_loc==16383)
	    {
                spectra.coarse_spectra[pfb_bin] = value;
	    }

            //Only generate string and insert into database if hit valid
	    if(fft_bin_loc!=16383 && goodfreq==1 && gooddata==1)
	    {
//                spectra.hits[ctr_numhits][0] = value;  
//                spectra.hits[ctr_numhits][1] = fft_bin;  

		//Calculate the frequency of the fine bins and barycenter
		bary_freq=freq_fft_bin+seti_dop_FreqOffsetAtBaryCenter(freq_fft_bin, 
			spec_time+2400000.5, frame.ra, frame.dec, 2000.0, AO_LAT, AO_LONG, AO_ELEV);


                //Prepare mysql query to insert hits
                sprintf(hitquery, "INSERT INTO hit (eventpower, meanpower, binnum, topocentric_freq, barycentric_freq, specid) VALUES (%f, %e, %d, %lf, %lf, %ld)", (double) value, (double) spectra.coarse_spectra[pfb_bin], fft_bin, freq_fft_bin, bary_freq, specid);

                //Write row to tmp file
                fprintf(fout, "\\N\t %f\t %e\t %d\t %lf\t %lf\t 0\t 0\t 0\t 0\t 0\t %ld\t \n", (double) value, (double) spectra.coarse_spectra[pfb_bin], fft_bin, freq_fft_bin, bary_freq, specid);
/*
#ifndef DEBUG
                // insert header data into serendipvv config table
                if (mysql_query(conn, hitquery)) {
                    fprintf(stderr, "Error inserting data into sql database... \n");
                    exiterr(3);
                }
#endif */

            }

            // fill spectraldata with available data and close file
//            fprintf(datatext, "%d, %d, %d, %e, %f, %d\n", k, beamnum, pfb_bin, (double) spectra.coarse_spectra[pfb_bin], (double) value, fft_bin);
	
            ctr_numhits++;
	    data_ptr++;
	    ctr++;		
	}//for(i=0; i<num_records; i++)

        fclose(fout);

        sprintf(hitquery, "LOAD DATA LOCAL INFILE 'hits_list.txt' INTO TABLE hit");
//        printf("%s\n", hitquery);

        if (mysql_query(conn, hitquery)) {
            fprintf(stderr, "Error inserting data into sql database... \n");
            exiterr(3);
        }

//        fclose(datatext);
#ifndef DEBUG
       if(load_blob(conn, specid, spectra.coarse_spectra)!=0)
       {
               fprintf(stderr, "Blob not loaded\n");
               specid=0;
       }
#endif

//	GracePrintf("autoticks");
//	GracePrintf("redraw");
//	GracePrintf("updateall");
//	GracePrintf("kill g0.s0");
//	GracePrintf("saveall \"plots/sample%d.agr\"",counter);
//	grace_init_deux(maxbin,log10(maxvalue),xmax);	

	counter++;
        
        for(i=0;i<4094;i++) {
            spectra.coarse_spectra[i] = spectra.coarse_spectra[i+1];
        }

#ifdef GRACE	
    	plot_beam(&spectra,beamnum);
        printf("num_records: %d spectra.numhits %d\n",num_records,spectra.numhits);
        usleep(200000);
    
	if(counter%10 == 0) { 
            printf("autoscaling...\n");
            GracePrintf("redraw");
            GracePrintf("updateall");
            GracePrintf("autoscale");

            /*
            //output pdf via grace

            GracePrintf("HARDCOPY DEVICE \"EPS\"");
            printf("start eps create\n");
            GracePrintf("PAGE SIZE 600, 600");
            GracePrintf("saveall \"sample.agr\"");
            GracePrintf("PRINT TO \"%s\"", "plot.eps");
            GracePrintf("PRINT");
            */

	}
#endif
    }
//=====================================================
/*
    // play with some text 
    for(i=0; i<10; i++){
         GracePrintf("WITH STRING %d", i);
         GracePrintf("STRING COLOR 0");
         GracePrintf("STRING FONT 8");

         GracePrintf("STRING DEF \"TEST\"");
         GracePrintf("STRING ON");

         GracePrintf("STRING LOCTYPE view");
         GracePrintf("STRING 0.70, %f", 0.95 - (((float) i) / 40.0) );
    }

    GracePrintf("redraw");

    sleep(5);
*/
//===========================================================

#ifdef GRACE
     if (GraceIsOpen()) {
         //Flush the output buffer and close Grace 
         GraceClose();
         // We are done 
         exit(EXIT_SUCCESS);
     } else {
         exit(EXIT_FAILURE);
     }
#endif

    //close file
    close(fd);
    
    return 0;
}