# Change XYZ to the UID of your CAN Bricklet

setup:
	# Configure transceiver for loopback mode
	publish '{"baud_rate": "1000kbps", "transceiver_mode": "loopback", "write_timeout": 0}' to tinkerforge/request/can_bricklet/XYZ/set_configuration

	# Handle incoming frame read callbacks
	subscribe to tinkerforge/callback/can_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"
			endif

			print "Identifier: " + identifier
			print "Data: " + data
			print "\n"
		endif
	endsubscribe

	publish '{"register": true}' to tinkerforge/register/can_bricklet/XYZ/frame_read # Register frame_read callback

	# Enable frame read callback
	publish '' to tinkerforge/request/can_bricklet/XYZ/enable_frame_read_callback

	# Write standard data frame with identifier 1742 and 3 bytes of data
	publish '{"frame_type": "StandardData", "identifier": 1742, "data": [42, 23, 17, 0, 0, 0, 0, 0], "length": 3}' to tinkerforge/request/can_bricklet/XYZ/write_frame

cleanup:
	# If you are done, run this to clean up
	publish '' to tinkerforge/request/can_bricklet/XYZ/disable_frame_read_callback
