SD
Dependencies: MPU6050_SIM5320_TEST
Diff: main.cpp
- Revision:
- 0:203cf529f52a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 14 16:50:16 2017 +0000 @@ -0,0 +1,191 @@ +#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"); + +int go_to_sleep = 0; +void mpuInterruptCallback() +{ + test=!test; + +} +void rtc_wakeup() +{ + go_to_sleep = 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"); + } + + else { + printf("Still connected or error occured!\r\n"); + } + + + + while(1) { + wait(1); + sim5320.sendCommand("AT",1); + } + */ + + + +/////////////////////////////////////////////////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); + time_t seconds = time(NULL); + printf("Time = %s\n", ctime(&seconds)); + 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; + + + 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]); + } + } + + for(int i=0;i<12;i++) + printf("_%d\n",write_sd_buffer[i]); + */ + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + +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