diff options
Diffstat (limited to 'lib/loader.py')
-rw-r--r-- | lib/loader.py | 158 |
1 files changed, 152 insertions, 6 deletions
diff --git a/lib/loader.py b/lib/loader.py index c0a1694..38d59fc 100644 --- a/lib/loader.py +++ b/lib/loader.py @@ -1621,6 +1621,7 @@ class EnergyTraceWithLogicAnalyzer: transition_names: list, with_traces=False, ): + """ Create a new EnergyTraceWithLogicAnalyzer object. @@ -1636,9 +1637,13 @@ class EnergyTraceWithLogicAnalyzer: self.errors = list() def load_data(self, log_data): - # TODO Daten laden - print("########################") - print(log_data[0].split("\n")[0]) + from data.timing.SigrokInterface import SigrokResult + from data.energy.EnergyInterface import EnergyInterface + + # Daten laden + self.sync_data = SigrokResult.fromString(log_data[0]) + self.energy_data = EnergyInterface.getDataFromString(str(log_data[1])) + pass def analyze_states(self, traces, offline_index: int): @@ -1666,7 +1671,89 @@ class EnergyTraceWithLogicAnalyzer: * `W_mean_delta_next`: Differenz zwischen W_mean und W_mean des Folgezustands """ - # TODO Tatsächlich Daten auswerten + # Tatsächlich Daten auswerten + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # remove Dirty Data from previously running program (happens if logic Analyzer Measurement starts earlier than + # the HW Reset from energytrace) + use_data_after_index = 0 + for x in range(1, len(self.sync_data.timestamps)): + if self.sync_data.timestamps[x] - self.sync_data.timestamps[x - 1] > 1.3: + use_data_after_index = x + break + + time_stamp_data = self.sync_data.timestamps[use_data_after_index:] + + start_offset = None + start_timestamp = None + end_offset = None + end_timestamp = None + + last_values = [] # maybe needed to flatten the data + plot_data_x = [] + plot_data_y = [] + last_data = [0, 0, 0, 0] + + power_sync_watt = 0.0162 + + # MAIN ENERGY DATA ITERATION + for energytrace_dataset in self.energy_data: + usedtime = energytrace_dataset[0] - last_data[0] + usedenergy = energytrace_dataset[3] - last_data[3] + power = usedenergy / usedtime * 10 ** -3 # in watts + + if power > 0: + if power > power_sync_watt and start_offset is None: + # automatic START offset calculation + start_offset = energytrace_dataset[0] / 1_000_000 - time_stamp_data[0] + start_timestamp = energytrace_dataset[0] / 1_000_000 + if power > power_sync_watt and start_offset is not None: # TODO BETTER + # automatic END offset calculation (Drift) + end_offset = energytrace_dataset[0] / 1_000_000 - time_stamp_data[-1] - start_offset + end_timestamp = energytrace_dataset[0] / 1_000_000 + if len(last_values) > 10: + last_values.pop(0) + last_values.append(power) + # print("%s \tUsed Energy: %i \tUsed Time: %i \tPower: %f \t l_10: %f" % (now_data[0], usedenergy, usedtime, power, sum(last_values) / len(last_values))) + plot_data_x.append(energytrace_dataset[0] / 1_000_000) + plot_data_y.append(power) + + last_data = energytrace_dataset + + # -------------------- + # add start offset to the data + modified_timestamps_with_offset = [] + for x in time_stamp_data: + if x + start_offset >= 0: + modified_timestamps_with_offset.append(x + start_offset) + + # -------------------- + # Add drift to datapoints + modified_timestamps_with_drift = [] + endFactor = (end_timestamp + end_offset - start_timestamp) / (end_timestamp - start_timestamp) + for x in modified_timestamps_with_offset: + modified_timestamps_with_drift.append(((x - start_timestamp) * endFactor) + start_timestamp) + + self.start_offset = 0 + def getPowerBetween(start, end): + first_index = 0 + all_power = 0 + all_power_count = 0 + for ind in range(self.start_offset, len(plot_data_x)): + first_index = ind + if plot_data_x[ind] > start: + break + + for ind in range(first_index, len(plot_data_x)): + all_power += plot_data_y[ind] + all_power_count += 1 + if plot_data_x[ind] > end: + self.start_offset = ind - 1 + break + return all_power / all_power_count + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ energy_trace = list() @@ -1697,7 +1784,65 @@ class EnergyTraceWithLogicAnalyzer: ) return energy_trace - for name, duration in expected_transitions: + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + end_transition_ts = None + timestamps_sync_start = 0 + energy_trace_new = list() + + for ts_index in range(0 + timestamps_sync_start, int(len(modified_timestamps_with_drift) / 2)): + start_transition_ts = modified_timestamps_with_drift[ts_index * 2] + if end_transition_ts is not None: + power = getPowerBetween(end_transition_ts, start_transition_ts) + #print("STATE", end_transition_ts * 10 ** 6, start_transition_ts * 10 ** 6, (start_transition_ts - end_transition_ts) * 10 ** 6, power) + if (start_transition_ts - end_transition_ts) * 10 ** 6 > 900_000 and power > power_sync_watt * 0.9 and ts_index > 10: + #remove last transition and stop (upcoming data only sync) + del energy_trace_new[-1] + break + pass + + state = { + "isa": "state", + "W_mean": power, + "W_std": 0.0001, + "s": (start_transition_ts - end_transition_ts), #* 10 ** 6, + } + energy_trace_new.append(state) + + energy_trace_new[-2]["W_mean_delta_next"] = ( + energy_trace_new[-2]["W_mean"] - energy_trace_new[-1]["W_mean"] + ) + + # get energy end_transition_ts + end_transition_ts = modified_timestamps_with_drift[ts_index * 2 + 1] + power = getPowerBetween(start_transition_ts, end_transition_ts) + #print("TRANS", start_transition_ts * 10 ** 6, end_transition_ts * 10 ** 6, (end_transition_ts - start_transition_ts) * 10 ** 6, power) + transition = { + "isa": "transition", + "W_mean": power, + "W_std": 0.0001, + "s": (end_transition_ts - start_transition_ts), #* 10 ** 6, + } + + if (end_transition_ts - start_transition_ts) * 10 ** 6 > 2_000_000: + # TODO Last data set corrupted? HOT FIX!!!!!!!!!!!! REMOVE LATER + for x in range(4): + del energy_trace_new[-1] + break + pass + + energy_trace_new.append(transition) + # print(start_transition_ts, "-", end_transition_ts, "-", end_transition_ts - start_transition_ts) + + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + energy_trace_new = energy_trace_new[4:] + + for number, item in enumerate(expected_transitions): + name, duration = item transition = { "isa": "transition", "W_mean": max(np.random.normal(0.023, 0.002), 0), @@ -1725,7 +1870,8 @@ class EnergyTraceWithLogicAnalyzer: energy_trace[-2]["W_mean"] - energy_trace[-1]["W_mean"] ) - return energy_trace + #print(len(energy_trace_new), " - ", len(energy_trace), " - ", ",".join([str(x["s"]) for x in energy_trace_new[-6:]]), " - ", ",".join([str(x["s"]) for x in energy_trace[-6:]])) + return energy_trace_new class EnergyTraceWithTimer(EnergyTraceWithLogicAnalyzer): |