Ejemplo n.º 1
0
def generate_output_strs(daten): #{{{
    """Create the strings for the Display (labels) """
    def start_stop_button_adjustments(phase):
        """ button adjustements """
        cfg.START_STOP.set_sensitive(True)
        #display start png
        if phase == 0:
            if cfg.START_STOP_HOVER:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/start_hover.png")
            else:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/start.png")
        #display stop png
        else:
            if cfg.START_STOP_HOVER:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/stop_hover.png")
            else:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/stop.png")

    # Assinging stuff from daten[] to locals
    try:
        #ausgang = str(int(daten[0][-1:])) #Ausgang
        #should already be 'clean' actually
        ausgang = str(int(daten[0])) #Ausgang
        zeit = daten[1] #Stunden Minuten Sekunden
        lade_v = "%5.2fV" % (int(daten[2])/1000.0) #format into string
        ampere = int(daten[3]) #Strom A
        if ampere >= 1000 or ampere <= -1000:
            ampere = "%+.2fA" % (ampere/1000.0)
        else:
            ampere = "%imA" % (ampere)

        amph = int(daten[4])/1000.0 #Ladungsmenge amph
        vers_u = int(daten[5])/1000.0 #Versorgungs-U mV
        rimohm_baldelta = int(daten[6]) #akku-unnen mOhm
        c_bat = int(daten[7]) #Akkutemperatur
        #Zellenzahl / bei Stop -> 'Fehlercode'
        tmp_zellen = int(daten[8])
        if tmp_zellen < 50:
            cfg.ANZAHL_ZELLEN[int(ausgang)] = tmp_zellen

        phase = int(daten[9]) #Ladephase 0-stop ...
        cfg.PHASE = phase #...needed for START/STOP button

        zyklus = int(daten[10]) #Zyklus
        #sp = int(daten[11]) #Aktive Akkuspeicher
    except ValueError, err:
        tmp = "Sollte nicht passieren. Bitte Nachricht"
        tmp += " an die Programmierer\n"
        tmp += "(generate_output_strs) ValueError: %s\n"\
                % str(err)
        tmp += ", ".join([str(x) for x in daten])
        tmp += "\n"
        print (tmp)
        cfg.FLOG.write(tmp)
        gtk_stuff.message_dialog(cfg.GTK_WINDOW, tmp)
Ejemplo n.º 2
0
def generate_output_strs(daten):  #{{{
    """Create the strings for the Display (labels) """
    def start_stop_button_adjustments(phase):
        """ button adjustements """
        cfg.START_STOP.set_sensitive(True)
        #display start png
        if phase == 0:
            if cfg.START_STOP_HOVER:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/start_hover.png")
            else:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/start.png")
        #display stop png
        else:
            if cfg.START_STOP_HOVER:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/stop_hover.png")
            else:
                cfg.START_STOP.set_from_file(cfg.EXE_DIR+\
                        "/bilder/stop.png")

    # Assinging stuff from daten[] to locals
    try:
        #ausgang = str(int(daten[0][-1:])) #Ausgang
        #should already be 'clean' actually
        ausgang = str(int(daten[0]))  #Ausgang
        zeit = daten[1]  #Stunden Minuten Sekunden
        lade_v = "%5.2fV" % (int(daten[2]) / 1000.0)  #format into string
        ampere = int(daten[3])  #Strom A
        if ampere >= 1000 or ampere <= -1000:
            ampere = "%+.2fA" % (ampere / 1000.0)
        else:
            ampere = "%imA" % (ampere)

        amph = int(daten[4]) / 1000.0  #Ladungsmenge amph
        vers_u = int(daten[5]) / 1000.0  #Versorgungs-U mV
        rimohm_baldelta = int(daten[6])  #akku-unnen mOhm
        c_bat = int(daten[7])  #Akkutemperatur
        #Zellenzahl / bei Stop -> 'Fehlercode'
        tmp_zellen = int(daten[8])
        if tmp_zellen < 50:
            cfg.ANZAHL_ZELLEN[int(ausgang)] = tmp_zellen

        phase = int(daten[9])  #Ladephase 0-stop ...
        cfg.PHASE = phase  #...needed for START/STOP button

        zyklus = int(daten[10])  #Zyklus
        #sp = int(daten[11]) #Aktive Akkuspeicher
    except ValueError, err:
        tmp = "Sollte nicht passieren. Bitte Nachricht"
        tmp += " an die Programmierer\n"
        tmp += "(generate_output_strs) ValueError: %s\n"\
                % str(err)
        tmp += ", ".join([str(x) for x in daten])
        tmp += "\n"
        print(tmp)
        cfg.FLOG.write(tmp)
        gtk_stuff.message_dialog(cfg.GTK_WINDOW, tmp)
