test

Dependencies:   mbed Lab5-03_create_satcode_step6_lite HEPTA_CDH_lite HEPTA_COM_lite LPS25HB_I2C HEPTA_SENSOR_lite HEPTA_EPS_lite

Committer:
RyusukeIwata
Date:
Sat Aug 20 11:38:09 2022 +0000
Revision:
4:a4ea741ca530
Parent:
3:e5ae22e02335
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
heptasat2021 0:da0f6aca15b8 1 #include "mbed.h"
heptasat2021 2:30f72f09756e 2 #include "HEPTA_EPS.h"
heptasat2021 1:ddac5ec89167 3 #include "HEPTA_CDH.h"
heptasat2021 2:30f72f09756e 4 #include "HEPTA_SENSOR.h"
heptasat2021 2:30f72f09756e 5 #include "HEPTA_COM.h"
RyusukeIwata 4:a4ea741ca530 6 #include "LPS.h"
heptasat2021 1:ddac5ec89167 7 HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd");
heptasat2021 2:30f72f09756e 8 HEPTA_EPS eps(PA_0,PA_4);
heptasat2021 2:30f72f09756e 9 HEPTA_SENSOR sensor(PA_7,PB_7,PB_6,0xD0);
heptasat2021 2:30f72f09756e 10 HEPTA_COM com(PA_9,PA_10,9600);
heptasat2021 3:e5ae22e02335 11 DigitalOut condition(PB_1);
RyusukeIwata 4:a4ea741ca530 12 DigitalOut analog_switch(PA_3);
RyusukeIwata 4:a4ea741ca530 13 Serial sat(USBTX,USBRX, 9600);
RyusukeIwata 4:a4ea741ca530 14 //I2C i2c(PB_7, PB_6);
RyusukeIwata 4:a4ea741ca530 15 I2C i2c(D4,D5);
heptasat2021 3:e5ae22e02335 16 Timer sattime;
RyusukeIwata 4:a4ea741ca530 17
RyusukeIwata 4:a4ea741ca530 18 LPS ps(i2c);
RyusukeIwata 4:a4ea741ca530 19 DigitalOut sp1(PA_1);
RyusukeIwata 4:a4ea741ca530 20 Ticker press;
RyusukeIwata 4:a4ea741ca530 21 Ticker sound;
RyusukeIwata 4:a4ea741ca530 22 int flag = 0; //condition flag
RyusukeIwata 4:a4ea741ca530 23 float batvol, temp; //voltage, temperature
RyusukeIwata 4:a4ea741ca530 24 int rcmd=0,cmdflag=0; //command variable
RyusukeIwata 4:a4ea741ca530 25 int i, ct = 0;
RyusukeIwata 4:a4ea741ca530 26 float pressure = 0.0, altitude = 0.0, temperature = 0.0;
RyusukeIwata 4:a4ea741ca530 27 float ax,ay,az,gx,gy,gz;
RyusukeIwata 4:a4ea741ca530 28 char cmd1,cmd2,cmd3;
RyusukeIwata 4:a4ea741ca530 29 int oto = 0;
RyusukeIwata 4:a4ea741ca530 30 #define mC 261.626
RyusukeIwata 4:a4ea741ca530 31 #define mD 293.665
RyusukeIwata 4:a4ea741ca530 32 #define mE 329.628
RyusukeIwata 4:a4ea741ca530 33 #define mF 349.228
RyusukeIwata 4:a4ea741ca530 34 #define mG 391.995
RyusukeIwata 4:a4ea741ca530 35 #define mA 440.000
RyusukeIwata 4:a4ea741ca530 36 #define mB 493.883
RyusukeIwata 4:a4ea741ca530 37 float mm[]={mC*4,mD*4,mE*4,mF*4,mG*4,mA*4,mB*4,mC*8}; //timbre
RyusukeIwata 4:a4ea741ca530 38
RyusukeIwata 4:a4ea741ca530 39 void tick(void)
RyusukeIwata 4:a4ea741ca530 40 {
RyusukeIwata 4:a4ea741ca530 41 sp1.write(oto);
RyusukeIwata 4:a4ea741ca530 42 oto=!oto;
RyusukeIwata 4:a4ea741ca530 43 }
RyusukeIwata 4:a4ea741ca530 44
RyusukeIwata 4:a4ea741ca530 45 void pre() {
RyusukeIwata 4:a4ea741ca530 46 com.printf("HEPTASAT::Time = %.4f [s], batvol = %.4f [V], temp = %.4f [deg C], altitude = %.4f [m]\r\n",sattime.read(),batvol,temp,altitude);
RyusukeIwata 4:a4ea741ca530 47 com.printf(" ::ax = %.4f, ay = %.4f, az = %.4f, gx = %.4f, gy = %.4f, gz = %.4f\r\n",ax,ay,az,gx,gy,gz);
RyusukeIwata 4:a4ea741ca530 48
RyusukeIwata 4:a4ea741ca530 49 }
RyusukeIwata 4:a4ea741ca530 50
heptasat2021 0:da0f6aca15b8 51 int main()
heptasat2021 0:da0f6aca15b8 52 {
heptasat2021 3:e5ae22e02335 53 sat.printf("From Sat : Nominal Operation\r\n");
heptasat2021 3:e5ae22e02335 54 com.printf("From Sat : Nominal Operation\r\n");
heptasat2021 3:e5ae22e02335 55 sattime.start();
RyusukeIwata 4:a4ea741ca530 56 eps.turn_on_regulator(); //turn on 3.3V conveter
RyusukeIwata 4:a4ea741ca530 57 analog_switch = 1; //turn on analog switch (transceiver mode)
RyusukeIwata 4:a4ea741ca530 58
RyusukeIwata 4:a4ea741ca530 59 mkdir("/sd/mydir", 0777);
RyusukeIwata 4:a4ea741ca530 60 FILE *fp = fopen("/sd/mydir/sdtest.csv", "w");
RyusukeIwata 4:a4ea741ca530 61 if(fp == NULL) {
RyusukeIwata 4:a4ea741ca530 62 error("Could not open file for write\r\n");
RyusukeIwata 4:a4ea741ca530 63 }
RyusukeIwata 4:a4ea741ca530 64 fclose(fp);
RyusukeIwata 4:a4ea741ca530 65
RyusukeIwata 4:a4ea741ca530 66 // initialize the pressure sensor
RyusukeIwata 4:a4ea741ca530 67 if (!ps.init()){
RyusukeIwata 4:a4ea741ca530 68 printf("Failed to autodetect pressure sensor!\r\n");
RyusukeIwata 4:a4ea741ca530 69 while (1);
RyusukeIwata 4:a4ea741ca530 70 }
RyusukeIwata 4:a4ea741ca530 71 ps.enableDefault(); // setting the pressure sensor
RyusukeIwata 4:a4ea741ca530 72 while(1){
heptasat2021 2:30f72f09756e 73 com.xbee_receive(&rcmd,&cmdflag);
heptasat2021 3:e5ae22e02335 74 if(cmdflag == 1){
RyusukeIwata 4:a4ea741ca530 75 if(rcmd == 'm'){
RyusukeIwata 4:a4ea741ca530 76 com.initialize(); //initializing
RyusukeIwata 4:a4ea741ca530 77 FILE *fp = fopen("/sd/mydir/sdtest.csv", "a");
RyusukeIwata 4:a4ea741ca530 78 int count = 0;
RyusukeIwata 4:a4ea741ca530 79 press.attach(&pre, 1.0);
RyusukeIwata 4:a4ea741ca530 80 while(1){
RyusukeIwata 4:a4ea741ca530 81 com.xbee_receive(&rcmd,&cmdflag);
RyusukeIwata 4:a4ea741ca530 82 //satellite condition led
RyusukeIwata 4:a4ea741ca530 83 condition = !condition;
RyusukeIwata 4:a4ea741ca530 84 //sensing HK data
RyusukeIwata 4:a4ea741ca530 85 eps.vol(&batvol);
RyusukeIwata 4:a4ea741ca530 86 sensor.temp_sense(&temp);
RyusukeIwata 4:a4ea741ca530 87
RyusukeIwata 4:a4ea741ca530 88 //sensing the
RyusukeIwata 4:a4ea741ca530 89 sensor.sen_acc(&ax,&ay,&az);
RyusukeIwata 4:a4ea741ca530 90 sensor.sen_gyro(&gx,&gy,&gz);
RyusukeIwata 4:a4ea741ca530 91 pressure = ps.readPressureMillibars();
RyusukeIwata 4:a4ea741ca530 92 altitude = ps.pressureToAltitudeMeters(pressure);
RyusukeIwata 4:a4ea741ca530 93 temperature = ps.readTemperatureC();
RyusukeIwata 4:a4ea741ca530 94 //if((count % 10) == 0){
RyusukeIwata 4:a4ea741ca530 95 // com.printf("HEPTASAT::Time = %.4f [s], batvol = %.4f [V], temp = %.4f [deg C], altitude = %.4f [m]\r\n",sattime.read(),batvol,temp,altitude);
RyusukeIwata 4:a4ea741ca530 96 // com.printf(" ::ax = %.4f, ay = %.4f, az = %.4f, gx = %.4f, gy = %.4f, gz = %.4f\r\n",ax,ay,az,gx,gy,gz);
RyusukeIwata 4:a4ea741ca530 97 // }
RyusukeIwata 4:a4ea741ca530 98 fprintf(fp,"%f, %f, %f, %f, %f, %f, %f, %f, %f, %f\r\n",sattime.read(),batvol,temp,altitude,ax,ay,az,gx,gy,gz);
RyusukeIwata 4:a4ea741ca530 99 wait_ms(100);
RyusukeIwata 4:a4ea741ca530 100 if(rcmd == 'f'){
RyusukeIwata 4:a4ea741ca530 101 fclose(fp);
RyusukeIwata 4:a4ea741ca530 102 press.detach();
RyusukeIwata 4:a4ea741ca530 103 sat.printf("finish sensing\r\n");
RyusukeIwata 4:a4ea741ca530 104 com.printf("finish sensing\r\n");
RyusukeIwata 4:a4ea741ca530 105 break;
RyusukeIwata 4:a4ea741ca530 106 }
RyusukeIwata 4:a4ea741ca530 107 count++;
heptasat2021 3:e5ae22e02335 108 }
RyusukeIwata 4:a4ea741ca530 109 }
RyusukeIwata 4:a4ea741ca530 110 }
RyusukeIwata 4:a4ea741ca530 111 if(rcmd == 'e'){
RyusukeIwata 4:a4ea741ca530 112 sat.printf("From Sat : End of while\r\n");
RyusukeIwata 4:a4ea741ca530 113 com.printf("From Sat : End of while\r\n");
RyusukeIwata 4:a4ea741ca530 114 com.initialize(); //initializing
RyusukeIwata 4:a4ea741ca530 115 while(1){
RyusukeIwata 4:a4ea741ca530 116 com.xbee_receive(&rcmd,&cmdflag);
RyusukeIwata 4:a4ea741ca530 117 if(rcmd == 'z'){
RyusukeIwata 4:a4ea741ca530 118 oto = 0;
RyusukeIwata 4:a4ea741ca530 119 break;
heptasat2021 3:e5ae22e02335 120 }
RyusukeIwata 4:a4ea741ca530 121 for(i=0;i < sizeof(mm)/sizeof(mm[0]);i++) {
RyusukeIwata 4:a4ea741ca530 122 sound.attach(&tick,1.0/mm[i]/2.0); //If warning appear, ignore
RyusukeIwata 4:a4ea741ca530 123 wait(0.5f);
heptasat2021 3:e5ae22e02335 124 }
RyusukeIwata 4:a4ea741ca530 125 sound.detach();
RyusukeIwata 4:a4ea741ca530 126 i = 0;
heptasat2021 2:30f72f09756e 127 }
RyusukeIwata 4:a4ea741ca530 128 break;
heptasat2021 2:30f72f09756e 129 }
RyusukeIwata 4:a4ea741ca530 130 com.initialize(); //initializing
heptasat2021 0:da0f6aca15b8 131 }
heptasat2021 3:e5ae22e02335 132 sattime.stop();
heptasat2021 3:e5ae22e02335 133 sat.printf("From Sat : End of operation\r\n");
heptasat2021 3:e5ae22e02335 134 com.printf("From Sat : End of operation\r\n");
heptasat2021 0:da0f6aca15b8 135 }