CLEON CONNECTOR  1.0
Parameter updating SW for cloud-offloaded GPS receiver (CLEON)
TestParameters.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.IO.Ports;
10 using System.Threading;
11 using System.Globalization;
12 using System.Diagnostics;
13 
14 namespace CLEON_Connector
15 {
16  public partial class Form1
17  {
18  // Test if parameters are properly set based on the power consumption of each operaions
19  // CLEON's power consumption for each operation is the same as below
20  // - Idle state (no sensing): 2.5 mA
21  // - GPS is in action : 30.5 mA
22  // - Writing to MicroSD : 40 mA
23  // GPS requires at least 400 ms for stabilization
24  // Each chunk requires at least 50 ms from GPS signal capturing to writing to MicroSD
25  private int TestIfParametersAreValid()
26  {
27  #region variable declaration
28  int iTimespanForASample;
29  ulong ulTotalTimespan;
30  double dTotalPowerConsumption;
31  double dExpectedBatteryCapacity;
32  ulong ulRequiredTimeForOperation;
33  #endregion
34 
35  #region updating variables
36  try
37  {
38  iSampleCount = int.Parse(textBox_SampleCount.Text);
39  iSampleGap = int.Parse(textBox_sampleGap.Text);
40  iChunkCount = int.Parse(textBox_ChunkCount.Text);
41  iChunkGap = int.Parse(textBox_chunkGap.Text);
42  iBatteryCapacity = int.Parse(textBox_batteryCapacity.Text);
43  }
44  catch
45  {
46 
47  }
48  #endregion
49 
50  // Sample count should be greater than 0
51  if (iSampleCount < 1)
52  {
53  textBox_sampleGap.Enabled = true;
54 
55  textBox_SampleCount.ForeColor = Color.Red;
56  toolStripStatusLabel.Text = "Sample count should be greater than 0";
57 
58  return Errors.invalidValue;
59  }
60  else if (iSampleCount == 1)
61  {
62  textBox_sampleGap.Enabled = false;
63 
64  textBox_SampleCount.ForeColor = Color.Black;
65  toolStripStatusLabel.Text = "Ready";
66  }
67  else
68  {
69  textBox_sampleGap.Enabled = true;
70 
71  textBox_SampleCount.ForeColor = Color.Black;
72  toolStripStatusLabel.Text = "Ready";
73  }
74 
75  // Chunk count should be greater than 0
76  if (iChunkCount < 1)
77  {
78  textBox_ChunkCount.ForeColor = Color.Red;
79  toolStripStatusLabel.Text = "Chunk count should be greater than 0";
80 
81  return Errors.invalidValue;
82  }
83  else
84  {
85  textBox_ChunkCount.ForeColor = Color.Black;
86  toolStripStatusLabel.Text = "Ready";
87  }
88  // Battery capacity should be greater than 0
89  if (iBatteryCapacity < 1)
90  {
91  textBox_batteryCapacity.ForeColor = Color.Red;
92  toolStripStatusLabel.Text = "Battery capacitoy should be greater than 0";
93 
94  return Errors.invalidValue;
95  }
96  else
97  {
98  textBox_batteryCapacity.ForeColor = Color.Black;
99  toolStripStatusLabel.Text = "Ready";
100  }
101  // Sample gap should be multiple of 1000 (meaning that seconds)
102  if (iSampleGap % 1000 != 0)
103  {
104  textBox_sampleGap.ForeColor = Color.Red;
105  toolStripStatusLabel.Text = "Sample gap should be multiple of 1000";
106 
107  return Errors.invalidValue;
108  }
109  else
110  {
111  textBox_sampleGap.ForeColor = Color.Black;
112  toolStripStatusLabel.Text = "Ready";
113  }
114  // Sample gap should be greater than chunk gap
115  if (iSampleGap < iChunkGap)
116  {
117  textBox_chunkGap.ForeColor = Color.Red;
118  textBox_sampleGap.ForeColor = Color.Red;
119  toolStripStatusLabel.Text = "Sample gap should be longer than chunk gap";
120 
121  return Errors.sampleGapIsShorterThanChunkGap;
122  }
123  else
124  {
125  textBox_chunkGap.ForeColor = Color.Black;
126  textBox_sampleGap.ForeColor = Color.Black;
127  toolStripStatusLabel.Text = "Ready";
128  }
129  // Chunk gap should be greater than required minimum capturing and storing time
130  if (iChunkGap < Constants.minimumTimespanForCapturingAndStoringAChunk)
131  {
132  textBox_chunkGap.ForeColor = Color.Red;
133  toolStripStatusLabel.Text = "Chunk gap should be longer than " + Constants.minimumTimespanForCapturingAndStoringAChunk.ToString() + " ms";
134 
135  return Errors.chunkGapIsTooShort;
136  }
137  else
138  {
139  textBox_chunkGap.ForeColor = Color.Black;
140  toolStripStatusLabel.Text = "Ready";
141  }
142 
143  // Sample gap should be longer than timespan of a sample
144  if (iSampleGap < Constants.minimumTimespanForGPSStabilization + iChunkCount * iChunkGap + Constants.minimumTimespanForCapturingAndStoringAChunk)
145  {
146  textBox_sampleGap.ForeColor = Color.Red;
147  textBox_ChunkCount.ForeColor = Color.Red;
148  textBox_chunkGap.ForeColor = Color.Red;
149  toolStripStatusLabel.Text = "Sample gap is too short";
150 
151  return Errors.sampleGapIsShorterThanRequiredMinimum;
152  }
153  else
154  {
155  textBox_sampleGap.ForeColor = Color.Black;
156  textBox_ChunkCount.ForeColor = Color.Black;
157  textBox_chunkGap.ForeColor = Color.Black;
158  toolStripStatusLabel.Text = "Ready";
159  }
160 
161  // Timespan for a sample (calculated based on user input)
162  iTimespanForASample = Constants.minimumTimespanForGPSStabilization
163  + iChunkGap * (iChunkCount - 1)
164  + Constants.minimumTimespanForCapturingAndStoringAChunk;
165 
166  // Total timespan for CLEON operation (calculated based on user input)
167  ulTotalTimespan = (ulong)(iSampleCount * iSampleGap);
168 
169  // Total power consumption (calculated based on user input) (Unit : mAmS)
170  dTotalPowerConsumption = ulTotalTimespan * Constants.powerConsumptionForIdleState
171  + iTimespanForASample * Constants.powerConsumptionForGPSinOperation
172  + iChunkCount * Constants.powerConsumptionForWritingToMicroSD * Constants.minimumTimespanForCapturingAndStoringAChunk;
173 
174  // Expected battery capacity (calculated based on user input) (Unit : mAh)
175  dExpectedBatteryCapacity = dTotalPowerConsumption / 1000 / 60 / 60;
176 
177  // Required battery capacity should be smaller than given battery capacity
178  if (dExpectedBatteryCapacity > iBatteryCapacity)
179  {
180  textBox_batteryCapacity.ForeColor = Color.Red;
181  toolStripStatusLabel.Text = "Insufficient battery capacity";
182 
183  return Errors.insufficientBatteryCapacity;
184  }
185  else
186  {
187  textBox_batteryCapacity.ForeColor = Color.Black;
188  toolStripStatusLabel.Text = "Ready";
189  }
190 
191  // Convert milliseconds to minutes
192  ulRequiredTimeForOperation = ulTotalTimespan / 1000 / 60;
193 
194  if ((ulRequiredTimeForOperation > 60) && (ulRequiredTimeForOperation <= 60 * 24))
195  {
196  int iHours = (int)(ulRequiredTimeForOperation / 60);
197  int iMinutes = (int)(ulRequiredTimeForOperation % 60);
198 
199  toolStripStatusLabel.Text = "Required time ≒ " + iHours + " hours " + iMinutes + " minutes";
200  }
201  else if (ulRequiredTimeForOperation > (60 * 24))
202  {
203  int iDays = (int)(ulRequiredTimeForOperation / 60 / 24);
204  int iHours = (int)(ulRequiredTimeForOperation /60) - iDays * 24;
205  int iMinutes = (int)(ulRequiredTimeForOperation) - iDays * 24 * 60 - iHours * 60;
206 
207  toolStripStatusLabel.Text = "Required time ≒ " + iDays + " days " + iHours + " hours " + iMinutes + " minutes";
208  }
209  else
210  {
211  toolStripStatusLabel.Text = "Required time ≒ " + ulRequiredTimeForOperation + " minutes";
212  }
213 
214  return Errors.NoErrors;
215  }
216  }
217 }