Ejemplo n.º 3
0
def read_line(): #{{{
    """Read serial data (called via interval via 
    gobject.timeout_add) and print it to display"""

    if cfg.FILE_BLOCK == True:
        tmp = "* [Debug] ********************* Blocked serial input\n"
        print tmp
        cfg.FLOG.write(tmp)
        return True

    try:
        lin = cfg.SER.readline()
    except serial.SerialException, err:
        tmp = "%s\n\n" % err
        print (tmp)
        cfg.FLOG.write(tmp)
        gtk_stuff.message_dialog(cfg.GTK_WINDOW, tmp)
        return True
Ejemplo n.º 4
0
def read_line():  #{{{
    """Read serial data (called via interval via 
    gobject.timeout_add) and print it to display"""

    if cfg.FILE_BLOCK == True:
        tmp = "* [Debug] ********************* Blocked serial input\n"
        print tmp
        cfg.FLOG.write(tmp)
        return True

    try:
        lin = cfg.SER.readline()
    except serial.SerialException, err:
        tmp = "%s\n\n" % err
        print(tmp)
        cfg.FLOG.write(tmp)
        gtk_stuff.message_dialog(cfg.GTK_WINDOW, tmp)
        return True
Ejemplo n.º 5
0
def serial_setup(): #{{{
    """ try to connect to the serial port """

    tmp = "* [ Serial Port ] ***********************************\n"
    tmp += ("Versuche zu oeffen den seriellen Port '%s': " % cfg.SERIAL_PORT)
    if platform.system() == "Windows":
        #needen on comx>10 - seems to work
        cfg.SERIAL_PORT = '\\\\.\\' + cfg.SERIAL_PORT

    try:
        cfg.SER = serial.Serial(
            port=cfg.SERIAL_PORT,
            baudrate = 9600,
            parity = serial.PARITY_NONE,
            stopbits = serial.STOPBITS_ONE,
            bytesize = serial.EIGHTBITS,
            xonxoff=0,
            rtscts=0,
            dsrdtr = False,
            timeout = 0.08, #some tuning around with that value possibly
            writeTimeout = 2.0)

        if platform.system() != "Windows":
            cfg.SER.open()

        cfg.SER.isOpen()
        tmp += "OK\n"

    except serial.SerialException, err:
        tmp += "Fehler\n"

        tmp += "Program Abruch: \"%s\"\n" % err
        time.sleep(3)
        cfg.FLOG.write(tmp)
        cfg.FLOG.close()
        gtk_stuff.message_dialog(None, tmp)
        time.sleep(10)
        sys.exit()
Ejemplo n.º 6
0
def serial_setup():  #{{{
    """ try to connect to the serial port """

    tmp = "* [ Serial Port ] ***********************************\n"
    tmp += ("Versuche zu oeffen den seriellen Port '%s': " % cfg.SERIAL_PORT)
    if platform.system() == "Windows":
        #needen on comx>10 - seems to work
        cfg.SERIAL_PORT = '\\\\.\\' + cfg.SERIAL_PORT

    try:
        cfg.SER = serial.Serial(
            port=cfg.SERIAL_PORT,
            baudrate=9600,
            parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            bytesize=serial.EIGHTBITS,
            xonxoff=0,
            rtscts=0,
            dsrdtr=False,
            timeout=0.08,  #some tuning around with that value possibly
            writeTimeout=2.0)

        if platform.system() != "Windows":
            cfg.SER.open()

        cfg.SER.isOpen()
        tmp += "OK\n"

    except serial.SerialException, err:
        tmp += "Fehler\n"

        tmp += "Program Abruch: \"%s\"\n" % err
        time.sleep(3)
        cfg.FLOG.write(tmp)
        cfg.FLOG.close()
        gtk_stuff.message_dialog(None, tmp)
        time.sleep(10)
        sys.exit()
Ejemplo n.º 7
0
    def serial_send_command (tname, com_str, retry_count): #{{{
        """ Send command and wait for Ack (or not) """

        retry_count += 1
        if retry_count > (cfg.COMMAND_RETRY):
            cfg.COMMAND_ABORT = True #skip on further soon to arrive commands
            return

        if retry_count == (cfg.COMMAND_RETRY):
            failed_string = " Failed"
            failed_color = "#cc6666"
        else:
            failed_string = " Resend"
            failed_color = "#cccccc"

        try:
            cfg.SER.write(com_str)
        except serial.SerialException, err:
            tmp = "%s" % err
            tmp += ":" + com_str + ", "+ tname
            print (tmp)
            cfg.FLOG.write(tmp)
            gtk_stuff.message_dialog(None, tmp)
