-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from RobertGawron/feature/rev_5_0
Feature/rev 5 0
- Loading branch information
Showing
17 changed files
with
385 additions
and
208 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import sys | ||
sys.path.append('../Software/DataAcquisition') | ||
|
||
from hardware_connection import HardwareConnection # noqa: E402 | ||
from physical_layer import PhysicalLayer # noqa: E402 | ||
from state_machine import IonizationChamberStateMachine # noqa: E402 | ||
import config # noqa: E402 | ||
|
||
if __name__ == "__main__": | ||
hardware = HardwareConnection(config) | ||
machine = IonizationChamberStateMachine(hardware) | ||
physicalLayer = PhysicalLayer(config) | ||
machine = IonizationChamberStateMachine(physicalLayer) | ||
|
||
while True: | ||
machine.tick() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
|
||
class PhysicalLayer: | ||
def __init__(self, config): | ||
pass | ||
|
||
def connect(self): | ||
pass | ||
|
||
def getData(self): | ||
return [1, 2, 3, 4, 5, 9] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from transport_layer import TransportLayer | ||
from enum import Enum | ||
|
||
|
||
class ADC_RESOLUTION(Enum): | ||
R12 = 1 | ||
R13 = 2 | ||
R14 = 3 | ||
|
||
|
||
def convert(upperByte, lowerByte, resolution): | ||
""" | ||
based on https://ww1.microchip.com/downloads/en/DeviceDoc/22072b.pdf | ||
assumed that gain = 1 | ||
""" | ||
def digitalToAnalog(value, lsb, pga): | ||
return (value * (lsb / pga)) | ||
|
||
digitalOutput = (upperByte << 8) | lowerByte | ||
|
||
if resolution == ADC_RESOLUTION.R12: | ||
return digitalToAnalog(digitalOutput, (1 * 0.01), 1) | ||
|
||
if resolution == ADC_RESOLUTION.R13: | ||
return digitalToAnalog(digitalOutput, (250 * 0.0000001), 1) | ||
|
||
if resolution == ADC_RESOLUTION.R14: | ||
return digitalToAnalog(digitalOutput, (62.5 * 0.000001), 1) | ||
|
||
|
||
class ApplicationLayer: | ||
def __init__(self, physicalLayer): | ||
self.transportLayer = TransportLayer(physicalLayer) | ||
|
||
def connect(self): | ||
self.transportLayer.connect() | ||
|
||
def getMeasurement(self): | ||
dataIn = self.transportLayer.getFrame() | ||
|
||
(msb, lsb) = (dataIn[2], dataIn[3]) | ||
deviceMeasurement = convert( | ||
msb, lsb, ADC_RESOLUTION.R14) | ||
|
||
return deviceMeasurement |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
|
||
from hardware_connection import HardwareConnection | ||
from physical_layer import PhysicalLayer | ||
from state_machine import IonizationChamberStateMachine | ||
import config | ||
|
||
if __name__ == "__main__": | ||
hardware = HardwareConnection(config) | ||
machine = IonizationChamberStateMachine(hardware) | ||
physicalLayer = PhysicalLayer(config) | ||
machine = IonizationChamberStateMachine(physicalLayer) | ||
|
||
while True: | ||
machine.tick() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import csv | ||
|
||
|
||
class MeasurementStorage: | ||
def __init__(self): | ||
self.CVS_FileName = "data.csv" | ||
self.CVS_Header = ['Time', 'Counter'] | ||
|
||
def connect(self): | ||
CVS_Handler = open(self.CVS_FileName, 'w', encoding='UTF8', newline='') | ||
self.CVS_Writter = csv.writer(CVS_Handler) | ||
self.CVS_Writter.writerow(self.CVS_Header) | ||
|
||
def saveMeasurement(self, date, measurement): | ||
self.CVS_Writter.writerow([date, measurement]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
import datetime | ||
from ionization_chamber import IonizationChamber | ||
from application_layer import ApplicationLayer | ||
from measurement_storage import MeasurementStorage | ||
|
||
|
||
class IonizationChamberStateMachine: | ||
def __init__(self, hardware): | ||
self.hardware = hardware | ||
def __init__(self, physicalLayer): | ||
self.applicationLayer = ApplicationLayer(physicalLayer) | ||
self.deviceMeasurement = 0.0 | ||
self.measurementStorage = MeasurementStorage() | ||
|
||
self.nextState = self.initIonizationChamber | ||
|
||
def tick(self): | ||
self.nextState() | ||
|
||
def initIonizationChamber(self): | ||
self.chamber = IonizationChamber(self.hardware) | ||
self.chamber.connect() | ||
self.nextState = self.initOutputFile | ||
self.applicationLayer.connect() | ||
|
||
self.nextState = self.initMeasurementStorage | ||
|
||
def initMeasurementStorage(self): | ||
self.measurementStorage.connect() | ||
|
||
def initOutputFile(self): | ||
self.logFile = open('data.csv', 'w') | ||
self.logFile.write("Time,Counter,DMM\n") | ||
self.nextState = self.getMeasurementFromIonizationChamber | ||
|
||
def getMeasurementFromIonizationChamber(self): | ||
self.deviceMeasurement = self.chamber.getMeasurement() | ||
self.deviceMeasurement = self.applicationLayer.getMeasurement() | ||
|
||
self.nextState = self.saveMeasurement | ||
|
||
def saveMeasurement(self): | ||
now = datetime.datetime.now() | ||
self.logFile.write("{0},{1}\n".format( | ||
now, self.deviceMeasurement)) | ||
|
||
self.logFile.flush() | ||
|
||
self.measurementStorage.saveMeasurement(now, self.deviceMeasurement) | ||
self.nextState = self.showMeasurementToUser | ||
|
||
def showMeasurementToUser(self): | ||
print("{0}".format(self.deviceMeasurement)) | ||
|
||
self.nextState = self.getMeasurementFromIonizationChamber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
class InvalidCRC(Exception): | ||
pass | ||
|
||
|
||
class MissingFrame(Exception): | ||
pass | ||
|
||
|
||
class InvalidMsgLength(Exception): | ||
pass | ||
|
||
|
||
class TransportLayer: | ||
def __init__(self, physicalLayer): | ||
self.physicalLayer = physicalLayer | ||
|
||
def connect(self): | ||
self.physicalLayer.connect() | ||
|
||
def getFrame(self): | ||
return self.physicalLayer.getData() |
Oops, something went wrong.