E03 Adding integer and event signals

Integer signals are quite similar to logic signals but focus on a value, not on its bits (and have no bit width). Event signals do not have any data at all, they just represent a point in time or any other unit. The article uses the ExampleIntegerReader and ExampleEventReader classes in the Extension Toolkit.

Integer Signals

Impulse integers are not limited to any bit width. The values can be given as integer, long or BigInteger values.

Interface

This is the interface:

public interface IIntegerSamplesWriter extends ISamplesWriter{
   
    boolean write(long units, boolean conflict, int value);    
    boolean write(long units, boolean conflict, long value); 
    boolean write(long units, boolean conflict, BigInteger value);

	// scripting 
    boolean writeInt(long units, boolean conflict, int value);    
    boolean writeLong(long units, boolean conflict, long value); 
    boolean writeBig(long units, boolean conflict, BigInteger value);
}	

The parameters have the following meaning:

units
No of domain units (e.g. ns)
conflict
Define this sample as a conflict one.
value
The given valuein different formats (integer/long/BigInteger)

Creating

Now we take a look at some examples (out of de.toem.impulse.serializer.ExampleIntegerReaderReader):

        Scope signals = addScope(record, "Signals");
        addSignal(signals, "Integer1", "An integer", ProcessType.Discrete, 
SignalType.Integer, SignalDescriptor.NONE); addSignal(signals, "Integer2", "A big integer", ProcessType.Discrete,
SignalType.Integer, SignalDescriptor.NONE);

To create an integer signal, you need to give the signal type SignalType.Integer and no signal descriptor.

Here some examples how to add samples.

        // And continue until 1000 ns        
        for (; t < 100000; t += 10) {
            integerWriter.write(t, false,(int)t);
        }        
        integerWriter =  (IIntegerSamplesWriter) getWriter(int2);
        integerWriter.write(10000, false, BigInteger.valueOf(5));
        integerWriter.write(20000, false, BigInteger.valueOf(-5));
        BigInteger integer = 
new BigInteger("C00000012345678C00000012345678C000000C00000012345678",16); integerWriter.write(30000, false, integer);

Event Signals

Event samples may contain enum values in form of integer or string, or arrays of int and String (dimension > 1).

Interface

This is the interface:

public interface IEventSamplesWriter extends ISamplesWriter{
   
    boolean write(long units, boolean conflict);
    boolean write(long units, boolean conflict, int value);
    boolean write(long units, boolean conflict, String value);
 	boolean write(long units, boolean conflict, int[] value);
	boolean write(long units, boolean conflict, String[] value);

	// scripting 
    boolean writeInt(long units, boolean conflict, int value);
    boolean writeString(long units, boolean conflict, String value);
    boolean writeIntArray(long units, boolean conflict, int[] value);
    boolean writeIntArgs(long units, boolean conflict, int... value);
    boolean writeStringArray(long units, boolean conflict, String[] value);
    boolean writeStringArgs(long units, boolean conflict, String... value);        
}	

The parameters have the following meaning:

units
No of domain units (e.g. ns)
conflict
Define this sample as a conflict one.
value
Enumeration value as string or integer.

Creating

Now look at these examples (out of de.toem.impulse.serializer.ExampleIntegerReaderReader):

        Signal event1 = addSignal(signals, "Event1", "Simple events", 
                ProcessType.Discrete, SignalType.Event, SignalDescriptor.DEFAULT);
        Signal event2 = addSignal(signals, "Event2", "Enum events with ints", 
                ProcessType.Discrete, SignalType.Event, SignalDescriptor.DEFAULT);
        Signal event3 = addSignal(signals, "Event3", "Enum events with strings", 
                ProcessType.Discrete, SignalType.Event, SignalDescriptor.DEFAULT);
        Signal event4 = addSignal(signals, "Event4", "2 Enums", 
                ProcessType.Discrete, SignalType.Event, 
                new SignalDescriptor(SignalDescriptor.CONTENT_DEFAULT,2,ISample.ACCURACY_DEFAULT,ISample.FORMAT_DEFAULT));

To create an integer signal, you need to give the signal type SignalType.Event but no signal descriptor.

Here some examples how to add samples.

        // simple events
        IEventSamplesWriter eventWriter = (IEventSamplesWriter) getWriter(event1);
        eventWriter.write(12000, false);
        eventWriter.write(22000, false);
        
        // enum events with strings
        eventWriter = (IEventSamplesWriter) getWriter(event2);
        eventWriter.write(13000, false,"Start");
        eventWriter.write(14000, false,"Continue");
        eventWriter.write(15000, false,"Stop");
        eventWriter.write(25000, false,"Destroy");     
        eventWriter.write(30000, false,"Start");  

        // enum events with ints
        eventWriter = (IEventSamplesWriter) getWriter(event3);
        for (int n=0;n<32;n++)
           eventWriter.write(0+n*2000, false,n);
          
        // enum events with arrays
        eventWriter = (IEventSamplesWriter) getWriter(event4);
        eventWriter.addMember("State", "STATE", ISample.FORMAT_SL_TEXT);
        eventWriter.addMember("Event", "EVENT", ISample.FORMAT_SL_TEXT);
        eventWriter.write(10000, false,new String[]{"","X1"});
        eventWriter.write(30000, false,new String[]{"Starting","X2"});
        eventWriter.write(50000, false,new String[]{"Started","Off"});
        eventWriter.write(60000, false,new String[]{"","X1"});
        eventWriter.write(70000, false,new String[]{"Running","Of2"}); 
        eventWriter.write(80000, false,new String[]{"Stopping","Of3"});    
        eventWriter.write(90000, false,new String[]{"Setopped","Of4"});    
        eventWriter.write(95000, false,new String[]{"Down","X1"});