Ejemplo n.º 8
0
    try:
        cfg.LART[cfg.GEWAEHLTER_AUSGANG] = int(daten[14]) #Ladeart
        lart_str = cfg.LADEART[int(daten[14])] #Ladeart

        cfg.STROMW[cfg.GEWAEHLTER_AUSGANG] = int(daten[15]) #stromwahl
        stromw_str = cfg.STROMWAHL[int(daten[15])] #stromwahl

        cfg.STOPPM[cfg.GEWAEHLTER_AUSGANG] = int(daten[16]) #stromwahl
        stoppm_str = cfg.STOPPMETHODE[int(daten[16])] #stromwahl

    except IndexError, err:
        tmp = "%s\n" % err
        tmp += "-> %i\n\n" % int(daten[14])
        print (tmp)
        cfg.FLOG.write(tmp)
        gtk_stuff.message_dialog(cfg.GTK_WINDOW, tmp)
        time.sleep(5)
        sys.exit()

    c_kk = int(daten[17]) #KK Celsius

    #cell cells
    tmp_a = []
    for cell in daten[18:-1]:
        try:
            tmp_a.append(int(cell))
        except IndexError:
            tmp = "00:00:00 to long error\n"
            tmp += daten + '\n'
            tmp +=  "----------------------\n\n"
            print (tmp)
Ejemplo n.º 9
0
    try:
        cfg.LART[cfg.GEWAEHLTER_AUSGANG] = int(daten[14])  #Ladeart
        lart_str = cfg.LADEART[int(daten[14])]  #Ladeart

        cfg.STROMW[cfg.GEWAEHLTER_AUSGANG] = int(daten[15])  #stromwahl
        stromw_str = cfg.STROMWAHL[int(daten[15])]  #stromwahl

        cfg.STOPPM[cfg.GEWAEHLTER_AUSGANG] = int(daten[16])  #stromwahl
        stoppm_str = cfg.STOPPMETHODE[int(daten[16])]  #stromwahl

    except IndexError, err:
        tmp = "%s\n" % err
        tmp += "-> %i\n\n" % int(daten[14])
        print(tmp)
        cfg.FLOG.write(tmp)
        gtk_stuff.message_dialog(cfg.GTK_WINDOW, tmp)
        time.sleep(5)
        sys.exit()

    c_kk = int(daten[17])  #KK Celsius

    #cell cells
    tmp_a = []
    for cell in daten[18:-1]:
        try:
            tmp_a.append(int(cell))
        except IndexError:
            tmp = "00:00:00 to long error\n"
            tmp += daten + '\n'
            tmp += "----------------------\n\n"
            print(tmp)
