util.clear()
util.print("CAN FD Example")
util.print("Transmission of some messages");

var DataArray = new ByteArray(64)
DataArray[0] = 1
DataArray[12] = 12
DataArray[63] = 63

//canfd.send(id, extendedFlag, brsFlag, length, DataArray)
canfd.send(0x2, false, false, 32, DataArray)
canfd.send(0x3, false, false, 64, DataArray)
canfd.send(0x4, false, true, 64, DataArray)
canfd.send(0x5, true, true, 64, DataArray)
canfd.send(0x6, false, true, 1, DataArray)

util.print("Now, I wait for CAN ID 0x200 (CAN FD message) for 25 seconds")
util.print("Please note that it only works with externally sent messages.");
//canfd.wait(canId, milliseconds_time_out)
var ret = false;
ret = canfd.wait(0x200,25000)
if (ret === true) {
	util.print("0x200 received")
} else {
	util.print("Timeout received ")
}

util.print("");
util.print("Print byte 0 and 63 if CAN-ID 1 .. 100 is received");

function urke (id, extendedFlag, brsFlag, length, byteArray) {
	util.print(id);
	util.print(extendedFlag);
	util.print(brsFlag);
	util.print(length);
	util.print( byteArray[0] )
	util.print( byteArray[63] )
}

for (i = 1; i < 0x100; i++) {
	canfd.registerCanEvent( i, "urke" );
}
