Take output filename as cmdline argument, align cell voltage index, added timestamp
This commit is contained in:
parent
65201ad875
commit
2688750caf
2 changed files with 15 additions and 4 deletions
14
Main.py
14
Main.py
|
|
@ -1,5 +1,7 @@
|
|||
import Messages
|
||||
import time
|
||||
import datetime
|
||||
import argparse
|
||||
from ProcessList import process_list
|
||||
from WriteToFile import report
|
||||
from PCANBasic import *
|
||||
|
|
@ -7,14 +9,20 @@ from PCANBasic import TPCANTimestamp, TPCANMsg
|
|||
#import matplotlib.pyplot as plt
|
||||
#import numpy as np
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-o", "--output", help="log file name", required=True)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
id_response = 0x7BB
|
||||
id_periodic = 0x1DB
|
||||
|
||||
filename = args.output # input("Please Enter a File Name: ")
|
||||
|
||||
# Initialize PCAN device and set filter for incoming messages with ID id_response
|
||||
PCAN = PCANBasic()
|
||||
res = PCAN.Initialize(PCAN_USBBUS1, PCAN_BAUD_500K)
|
||||
#PCAN.FilterMessages(PCAN_USBBUS1, id_response, id_response, PCAN_MESSAGE_STANDARD)
|
||||
filename = input("Please Enter a File Name: ")
|
||||
|
||||
|
||||
# Infinite loop runs until program is closed
|
||||
|
|
@ -115,7 +123,9 @@ while True:
|
|||
charge_string = charge_byte1 + charge_byte2 + charge_byte3
|
||||
pack_charge = float(int(charge_string, 2))/10000
|
||||
|
||||
report_string = report(vv, pack_voltage, pack_current, pack_health, pack_charge)
|
||||
tnow = datetime.datetime.now()
|
||||
|
||||
report_string = report(vv, pack_voltage, pack_current, pack_health, pack_charge, tnow.ctime())
|
||||
print (report_string)
|
||||
with open(filename, "a") as f:
|
||||
f.write(report_string)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
def report (vv, pack_voltage, pack_current, pack_health, pack_charge):
|
||||
def report (vv, pack_voltage, pack_current, pack_health, pack_charge, timestamp):
|
||||
return (
|
||||
"\n".join([
|
||||
"Cell {} = {:.3f}\t\t\tCell {} = {:.3f}".format(str(i+1), vv[i], str(i+49), vv[i+48])
|
||||
"Cell {:2d} = {:.3f}\t\t\tCell {:2d} = {:.3f}".format((i+1), vv[i], (i+49), vv[i+48])
|
||||
for i in range(48)]) +
|
||||
"\nCell Voltage Sum = {:.2f}".format(sum(vv)) +
|
||||
"\nPack Voltage = {:.2f} V" .format(pack_voltage) +
|
||||
"\nPack Current = {:.2f} A" .format(pack_current) +
|
||||
"\nState of Health = {:.2f} %" .format(pack_health) +
|
||||
"\nState of Charge = {:.2f} %" .format(pack_charge) +
|
||||
"\nTime = {}" .format(timestamp) +
|
||||
"\n")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue