08 Arrays


Arrays

Array are similar to structures with the difference that all members have the same type. Supported types are integer, float and event. To declare an array signal you need to select the corresponding array type (FLX_TYPE_INTEGER_ARRAY, FLX_TYPE_FLOAT_ARRAY or FLX_TYPE_EVENT_ARRAY) and define a signal descriptor with a dimension (dim) declaration.

	// array signals
	flxAddScope(trace, 1, 0, "Arrays", "Scope Description");
	flxAddSignal(trace, 2, 1, "integer array", "2 elements", FLX_TYPE_INTEGER_ARRAY, "default<dim=2>");
	flxAddSignal(trace, 3, 1, "float array", "2 elements", FLX_TYPE_FLOAT_ARRAY, "default<dim=2>");
	flxAddSignal(trace, 4, 1, "event array", "2 elements", FLX_TYPE_EVENT_ARRAY, "default<dim=2>");

	// open
	flxOpen(trace, 0, "ns", 0, 0);

	// write array defs for arrays (may be omitted)
	flxWriteArrayDef(trace, 2, 0, "x");
	flxWriteArrayDef(trace, 2, 1, "y");
	flxWriteArrayDef(trace, 3, 0, "x");
	flxWriteArrayDef(trace, 3, 1, "y");
	flxWriteArrayDef(trace, 4, 0, "state");
	flxWriteArrayDef(trace, 4, 1, "done");

	// write enums for for signal 4  (enum array)
	flxWriteEnumDef(trace, 4, FLX_ENUM_MEMBER_0 + 0, "Yes", 1);
	flxWriteEnumDef(trace, 4, FLX_ENUM_MEMBER_0 + 0, "No", 0);
	flxWriteEnumDef(trace, 4, FLX_ENUM_MEMBER_0 + 1, "Low", 1);
	flxWriteEnumDef(trace, 4, FLX_ENUM_MEMBER_0 + 1, "High", 0);
    

The declaration of the enum values can be either local (FLX_ENUM_MEMBER_0+n) or global. 
 

// iterate over n

	// values
	int iaVal[2];
	float faVal[2];
	flxuint eaVal[2];
    
	// integer array
	iaVal[0] = n % 16;
	iaVal[1] = n % 1024;
	flxWriteIntArrayAt(trace, 2, 0, n*10, 0, iaVal, sizeof(int), 0, 2);

	// float array
	faVal[0] = sin(n / 1000.);
	faVal[1] = cos(n / 100.);
	flxWriteFloatArrayAt(trace, 3, 0, 0, 1, faVal, sizeof(float), 2);

	// event array
	eaVal[0] = n % 2;
	eaVal[1] = (n + 1) % 2;
	flxWriteEventArrayAt(trace, 4, 0, 0, 1, eaVal, 2);

toem

technical software and tooling

Company

Contact Us

This email address is being protected from spambots. You need JavaScript enabled to view it.