2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Windows.Forms;
10 using System.Threading;
11 using System.Globalization;
12 using System.Diagnostics;
14 namespace CLEON_Connector
16 public partial class Form1
25 private int TestIfParametersAreValid()
27 #region variable declaration
28 int iTimespanForASample;
29 ulong ulTotalTimespan;
30 double dTotalPowerConsumption;
31 double dExpectedBatteryCapacity;
32 ulong ulRequiredTimeForOperation;
35 #region updating variables
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);
53 textBox_sampleGap.Enabled =
true;
55 textBox_SampleCount.ForeColor = Color.Red;
56 toolStripStatusLabel.Text =
"Sample count should be greater than 0";
58 return Errors.invalidValue;
60 else if (iSampleCount == 1)
62 textBox_sampleGap.Enabled =
false;
64 textBox_SampleCount.ForeColor = Color.Black;
65 toolStripStatusLabel.Text =
"Ready";
69 textBox_sampleGap.Enabled =
true;
71 textBox_SampleCount.ForeColor = Color.Black;
72 toolStripStatusLabel.Text =
"Ready";
78 textBox_ChunkCount.ForeColor = Color.Red;
79 toolStripStatusLabel.Text =
"Chunk count should be greater than 0";
81 return Errors.invalidValue;
85 textBox_ChunkCount.ForeColor = Color.Black;
86 toolStripStatusLabel.Text =
"Ready";
89 if (iBatteryCapacity < 1)
91 textBox_batteryCapacity.ForeColor = Color.Red;
92 toolStripStatusLabel.Text =
"Battery capacitoy should be greater than 0";
94 return Errors.invalidValue;
98 textBox_batteryCapacity.ForeColor = Color.Black;
99 toolStripStatusLabel.Text =
"Ready";
102 if (iSampleGap % 1000 != 0)
104 textBox_sampleGap.ForeColor = Color.Red;
105 toolStripStatusLabel.Text =
"Sample gap should be multiple of 1000";
107 return Errors.invalidValue;
111 textBox_sampleGap.ForeColor = Color.Black;
112 toolStripStatusLabel.Text =
"Ready";
115 if (iSampleGap < iChunkGap)
117 textBox_chunkGap.ForeColor = Color.Red;
118 textBox_sampleGap.ForeColor = Color.Red;
119 toolStripStatusLabel.Text =
"Sample gap should be longer than chunk gap";
121 return Errors.sampleGapIsShorterThanChunkGap;
125 textBox_chunkGap.ForeColor = Color.Black;
126 textBox_sampleGap.ForeColor = Color.Black;
127 toolStripStatusLabel.Text =
"Ready";
130 if (iChunkGap < Constants.minimumTimespanForCapturingAndStoringAChunk)
132 textBox_chunkGap.ForeColor = Color.Red;
133 toolStripStatusLabel.Text =
"Chunk gap should be longer than " + Constants.minimumTimespanForCapturingAndStoringAChunk.ToString() +
" ms";
135 return Errors.chunkGapIsTooShort;
139 textBox_chunkGap.ForeColor = Color.Black;
140 toolStripStatusLabel.Text =
"Ready";
144 if (iSampleGap < Constants.minimumTimespanForGPSStabilization + iChunkCount * iChunkGap + Constants.minimumTimespanForCapturingAndStoringAChunk)
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";
151 return Errors.sampleGapIsShorterThanRequiredMinimum;
155 textBox_sampleGap.ForeColor = Color.Black;
156 textBox_ChunkCount.ForeColor = Color.Black;
157 textBox_chunkGap.ForeColor = Color.Black;
158 toolStripStatusLabel.Text =
"Ready";
162 iTimespanForASample = Constants.minimumTimespanForGPSStabilization
163 + iChunkGap * (iChunkCount - 1)
164 + Constants.minimumTimespanForCapturingAndStoringAChunk;
167 ulTotalTimespan = (ulong)(iSampleCount * iSampleGap);
170 dTotalPowerConsumption = ulTotalTimespan * Constants.powerConsumptionForIdleState
171 + iTimespanForASample * Constants.powerConsumptionForGPSinOperation
172 + iChunkCount * Constants.powerConsumptionForWritingToMicroSD * Constants.minimumTimespanForCapturingAndStoringAChunk;
175 dExpectedBatteryCapacity = dTotalPowerConsumption / 1000 / 60 / 60;
178 if (dExpectedBatteryCapacity > iBatteryCapacity)
180 textBox_batteryCapacity.ForeColor = Color.Red;
181 toolStripStatusLabel.Text =
"Insufficient battery capacity";
183 return Errors.insufficientBatteryCapacity;
187 textBox_batteryCapacity.ForeColor = Color.Black;
188 toolStripStatusLabel.Text =
"Ready";
192 ulRequiredTimeForOperation = ulTotalTimespan / 1000 / 60;
194 if ((ulRequiredTimeForOperation > 60) && (ulRequiredTimeForOperation <= 60 * 24))
196 int iHours = (int)(ulRequiredTimeForOperation / 60);
197 int iMinutes = (int)(ulRequiredTimeForOperation % 60);
199 toolStripStatusLabel.Text =
"Required time ≒ " + iHours +
" hours " + iMinutes +
" minutes";
201 else if (ulRequiredTimeForOperation > (60 * 24))
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;
207 toolStripStatusLabel.Text =
"Required time ≒ " + iDays +
" days " + iHours +
" hours " + iMinutes +
" minutes";
211 toolStripStatusLabel.Text =
"Required time ≒ " + ulRequiredTimeForOperation +
" minutes";
214 return Errors.NoErrors;