# Change XYZ to the UID of your CAN Bricklet 2.0

setup:
	# Configure transceiver for loopback mode
	publish '{"baud_rate": 1000000, "sample_point": 625, "transceiver_mode": "loopback"}' to tinkerforge/request/can_v2_bricklet/XYZ/set_transceiver_configuration 
	
	# Handle incoming frame read callbacks
	subscribe to tinkerforge/callback/can_v2_bricklet/XYZ/frame_read
        if a message arrives:
            # message contains frame_type as int with symbols, identifier as int and data as int array
            if frame_type == "StandardData"
                print "Frame Type: Standard Data"
            elseif frame_type == "StandardRemote"
                print "Frame Type: Standard Remote"
            elseif frame_type == "ExtendedData"
                print "Frame Type: Extended Remote"
            elseif frame_type == "ExtendedRemote"
                print "Frame Type: Extended Remote"
            
            print "Identifier: " + identifier
            print "Data: " + data
            print "\n"
        endif
	endsubscribe
	
	publish '{"register": true}' to tinkerforge/register/can_v2_bricklet/XYZ/frame_read
	
	# Enable frame read callback
	publish '{"enabled": true}' to tinkerforge/request/can_v2_bricklet/XYZ/set_frame_read_callback_configuration 
	
	# Write standard data frame with identifier 1742 and 3 bytes of data
	publish '{"frame_type": "StandardData", "identifier": 1742, "data": [42, 23, 17]}' to tinkerforge/request/can_v2_bricklet/XYZ/write_frame 

cleanup:
	# If you are done, run this to clean up
	publish '{"enabled": false}' to tinkerforge/request/can_v2_bricklet/XYZ/set_frame_read_callback_configuration 
