from __future__ import print_function
import can
import time


def send_one():
    bus = can.interface.Bus()
    msg = can.Message(arbitration_id=0x7bf,
                      data=[0x31, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00],
                      extended_id=False)
    try:
        bus.send(msg)
        print("Message sent on {}".format(bus.channel_info))
    except can.CanError:
        print("Message NOT sent")

def ask_config(datas):
	messages = []
	bus = can.interface.Bus()
	for d in datas:
		messages.append(can.Message(arbitration_id=0x7bf,data=d,extended_id=False))
	for msg in messages:
		try:
			bus.send(msg)
			print("Message sent on {}".format(bus.channel_info))
		except can.CanError:
			print("Message NOT sent")
		time.sleep(0.3)
      
if __name__ == "__main__":
    #send_one()
    datas = [
		[0x31, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x01, 0x95, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x01, 0x99, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00],
		[0x31, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00],
    ]
    ask_config(datas)
