Skip to content

Commit

Permalink
added updated pb file
Browse files Browse the repository at this point in the history
- added serialized pb for testing
- added hw component in tc and rtd
- added diff calib for adc
- changed pb mapping dataclass to a standalone class
- modified edgepi_dac to accommodate the importing
- edgepi_adc to accommodate the importing
  • Loading branch information
sjpark608 committed Dec 16, 2022
1 parent df069f9 commit 23b2195
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 353 deletions.
2 changes: 1 addition & 1 deletion src/edgepi/adc/edgepi_adc.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(
# Load eeprom data and generate dictionary of calibration dataclass
eeprom = EdgePiEEPROM()
eeprom_data = eeprom.get_edgepi_reserved_data()
self.adc_calib_params = eeprom_data.adc_calib_parms
self.adc_calib_params = eeprom_data.adc_calib_params

self.adc_ops = ADCCommands()
self.gpio = EdgePiGPIO()
Expand Down
6 changes: 5 additions & 1 deletion src/edgepi/calibration/eeprom_mapping.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ syntax = "proto3";

message EepromLayout{
message ModuleCalibParams{
message ChannelCalib {
message ChannelCalib{
optional float gain = 1;
optional float offset = 2;
}
message HardwareValue{
optional float ref_resistor = 1;
}
repeated ChannelCalib calibs = 1;
repeated HardwareValue hw_val = 2;
}
message AwsKey{
string private_key = 1;
Expand Down
286 changes: 18 additions & 268 deletions src/edgepi/calibration/eeprom_mapping_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions src/edgepi/calibration/protobuf_mapping.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""module to map protobuf data to a class"""

from dataclasses import dataclass
from edgepi.calibration.eeprom_mapping_pb2 import EepromLayout
from edgepi.calibration.calibration_constants import CalibParam
from dataclasses import dataclass

@dataclass
class Keys:
Expand All @@ -28,30 +28,45 @@ class EdgePiEEPROMData:
client_id (str)
"""
def __init__(self, data_to_unpack: EepromLayout = None):
self.dac_calib_parms = self.message_to_dict(data_to_unpack.dac)
self.adc_calib_parms = self.message_to_dict(data_to_unpack.dac)
self.rtd_calib_parms = self.message_to_dict(data_to_unpack.dac)
self.tc_calib_parms = self.message_to_dict(data_to_unpack.dac)
self.dac_calib_params = self.calib_message_to_dict(data_to_unpack.dac)
self.adc_calib_params = self.calib_message_to_dict(data_to_unpack.adc)
self.rtd_calib_params = self.calib_message_to_dict(data_to_unpack.rtd)
self.rtd_hw_params = self.hw_message_to_dict(data_to_unpack.rtd)
self.tc_calib_params = self.calib_message_to_dict(data_to_unpack.tc)
self.tc_hw_params = self.hw_message_to_dict(data_to_unpack.tc)
self.config_key = self.keys_to_dataclass(data_to_unpack.config_key)
self.data_key = self.keys_to_dataclass(data_to_unpack.data_key)
self.serial = data_to_unpack.serial_number
self.model = data_to_unpack.model
self.client_id = data_to_unpack.client_id

def message_to_dict(self, data_to_unpack: EepromLayout = None):
def calib_message_to_dict(self, data_to_unpack: EepromLayout = None):
"""
Function to unpack message to list
Args:
data_to_unpack: EepromLayout message modules
Returns:
calib_list: 1-D array
calib_dict: calib param to dictionary
"""
calib_dict={}
for indx, ch in enumerate(data_to_unpack.calibs):
calib_dict[indx] = CalibParam(gain=ch.gain,
offset=ch.offset)
return calib_dict

def hw_message_to_dict(self, data_to_unpack: EepromLayout = None):
"""
Function to unpack message to list
Args:
data_to_unpack: EepromLayout message modules
Returns:
hw_params: hardware param to dictionary
"""
hw_dict={}
for indx, ch in enumerate(data_to_unpack.hw_val):
hw_dict[indx] = ch.ref_resistor
return hw_dict

def keys_to_dataclass(self, data_to_unpack: EepromLayout = None):
"""
Function to unpack message and populate into Keys dataclass in string format
Expand Down
2 changes: 1 addition & 1 deletion src/edgepi/dac/edgepi_dac.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self):
# Read edgepi reserved data and generate calibration parameter dictionary
eeprom = EdgePiEEPROM()
eeprom_data = eeprom.get_edgepi_reserved_data()
dac_calib_params = eeprom_data.dac_calib_parms
dac_calib_params = eeprom_data.dac_calib_params

self.dac_ops = DACCommands(dac_calib_params)
self.gpio = EdgePiGPIO()
Expand Down
Binary file modified src/test_edgepi/unit_tests/test_calibration/serializedFile
Binary file not shown.
Loading

0 comments on commit 23b2195

Please sign in to comment.