'''
Created on 27 set 2019

@author: Emanuele Trabattoni
'''
import time 
import sys
import printer as p
import commands
import logging
import test

def main():
    isRunning = True
    while isRunning:
        connessa=True
        #printer = p.MarkoPrinter('./conf.json', LOGGER)
        #connessa = printer.connetti()
        while connessa:
            lastTimestamp = int(time.time()*100)
            commandString = test.cmdString('callPrintImage', {'imageName': 'TM2.00I',
                                                              'printMode': '10',
                                                              'fieldContent': '{0}\r{0}\r'.format(lastTimestamp)
                                                              }
                                            )
            LOGGER.debug(commandString)
            #printer.sendCommand(commandString)
            pass
        pass
    pass

if __name__ == '__main__':
    # Setup Logger
    LOGGER = logging.getLogger(__name__)
    LOGGER.setLevel(logging.DEBUG)
    LOGGER.propagate = False
    FORMATTER = logging.Formatter(("%(asctime)s|%(levelname)-7s|%(funcName)-10s|%(lineno)-3d: %(message)-50s"), 
                                  ("%m-%d %H:%M:%S"))
    # File Logging
    fh = logging.FileHandler(("./log/dimelog.log"))
    fh.setLevel(logging.WARNING)
    fh.setFormatter(FORMATTER)
    LOGGER.addHandler(fh)
    # Console Logging
    cl= logging.StreamHandler(sys.stdout)
    cl.setLevel(logging.INFO)
    cl.setFormatter(FORMATTER)
    LOGGER.addHandler(cl)
    
    LOGGER.warning("MarcaturaDime Started!")
    
    sys.exit(main())
    pass