def test_init(self): p = esmPrint.esmPrint(False) serPorts = [ (esmSerial.esmSerialPorts.panelMicro, "test", serCallback), ] with self.assertRaises(TypeError): self.s1 = esmSerial.esmSerial() self.s1 = esmSerial.esmSerial(p, serPorts) # Test missing port self.assertTrue( self.s1.sendSerial(esmSerial.esmSerialPorts.electronicLoad, bytearray([0, 1]))) self.s1.close() p = esmPrint.esmPrint(False) serPorts = [ (esmSerial.esmSerialPorts.panelMicro, "test", serCallback), (esmSerial.esmSerialPorts.electronicLoad, "test", serCallback), ] self.s1 = esmSerial.esmSerial(p, serPorts) self.assertEqual( self.s1.sendSerial(esmSerial.esmSerialPorts.panelMicro, bytearray([0, 1])), 2) self.assertIsNone( self.s1.write(esmSerial.esmSerialPorts.panelMicro, bytearray([0])))
def test_gps(self): Dprint = esmPrint.esmPrint(False) pm = esmPanelMicro.esmPanelMicro(Dprint) self.pm = pm for c in '{"lat" : 42964055, "long" : -85677421}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02) self.assertEqual(pm.location, (42.964055, -85.677421)) for c in '{"pitch" : 17.0}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02) self.assertEqual(pm.pitch, -17) for c in '{"roll" : 13.0}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02) self.assertEqual(pm.roll, 13) for c in '{"temp" : 73.0}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02) self.assertEqual(pm.temp, 73) for c in '{"date" : 210616, "time": 1120000}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02) self.assertEqual(pm.timestamp, datetime.datetime(2016, 6, 21, 1, 12, 00)) for c in '{"mx" : -48, "my" : 2188}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02) self.assertEqual(pm.heading, 75)
def test_gps(self): Dprint = esmPrint.esmPrint(False) pm = esmPanelMicro.esmPanelMicro(Dprint) self.pm = pm for c in '{"lat" : 42964055, "long" : -85677421}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02); self.assertEqual(pm.location,(42.964055,-85.677421)) for c in '{"pitch" : 17.0}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02); self.assertEqual(pm.pitch,-17) for c in '{"roll" : 13.0}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02); self.assertEqual(pm.roll,13) for c in '{"temp" : 73.0}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02); self.assertEqual(pm.temp,73) for c in '{"date" : 210616, "time": 1120000}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02); self.assertEqual(pm.timestamp,datetime.datetime(2016,6,21,1,12,00)) for c in '{"mx" : -48, "my" : 2188}\n': pm.respQ.put(c.encode('ascii')) time.sleep(0.02); self.assertEqual(pm.heading,75)
def test_trackMPPT(self): with self.assertRaises(AttributeError): dc = esmDCLoad.esmDCLoad(None) p = esmPrint.esmPrint(False) dc = esmDCLoad.esmDCLoad(p) serPorts = [(esmSerial.esmSerialPorts.electronicLoad,"test", dc.getCallback(),38400)] self.s = esmSerial.esmSerial(p,serPorts) self.assertTrue(dc.trackMPPT(None,500)[0]) self.assertTrue(dc.trackMPPT(self.s,500)[0])
def test_trackMPPT(self): with self.assertRaises(AttributeError): dc = esmDCLoad.esmDCLoad(None) p = esmPrint.esmPrint(False) dc = esmDCLoad.esmDCLoad(p) serPorts = [(esmSerial.esmSerialPorts.electronicLoad, "test", dc.getCallback(), 38400)] self.s = esmSerial.esmSerial(p, serPorts) self.assertTrue(dc.trackMPPT(None, 500)[0]) self.assertTrue(dc.trackMPPT(self.s, 500)[0])
def test_init(self): p = esmPrint.esmPrint(False) serPorts = [ (esmSerial.esmSerialPorts.panelMicro,"test", serCallback), ] with self.assertRaises(TypeError): self.s1 = esmSerial.esmSerial() self.s1 = esmSerial.esmSerial(p,serPorts) # Test missing port self.assertTrue(self.s1.sendSerial(esmSerial.esmSerialPorts.electronicLoad,bytearray([0,1]))) self.s1.close() p = esmPrint.esmPrint(False) serPorts = [ (esmSerial.esmSerialPorts.panelMicro,"test", serCallback), (esmSerial.esmSerialPorts.electronicLoad,"test", serCallback), ] self.s1 = esmSerial.esmSerial(p,serPorts) self.assertEqual(self.s1.sendSerial(esmSerial.esmSerialPorts.panelMicro,bytearray([0,1])),2) self.assertIsNone(self.s1.write(esmSerial.esmSerialPorts.panelMicro,bytearray([0])))
def test_initFile(self): p = esmPrint.esmPrint(True) self.assertFalse(p.dprint(esmPrint.esmPrintSource.serial,"Test"))
def test_noInit(self): q = esmPrint.esmPrint() self.assertFalse(q.toFile)
def __init__(self): # Global exit value self.exitAllThreads = False with open('pass') as passFile: serverPass = bytes(passFile.read(),'ascii') output = (False,200) # Setup the debug print interface self.p = esmPrint.esmPrint(True) self.dprint = self.p.dprint self.dprint(ps.main, '') self.dprint(ps.main, '********************') self.dprint(ps.main, 'ESM Started') self.dprint(ps.main, '*********************') self.dprint(ps.main, '') # Setup the DC load object self.dc = esmDCLoad.esmDCLoad(self.p) # Setup the GPIO driver self.esmGPIO = esmGPIO.esmGPIO() # Setup the web interface self.webInterface = esmWebInterface.esmWebInterface('http://egr.gvsu.edu/~esm/data/',serverPass) # Setup the panel micro self.pm = esmPanelMicro.esmPanelMicro(self.p) # Setup Serial Ports serPorts = [ (esmSerial.esmSerialPorts.electronicLoad,elSer,self.dc.getCallback(),38400), (esmSerial.esmSerialPorts.panelMicro,pmSer,self.pm.respQ,115200), (esmSerial.esmSerialPorts.leds,ledSer,None,115200) ] self.s = esmSerial.esmSerial(self.p,serPorts) # Setup LED interface self.esmLed = esmLED.esmLeds(self.s) # Start the trailer display backend esmTrailerBackend.startThread() # Create the main message Queue self.queue = Queue() # Setup fan mode self.fanMode = True # Setup temperature sensor esmTemp.setup() # Setup the ADC self.adc = esmADC.esmADC() # Create the datapoint self.dp = esmWebInterface.esmDataPoint() # Setup battery level reporting self.batteryLevel = 100 # Create threads container self.threads = [] # Create the DC load thread self.threads.append(Thread(target=self.dcLoadThread,args=(self.queue,))) self.threads.append(Thread(target=self.mainThread,args=(self.queue,))) self.threads.append(Thread(target=self.tempThread,args=(self.queue,))) self.threads.append(Thread(target=self.panelMicroThread,args=(self.queue,))) self.threads.append(Thread(target=self.batteryThread,args=(self.queue,))) self.threads.append(Thread(target=self.windThread,args=(self.queue,))) self.threads.append(Thread(target=self.ledThread,args=(self.queue,))) for th in self.threads: th.start()
def __init__(self): # Global exit value self.exitAllThreads = False with open('pass') as passFile: serverPass = bytes(passFile.read(), 'ascii') output = (False, 200) # Setup the debug print interface self.p = esmPrint.esmPrint(True) self.dprint = self.p.dprint self.dprint(ps.main, '') self.dprint(ps.main, '********************') self.dprint(ps.main, 'ESM Started') self.dprint(ps.main, '*********************') self.dprint(ps.main, '') # Setup the DC load object self.dc = esmDCLoad.esmDCLoad(self.p) # Setup the GPIO driver self.esmGPIO = esmGPIO.esmGPIO() # Setup the web interface self.webInterface = esmWebInterface.esmWebInterface( 'http://egr.gvsu.edu/~esm/data/', serverPass) # Setup the panel micro self.pm = esmPanelMicro.esmPanelMicro(self.p) # Setup Serial Ports serPorts = [(esmSerial.esmSerialPorts.electronicLoad, elSer, self.dc.getCallback(), 38400), (esmSerial.esmSerialPorts.panelMicro, pmSer, self.pm.respQ, 115200), (esmSerial.esmSerialPorts.leds, ledSer, None, 115200)] self.s = esmSerial.esmSerial(self.p, serPorts) # Setup LED interface self.esmLed = esmLED.esmLeds(self.s) # Start the trailer display backend esmTrailerBackend.startThread() # Create the main message Queue self.queue = Queue() # Setup fan mode self.fanMode = True # Setup temperature sensor esmTemp.setup() # Setup the ADC self.adc = esmADC.esmADC() # Create the datapoint self.dp = esmWebInterface.esmDataPoint() # Setup battery level reporting self.batteryLevel = 100 # Create threads container self.threads = [] # Create the DC load thread self.threads.append( Thread(target=self.dcLoadThread, args=(self.queue, ))) self.threads.append(Thread(target=self.mainThread, args=(self.queue, ))) self.threads.append(Thread(target=self.tempThread, args=(self.queue, ))) self.threads.append( Thread(target=self.panelMicroThread, args=(self.queue, ))) self.threads.append( Thread(target=self.batteryThread, args=(self.queue, ))) self.threads.append(Thread(target=self.windThread, args=(self.queue, ))) self.threads.append(Thread(target=self.ledThread, args=(self.queue, ))) for th in self.threads: th.start()
def test_initFile(self): p = esmPrint.esmPrint(True) self.assertFalse(p.dprint(esmPrint.esmPrintSource.serial, "Test"))