Ejemplo n.º 10
0
def gnuplot(): #{{{
    """Create charts"""

    filesplit() #delete and generate new .dat files

    gpl = Gnuplot.Gnuplot(debug=0)

    qiv_files = ""
    dir_list = os.listdir(cfg.TMP_DIR)
    dir_list.sort()
    tmp = "\n* [Gnu-Plotting] ************************************************"
    print (tmp)
    cfg.FLOG.write(tmp + '\n')

    anzbild = 0
    for fname in dir_list:
        if fname[0:4] == "Akku" and fname[4:6] == str(cfg.GEWAEHLTER_AUSGANG)+\
                "-" and fname [8:12] == ".dat":

            #byte - about 2 minutes minimum
            if os.path.getsize(cfg.TMP_DIR + "/" + fname) < 8000:
                #skip on too little data-packages
                continue

            qiv_files += cfg.CHART_DIR + "/" + fname[:-4] + ".png "
            anzbild += 1

            fhan = helper.open_file(cfg.TMP_DIR + "/" + fname, "r")
            while True: #ignore other than real data lines
                lin = fhan.readline()
                if lin[0] != "#":
                    break
            fhan.close()
            if platform.system() == "Windows":
                line_a = lin.split(" ")
            else:
                line_a = lin.split("\xff")

            phasenr = int(line_a[9])
            atyp_i = int(line_a[12])

            #titel stuff
            atyp_str = cfg.AKKU_TYP[int(line_a[12])] #Akkutyp
            prg_str = cfg.AMPROGRAMM[int(line_a[13])] #Programm
            lart_str = cfg.LADEART[int(line_a[14])] #Ladeart
            stromw_str = cfg.STROMWAHL[int(line_a[15])] #stromwahl
            stoppm_str = cfg.STOPPMETHODE[int(line_a[16])] #stromwahl
            #Stop >= 50?
            anz_zellen = int(line_a[8]) #Zellenzahl / bei Stop -> 'Fehlercode'
            anz_z = anz_zellen
            if anz_zellen >= 40: # not really needed there in the title anyway.
                anz_z_str = ""
                anz_z = -1 #unknown
            else:
                anz_z_str = str(anz_zellen) + "x"

            titel_plus = " ["+anz_z_str+atyp_str+", "+prg_str+", "+lart_str+", " \
                    +stromw_str+", "+stoppm_str+"] - "
            titel_little = " ["+anz_z_str+atyp_str+"] - "

            rangeval = -1 # stays like that when no balancer attached
            #lipo -> Balancer graph TODO what when no balancer?
            if atyp_i == 5 and len(line_a) > 19:
                fhan = helper.open_file(cfg.TMP_DIR + "/" + fname, "r")
                rangeval = get_balancer_range(fhan)
                fhan.close()

            if phasenr >= 1 and phasenr <= 5:
                titel = "LADEN" + titel_plus
                gpl('set yrange [0:*];')
            elif phasenr >= 7 and phasenr < 9:
                titel = "ENTLADEN" + titel_little
                gpl('set yrange [*:0];')
            elif phasenr == 10:
                titel = "PAUSE - Entladespannung erreicht" + titel_little
                gpl('set yrange [*:*];')
            elif phasenr == 0:
                titel = "STOP (Erhaltungladung)" + titel_plus
                gpl('set yrange [*:*];')
            else:
                titel = "Unbekannte Phase <"+str(phasenr)+">" + titel_plus
                gpl('set yrange [*:*];')

            gpl('set terminal png size 1280, 1024;')
            #gnuplot does not like MS-Windoof's \
            gpl('set output "' + (cfg.CHART_DIR).replace('\\','/') +\
            "/" + fname[:-4] + '.png"')

            gpl('set xdata time;')

            if platform.system() == "Windows":
                gpl("set datafile separator ' ';")
            else:
                gpl("set datafile separator '\xff';")

            gpl('set timefmt "%H:%M:%S";')
            gpl('set grid')

            #set bmargin 5
            gpl('set lmargin 10')
            gpl('set rmargin 10')
            #set tmargin 5

            gpl('set multiplot;')

            gpl('set key box')
            gpl('set ylabel "Laden mA / Kapazitaet mAh"')
            gpl('set ytics nomirror;')

            gpl('set y2range [-10:70];')
            gpl('set y2label "Grad Celsius";')
            gpl('set y2tics border;')

            gpl('set nolabel;')
            gpl('set xtics axis;')

            gpl('set size 1.0,0.45;')
            gpl('set origin 0.0,0.5;')


            #gnuplot does not like MS-Windoof's \
            gpl('wfile="' + cfg.TMP_DIR.replace('\\', '/') + "/" + fname + '";')
            gpl('set title "Akkumatik - ' + titel + ' (' + str(anzbild) + ')";')


            gpl('plot \
                wfile using 2:4 with lines title "mA" lw 2 lc rgbcolor\
                "#009900" , \
                wfile using 2:5 smooth bezier with lines title "mAh" lw\
                2 lc rgbcolor "#0000ff", \
                wfile using 2:8 smooth bezier with lines title "Bat C"\
                axes x1y2 lc rgbcolor "#cc0000" , \
                wfile using 2:18 smooth bezier with lines title "KK C"\
                axes x1y2 lc rgbcolor "#222222";')

            gpl('set nolabel;')
            gpl('set notitle;')

            gpl('set size 1.0,0.45;')
            gpl('set origin 0.0,0.0;')

            if atyp_i == 5:
                gpl(lipo_gnuplot(line_a, rangeval, anz_z))
            elif atyp_i == 0 or atyp_i == 1:
                gpl(nixx_gnuplot())
            else:
                gpl(else_gnuplot())

            gpl('set nomultiplot;')
            gpl('reset')
            tmp = "Generiert:  "+"%44s" % (cfg.CHART_DIR + "/"+\
                    fname[-27:-4])+".png"
            print (tmp)
            cfg.FLOG.write(tmp + '\n')
        else:
            continue

    if len(qiv_files) > 0:
        time.sleep(1.8) #sonst finded qiv (noch) nichts allenfalls
        args = shlex.split(qiv_files)
        arguments = ' '.join(str(n) for n in args)
        if platform.system() == "Windows":
            for xtmp in args[-1:]:
                # os.startfile(xtmp)
                thread.start_new_thread(os.startfile,(xtmp,))
                break #one (letzte) is enough for eg. irfanview
        else:
            thread.start_new_thread(os.system,(cfg.PICTURE_EXE+' '+arguments,))
    else:
        tmp = "Nicht genügend serielle Daten vorhanden\n"
        tmp += "(Etwa 2 min von der selben 'Phase' werden benoetigt.)"
        gtk_stuff.message_dialog(cfg.GTK_WINDOW, tmp)