-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWriteMeasurement.py
134 lines (104 loc) · 5.28 KB
/
WriteMeasurement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
""" Example of how a python class can be written. """
from System.Collections.Generic import List
import sys
import opentap
import clr
clr.AddReference("System.Collections")
from opentap import *
import time
import OpenTap
import math
from OpenTap import Log, AvailableValues
## Import necessary .net APIs
# These represents themselves as regular Python modules but they actually reflect
# .NET libraries.
import System
from System import Array, Double, Byte, Int32, String, Boolean # Import types to reference for generic methods
from System.ComponentModel import Browsable # BrowsableAttribute can be used to hide things from the user.
#import System.Xml
#from System.Xml.Serialization import XmlIgnore
from .ECUDut import ECUDut
from .ECUSettings import ECUSettings
# Here is how a test step plugin is defined:
#Use the Display attribute to define how the test step should be presented to the user.
@attribute(OpenTap.Display("WriteMeasurement", "Write a Measurement from the OpenECU.", "OpenECU Steps"))
#AllowAnyChildAttribute is attribute that allows any child step to attached to this step
@attribute(OpenTap.AllowAnyChild())
class WriteMeasurement(TestStep): # Inheriting from opentap.TestStep causes it to be a test step plugin.
# Add properties (name, value, C# type)
Dut = property(ECUDut, None).add_attribute(OpenTap.Display( "DUT", "The DUT to use in the step.", "Resources"))
Measurement = property(String, "")\
.add_attribute(OpenTap.AvailableValues("Available"))\
.add_attribute(OpenTap.Display("Measurement", "Measurement to Write.", "Signal to Write",1))
# This property is based on a C# list of items 'List<int>', List<double>, List<string> can also be used.
Available = property(List[String], "")\
.add_attribute(Browsable(False))\
.add_attribute(OpenTap.Display("Available Values", "Select which values are available for 'Selectable'.", "Selectable"))
Filter = property(String,"")\
.add_attribute(OpenTap.Display("Measurement Filter", "", "Signal to Write", 0))
PrevFilter = ""
IsRunning = False
MeasurementValue = property(Double, 1.0)\
.add_attribute(OpenTap.Display("Value", "", "Input", 0))
##@attribute(OpenTap.EnabledIf("FrequencyIsDefault", False, HideIfDisabled = True))
def __init__(self):
super().__init__() # The base class initializer must be invoked.
self.log.Info("Init WriteMeasurement message")
self.Available = List[String]()
self.IsRunning = False
# object types should be initialized in the constructor.
self.Logging = OpenTap.Enabled[String]()
# assign available cal from DUT characteristics list
for x in self.Dut.Measurements:
s = "{}".format(x)
#self.log.Debug("current measurement = " + s)
if self.is_InFilter(s): #.Contains(self.Filter):
self.Available.Add(s)
self.Rules.Add(Rule("Filter", lambda: self.RunRule() , lambda: 'Filter sepcified'))
def is_InFilter(self, s = ""):
#self.log.Debug("is_InFilter s = " + s + "filter = " + self.Filter)
if (self.Filter != ""):
if s.find(self.Filter) == -1:
return False # not in string
else:
return True
else:
return True
def RunRule(self):
if (( not self.IsRunning ) and (self.Filter != self.PrevFilter)):
self.log.Debug("WMrunning Rule")
self.Available.Clear()
for x in self.Dut.Measurements:
s = "{}".format(x)
#self.log.Debug("current measurement = " + s)
if self.is_InFilter(s): #.Contains(self.Filter):
self.Available.Add(s)
#self.log.Debug("added")
self.PrevFilter = self.Filter
return True
def PrePlanRun(self):
self.IsRunning = True
return super().PrePlanRun()
def PostPlanRun(self):
self.log.Debug("WMeasPostRun")
self.IsRunning = False
#return super().PostPlanRun()
def Run(self):
super().Run() ## 3.0: Required for debugging to work.
# Write some log messages
self.log.Info("Lets create some results: " + self.Measurement)
# call Write Measurement function here
try:
self.Dut.WriteMeasurement(self.Measurement, self.MeasurementValue);
#self.log.Debug("Write Measurement {0}", cvalue )
self.MeasurementValue = self.MeasurementValue + 1.0;
# self.log.Info("Lets create some results: " + self.MeasurementValue)
self.log.Info("Write Measurement {0} = {1}.",self.Measurement ,self.MeasurementValue)
# self.log.Debug("Write Measurement {0}", self.Measurement )
# Set verdict
self.UpgradeVerdict(OpenTap.Verdict.Pass)
except Exception as e:
self.log.Error("Failed to write Measuement {0}", self.Measurement)
self.log.Debug(e)
self.UpgradeVerdict(OpenTap.Verdict.Error)
self.PublishResult("Write Measurement", ["Timestamp", "Measurement", "Value"], [time.asctime(), self.Measurement, self.MeasurementValue]);