File indexing completed on 2024-05-26 12:28:50

0001 #!/usr/bin/python
0002 # SPDX-FileCopyrightText: AtCore Authors
0003 # SPDX-License-Identifier: MIT
0004 import sys
0005 import time
0006 import serial
0007 
0008 fwlist = {
0009     'repetier' : """FIRMWARE_NAME:Repetier_XXX FIRMWARE_URL:XXX
0010             PROTOCOL_VERSION:1.0 MACHINE_TYPE:XXX EXTRUDER_COUNT:XXX 
0011             REPETIER_PROTOCOL:3\n\r""",
0012     'marlin' : """FIRMWARE_NAME:Marlin XXX SOURCE_CODE_URL:XXX
0013             PROTOCOL_VERSION:XXX MACHINE_TYPE:XXX EXTRUDER_COUNT:XXX
0014             UUID:XXX\n\r""",
0015     'sprinter' : """FIRMWARE_NAME: Sprinter Experimental PROTOCOL_VERSION:1.0
0016             MACHINE_TYPE:Mendel EXTRUDER_COUNT:1\n\r""",
0017     'teacup' : """FIRMWARE_NAME:Teacup FIRMWARE_URL:http://github.com/traumflug/Teacup_Firmware/
0018             PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:X
0019             TEMP_SENSOR_COUNT:X HEATER_COUNT:X\n\r""",
0020     'aprinter' :"ok FIRMWARE_NAME:APrinter\n\r",
0021 }
0022 
0023 fwname = 'repetier'
0024 if(len(sys.argv) == 1):
0025     print('Add an argument to run the correct firmware:')
0026     for fw in  fwlist:
0027         print('\t',fw)
0028     print('Default: ',fwname)
0029 if(len(sys.argv) == 2):
0030     if(sys.argv[1] in fwlist):
0031         fwname = sys.argv[1]
0032         print('Firmware: ',fwname)
0033 
0034 ser = serial.Serial('/dev/ttyVirtual2')
0035 
0036 def check(msg):
0037     if(msg == 'M115'):
0038         return fwlist[fwname]
0039     return 'ok\n\r'
0040 
0041 while(True):
0042     line = ser.readline().strip()
0043     print(line)
0044     ans = check(line.decode()).encode()
0045     print(ans)
0046     ser.write(ans)
0047     while(ser.inWaiting()<1):
0048         time.sleep(0.01)
0049