for checking i2c with integrated bae

Dependencies:   SDFileSystem mbed-rtos mbed

Committer:
viswa_chaitanya
Date:
Mon Sep 15 14:01:49 2014 +0000
Revision:
0:cb112a717428
cdms master(hk runs every 20s)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
viswa_chaitanya 0:cb112a717428 1 #include "sdcard.h"
viswa_chaitanya 0:cb112a717428 2
viswa_chaitanya 0:cb112a717428 3 /*SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, clk, cs, name
viswa_chaitanya 0:cb112a717428 4
viswa_chaitanya 0:cb112a717428 5 void writedummies(SensorData* Sensor){
viswa_chaitanya 0:cb112a717428 6 int i;
viswa_chaitanya 0:cb112a717428 7 printf("Writing dummy values\n"); //Debug statement
viswa_chaitanya 0:cb112a717428 8 for(i=0; i<10; i++) (*Sensor).Voltage[i] = 35.14; //dummy values. Will be removed
viswa_chaitanya 0:cb112a717428 9 for(i=0; i<10; i++) (*Sensor).Current[i] = 644.46;
viswa_chaitanya 0:cb112a717428 10 for(i=0; i<10; i++) (*Sensor).Temp[i] = 6534.03;
viswa_chaitanya 0:cb112a717428 11 printf("Done writing dummy values\n");
viswa_chaitanya 0:cb112a717428 12 }
viswa_chaitanya 0:cb112a717428 13
viswa_chaitanya 0:cb112a717428 14 void setfilenames(char* beaname, char* acsname, char* epsname, time_t seconds){
viswa_chaitanya 0:cb112a717428 15 char date[7];
viswa_chaitanya 0:cb112a717428 16 printf("Setting file names\n");
viswa_chaitanya 0:cb112a717428 17 strftime(date, 7, "%d%m%y", localtime(&seconds)); //getting ddmmyy from unix time
viswa_chaitanya 0:cb112a717428 18 printf("%s\t%s\t%s\n", beaname, acsname, epsname);
viswa_chaitanya 0:cb112a717428 19
viswa_chaitanya 0:cb112a717428 20 printf("Appending file extensions\n");
viswa_chaitanya 0:cb112a717428 21 for(int i=10; i<16; i++){
viswa_chaitanya 0:cb112a717428 22 printf("In %dth iteration",i);
viswa_chaitanya 0:cb112a717428 23 beaname[i] = date[i-10]; //creating file name for beacon hk
viswa_chaitanya 0:cb112a717428 24 }
viswa_chaitanya 0:cb112a717428 25 beaname[16] = '.'; beaname[17] = 't'; beaname[18] = 'x'; beaname[19] = 't'; beaname[20]='\0';
viswa_chaitanya 0:cb112a717428 26
viswa_chaitanya 0:cb112a717428 27 for(int i=10; i<16; i++) acsname[i] = date[i-10]; //creating file name for acs hk
viswa_chaitanya 0:cb112a717428 28 acsname[16] = '.'; acsname[17] = 't'; acsname[18] = 'x'; acsname[19] = 't'; acsname[20]='\0';
viswa_chaitanya 0:cb112a717428 29
viswa_chaitanya 0:cb112a717428 30 for(int i=10; i<16; i++) epsname[i] = date[i-10]; //creating file name for eps hk
viswa_chaitanya 0:cb112a717428 31 epsname[16] = '.'; epsname[17] = 't'; epsname[18] = 'x'; epsname[19] = 't'; epsname[20]='\0';
viswa_chaitanya 0:cb112a717428 32
viswa_chaitanya 0:cb112a717428 33 printf("All filenames created\n"); //Debug statement
viswa_chaitanya 0:cb112a717428 34 }
viswa_chaitanya 0:cb112a717428 35
viswa_chaitanya 0:cb112a717428 36 void writevaluesf(char* beaname, char* acsname, char* epsname, time_t seconds, SensorData* Sensor){
viswa_chaitanya 0:cb112a717428 37 FILE* fp;
viswa_chaitanya 0:cb112a717428 38 char time[7];
viswa_chaitanya 0:cb112a717428 39 strftime(time, 7, "%H%M%S", localtime(&seconds)); //getting time from unix time
viswa_chaitanya 0:cb112a717428 40
viswa_chaitanya 0:cb112a717428 41 fp = fopen(beaname,"w");
viswa_chaitanya 0:cb112a717428 42 if(fp == NULL) {
viswa_chaitanya 0:cb112a717428 43 error("Could not open file for write\n");
viswa_chaitanya 0:cb112a717428 44 }
viswa_chaitanya 0:cb112a717428 45 else{
viswa_chaitanya 0:cb112a717428 46 //fprintf(fp,"%s\n",time); //time stamping: Look for a better way
viswa_chaitanya 0:cb112a717428 47 fwrite((*Sensor).Voltage, sizeof(float), BEANUM, fp); //needs to be changed
viswa_chaitanya 0:cb112a717428 48 fclose(fp);
viswa_chaitanya 0:cb112a717428 49 }
viswa_chaitanya 0:cb112a717428 50
viswa_chaitanya 0:cb112a717428 51 fp = fopen(acsname,"w");
viswa_chaitanya 0:cb112a717428 52 if(fp == NULL) {
viswa_chaitanya 0:cb112a717428 53 error("Could not open file for write\n");
viswa_chaitanya 0:cb112a717428 54 }
viswa_chaitanya 0:cb112a717428 55 else{
viswa_chaitanya 0:cb112a717428 56 //fprintf(fp,"%s\n",time); //time stamping: Look for a better way
viswa_chaitanya 0:cb112a717428 57 fwrite((*Sensor).Current, sizeof(float), ACSNUM, fp); //needs to be changed
viswa_chaitanya 0:cb112a717428 58 fclose(fp);
viswa_chaitanya 0:cb112a717428 59 }
viswa_chaitanya 0:cb112a717428 60
viswa_chaitanya 0:cb112a717428 61 fp = fopen(epsname,"w");
viswa_chaitanya 0:cb112a717428 62 if(fp == NULL) {
viswa_chaitanya 0:cb112a717428 63 error("Could not open file for write\n");
viswa_chaitanya 0:cb112a717428 64 }
viswa_chaitanya 0:cb112a717428 65 else{
viswa_chaitanya 0:cb112a717428 66 //fprintf(fp,"%s\n",time); //time stamping: Look for a better way
viswa_chaitanya 0:cb112a717428 67 fwrite((*Sensor).Temp, sizeof(float), EPSNUM, fp); //needs to be changed
viswa_chaitanya 0:cb112a717428 68 fclose(fp);
viswa_chaitanya 0:cb112a717428 69 }
viswa_chaitanya 0:cb112a717428 70
viswa_chaitanya 0:cb112a717428 71 printf("Writing over\n"); //Debug statement
viswa_chaitanya 0:cb112a717428 72 }
viswa_chaitanya 0:cb112a717428 73
viswa_chaitanya 0:cb112a717428 74 //Function for debugging purposes
viswa_chaitanya 0:cb112a717428 75 void readvaluesff(char* beaname, char* acsname, char* epsname, SensorData* Sensor){
viswa_chaitanya 0:cb112a717428 76 FILE* fpr; //debug only
viswa_chaitanya 0:cb112a717428 77 float* readstr = (float*) malloc( sizeof(float) * 30); //reading back for debugging
viswa_chaitanya 0:cb112a717428 78
viswa_chaitanya 0:cb112a717428 79 fpr = fopen(beaname,"r");
viswa_chaitanya 0:cb112a717428 80 if(fpr == NULL) {
viswa_chaitanya 0:cb112a717428 81 error("Could not open file for read\n");
viswa_chaitanya 0:cb112a717428 82 }
viswa_chaitanya 0:cb112a717428 83 else{
viswa_chaitanya 0:cb112a717428 84 fread(readstr, sizeof(float), 10, fpr);
viswa_chaitanya 0:cb112a717428 85 }
viswa_chaitanya 0:cb112a717428 86 fclose(fpr);
viswa_chaitanya 0:cb112a717428 87
viswa_chaitanya 0:cb112a717428 88 fpr = fopen(acsname,"r");
viswa_chaitanya 0:cb112a717428 89 if(fpr == NULL) {
viswa_chaitanya 0:cb112a717428 90 error("Could not open file for read\n");
viswa_chaitanya 0:cb112a717428 91 }
viswa_chaitanya 0:cb112a717428 92 else{
viswa_chaitanya 0:cb112a717428 93 fread((readstr+10), sizeof(float), 10, fpr);
viswa_chaitanya 0:cb112a717428 94 }
viswa_chaitanya 0:cb112a717428 95 fclose(fpr);
viswa_chaitanya 0:cb112a717428 96
viswa_chaitanya 0:cb112a717428 97 fpr = fopen(epsname,"r");
viswa_chaitanya 0:cb112a717428 98 if(fpr == NULL) {
viswa_chaitanya 0:cb112a717428 99 error("Could not open file for read\n");
viswa_chaitanya 0:cb112a717428 100 }
viswa_chaitanya 0:cb112a717428 101 else{
viswa_chaitanya 0:cb112a717428 102 fread((readstr+20), sizeof(float), 10, fpr);
viswa_chaitanya 0:cb112a717428 103 }
viswa_chaitanya 0:cb112a717428 104 fclose(fpr);
viswa_chaitanya 0:cb112a717428 105
viswa_chaitanya 0:cb112a717428 106 for(int i=0; i<30; i++)
viswa_chaitanya 0:cb112a717428 107 printf("%f\n",readstr[i]);
viswa_chaitanya 0:cb112a717428 108 }
viswa_chaitanya 0:cb112a717428 109 */