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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
#include "medPing.h"
#include <cassert>
#include <chrono>
#include <thread>
#include <ctime>
#include <windows.h>
const long MAX_HISTORY = 5; // can store upto (last) MAX_HISTORY sets of vital signs
const long MAX_WAIT_SEC = 4; // will random pause from 1 to MAX_WAIT_SEC
struct oneVitalHistoryRecord
{
double bodyTemp_F; // The structure of body temperature.
short pulseRate; // The structure of pulse rate.
long nSecs; // The structure of seconds.
short dia; // The structure of diastolic.
short sys; // The structure of systolic.
};
//========================================
// function prototypes for keeping track of HISTORY
// (see bottom of this file where you'll write the definitions)
void AddHistoryRecord(long nSecs, // The prototype function for AddHistoryRecord.
double new_mp_bodyTemp_F,
short new_mp_pulseRate,
short sys,
short dia,
// you need more vital signs here
oneVitalHistoryRecord vitalHistory[ ],
long& hmr
);
long FindDateTime() { // The prototype function for FindDateTime.
time_t rawtime;
time(&rawtime);
printf("\t The current local time is: %s", ctime(&rawtime));
return 0;
}
const long NOT_FOUND = -1; // used to indicate failure on linear search
long FindVitalRecord(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr, long del);
void DeleteHistoryRecord(oneVitalHistoryRecord* vitalHistory)
{
delete vitalHistory;
}
void printAllVitalRecords(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr);
// end function prototypes
//-----------------------------------------------------------------------
//create a medPing object (mP object has global file scope)
medPing mP; // The medPing object.
//--------------
// medPing_Main \
//----------------------------------------------------------------------
// called from iPhone runSim-tab
int medPing_Main() // The program.
{
// print a message to the cell phone
mP.CELL_PrintF("Hello medPing patient ...\n\n");
//======= DATA STRUCTURE ======================================
// to hold patient's history of vital signs
oneVitalHistoryRecord vitalHistory[MAX_HISTORY];
// hmr (how many really) vital signs 0 <= hmr < MAX_HISTORY
long hmr = 0;
//=============================================================
RandGen randGenerator; // i need a random number generator // Our random generator for the program to use for the data.
time_t start, now; // keep track of time in simulation // Our time vital sign.
// ask user at CELL to input length of simulation
mP.CELL_PrintF("How many SECONDS would you like to simulate?\n"); // Asks the user to type in an amount of seconds for the program to run.
double simulationTime = mP.CELL_fetchReal();
time(&start);
// simulation loop ....
time(&now);
while ( difftime(now,start) < simulationTime ) // while still time to simulate ...
{
long waitThisLongSEC = randGenerator.RandInt(1, MAX_WAIT_SEC);
mP.CELL_PrintF("\n--------------------------\n");
mP.CELL_PrintF("\n[PAUSE ... (%d seconds) ]\n", waitThisLongSEC);
std::this_thread::sleep_for(std::chrono::milliseconds(waitThisLongSEC*1000));
// sleep(waitThisLongSEC); // ZZzzzz.....
// WINDOWS uses the function called: Sleep( milliseconds )
// Sleep(waitThisLongSEC*1000); // ZZzzzz.....
// check our watch ...
long nSecs = time(&now); // The function that checks the seconds.
// fetch vital signs from the medPing chip HERE (use mP object)
double newTemp; // The vital sign for a new temperature.
newTemp = mP.getBodyTemperature_F();
short newPulseRate; // The vital sign for a new pulse rate.
newPulseRate = mP.getPulseRate_BPM();
short sys, dia; // The vital signs for systolic and dissystolic
mP.getBloodPressure_mmHg(sys, dia);
// :
// :
// once medPing has given you all the vital signs (see above)
// now ADD these new vital signs to our history DATA STRUCTURE
AddHistoryRecord(nSecs, newTemp, newPulseRate, sys, dia, vitalHistory, hmr); //Vital signs for the data structure.
// PRINT ALL of the series of vital signs so far
printAllVitalRecords(mP, vitalHistory, hmr); // Vital signs for printing.
} // while still more to simulate ...
mP.CELL_PrintF("\n\nSIMULATION OVER.\n\n"); // Lets the user know that the record counter has ended.
// prompt for a record to delete HERE,
mP.CELL_PrintF("What record do you want to delete?\n"); // Asks the user to type in a raw time of a record for it to delete said record.
long del;
del = mP.CELL_fetchInteger();
long whichBox;
whichBox = FindVitalRecord(mP, vitalHistory, hmr, del);
int i;
if(del == vitalHistory[i].nSecs)
return i;
// find it (using your Find function)
// and delete it if found (using your Delete function)
mP.CELL_PrintF("\n\nDONE.\n");
// WINDOWS
// system("PAUSE");
return 0;
} // end medPing_Main()
// helpful HISTORY functions below
void AddHistoryRecord(long secs, double newTemp, short newPulseRate, short sys, short dia,
oneVitalHistoryRecord vitalHistory[ ],
long& hmr ) // The function for adding a history record.
{
vitalHistory[hmr].bodyTemp_F = newTemp; // The variable for a new temperature.
vitalHistory[hmr].nSecs = secs; // The variable for the amount of seconds.
vitalHistory[hmr].pulseRate = newPulseRate; // The variable for a new pulse rate.
vitalHistory[hmr].sys = sys; // The variable for systolic.
vitalHistory[hmr].dia = dia; // The variable for dissystolic.
hmr++;
}
long FindVitalRecord(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr, long del)
{
mP.CELL_PrintF("\t I am about to delete this record. \t%ld\n", del);
}
//---------------------\
// printAllVitalRecords \
//---------------------------------------------------------------------------------------------
// Prints history (last set of) hmr vital signs (to medPing output)
// PRE: nSecs(assigned) with a result of time() function and
//hmr(assigned) and 0 <= hmr < MAX_HISTORY and
//oneVitalHistoryRecord[0..(hmr-1)](assigned)
// POST: if nSecs found within oneVitalHistoryRecord[]
//then RETURNS index of array cell where found
//otherwise RETURNS “NOT_FOUND” (constant indicating “not found”
// SIDE EFFECTS:
//---------------------------------------------------------------------------------------------
void printAllVitalRecords(medPing& mP, const oneVitalHistoryRecord vitalHistory[ ], long hmr) // Void for printing all of the Vital Record data.
{
if (hmr > 0)
{
mP.CELL_PrintF("\n---- Records (so far) ----"); // Displays above all the records.
for(long i=0; i < hmr; i++)
{
mP.CELL_PrintF("\nRECORD [%02d]\n", i); // Prints the title for the record.
mP.CELL_PrintF("\t raw time: \t%4d\n", vitalHistory[i].nSecs); // Prints the raw time for the record.
mP.CELL_PrintF(reinterpret_cast<const char *>(FindDateTime())); // Prints the date and time for the record.
mP.CELL_PrintF("\t temp(F): \t%4.1f\n", vitalHistory[i].bodyTemp_F); // Prints the temperature for the record.
mP.CELL_PrintF("\t pulse(BPM): \t%4d\n", vitalHistory[i].pulseRate); // Prints the pulse rate for the record.
mP.CELL_PrintF("\t Systolic: \t%4d\n", vitalHistory[i].sys); // Prints the systolic for the record.
mP.CELL_PrintF("\t Diasystolic: \t%4d\n", vitalHistory[i].dia); // Prints the dissystolic for the record.
} // for all records so far
mP.CELL_PrintF("\n---- end History ----\n\n"); // When the program is finished with the records.
} // if any records
else
mP.CELL_PrintF("\nNo History so far ...\n\n"); // Incase the code doesn't work.
} // printAllVitalRecords()
|