Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of Int_Demo_09May2017_Suhasini_HRavg_Nikita_ili9341 by
Diff: sdcard.cpp
- Revision:
- 26:53ff13a164f3
- Parent:
- 24:d992ee8369f4
- Child:
- 27:907f8ce0025e
--- a/sdcard.cpp Sun Jul 02 19:22:34 2017 +0000
+++ b/sdcard.cpp Wed Jul 05 15:36:58 2017 +0000
@@ -491,7 +491,7 @@
}
//------------New function added to print ECG data to Sd card using fwrite
-void sd_ecgwrite(int *ecg_ptr)
+void sd_ecgwrite(uint32_t *ecg_ptr)
{
fwrite(ecg_ptr, sizeof(int), 1, fpeecg);
}
@@ -503,27 +503,31 @@
char buffer3[32];
sprintf(buffer3, "/sd/%d.csv", pid);
fpmain = fopen(buffer3, "a"); // Main File is opened in Append mode
-
+ snd.printf("opening main file\n");
sprintf(buffer3, "/sd/%d_ECG.csv", pid); // ECG file is opened in read mode
fpeecg = fopen(buffer3, "r");
-
- for(int i=0; i<10; i++)
+ snd.printf("opening temp file\n");
+ for(int i=0; i<20; i++) //the loop runs as 20 times of 100 i.e., 2k
{
int bigbuf[100] = {0} ;
fread(bigbuf, sizeof(int),100 , fpeecg);
fwrite(bigbuf, sizeof(int), 100, fpmain);
}
+ snd.printf("to close temp file\n");
fclose(fpeecg); // Both files are Closed
+ snd.printf("to come out of main file\n");
fclose(fpmain);
- /*
+ snd.printf("COPY complete Files Closed\n");
+
sprintf(buffer3, "/sd/%d_ECG.csv", pid); // ECG file is opened in write mode to empty the file
- fpeecg = fopen(buffer3, "w");
- fclose(fpecg);
- */ // File is closed
+ fpeecg = fopen(buffer3, "r");
+ fclose(fpeecg);
+ // File is closed
int success;
sprintf(buffer3, "/sd/%d_ECG.csv", pid);
- success = remove(buffer3);
+ success = remove(buffer3);
+ snd.printf("DELETE STATUS = %d\n", success);
}
@@ -599,146 +603,3 @@
}
-uint16_t heart_cal(int pid) // Function created on 10/6/17, Function modified on 13/6/17 Nidhin
-// Objective ti understand how file pointers work
-{
- //FILE *fpeecg2; // Secondary File
-
- char buffer3[32];
-
-
- int32_t buff1[1] ; int32_t buff2[2]; int32_t buff3[1]; // Buff 12 &3 Stores sample 1, 2 & 10th sample
- int32_t fppos; // Variable to hold pointer position
-
- int32_t val1_val10; // VARIABLE holding difference of sample 1 and 10
-
- int32_t peakpos[10]; //array taht holds the peak position //Changed to 10 (ORG 4) Nidhin 20/6/17
- int32_t peakval[10]; // Array holding peak values ////Changed to 10 (ORG 4) Nidhin 20/6/17
- int32_t pk = 0; // Variable to access array
-
- int32_t no_of_peaks =0; // Variable holding toatl number of peaks ; increments on each peak
-
- float hrt_rate; // Heart rate in float varoable
- uint16_t heart_rate; // Heart rate to be type casted to int
-
- sprintf(buffer3, "/sd/%d_ECG.csv", pid); // For opening a specific file
- fpeecg = fopen(buffer3, "r");
-
- /*
- fppos = ftell(fpeecg);
- snd.printf("Main pointer is at Position : %d \n", fppos);
- */
- int32_t m =0; // Variable to move the file pointer in fseek function Org Static Nidhin 22/6/17
- int32_t i =0; // Variable to count sample number, ORG Static Nidhin 22/6/17
-
- for ( i = 0; i < 1000; i++) // for 1024 samples in file
- {
- rewind(fpeecg); // Go to satrt of file each time
- fseek(fpeecg, m, SEEK_CUR); // Update the count value according to move pointer
-
- fread(buff1, sizeof(int32_t), 1, fpeecg); // Read sample 1
- //fpeecg2 = fpeecg;
- fread(buff2, sizeof(int32_t), 1, fpeecg); // Read Sample 2
-
- int32_t n = 28; // Variable to move to 10th sampple from current
-
-
- fseek(fpeecg, n, SEEK_CUR); // Moving to tenth sample
- fread(buff3, sizeof(int32_t), 1, fpeecg); // Read 3rd sample
-
- snd.printf("buff1 = %d , buff2 = %d, buff3 = %d\n",buff1[0],buff2[0],buff3[0] ); //Test Value heald by buffer each round
-
- val1_val10 = buff1[0] - buff3[0]; // Difference of sample 1 and 10
-
- if(buff1[0] > buff2[0] && val1_val10 > 10000) // Condition for -ve gradient and difference of 10000
- {
- peakpos[pk] = i; // Peak detected sample number updated in array
- peakval[pk] = buff1[0]; // Peak value updated in array
- pk++; // Array pointer incremented
- i = i+120; // i incremented to 120 for next 120 samples
- no_of_peaks = no_of_peaks + 1; // no. of peaks incremented
- //fseek(fpeecg, 480, SEEK_CUR); // push the pointer to
- //fppos = ftell(fpeecg); Commenetd Nidhin 20/6/17
- //snd.printf("in if : The Pointer is moved to positon %d\n", fppos);
- m = m + 480;
-
- }
-
- else
- {
- m = m+4;
- //fpeecg = fpeecg2;
- //i = i+1;
- //fppos = ftell(fpeecg); COMMENTED NIDHIN 20/6/17
- //snd.printf("in Else : The Pointer is moved to positon %d\n", fppos);
- }
- }
-
- snd.printf("The No: of Peaks is %d\n", no_of_peaks);
-
- for(int j=0; j<no_of_peaks; j++)
- {
- snd.printf("The Peak %d, is at %d & value is %d\n",j, peakpos[j], peakval[j]);
- }
-
- // Heart rate calculation
- //Testing
- int32_t t_diff;
- t_diff = peakpos[1] - peakpos[0];
- snd.printf("t_diff is %d\n", t_diff);
-
- hrt_rate = 60.0/(t_diff*2);
- //snd.printf("Hear rate in float is %f\n", hrt_rate); COMMENETD NIDHIN 20/6/17
-
- hrt_rate = float (hrt_rate*1000);
- snd.printf("Hear rate in float is %f\n", hrt_rate);
-
- heart_rate = uint16_t(hrt_rate + 0.5);
- snd.printf("The heart rate after type casting is %d\n", heart_rate);
-
- /*
- fppos = ftell(fpeecg);
- snd.printf("The first data is = %d\n", buff1);
- snd.printf("The Position after reading first data is = %d\n\n", fppos);
-
- fread(buff2, sizeof(int32_t), 1, fpeecg);
- fppos = ftell(fpeecg);
- snd.printf("The Second data is = %d\n", buff2);
- snd.printf("The Position after reading Second data is = %d\n\n", fppos);
-
- fseek(fpeecg, 32,SEEK_CUR);
-
- fread(buff3, sizeof(int32_t), 1, fpeecg);
- fppos = ftell(fpeecg);
- snd.printf("The third data is = %d\n", buff3);
- snd.printf("The Position after reading Second data is = %d\n\n", fppos);
-
- fseek(fpeecg, -24,SEEK_CUR);
-
- fread(buff3, sizeof(int32_t), 1, fpeecg);
- fppos = ftell(fpeecg);
- snd.printf("The fourth data is = %d\n", buff3);
- snd.printf("The Position after reading fourth data is = %d\n", fppos);
-
- }
- /*
- snd.printf("Printing from 500-999\n\n");
- fread(ecgbufnew, sizeof(int), 500, fpeecg);
- for(int i=0; i<500; i++)
- {
- //snd.printf("%d\n", ecgbufnew[i]);
- }
-
- rewind(fpeecg);
- fseek(fpeecg, 996, SEEK_SET); // Try modifying with 996 = 249*4 if not working
-
- snd.printf("Printing from 250-749\n\n");
- fread(ecgbufnew, sizeof(int), 500, fpeecg);
- for(int i=0; i<500; i++)
- {
- //snd.printf("%d\n", ecgbufnew[i]);
- }
- */
- fclose(fpeecg);
- return heart_rate;
-}
\ No newline at end of file
