16 */ |
16 */ |
17 |
17 |
18 package com.nokia.carbide.cpp.pi.power; |
18 package com.nokia.carbide.cpp.pi.power; |
19 |
19 |
20 import java.util.ArrayList; |
20 import java.util.ArrayList; |
|
21 import java.util.Map; |
|
22 import java.util.TreeMap; |
21 |
23 |
22 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository; |
24 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository; |
23 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace; |
25 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace; |
24 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph; |
26 import com.nokia.carbide.cpp.internal.pi.visual.GenericTraceGraph; |
25 import com.nokia.carbide.cpp.pi.editors.PIPageEditor; |
27 import com.nokia.carbide.cpp.pi.editors.PIPageEditor; |
31 |
33 |
32 transient private PowerTraceGraph[] graphs = null; |
34 transient private PowerTraceGraph[] graphs = null; |
33 transient private boolean complete = false; |
35 transient private boolean complete = false; |
34 transient private ArrayList<PwrSample> powerChangePoints; // times when power samples change |
36 transient private ArrayList<PwrSample> powerChangePoints; // times when power samples change |
35 transient private long maxEndTime; |
37 transient private long maxEndTime; |
|
38 transient private TreeMap<Long, Integer> backlightChangePoints; |
36 |
39 |
37 private float voltage = 3.7f; |
40 private float voltage = 3.7f; |
38 |
41 |
39 // used when manually positioning the trace |
42 // used when manually positioning the trace |
40 public int offset = 0; |
43 public int offset = 0; |
43 |
46 |
44 private double scale = 0.0; |
47 private double scale = 0.0; |
45 private double min = 0.0; |
48 private double min = 0.0; |
46 private double max = 0.0; |
49 private double max = 0.0; |
47 private double synchValue = 0.0; |
50 private double synchValue = 0.0; |
48 |
51 private boolean backlightEnabled; |
|
52 |
49 transient private int[] sampleTimes; |
53 transient private int[] sampleTimes; |
50 transient private int[] ampValues; |
54 transient private int[] ampValues; |
51 transient private int[] voltValues; |
55 transient private int[] voltValues; |
52 transient private int[] capaValues; |
56 transient private int[] capaValues; |
53 transient private double maxAmps = Double.MIN_VALUE; |
57 transient private double maxAmps = Double.MIN_VALUE; |
54 transient private double minAmps = Double.MAX_VALUE; |
58 transient private double minAmps = Double.MAX_VALUE; |
55 transient private double maxPower = 0.0; |
59 transient private double maxPower = 0.0; |
|
60 |
56 |
61 |
57 public GenericTraceGraph getTraceGraph(int graphIndex, int uid) |
62 public GenericTraceGraph getTraceGraph(int graphIndex, int uid) |
58 { |
63 { |
59 return getPowerGraph(graphIndex, uid); |
64 return getPowerGraph(graphIndex, uid); |
60 } |
65 } |
195 // power traces are typically done at 250Khz. |
200 // power traces are typically done at 250Khz. |
196 // |
201 // |
197 public void initData() |
202 public void initData() |
198 { |
203 { |
199 ArrayList<PwrSample> powerChangePoints = new ArrayList<PwrSample>(); |
204 ArrayList<PwrSample> powerChangePoints = new ArrayList<PwrSample>(); |
|
205 if(backlightEnabled){ |
|
206 backlightChangePoints = new TreeMap<Long, Integer>(); |
|
207 } |
200 PwrSample sample = (PwrSample) this.samples.get(0); |
208 PwrSample sample = (PwrSample) this.samples.get(0); |
201 |
209 |
202 long currentTime = sample.sampleSynchTime; |
210 long currentTime = sample.sampleSynchTime; |
203 double currentCurrent = sample.current; |
211 double currentCurrent = sample.current; |
204 double currentVoltage = sample.voltage; |
212 double currentVoltage = sample.voltage; |
205 double currentCapacity = sample.capacity; |
213 double currentCapacity = sample.capacity; |
|
214 int currentBacklight = sample.backlight; |
|
215 if(backlightEnabled){ |
|
216 backlightChangePoints.put(currentTime, currentBacklight); |
|
217 } |
206 |
218 |
207 for (int i = 1; i < this.samples.size(); i++) { |
219 for (int i = 1; i < this.samples.size(); i++) { |
208 sample = (PwrSample) this.samples.get(i); |
220 sample = (PwrSample) this.samples.get(i); |
209 if ( sample.current != currentCurrent |
221 if ( sample.current != currentCurrent |
210 || sample.voltage != currentVoltage |
222 || sample.voltage != currentVoltage |
214 currentTime = sample.sampleSynchTime; |
226 currentTime = sample.sampleSynchTime; |
215 currentCurrent = sample.current; |
227 currentCurrent = sample.current; |
216 currentVoltage = sample.voltage; |
228 currentVoltage = sample.voltage; |
217 currentCapacity = sample.capacity; |
229 currentCapacity = sample.capacity; |
218 } |
230 } |
219 } |
231 if(backlightEnabled){ |
|
232 if(sample.backlight != currentBacklight){ |
|
233 backlightChangePoints.put(sample.sampleSynchTime, sample.backlight); |
|
234 currentBacklight = sample.backlight; |
|
235 } |
|
236 } |
220 |
237 |
221 sample = powerChangePoints.get(powerChangePoints.size() - 1); |
238 } |
222 if ( sample.current != currentCurrent |
239 |
223 || sample.voltage != currentVoltage |
240 if(powerChangePoints.size() > 0){ |
224 || sample.capacity != currentCapacity) { |
241 sample = powerChangePoints.get(powerChangePoints.size() - 1); |
225 powerChangePoints.add(new PwrSample(currentTime, currentCurrent, currentVoltage, currentCapacity)); |
242 if ( sample.current != currentCurrent |
|
243 || sample.voltage != currentVoltage |
|
244 || sample.capacity != currentCapacity) { |
|
245 powerChangePoints.add(new PwrSample(currentTime, currentCurrent, currentVoltage, currentCapacity)); |
|
246 } |
226 } |
247 } |
227 |
248 |
228 this.powerChangePoints = powerChangePoints; |
249 this.powerChangePoints = powerChangePoints; |
229 |
250 |
230 sampleTimes = new int[this.powerChangePoints.size()]; |
251 sampleTimes = new int[this.powerChangePoints.size()]; |
317 } |
338 } |
318 |
339 |
319 public boolean isComplete() { |
340 public boolean isComplete() { |
320 return this.complete; |
341 return this.complete; |
321 } |
342 } |
|
343 |
|
344 public boolean isBacklightEnabled(){ |
|
345 //TODO remove this for enabling backlight visualization |
|
346 return false; |
|
347 //return backlightEnabled; |
|
348 } |
|
349 |
|
350 public void setBacklightEnabled(boolean backlightEnabled){ |
|
351 this.backlightEnabled = backlightEnabled; |
|
352 } |
|
353 |
|
354 public Map<Long, Integer> getBacklightChangePoints(){ |
|
355 return backlightChangePoints; |
|
356 } |
322 } |
357 } |