Repository for import to local machine

Dependencies:   DMBasicGUI DMSupport

Committer:
jmitc91516
Date:
Mon Jul 31 15:37:57 2017 +0000
Revision:
8:26e49e6955bd
Parent:
1:a5258871b33d
Method ramp scrolling improved, and more bitmaps moved to QSPI memory

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmitc91516 1:a5258871b33d 1 /*
jmitc91516 1:a5258871b33d 2 These classes do what the name implies - handle service intervals. These are measured
jmitc91516 1:a5258871b33d 3 either in instrument cycles (i.e. runs), or time - in the latter case, the interval
jmitc91516 1:a5258871b33d 4 is always twelve months.
jmitc91516 1:a5258871b33d 5
jmitc91516 1:a5258871b33d 6 Each ServiceInterval object deals with one (and only one) service interval, allowing the caller
jmitc91516 1:a5258871b33d 7 to specify its description (a text string).
jmitc91516 1:a5258871b33d 8
jmitc91516 1:a5258871b33d 9 Note that the caller must 'poll' the ServiceInterval object to find out whether or not
jmitc91516 1:a5258871b33d 10 it has expired - it does not raise an interrupt, or call a callback function,
jmitc91516 1:a5258871b33d 11 or do anything unsolicited.
jmitc91516 1:a5258871b33d 12 */
jmitc91516 1:a5258871b33d 13
jmitc91516 1:a5258871b33d 14 #include "ServiceInterval.h"
jmitc91516 1:a5258871b33d 15 #include "SettingsHandler.h"
jmitc91516 1:a5258871b33d 16 #include "EasyGUITouchAreaIndices.h"
jmitc91516 1:a5258871b33d 17 #include "GCRealTimeClock.h"
jmitc91516 1:a5258871b33d 18
jmitc91516 1:a5258871b33d 19
jmitc91516 1:a5258871b33d 20 // Static members
jmitc91516 1:a5258871b33d 21
jmitc91516 1:a5258871b33d 22 // Have to manually make sure we have the correct number of NULLs here - we do not want any invalid pointer values
jmitc91516 1:a5258871b33d 23 ServiceInterval* ServiceInterval::serviceIntervalArray[SERVICE_INTERVAL_COUNT] = { NULL, NULL, NULL, NULL, NULL, NULL };
jmitc91516 1:a5258871b33d 24
jmitc91516 1:a5258871b33d 25 // Static member functions
jmitc91516 1:a5258871b33d 26
jmitc91516 1:a5258871b33d 27 /*
jmitc91516 1:a5258871b33d 28 Sets up all our service intervals.
jmitc91516 1:a5258871b33d 29
jmitc91516 1:a5258871b33d 30 This is effectively a 'static constructor' -
jmitc91516 1:a5258871b33d 31 but it has to be called manually before the ServiceInterval objects can be used
jmitc91516 1:a5258871b33d 32 *******************************************************************************
jmitc91516 1:a5258871b33d 33 */
jmitc91516 1:a5258871b33d 34 void ServiceInterval::SetupAllServiceIntervals(void)
jmitc91516 1:a5258871b33d 35 {
jmitc91516 1:a5258871b33d 36 // For the service intervals based on numbers of cycles, set some default values for the cycle counts
jmitc91516 1:a5258871b33d 37 CyclesServiceInterval* cyclesServiceInterval = new CyclesServiceInterval("Column", COMPONENT_1_SERVICED);
jmitc91516 1:a5258871b33d 38 cyclesServiceInterval->SetDurationInNumberOfInstrumentCycles(2); // *** Unrealistic value - testing only ***
jmitc91516 1:a5258871b33d 39 serviceIntervalArray[0] = cyclesServiceInterval;
jmitc91516 1:a5258871b33d 40
jmitc91516 1:a5258871b33d 41 cyclesServiceInterval = new CyclesServiceInterval("Liner", COMPONENT_2_SERVICED);
jmitc91516 1:a5258871b33d 42 cyclesServiceInterval->SetDurationInNumberOfInstrumentCycles(3); // *** Unrealistic value - testing only ***
jmitc91516 1:a5258871b33d 43 serviceIntervalArray[1] = cyclesServiceInterval;
jmitc91516 1:a5258871b33d 44
jmitc91516 1:a5258871b33d 45 cyclesServiceInterval = new CyclesServiceInterval("Septa", COMPONENT_3_SERVICED);
jmitc91516 1:a5258871b33d 46 cyclesServiceInterval->SetDurationInNumberOfInstrumentCycles(4); // *** Unrealistic value - testing only ***
jmitc91516 1:a5258871b33d 47 serviceIntervalArray[2] = cyclesServiceInterval;
jmitc91516 1:a5258871b33d 48
jmitc91516 1:a5258871b33d 49 // TODO: fill the rest of the array with TwelveMonthServiceInterval objects,
jmitc91516 1:a5258871b33d 50 // one for each component that actually does require to be replaced every twelve months
jmitc91516 1:a5258871b33d 51 serviceIntervalArray[3] = new TwelveMonthServiceInterval("Detector", COMPONENT_4_SERVICED);
jmitc91516 1:a5258871b33d 52 serviceIntervalArray[4] = new TwelveMonthServiceInterval("O-ring", COMPONENT_5_SERVICED);
jmitc91516 1:a5258871b33d 53 serviceIntervalArray[5] = new TwelveMonthServiceInterval("Amplifier fan", COMPONENT_6_SERVICED);
jmitc91516 1:a5258871b33d 54
jmitc91516 1:a5258871b33d 55 // If we add more ServiceInterval objects (of either derived class), need to increase SERVICE_INTERVAL_COUNT enum value - see header
jmitc91516 1:a5258871b33d 56 }
jmitc91516 1:a5258871b33d 57
jmitc91516 1:a5258871b33d 58 /*
jmitc91516 1:a5258871b33d 59 Start all the service intervals
jmitc91516 1:a5258871b33d 60 */
jmitc91516 1:a5258871b33d 61 void ServiceInterval::StartAllServiceIntervals(void)
jmitc91516 1:a5258871b33d 62 {
jmitc91516 1:a5258871b33d 63 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 64 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 65 serviceIntervalArray[index]->Start();
jmitc91516 1:a5258871b33d 66 }
jmitc91516 1:a5258871b33d 67 }
jmitc91516 1:a5258871b33d 68 }
jmitc91516 1:a5258871b33d 69
jmitc91516 1:a5258871b33d 70
jmitc91516 1:a5258871b33d 71 /*
jmitc91516 1:a5258871b33d 72 Returns a pointer to one of the service interval objects,
jmitc91516 1:a5258871b33d 73 specified by its index, or NULL if there is no such interval
jmitc91516 1:a5258871b33d 74 (e.g. the index is invalid).
jmitc91516 1:a5258871b33d 75
jmitc91516 1:a5258871b33d 76 Args: the index of the service interval required. The allowed range
jmitc91516 1:a5258871b33d 77 is from zero to (count of service intervals - 1).
jmitc91516 1:a5258871b33d 78 Call GetServiceIntervalCount to find out how many service intervals there are
jmitc91516 1:a5258871b33d 79
jmitc91516 1:a5258871b33d 80 Returns a pointer to the specified service interval object,
jmitc91516 1:a5258871b33d 81 or NULL if there is no such interval.
jmitc91516 1:a5258871b33d 82
jmitc91516 1:a5258871b33d 83 Caller must check for NULL.
jmitc91516 1:a5258871b33d 84 **************************
jmitc91516 1:a5258871b33d 85 */
jmitc91516 1:a5258871b33d 86 ServiceInterval* ServiceInterval::GetServiceInterval(int serviceIntervalIndex)
jmitc91516 1:a5258871b33d 87 {
jmitc91516 1:a5258871b33d 88 if((serviceIntervalIndex >= 0) && (serviceIntervalIndex < SERVICE_INTERVAL_COUNT)) {
jmitc91516 1:a5258871b33d 89 return serviceIntervalArray[serviceIntervalIndex];
jmitc91516 1:a5258871b33d 90 }
jmitc91516 1:a5258871b33d 91
jmitc91516 1:a5258871b33d 92 // 'else' index invalid
jmitc91516 1:a5258871b33d 93 return NULL;
jmitc91516 1:a5258871b33d 94 }
jmitc91516 1:a5258871b33d 95
jmitc91516 1:a5258871b33d 96 /*
jmitc91516 1:a5258871b33d 97 Tell all our service interval objects that the instrument
jmitc91516 1:a5258871b33d 98 has performed another cycle
jmitc91516 1:a5258871b33d 99 */
jmitc91516 1:a5258871b33d 100 void ServiceInterval::TellAllServiceIntervalsInstrumentHasCycled(void)
jmitc91516 1:a5258871b33d 101 {
jmitc91516 1:a5258871b33d 102 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 103 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 104 serviceIntervalArray[index]->InstrumentHasCycled();
jmitc91516 1:a5258871b33d 105 }
jmitc91516 1:a5258871b33d 106 }
jmitc91516 1:a5258871b33d 107 }
jmitc91516 1:a5258871b33d 108
jmitc91516 1:a5258871b33d 109 /*
jmitc91516 1:a5258871b33d 110 Tells the caller if at least one service interval has expired.
jmitc91516 1:a5258871b33d 111 (It is then up to the caller to find out how many have expired,
jmitc91516 1:a5258871b33d 112 and which ones, by calling the 'GetNextExpiredServiceInterval' function.)
jmitc91516 1:a5258871b33d 113
jmitc91516 1:a5258871b33d 114 No args.
jmitc91516 1:a5258871b33d 115
jmitc91516 1:a5258871b33d 116 Returns true if at least one service interval has expired, false if not.
jmitc91516 1:a5258871b33d 117 */
jmitc91516 1:a5258871b33d 118 bool ServiceInterval::AtLeastOneServiceIntervalHasExpired(void)
jmitc91516 1:a5258871b33d 119 {
jmitc91516 1:a5258871b33d 120 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 121 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 122 if(serviceIntervalArray[index]->HasExpired()) {
jmitc91516 1:a5258871b33d 123 return true;
jmitc91516 1:a5258871b33d 124 }
jmitc91516 1:a5258871b33d 125 }
jmitc91516 1:a5258871b33d 126 }
jmitc91516 1:a5258871b33d 127
jmitc91516 1:a5258871b33d 128 // 'else' - none have expired
jmitc91516 1:a5258871b33d 129 return false;
jmitc91516 1:a5258871b33d 130 }
jmitc91516 1:a5258871b33d 131
jmitc91516 1:a5258871b33d 132 /*
jmitc91516 1:a5258871b33d 133 Given a pointer to a ServiceInterval object that has expired, this function looks for
jmitc91516 1:a5258871b33d 134 the next ServiceInterval object that has expired, and returns a pointer to it,
jmitc91516 1:a5258871b33d 135 or NULL if there are no more expired service intervals.
jmitc91516 1:a5258871b33d 136
jmitc91516 1:a5258871b33d 137 If the pointer passed to it - i.e. 'thisExpiredInterval' - is NULL, this function
jmitc91516 1:a5258871b33d 138 starts at the beginning of the array. Note that it does not check
jmitc91516 1:a5258871b33d 139 that 'thisExpiredInterval' (if not NULL) actually has expired.
jmitc91516 1:a5258871b33d 140
jmitc91516 1:a5258871b33d 141 The idea is that you first call this function with 'thisExpiredInterval' set to NULL,
jmitc91516 1:a5258871b33d 142 then (if it did not return NULL) you call it again, passing it the ServiceInterval pointer
jmitc91516 1:a5258871b33d 143 it returned, and you keep on doing this until it returns NULL. The ServiceInterval pointers
jmitc91516 1:a5258871b33d 144 that it returned during this sequence, are the ones that have expired.
jmitc91516 1:a5258871b33d 145
jmitc91516 1:a5258871b33d 146 Args: a pointer to the 'current' expired ServiceInterval - it starts its search
jmitc91516 1:a5258871b33d 147 at the next object after that. If this is NULL, it starts
jmitc91516 1:a5258871b33d 148 at the beginning of the array.
jmitc91516 1:a5258871b33d 149
jmitc91516 1:a5258871b33d 150 Returns a pointer to the next ServiceInterval that has expired, or NULL if there are no more.
jmitc91516 1:a5258871b33d 151 *** Caller must check for NULL (obviously) ***
jmitc91516 1:a5258871b33d 152
jmitc91516 1:a5258871b33d 153 */
jmitc91516 1:a5258871b33d 154 ServiceInterval* ServiceInterval::GetNextExpiredServiceInterval(ServiceInterval* thisExpiredInterval)
jmitc91516 1:a5258871b33d 155 {
jmitc91516 1:a5258871b33d 156 int startIndex = 0;
jmitc91516 1:a5258871b33d 157
jmitc91516 1:a5258871b33d 158 if(thisExpiredInterval != NULL) {
jmitc91516 1:a5258871b33d 159 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 160 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 161 if(serviceIntervalArray[index] == thisExpiredInterval) {
jmitc91516 1:a5258871b33d 162 startIndex = index + 1;
jmitc91516 1:a5258871b33d 163 break;
jmitc91516 1:a5258871b33d 164 }
jmitc91516 1:a5258871b33d 165 }
jmitc91516 1:a5258871b33d 166 }
jmitc91516 1:a5258871b33d 167 }
jmitc91516 1:a5258871b33d 168
jmitc91516 1:a5258871b33d 169 for (int index = startIndex; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 170 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 171 if(serviceIntervalArray[index]->HasExpired()) {
jmitc91516 1:a5258871b33d 172 return serviceIntervalArray[index];
jmitc91516 1:a5258871b33d 173 }
jmitc91516 1:a5258871b33d 174 }
jmitc91516 1:a5258871b33d 175 }
jmitc91516 1:a5258871b33d 176
jmitc91516 1:a5258871b33d 177 return NULL;
jmitc91516 1:a5258871b33d 178 }
jmitc91516 1:a5258871b33d 179
jmitc91516 1:a5258871b33d 180 /*
jmitc91516 1:a5258871b33d 181 Saves the states of all our ServiceInterval objects to QSPI settings,
jmitc91516 1:a5258871b33d 182 so that they can be restored later.
jmitc91516 1:a5258871b33d 183 */
jmitc91516 1:a5258871b33d 184 void ServiceInterval::SaveAllServiceIntervalsToQSPISettings(void)
jmitc91516 1:a5258871b33d 185 {
jmitc91516 1:a5258871b33d 186 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 187 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 188 serviceIntervalArray[index]->SaveToQSPISettings();
jmitc91516 1:a5258871b33d 189 }
jmitc91516 1:a5258871b33d 190 }
jmitc91516 1:a5258871b33d 191 }
jmitc91516 1:a5258871b33d 192
jmitc91516 1:a5258871b33d 193 /*
jmitc91516 1:a5258871b33d 194 Restores the states of all our ServiceInterval objects from QSPI settings,
jmitc91516 1:a5258871b33d 195 to their values at the last 'SaveAllServiceIntervalsToQSPISettings' call.
jmitc91516 1:a5258871b33d 196 */
jmitc91516 1:a5258871b33d 197 void ServiceInterval::ReadAllServiceIntervalsFromQSPISettings(void)
jmitc91516 1:a5258871b33d 198 {
jmitc91516 1:a5258871b33d 199 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 200 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 201 serviceIntervalArray[index]->ReadFromQSPISettings();
jmitc91516 1:a5258871b33d 202 }
jmitc91516 1:a5258871b33d 203 }
jmitc91516 1:a5258871b33d 204 }
jmitc91516 1:a5258871b33d 205
jmitc91516 1:a5258871b33d 206 /*
jmitc91516 1:a5258871b33d 207 Tells the caller whether or not a particular touch area is a
jmitc91516 1:a5258871b33d 208 "this component has been serviced" touch area.
jmitc91516 1:a5258871b33d 209
jmitc91516 1:a5258871b33d 210 Args: the index of the touch area in question
jmitc91516 1:a5258871b33d 211
jmitc91516 1:a5258871b33d 212 Returns true if the specified touch area corresponds
jmitc91516 1:a5258871b33d 213 to the "this component has been serviced" touch area index
jmitc91516 1:a5258871b33d 214 of any of our ServiceInterval objects.
jmitc91516 1:a5258871b33d 215 */
jmitc91516 1:a5258871b33d 216 bool ServiceInterval::IsServicedTouchArea(int touchAreaIndex)
jmitc91516 1:a5258871b33d 217 {
jmitc91516 1:a5258871b33d 218 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 219 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 220 if(serviceIntervalArray[index]->servicedTouchArea == touchAreaIndex) {
jmitc91516 1:a5258871b33d 221 return true;
jmitc91516 1:a5258871b33d 222 }
jmitc91516 1:a5258871b33d 223 }
jmitc91516 1:a5258871b33d 224 }
jmitc91516 1:a5258871b33d 225
jmitc91516 1:a5258871b33d 226 // 'else' - no matching touch area found
jmitc91516 1:a5258871b33d 227 return false;
jmitc91516 1:a5258871b33d 228 }
jmitc91516 1:a5258871b33d 229
jmitc91516 1:a5258871b33d 230 /*
jmitc91516 1:a5258871b33d 231 If a specified touch area corresponds to one of our
jmitc91516 1:a5258871b33d 232 "this component has been serviced" touch areas,
jmitc91516 1:a5258871b33d 233 deals with it by restarting that component's service interval
jmitc91516 1:a5258871b33d 234
jmitc91516 1:a5258871b33d 235 Args: the index of the touch area in question
jmitc91516 1:a5258871b33d 236
jmitc91516 1:a5258871b33d 237 Returns true if the specified touch area corresponded
jmitc91516 1:a5258871b33d 238 to the "this component has been serviced" touch area index
jmitc91516 1:a5258871b33d 239 of any of our ServiceInterval objects, and we have therefore
jmitc91516 1:a5258871b33d 240 restarted it - false if not, and we have therefore done nothing
jmitc91516 1:a5258871b33d 241 */
jmitc91516 1:a5258871b33d 242 bool ServiceInterval::DealWithServicedTouchArea(int touchAreaIndex)
jmitc91516 1:a5258871b33d 243 {
jmitc91516 1:a5258871b33d 244 for (int index = 0; index < SERVICE_INTERVAL_COUNT; ++index) {
jmitc91516 1:a5258871b33d 245 if(serviceIntervalArray[index] != NULL) {
jmitc91516 1:a5258871b33d 246 if(serviceIntervalArray[index]->servicedTouchArea == touchAreaIndex) {
jmitc91516 1:a5258871b33d 247
jmitc91516 1:a5258871b33d 248 serviceIntervalArray[index]->Start();
jmitc91516 1:a5258871b33d 249
jmitc91516 1:a5258871b33d 250 return true;
jmitc91516 1:a5258871b33d 251 }
jmitc91516 1:a5258871b33d 252 }
jmitc91516 1:a5258871b33d 253 }
jmitc91516 1:a5258871b33d 254
jmitc91516 1:a5258871b33d 255 // 'else' - no matching touch area found
jmitc91516 1:a5258871b33d 256 return false;
jmitc91516 1:a5258871b33d 257 }
jmitc91516 1:a5258871b33d 258
jmitc91516 1:a5258871b33d 259 // End of static member functions
jmitc91516 1:a5258871b33d 260
jmitc91516 1:a5258871b33d 261
jmitc91516 1:a5258871b33d 262 // ServiceInterval class members
jmitc91516 1:a5258871b33d 263 // *****************************
jmitc91516 1:a5258871b33d 264
jmitc91516 1:a5258871b33d 265 /*
jmitc91516 1:a5258871b33d 266 Create a new ServiceInterval object, with the specified description.
jmitc91516 1:a5258871b33d 267 Note that the service interval does not start its 'countdown' at this point.
jmitc91516 1:a5258871b33d 268
jmitc91516 1:a5258871b33d 269 Args: the interval description, as a null-terminated string
jmitc91516 1:a5258871b33d 270 */
jmitc91516 1:a5258871b33d 271 ServiceInterval::ServiceInterval(char *intervalDescription, int touchAreaIndex)
jmitc91516 1:a5258871b33d 272 {
jmitc91516 1:a5258871b33d 273 // Do not use up more memory than we need for the description
jmitc91516 1:a5258871b33d 274 int descriptionLength = strlen(intervalDescription);
jmitc91516 1:a5258871b33d 275 description = new char[descriptionLength + 1];
jmitc91516 1:a5258871b33d 276 strcpy(description, intervalDescription);
jmitc91516 1:a5258871b33d 277
jmitc91516 1:a5258871b33d 278 intervalHasStarted = false;
jmitc91516 1:a5258871b33d 279
jmitc91516 1:a5258871b33d 280 servicedTouchArea = touchAreaIndex;
jmitc91516 1:a5258871b33d 281 }
jmitc91516 1:a5258871b33d 282
jmitc91516 1:a5258871b33d 283 /*
jmitc91516 1:a5258871b33d 284 Destroy this service interval cleanly - free up allocated memory
jmitc91516 1:a5258871b33d 285 */
jmitc91516 1:a5258871b33d 286 ServiceInterval::~ServiceInterval()
jmitc91516 1:a5258871b33d 287 {
jmitc91516 1:a5258871b33d 288 if(description != NULL) {
jmitc91516 1:a5258871b33d 289 delete [] description;
jmitc91516 1:a5258871b33d 290
jmitc91516 1:a5258871b33d 291 description = NULL;
jmitc91516 1:a5258871b33d 292 }
jmitc91516 1:a5258871b33d 293 }
jmitc91516 1:a5258871b33d 294
jmitc91516 1:a5258871b33d 295
jmitc91516 1:a5258871b33d 296 /*
jmitc91516 1:a5258871b33d 297 Tells the caller how long the description is, so that the caller can make sure it has enough memory
jmitc91516 1:a5258871b33d 298 for its own copy of the description.
jmitc91516 1:a5258871b33d 299
jmitc91516 1:a5258871b33d 300 Note that the length value returned does *not* include the terminating zero byte.
jmitc91516 1:a5258871b33d 301
jmitc91516 1:a5258871b33d 302 No arguments
jmitc91516 1:a5258871b33d 303
jmitc91516 1:a5258871b33d 304 Returns the number of characters in the description string, not including the terminating zero byte.
jmitc91516 1:a5258871b33d 305 */
jmitc91516 1:a5258871b33d 306 int ServiceInterval::GetDescriptionLength(void)
jmitc91516 1:a5258871b33d 307 {
jmitc91516 1:a5258871b33d 308 return strlen(description);
jmitc91516 1:a5258871b33d 309 }
jmitc91516 1:a5258871b33d 310
jmitc91516 1:a5258871b33d 311 /*
jmitc91516 1:a5258871b33d 312 Returns the interval description, as a null-terminated string,
jmitc91516 1:a5258871b33d 313 in a buffer provided by the caller.
jmitc91516 1:a5258871b33d 314
jmitc91516 1:a5258871b33d 315 Args: a pointer to the buffer which is to contain the description.
jmitc91516 1:a5258871b33d 316 Note that it is up to the caller to make sure that this
jmitc91516 1:a5258871b33d 317 is long enough to contain the description, plus
jmitc91516 1:a5258871b33d 318 the null terminator
jmitc91516 1:a5258871b33d 319 */
jmitc91516 1:a5258871b33d 320 void ServiceInterval::GetDescription(char *buffer)
jmitc91516 1:a5258871b33d 321 {
jmitc91516 1:a5258871b33d 322 strcpy(buffer, description);
jmitc91516 1:a5258871b33d 323 }
jmitc91516 1:a5258871b33d 324
jmitc91516 1:a5258871b33d 325
jmitc91516 1:a5258871b33d 326 // CyclesServiceInterval class members
jmitc91516 1:a5258871b33d 327 // ***********************************
jmitc91516 1:a5258871b33d 328
jmitc91516 1:a5258871b33d 329 /*
jmitc91516 1:a5258871b33d 330 CyclesServiceInterval keeps its description in the base class
jmitc91516 1:a5258871b33d 331 */
jmitc91516 1:a5258871b33d 332 CyclesServiceInterval::CyclesServiceInterval(char *intervalDescription, int touchAreaIndex) : ServiceInterval(intervalDescription, touchAreaIndex)
jmitc91516 1:a5258871b33d 333 {
jmitc91516 1:a5258871b33d 334 durationInNumberOfInstrumentCycles = 0;
jmitc91516 1:a5258871b33d 335 countOfRemainingCycles = -1; // Not yet set
jmitc91516 1:a5258871b33d 336 intervalHasExpired = false;
jmitc91516 1:a5258871b33d 337 }
jmitc91516 1:a5258871b33d 338
jmitc91516 1:a5258871b33d 339 /*
jmitc91516 1:a5258871b33d 340 Sets the service interval duration to the number of instrument cycles (i.e. runs) specified.
jmitc91516 1:a5258871b33d 341 Note that this function does not start the 'countdown' - the 'Start' function does that.
jmitc91516 1:a5258871b33d 342
jmitc91516 1:a5258871b33d 343 Args: the number of cycles that represents a new service interval
jmitc91516 1:a5258871b33d 344 */
jmitc91516 1:a5258871b33d 345 void CyclesServiceInterval::SetDurationInNumberOfInstrumentCycles(int newDurationInNumberOfInstrumentCycles)
jmitc91516 1:a5258871b33d 346 {
jmitc91516 1:a5258871b33d 347 durationInNumberOfInstrumentCycles = newDurationInNumberOfInstrumentCycles;
jmitc91516 1:a5258871b33d 348 }
jmitc91516 1:a5258871b33d 349
jmitc91516 1:a5258871b33d 350
jmitc91516 1:a5258871b33d 351 /*
jmitc91516 1:a5258871b33d 352 Start the next service interval now.
jmitc91516 1:a5258871b33d 353
jmitc91516 1:a5258871b33d 354 No arguments, no return code
jmitc91516 1:a5258871b33d 355 */
jmitc91516 1:a5258871b33d 356 void CyclesServiceInterval::Start(void)
jmitc91516 1:a5258871b33d 357 {
jmitc91516 1:a5258871b33d 358 countOfRemainingCycles = durationInNumberOfInstrumentCycles;
jmitc91516 1:a5258871b33d 359 intervalHasExpired = false;
jmitc91516 1:a5258871b33d 360
jmitc91516 1:a5258871b33d 361 intervalHasStarted = true;
jmitc91516 1:a5258871b33d 362 }
jmitc91516 1:a5258871b33d 363
jmitc91516 1:a5258871b33d 364
jmitc91516 1:a5258871b33d 365 /*
jmitc91516 1:a5258871b33d 366 Caller is telling us that the instrument either is about to perform another cycle,
jmitc91516 1:a5258871b33d 367 or has just completed another cycle - it does not matter which, as long
jmitc91516 1:a5258871b33d 368 as this function is called once, and only once, per cycle.
jmitc91516 1:a5258871b33d 369
jmitc91516 1:a5258871b33d 370 This function then works out if this service interval has now expired -
jmitc91516 1:a5258871b33d 371 caller must call this class' 'HasExpired()' member function (see header file)
jmitc91516 1:a5258871b33d 372 to find out.
jmitc91516 1:a5258871b33d 373
jmitc91516 1:a5258871b33d 374 No arguments, no return code
jmitc91516 1:a5258871b33d 375 */
jmitc91516 1:a5258871b33d 376 void CyclesServiceInterval::InstrumentHasCycled(void)
jmitc91516 1:a5258871b33d 377 {
jmitc91516 1:a5258871b33d 378 if(intervalHasStarted && (!intervalHasExpired)) {
jmitc91516 1:a5258871b33d 379
jmitc91516 1:a5258871b33d 380 --countOfRemainingCycles;
jmitc91516 1:a5258871b33d 381
jmitc91516 1:a5258871b33d 382 if(countOfRemainingCycles <= 0) {
jmitc91516 1:a5258871b33d 383
jmitc91516 1:a5258871b33d 384 // Make sure the cycle count has a legal value
jmitc91516 1:a5258871b33d 385 countOfRemainingCycles = 0;
jmitc91516 1:a5258871b33d 386
jmitc91516 1:a5258871b33d 387 intervalHasExpired = true;
jmitc91516 1:a5258871b33d 388
jmitc91516 1:a5258871b33d 389 intervalHasStarted = false;
jmitc91516 1:a5258871b33d 390 }
jmitc91516 1:a5258871b33d 391 }
jmitc91516 1:a5258871b33d 392 }
jmitc91516 1:a5258871b33d 393
jmitc91516 1:a5258871b33d 394 /*
jmitc91516 1:a5258871b33d 395 Save the current state of this service interval to QSPI settings,
jmitc91516 1:a5258871b33d 396 so that we can later read the state from QSPI, and restore it
jmitc91516 1:a5258871b33d 397 exactly as it was
jmitc91516 1:a5258871b33d 398
jmitc91516 1:a5258871b33d 399 No arguments, no return code
jmitc91516 1:a5258871b33d 400 */
jmitc91516 1:a5258871b33d 401 void CyclesServiceInterval::SaveToQSPISettings(void)
jmitc91516 1:a5258871b33d 402 {
jmitc91516 1:a5258871b33d 403 int descriptionLength = GetDescriptionLength();
jmitc91516 1:a5258871b33d 404 char descriptionBuff[descriptionLength + 10];
jmitc91516 1:a5258871b33d 405 GetDescription(descriptionBuff);
jmitc91516 1:a5258871b33d 406
jmitc91516 1:a5258871b33d 407 char settingNameBuff[descriptionLength + 100];
jmitc91516 1:a5258871b33d 408
jmitc91516 1:a5258871b33d 409 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".intervalHasStarted");
jmitc91516 1:a5258871b33d 410 SettingsHandler::PutIntegerValueToQSPISettings(settingNameBuff, intervalHasStarted ? 1 : 0);
jmitc91516 1:a5258871b33d 411
jmitc91516 1:a5258871b33d 412 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".durationInNumberOfInstrumentCycles");
jmitc91516 1:a5258871b33d 413 SettingsHandler::PutIntegerValueToQSPISettings(settingNameBuff, durationInNumberOfInstrumentCycles);
jmitc91516 1:a5258871b33d 414
jmitc91516 1:a5258871b33d 415 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".countOfRemainingCycles");
jmitc91516 1:a5258871b33d 416 SettingsHandler::PutIntegerValueToQSPISettings(settingNameBuff, countOfRemainingCycles);
jmitc91516 1:a5258871b33d 417
jmitc91516 1:a5258871b33d 418 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".intervalHasExpired");
jmitc91516 1:a5258871b33d 419 SettingsHandler::PutIntegerValueToQSPISettings(settingNameBuff, intervalHasExpired ? 1 : 0);
jmitc91516 1:a5258871b33d 420 }
jmitc91516 1:a5258871b33d 421
jmitc91516 1:a5258871b33d 422 /*
jmitc91516 1:a5258871b33d 423 Reads the state of this service interval from QSPI settings.
jmitc91516 1:a5258871b33d 424
jmitc91516 1:a5258871b33d 425 No arguments, no return code
jmitc91516 1:a5258871b33d 426
jmitc91516 1:a5258871b33d 427 */
jmitc91516 1:a5258871b33d 428 void CyclesServiceInterval::ReadFromQSPISettings(void)
jmitc91516 1:a5258871b33d 429 {
jmitc91516 1:a5258871b33d 430 int descriptionLength = GetDescriptionLength();
jmitc91516 1:a5258871b33d 431 char descriptionBuff[descriptionLength + 10];
jmitc91516 1:a5258871b33d 432 GetDescription(descriptionBuff);
jmitc91516 1:a5258871b33d 433
jmitc91516 1:a5258871b33d 434 char settingNameBuff[descriptionLength + 100];
jmitc91516 1:a5258871b33d 435
jmitc91516 1:a5258871b33d 436 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".intervalHasStarted");
jmitc91516 1:a5258871b33d 437 intervalHasStarted = (SettingsHandler::GetIntegerValueFromQSPISettings(settingNameBuff, 0) != 0);
jmitc91516 1:a5258871b33d 438
jmitc91516 1:a5258871b33d 439 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".durationInNumberOfInstrumentCycles");
jmitc91516 1:a5258871b33d 440 durationInNumberOfInstrumentCycles = SettingsHandler::GetIntegerValueFromQSPISettings(settingNameBuff, 0);
jmitc91516 1:a5258871b33d 441
jmitc91516 1:a5258871b33d 442 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".countOfRemainingCycles");
jmitc91516 1:a5258871b33d 443 countOfRemainingCycles = SettingsHandler::GetIntegerValueFromQSPISettings(settingNameBuff, 0);
jmitc91516 1:a5258871b33d 444
jmitc91516 1:a5258871b33d 445 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".intervalHasExpired");
jmitc91516 1:a5258871b33d 446 intervalHasExpired = (SettingsHandler::GetIntegerValueFromQSPISettings(settingNameBuff, 0) != 0);
jmitc91516 1:a5258871b33d 447 }
jmitc91516 1:a5258871b33d 448
jmitc91516 1:a5258871b33d 449
jmitc91516 1:a5258871b33d 450 // TwelveMonthServiceInterval class members
jmitc91516 1:a5258871b33d 451 // ****************************************
jmitc91516 1:a5258871b33d 452
jmitc91516 1:a5258871b33d 453 // Static function
jmitc91516 1:a5258871b33d 454
jmitc91516 1:a5258871b33d 455 /*
jmitc91516 1:a5258871b33d 456 Gets the current local time as a 'tm' structure. Provided so that we do this
jmitc91516 1:a5258871b33d 457 the same way everywhere (we may need to apply a correction to the value
jmitc91516 1:a5258871b33d 458 returned by the time() function).
jmitc91516 1:a5258871b33d 459
jmitc91516 1:a5258871b33d 460 Args: pointer to a 'tm' structure to receive the local time
jmitc91516 1:a5258871b33d 461 *** This must not be NULL ***
jmitc91516 1:a5258871b33d 462
jmitc91516 1:a5258871b33d 463 No return code.
jmitc91516 1:a5258871b33d 464 */
jmitc91516 1:a5258871b33d 465 void TwelveMonthServiceInterval::GetCurrentLocalTime(struct tm *currentLocalTime)
jmitc91516 1:a5258871b33d 466 {
jmitc91516 1:a5258871b33d 467 time_t seconds = time(NULL); // Get current time
jmitc91516 1:a5258871b33d 468 *currentLocalTime = *(localtime(&seconds));
jmitc91516 1:a5258871b33d 469 }
jmitc91516 1:a5258871b33d 470
jmitc91516 1:a5258871b33d 471
jmitc91516 1:a5258871b33d 472 // Non-static functions
jmitc91516 1:a5258871b33d 473
jmitc91516 1:a5258871b33d 474 /*
jmitc91516 1:a5258871b33d 475 TwelveMonthServiceInterval keeps its description in the base class
jmitc91516 1:a5258871b33d 476 */
jmitc91516 1:a5258871b33d 477 TwelveMonthServiceInterval::TwelveMonthServiceInterval(char *intervalDescription, int touchAreaIndex) : ServiceInterval(intervalDescription, touchAreaIndex)
jmitc91516 1:a5258871b33d 478 {
jmitc91516 1:a5258871b33d 479 }
jmitc91516 1:a5258871b33d 480
jmitc91516 1:a5258871b33d 481 /*
jmitc91516 1:a5258871b33d 482 Start the next service interval now.
jmitc91516 1:a5258871b33d 483
jmitc91516 1:a5258871b33d 484 No arguments, no return code
jmitc91516 1:a5258871b33d 485 */
jmitc91516 1:a5258871b33d 486 void TwelveMonthServiceInterval::Start(void)
jmitc91516 1:a5258871b33d 487 {
jmitc91516 1:a5258871b33d 488 GetCurrentLocalTime(&startTime);
jmitc91516 1:a5258871b33d 489
jmitc91516 1:a5258871b33d 490 intervalHasStarted = true;
jmitc91516 1:a5258871b33d 491 }
jmitc91516 1:a5258871b33d 492
jmitc91516 1:a5258871b33d 493 /*
jmitc91516 1:a5258871b33d 494 This function does nothing in this class - we are not interested in machine cycles,
jmitc91516 1:a5258871b33d 495 only in elapsed time. Provided so that the caller does not need to know
jmitc91516 1:a5258871b33d 496 the type of this object before calling this function
jmitc91516 1:a5258871b33d 497 */
jmitc91516 1:a5258871b33d 498 void TwelveMonthServiceInterval::InstrumentHasCycled(void)
jmitc91516 1:a5258871b33d 499 {
jmitc91516 1:a5258871b33d 500 }
jmitc91516 1:a5258871b33d 501
jmitc91516 1:a5258871b33d 502 /*
jmitc91516 1:a5258871b33d 503 Tell the caller whether or not this service interval has expired -
jmitc91516 1:a5258871b33d 504 i.e. whether twelve full months (at least) have gone by
jmitc91516 1:a5258871b33d 505 since the interval started.
jmitc91516 1:a5258871b33d 506 */
jmitc91516 1:a5258871b33d 507 bool TwelveMonthServiceInterval::HasExpired(void)
jmitc91516 1:a5258871b33d 508 {
jmitc91516 1:a5258871b33d 509 if(intervalHasStarted) {
jmitc91516 1:a5258871b33d 510 struct tm currentTime;
jmitc91516 1:a5258871b33d 511 GetCurrentLocalTime(&currentTime);
jmitc91516 1:a5258871b33d 512
jmitc91516 1:a5258871b33d 513 int yearsGoneBy = currentTime.tm_year - startTime.tm_year;
jmitc91516 1:a5258871b33d 514
jmitc91516 1:a5258871b33d 515 if((yearsGoneBy) > 1) {
jmitc91516 1:a5258871b33d 516 // Twelve month service interval has expired
jmitc91516 1:a5258871b33d 517 intervalHasStarted = false;
jmitc91516 1:a5258871b33d 518 return true;
jmitc91516 1:a5258871b33d 519 }
jmitc91516 1:a5258871b33d 520
jmitc91516 1:a5258871b33d 521 if(yearsGoneBy == 1) {
jmitc91516 1:a5258871b33d 522 int monthsGoneBy = currentTime.tm_mon - startTime.tm_mon + 12;
jmitc91516 1:a5258871b33d 523
jmitc91516 1:a5258871b33d 524 if(monthsGoneBy > 12) {
jmitc91516 1:a5258871b33d 525 // Twelve month service interval has expired
jmitc91516 1:a5258871b33d 526 intervalHasStarted = false;
jmitc91516 1:a5258871b33d 527 return true;
jmitc91516 1:a5258871b33d 528 }
jmitc91516 1:a5258871b33d 529
jmitc91516 1:a5258871b33d 530 if(monthsGoneBy == 12) {
jmitc91516 1:a5258871b33d 531 if(currentTime.tm_mday > startTime.tm_mday) {
jmitc91516 1:a5258871b33d 532 // Twelve month service interval has expired
jmitc91516 1:a5258871b33d 533 intervalHasStarted = false;
jmitc91516 1:a5258871b33d 534 return true;
jmitc91516 1:a5258871b33d 535 }
jmitc91516 1:a5258871b33d 536 }
jmitc91516 1:a5258871b33d 537 }
jmitc91516 1:a5258871b33d 538
jmitc91516 1:a5258871b33d 539 // If we get here, the twelve month service interval has not expired
jmitc91516 1:a5258871b33d 540 }
jmitc91516 1:a5258871b33d 541
jmitc91516 1:a5258871b33d 542 // 'else' - either the interval has not expired, or has not even started
jmitc91516 1:a5258871b33d 543 return false;
jmitc91516 1:a5258871b33d 544 }
jmitc91516 1:a5258871b33d 545
jmitc91516 1:a5258871b33d 546 /*
jmitc91516 1:a5258871b33d 547 Save the current state of this service interval to QSPI settings,
jmitc91516 1:a5258871b33d 548 so that we can later read the state from QSPI, and restore it
jmitc91516 1:a5258871b33d 549 exactly as it was
jmitc91516 1:a5258871b33d 550
jmitc91516 1:a5258871b33d 551 No arguments, no return code
jmitc91516 1:a5258871b33d 552 */
jmitc91516 1:a5258871b33d 553 void TwelveMonthServiceInterval::SaveToQSPISettings(void)
jmitc91516 1:a5258871b33d 554 {
jmitc91516 1:a5258871b33d 555 int descriptionLength = GetDescriptionLength();
jmitc91516 1:a5258871b33d 556 char descriptionBuff[descriptionLength + 10];
jmitc91516 1:a5258871b33d 557 GetDescription(descriptionBuff);
jmitc91516 1:a5258871b33d 558
jmitc91516 1:a5258871b33d 559 char settingNameBuff[descriptionLength + 100];
jmitc91516 1:a5258871b33d 560
jmitc91516 1:a5258871b33d 561 // We are only interested in the year, month and day of the month values in the start time -
jmitc91516 1:a5258871b33d 562 // we do not use the other values
jmitc91516 1:a5258871b33d 563
jmitc91516 1:a5258871b33d 564 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".startTime.tm_year");
jmitc91516 1:a5258871b33d 565 SettingsHandler::PutIntegerValueToQSPISettings(settingNameBuff, startTime.tm_year);
jmitc91516 1:a5258871b33d 566
jmitc91516 1:a5258871b33d 567 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".startTime.tm_mon");
jmitc91516 1:a5258871b33d 568 SettingsHandler::PutIntegerValueToQSPISettings(settingNameBuff, startTime.tm_mon);
jmitc91516 1:a5258871b33d 569
jmitc91516 1:a5258871b33d 570 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".startTime.tm_mday");
jmitc91516 1:a5258871b33d 571 SettingsHandler::PutIntegerValueToQSPISettings(settingNameBuff, startTime.tm_mday);
jmitc91516 1:a5258871b33d 572 }
jmitc91516 1:a5258871b33d 573
jmitc91516 1:a5258871b33d 574 /*
jmitc91516 1:a5258871b33d 575 Read the state of this service interval from QSPI settings
jmitc91516 1:a5258871b33d 576
jmitc91516 1:a5258871b33d 577 No arguments, no return code
jmitc91516 1:a5258871b33d 578 */
jmitc91516 1:a5258871b33d 579 void TwelveMonthServiceInterval::ReadFromQSPISettings(void)
jmitc91516 1:a5258871b33d 580 {
jmitc91516 1:a5258871b33d 581 int descriptionLength = GetDescriptionLength();
jmitc91516 1:a5258871b33d 582 char descriptionBuff[descriptionLength + 10];
jmitc91516 1:a5258871b33d 583 GetDescription(descriptionBuff);
jmitc91516 1:a5258871b33d 584
jmitc91516 1:a5258871b33d 585 char settingNameBuff[descriptionLength + 100];
jmitc91516 1:a5258871b33d 586
jmitc91516 1:a5258871b33d 587 // We are only interested in the year, month and day of the month values in the start time -
jmitc91516 1:a5258871b33d 588 // we do not use the other values
jmitc91516 1:a5258871b33d 589
jmitc91516 1:a5258871b33d 590 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".startTime.tm_year");
jmitc91516 1:a5258871b33d 591 startTime.tm_year = SettingsHandler::GetIntegerValueFromQSPISettings(settingNameBuff, 0);
jmitc91516 1:a5258871b33d 592
jmitc91516 1:a5258871b33d 593 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".startTime.tm_mon");
jmitc91516 1:a5258871b33d 594 startTime.tm_mon = SettingsHandler::GetIntegerValueFromQSPISettings(settingNameBuff, 0);
jmitc91516 1:a5258871b33d 595
jmitc91516 1:a5258871b33d 596 sprintf(settingNameBuff, "%s%s", descriptionBuff, ".startTime.tm_mday");
jmitc91516 1:a5258871b33d 597 startTime.tm_mday = SettingsHandler::GetIntegerValueFromQSPISettings(settingNameBuff, 0);
jmitc91516 1:a5258871b33d 598 }
jmitc91516 1:a5258871b33d 599
jmitc91516 1:a5258871b33d 600
jmitc91516 1:a5258871b33d 601
jmitc91516 1:a5258871b33d 602