code

Dependencies:   MPU6050_SIM5320_TEST SDFileSystem WakeUp

Fork of Nucleo_L476RG_SDCard_WorkingSample by Mariwan J.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 #include "SIM5320.h"
00004 #include "MPU6050.h"
00005 #include "SensorBoards.h"
00006 #include "WakeUp.h"
00007 
00008 
00009 DigitalOut myled(D13);
00010 
00011 
00012 void create_sensor_data(uint8_t *write_sd_buffer, uint8_t *sensor_board_readings, uint8_t b_id, uint8_t s_id);
00013 //SIM5320 sim5320(PA_9,PA_10);
00014 DigitalOut SIM5320_PWR(PA_1);
00015 DigitalOut SIM_PWR_KEY(PA_15);
00016 InterruptIn mpuInterrupt(PB_6);
00017 uint8_t sensor_board_readings[4];
00018 bool test = false;
00019 //              MOSI, MISO, SCLK, CS, name
00020 SDFileSystem sd(PA_7, PA_6, PA_5, PA_4, "sd");
00021 
00022 
00023 uint8_t write_sd_buffer[12];
00024 
00025 void mpuInterruptCallback()
00026 {
00027     test=!test;
00028 
00029 }
00030 MPU6050 mpu;
00031 int main()
00032 {
00033     wait(2);
00034     printf("Pocetak\n");
00035 
00036 //////////////////////////////////////////////CODE FOR MPU////////////////////////////////////////////////////////////////
00037     /*
00038     mpuInterrupt.fall(mpuInterruptCallback);
00039     wait(2);
00040     mpu.calibrate(accelBias, gyroBias);
00041     mpu.initialize();
00042     mpu.setSleepEnabled(0);
00043     wait(2);
00044     mpu.setIntFreefallEnabled(1);
00045     mpu.setIntZeroMotionEnabled(0);
00046     mpu.setIntMotionEnabled(1);
00047     //printf("Setting mpu parameters...\r\n");
00048     mpu.setMotionDetectionThreshold(1);
00049     mpu.setMotionDetectionDuration(15);
00050 
00051 
00052     while(1){
00053         if(test){
00054             printf("Desio se motion\r\n");
00055             test = 0;
00056             }
00057         }
00058     */
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 ///////////////////////////////////////////////////////////////CODE_FOR_GPS///////////////////////////////////////////////////////////
00073     /*
00074         wait(3);
00075         printf("Star...\r\n");
00076         SIM5320_PWR = 1;
00077         SIM_PWR_KEY = 1;
00078         wait(1);
00079         SIM_PWR_KEY = 0;
00080         wait(25);
00081         wait(2);
00082         printf("Starting...\r\n");
00083         printf("Starting...\r\n");
00084         printf("Starting...\r\n");
00085         printf("Starting...\r\n");
00086         sim5320.sendCommand("AT+CNUM",2);
00087         printf("Checking credit balance...\r\n");
00088         sim5320.sendCommand("AT+CUSD=1, \"*100#\",15",5);
00089         //Testing GPS
00090 
00091         sim5320.enableGPS(true);
00092         wait(30);
00093 
00094         //Gettting GPS location
00095         sim5320.sendCommand("AT+CGPSINFO",2);
00096         sim5320.sendCommand("AT+CGPSINFO",2);
00097         sim5320.sendCommand("AT+CGPSINFO",2);
00098 
00099       */
00100 
00101 
00102 
00103 
00104 
00105 ///////////////////////////////////////CODE FOR GPRS/////////////////////////////////////////////////////////////////////////////////
00106     /*
00107         wait(20);
00108         //Testing network connection and disconnection
00109         sim5320.connect("active.bhmobile.ba","","");
00110         wait(2);
00111         if(sim5320.disconnect()) {
00112             sim5320.printDebug("Disconnected\r\n");
00113         }
00114 
00115         else {
00116             sim5320.printDebug("Still connected or error occured!\r\n");
00117         }
00118 
00119     */
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 ///////////////////////////////////////////CODE FOR SD CARD//////////////////////////////////////////////
00132 
00133     /*
00134     mkdir("/sd/mydir3", 0777);
00135     printf("\nDirectory created\n");
00136     char buf[9];
00137     sd.writeSD("/sd/mydir3/sdtest2.txt", "1111111\n");
00138     sd.writeSD("/sd/mydir3/sdtest2.txt", "2222222\n");
00139     sd.writeSD("/sd/mydir3/sdtest2.txt", "3333333\n");
00140     printf("Upisao 1,2 i3\n");
00141     sd.readSD("/sd/mydir3/sdtest2.txt",buf);
00142     printf("line=%s\n",buf);
00143     sd.readSD("/sd/mydir3/sdtest2.txt",buf);
00144     printf("line=%s\n",buf);
00145     sd.readSD("/sd/mydir3/sdtest2.txt",buf);
00146     printf("line=%s\n",buf);
00147     */
00148 
00149 
00150 
00151 //////////////////////////////////////////////CODE FOR SENDOR_BOARDS////////////////////////////////////////////////////////////////
00152 /*
00153     uint8_t IDBuffer[8];
00154     uint8_t IDMeasure[4];
00155     float measure=0.0;
00156     float measure2=0.0;
00157 
00158     SensorBoards B1;
00159     B1.sensorBoardScanner();
00160     B1.getSensorNumbers();
00161     B1.getSensorIDs();
00162     for(int k=0; k<B1.numberOfBoards; k++) {
00163        // printf("broj senzora %d \n",B1.boards[k].numberOfSensors);
00164         for(int i=0; i<B1.boards[k].numberOfSensors; i++){
00165             B1.getSensorReadings(B1.boards[k].I2CAddress,B1.boards[k].sensorIDs[i],IDMeasure);
00166             printf("measure=%d %d %d %d keaj\n",IDMeasure[0],IDMeasure[1],IDMeasure[2],IDMeasure[3]);
00167             create_sensor_data(write_sd_buffer,IDMeasure,B1.boards[k].I2CAddress,B1.boards[k].sensorIDs[i]);
00168             }
00169     }
00170 
00171 for(int i=0;i<12;i++)
00172 printf("_%d\n",write_sd_buffer[i]);
00173 */
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
00182 //set_time(1505233738);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
00183 WakeUp::calibrate();
00184 myled = 0;
00185     while (true) {
00186 //        time_t seconds = time(NULL);
00187 //        printf("T= %d\n", seconds);
00188 //        printf("Time = %s", ctime(&seconds));
00189 //        wait(1);
00190 
00191 WakeUp::set_ms(7000);
00192 printf("sleep\n");
00193 wait(2);
00194 deepsleep();
00195 wait(2);
00196 //myled = !myled;
00197 printf("wAKE_UP\n");
00198 
00199     }
00200 
00201 
00202 
00203 
00204 }
00205 void create_sensor_data(uint8_t *write_sd_buffer, uint8_t *sensor_board_readings, uint8_t b_id, uint8_t s_id)
00206 {
00207     //pcf8563_read(&rtc);
00208     
00209     write_sd_buffer[0]=0;
00210     write_sd_buffer[1]=1;
00211     write_sd_buffer[2]=2;
00212     write_sd_buffer[3]=3;
00213     write_sd_buffer[4]=4;
00214     write_sd_buffer[5] =b_id;       //sensor boaard id
00215     write_sd_buffer[6] =s_id;    //sensor id
00216     write_sd_buffer[7] =sensor_board_readings[3];          //sensor reading
00217     write_sd_buffer[8] =sensor_board_readings[2];          //sensor reading
00218     write_sd_buffer[9] =sensor_board_readings[1];          //sensor reading
00219     write_sd_buffer[10]=sensor_board_readings[0];         //sensor reading
00220     write_sd_buffer[11]=0xFF;
00221     write_sd_buffer[12]=0xFF;
00222     
00223 }