fork
Dependencies: MPU6050_SIM5320_TEST
Fork of MPU_SDCARD by
Revision 1:483775fd3399, committed 2017-11-10
- Comitter:
- suads
- Date:
- Fri Nov 10 14:45:54 2017 +0000
- Parent:
- 0:203cf529f52a
- Commit message:
- first
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 203cf529f52a -r 483775fd3399 main.cpp --- a/main.cpp Thu Sep 14 16:50:16 2017 +0000 +++ b/main.cpp Fri Nov 10 14:45:54 2017 +0000 @@ -1,191 +1,148 @@ -#include "mbed.h" -#include "SDFileSystem.h" -#include "SIM5320.h" -#include "MPU6050.h" -#include "SensorBoards.h" -#include "WakeUp.h" - -uint8_t write_sd_buffer[12]; -void create_sensor_data(uint8_t *write_sd_buffer, uint8_t *sensor_board_readings, uint8_t b_id, uint8_t s_id); -//SIM5320 sim5320(PA_9,PA_10); -DigitalOut SIM5320_PWR(PA_1); -DigitalOut SIM_PWR_KEY(PA_15); -InterruptIn mpuInterrupt(PB_6); -uint8_t sensor_board_readings[4]; -bool test = false; -// MOSI, MISO, SCLK, CS, name -SDFileSystem sd(PA_7, PA_6, PA_5, PA_4, "sd"); +#include "mbed.h" + + time_t read_rtc(void) { + return 0; +} +int main() { + + // attach_rtc(&read_rtc, NULL, NULL, NULL); -int go_to_sleep = 0; -void mpuInterruptCallback() -{ - test=!test; - -} -void rtc_wakeup() -{ - go_to_sleep = 1; + + set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 + + while (true) { + time_t seconds = time(NULL); + + printf("Time as seconds since January 1, 1970 = %d\n", seconds); + + printf("Time as a basic string = %s", ctime(&seconds)); + + char buffer[32]; + strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); + printf("Time as a custom formatted string = %s", buffer); + + wait(1); + } } -MPU6050 mpu; -int main() -{ -/////////////////////////////////////////////////MPU_DEEP_SLEEP_WAKEUP//////////////////////////// -/* - mpuInterrupt.fall(mpuInterruptCallback); - wait(2); - mpu.calibrate(accelBias, gyroBias); - mpu.initialize(); - mpu.setSleepEnabled(0); - wait(2); - mpu.setIntFreefallEnabled(1); - mpu.setIntZeroMotionEnabled(0); - mpu.setIntMotionEnabled(1); - printf("Setting mpu parameters...\r\n"); - mpu.setMotionDetectionThreshold(1); - mpu.setMotionDetectionDuration(15); - - while(1){ - printf("sleep\r\n"); - deepsleep(); - if(test){ - wait(1); - printf("Desio se motion\r\n"); - test = 0; - } - } -*/ - -/////////////////////////////////////////////////////////////////////////////////////////// - - // wait(3); - // SIM5320_PWR = 1; - // SIM_PWR_KEY = 1; - // wait(1); - // SIM_PWR_KEY = 0; - /* - wait(25); - wait(2); - printf("Starting...\r\n"); - printf("Starting...\r\n"); - printf("Starting...\r\n"); - printf("Starting...\r\n"); - sim5320.sendCommand("AT+CNUM",2); - printf("Checking credit balance...\r\n"); - sim5320.sendCommand("AT+CUSD=1, \"*100#\",15",5); - //Testing GPS - - sim5320.enableGPS(true); - wait(30); - - //Gettting GPS location - sim5320.sendCommand("AT+CGPSINFO",2); - sim5320.sendCommand("AT+CGPSINFO",2); - sim5320.sendCommand("AT+CGPSINFO",2); - //Testing network connection and disconnection - sim5320.connect("active.bhmobile.ba","",""); - wait(2); - if(sim5320.disconnect()) { - printf("Disconnected\r\n"); - } +/* + +#include "mbed.h" + +void get(char* buffer,uint16_t &tempDate,uint16_t &tempTime); - else { - printf("Still connected or error occured!\r\n"); - } +char buffer[26]; + +time_t read_rtc(void) { + return 0; +} + - - while(1) { - wait(1); - sim5320.sendCommand("AT",1); - } - */ + +int main() { + + -/////////////////////////////////////////////////RTC_DEEP_SLEEP_WAKEUP//////////////////////////// - /* - set_time(1495040081); // Set RTC time to Wed, 28 Oct 2009 11:35:37 - WakeUp::attach(&rtc_wakeup); - WakeUp::calibrate(); - while (1) { - WakeUp::set_ms(5000); + set_time(1503687670); // Set RTC time to Wed, 28 Oct 2009 11:35:37 + + while (true) { + uint16_t datum; + uint16_t vrijeme; time_t seconds = time(NULL); - printf("Time = %s\n", ctime(&seconds)); + + //printf("Time as seconds since January 1, 1970 = %d\n", seconds); + + sprintf(buffer,"%s", ctime(&seconds)); + + // char buffer[32]; + // strftime(buffer, 32,"%s",ctime(&seconds)); + // printf("Time as a custom formatted string = %s\n", seconds); + //sprintf (buffer,"%s",seconds); + printf("|%s|",buffer); + buffer[25]='\0'; + get(buffer,datum,vrijeme); + printf("aaa %d bb %d\n",datum,vrijeme); + wait(1); - printf("sleep\n"); - deepsleep(); - if (go_to_sleep == 1) { - wait(1); - printf("Wake_up\n"); - go_to_sleep=0; - } } -*/ -//////////////////////////////////////////////////////////////////////////////////////////////// +} -//////////////////////////////////////////////CODE FOR SENDOR_BOARDS//////////////////////////////////////////////////////////////// - /* - uint8_t IDBuffer[8]; - uint8_t IDMeasure[4]; - float measure=0.0; - float measure2=0.0; - +void get(char* buffer,uint16_t &tempDate,uint16_t &tempTime){ + // char *a=buffer; +//uint8_t month=0; +char month[2]={'0','0'}; +char hour[2]; +char minute[2]; +char day[2]; - SensorBoards B1; - B1.getSensorReadings(0x4a,0x10,IDMeasure); - printf("number_of__boards= %d\n",B1.numberOfBoards); - B1.sensorBoardScanner(); - printf("SnesorBoardAdress= %d\n",B1.boards[0].I2CAddress); - B1.getSensorNumbers(); - printf("SensorBoardsensors= %d\n",B1.boards[0].numberOfSensors); - B1.getSensorIDs(); - printf("SensorBoardIDs=%d %d \n",B1.boards[0].sensorIDs[0],B1.boards[0].sensorIDs[1]); - - B1.getSensorReadings(0x4a,0x10,IDMeasure); - - for(int k=0; k<1; k++) { - printf("broj senzora %d \n",B1.boards[k].numberOfSensors); - for(int i=0; i<B1.boards[k].numberOfSensors; i++){ - B1.getSensorReadings(B1.boards[k].I2CAddress,B1.boards[k].sensorIDs[i],IDMeasure); - printf("measure=%d %d %d %d keaj\n",IDMeasure[0],IDMeasure[1],IDMeasure[2],IDMeasure[3]); - //create_sensor_data(write_sd_buffer,IDMeasure,B1.boards[k].I2CAddress,B1.boards[k].sensorIDs[i]); - } - } +day[0]=buffer[8]; +day[1]=buffer[9]; +hour[0]=buffer[11]; +hour[1]=buffer[12]; +minute[0]=buffer[14]; +minute[1]=buffer[15]; +char *output = NULL; +//output = strstr (buffer,"Mar"); +if(strstr (buffer,"Jan")) +month[1]='1'; +else if(strstr (buffer,"Feb")) +month[1]='2'; +else if(strstr (buffer,"Mar")) +month[1]='3'; +else if(strstr (buffer,"Apr")) +month[1]='4'; +else if(strstr (buffer,"May")) +month[1]='5'; +else if(strstr (buffer,"Jun")) +month[1]='6'; +else if(strstr (buffer,"Jul")) +month[1]='7'; +else if(strstr (buffer,"Aug")) +month[1]='8'; +else if(strstr (buffer,"Sep")) +month[1]='9'; +else if(strstr (buffer,"Okt")) +{ +month[0]='1'; +month[1]='0'; +} +else if(strstr (buffer,"Nov")) +{ +month[0]='1'; +month[1]='1'; +} +else if(strstr (buffer,"Dec")) +{ +month[0]='1'; +month[1]='2'; +} +printf("Datum je |%s|.|%s| |%s|:|%s| \n",day,month,hour,minute); +char tempdate [4]; +sprintf(tempdate,"%s%s",month,day); +int i =atoi(tempdate); +tempDate=i; - for(int i=0;i<12;i++) - printf("_%d\n",write_sd_buffer[i]); - */ +printf("Datum je |%d|\n",i); -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +char temptime [4]; +sprintf(temptime,"%s%s",hour,minute); +int x=atoi(temptime); +printf("Vrijeme je |%d|\n",x); +tempTime=x; + - -return 0; -} -void create_sensor_data(uint8_t *write_sd_buffer, uint8_t *sensor_board_readings, uint8_t b_id, uint8_t s_id) -{ - //pcf8563_read(&rtc); - - write_sd_buffer[0]=0; - write_sd_buffer[1]=1; - write_sd_buffer[2]=2; - write_sd_buffer[3]=3; - write_sd_buffer[4]=4; - write_sd_buffer[5] =b_id; //sensor boaard id - write_sd_buffer[6] =s_id; //sensor id - write_sd_buffer[7] =sensor_board_readings[3]; //sensor reading - write_sd_buffer[8] =sensor_board_readings[2]; //sensor reading - write_sd_buffer[9] =sensor_board_readings[1]; //sensor reading - write_sd_buffer[10]=sensor_board_readings[0]; //sensor reading - write_sd_buffer[11]=0xFF; - write_sd_buffer[12]=0xFF; - -} \ No newline at end of file + } + + + */