EEPROM読み取り用

Dependencies:   mbed PQ_EEPROM

Committer:
tanahashi
Date:
Mon Mar 08 16:55:29 2021 +0000
Revision:
0:3fb5ae3480ae
Child:
1:daa7e093ac88
version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tanahashi 0:3fb5ae3480ae 1 #include "mbed.h"
tanahashi 0:3fb5ae3480ae 2
tanahashi 0:3fb5ae3480ae 3 #include "PQ_EEPROM.h"
tanahashi 0:3fb5ae3480ae 4
tanahashi 0:3fb5ae3480ae 5 Serial pc(USBTX, USBRX, 115200);
tanahashi 0:3fb5ae3480ae 6
tanahashi 0:3fb5ae3480ae 7 I2C i2c(p28, p27);
tanahashi 0:3fb5ae3480ae 8
tanahashi 0:3fb5ae3480ae 9 EEPROM eeprom(i2c);
tanahashi 0:3fb5ae3480ae 10
tanahashi 0:3fb5ae3480ae 11 char data[128];
tanahashi 0:3fb5ae3480ae 12
tanahashi 0:3fb5ae3480ae 13 char *phase_names[] = {"SAFETY", "READY", "FLIGHT", "SEP", "EMERGENCY", "RECOVERY"};
tanahashi 0:3fb5ae3480ae 14
tanahashi 0:3fb5ae3480ae 15 int mission_time;
tanahashi 0:3fb5ae3480ae 16 float flight_time;
tanahashi 0:3fb5ae3480ae 17 char phase;
tanahashi 0:3fb5ae3480ae 18 char f_launched;
tanahashi 0:3fb5ae3480ae 19 char f_burning;
tanahashi 0:3fb5ae3480ae 20 char f_apogee;
tanahashi 0:3fb5ae3480ae 21 char f_mission;
tanahashi 0:3fb5ae3480ae 22 char f_relay;
tanahashi 0:3fb5ae3480ae 23 char f_flight_pin;
tanahashi 0:3fb5ae3480ae 24 char f_sep;
tanahashi 0:3fb5ae3480ae 25 char f_buzzer;
tanahashi 0:3fb5ae3480ae 26 char f_sd;
tanahashi 0:3fb5ae3480ae 27 char f_gps;
tanahashi 0:3fb5ae3480ae 28 char f_adxl;
tanahashi 0:3fb5ae3480ae 29 char f_ina_in;
tanahashi 0:3fb5ae3480ae 30 char f_ina_ex;
tanahashi 0:3fb5ae3480ae 31 char f_lps;
tanahashi 0:3fb5ae3480ae 32 char f_mpu;
tanahashi 0:3fb5ae3480ae 33 char f_mpu_ak;
tanahashi 0:3fb5ae3480ae 34 float lat;
tanahashi 0:3fb5ae3480ae 35 float lon;
tanahashi 0:3fb5ae3480ae 36 int sat;
tanahashi 0:3fb5ae3480ae 37 int fix;
tanahashi 0:3fb5ae3480ae 38 float hdop;
tanahashi 0:3fb5ae3480ae 39 float alt;
tanahashi 0:3fb5ae3480ae 40 float geoid;
tanahashi 0:3fb5ae3480ae 41 float high_accel[3];
tanahashi 0:3fb5ae3480ae 42 float voltage_in;
tanahashi 0:3fb5ae3480ae 43 float current_in;
tanahashi 0:3fb5ae3480ae 44 float voltage_ex;
tanahashi 0:3fb5ae3480ae 45 float current_ex;
tanahashi 0:3fb5ae3480ae 46 float press;
tanahashi 0:3fb5ae3480ae 47 float temp;
tanahashi 0:3fb5ae3480ae 48 float accel[3];
tanahashi 0:3fb5ae3480ae 49 float gyro[3];
tanahashi 0:3fb5ae3480ae 50 float mag[3];
tanahashi 0:3fb5ae3480ae 51
tanahashi 0:3fb5ae3480ae 52 int mission_hour, mission_min, mission_sec;
tanahashi 0:3fb5ae3480ae 53
tanahashi 0:3fb5ae3480ae 54 int main()
tanahashi 0:3fb5ae3480ae 55 {
tanahashi 0:3fb5ae3480ae 56 for(int addr = 0x000000; addr < 0x07FFFF; addr += 0x80) {
tanahashi 0:3fb5ae3480ae 57 eeprom.read(addr, data, 128);
tanahashi 0:3fb5ae3480ae 58 mission_time = *(int*)&data[0];
tanahashi 0:3fb5ae3480ae 59 flight_time = *(float*)&data[4];
tanahashi 0:3fb5ae3480ae 60 phase = *(float*)&data[8];
tanahashi 0:3fb5ae3480ae 61 f_launched = *(float*)&data[9];
tanahashi 0:3fb5ae3480ae 62 f_burning = *(float*)&data[10];
tanahashi 0:3fb5ae3480ae 63 f_apogee = *(float*)&data[11];
tanahashi 0:3fb5ae3480ae 64 f_mission = *(float*)&data[12];
tanahashi 0:3fb5ae3480ae 65 f_relay = *(float*)&data[13];
tanahashi 0:3fb5ae3480ae 66 f_flight_pin = *(float*)&data[14];
tanahashi 0:3fb5ae3480ae 67 f_sep = *(float*)&data[15];
tanahashi 0:3fb5ae3480ae 68 f_buzzer = *(float*)&data[16];
tanahashi 0:3fb5ae3480ae 69 f_sd = *(float*)&data[17];
tanahashi 0:3fb5ae3480ae 70 f_gps = *(float*)&data[18];
tanahashi 0:3fb5ae3480ae 71 f_adxl = *(float*)&data[19];
tanahashi 0:3fb5ae3480ae 72 f_ina_in = *(float*)&data[20];
tanahashi 0:3fb5ae3480ae 73 f_ina_ex = *(float*)&data[21];
tanahashi 0:3fb5ae3480ae 74 f_lps = *(float*)&data[22];
tanahashi 0:3fb5ae3480ae 75 f_mpu = *(float*)&data[23];
tanahashi 0:3fb5ae3480ae 76 f_mpu_ak = *(float*)&data[24];
tanahashi 0:3fb5ae3480ae 77 lat = *(float*)&data[25];
tanahashi 0:3fb5ae3480ae 78 lon = *(float*)&data[29];
tanahashi 0:3fb5ae3480ae 79 sat = *(float*)&data[33];
tanahashi 0:3fb5ae3480ae 80 fix = *(float*)&data[37];
tanahashi 0:3fb5ae3480ae 81 hdop = *(float*)&data[41];
tanahashi 0:3fb5ae3480ae 82 alt = *(float*)&data[45];
tanahashi 0:3fb5ae3480ae 83 geoid = *(float*)&data[49];
tanahashi 0:3fb5ae3480ae 84 high_accel[0] = *(float*)&data[53];
tanahashi 0:3fb5ae3480ae 85 high_accel[1] = *(float*)&data[57];
tanahashi 0:3fb5ae3480ae 86 high_accel[2] = *(float*)&data[61];
tanahashi 0:3fb5ae3480ae 87 voltage_in = *(float*)&data[65];
tanahashi 0:3fb5ae3480ae 88 current_in = *(float*)&data[69];
tanahashi 0:3fb5ae3480ae 89 voltage_ex = *(float*)&data[73];
tanahashi 0:3fb5ae3480ae 90 current_ex = *(float*)&data[77];
tanahashi 0:3fb5ae3480ae 91 press = *(float*)&data[81];
tanahashi 0:3fb5ae3480ae 92 temp = *(float*)&data[85];
tanahashi 0:3fb5ae3480ae 93 accel[0] = *(float*)&data[89];
tanahashi 0:3fb5ae3480ae 94 accel[1] = *(float*)&data[93];
tanahashi 0:3fb5ae3480ae 95 accel[2] = *(float*)&data[97];
tanahashi 0:3fb5ae3480ae 96 gyro[0] = *(float*)&data[101];
tanahashi 0:3fb5ae3480ae 97 gyro[1] = *(float*)&data[105];
tanahashi 0:3fb5ae3480ae 98 gyro[2] = *(float*)&data[109];
tanahashi 0:3fb5ae3480ae 99 mag[0] = *(float*)&data[113];
tanahashi 0:3fb5ae3480ae 100 mag[1] = *(float*)&data[117];
tanahashi 0:3fb5ae3480ae 101 mag[2] = *(float*)&data[121];
tanahashi 0:3fb5ae3480ae 102
tanahashi 0:3fb5ae3480ae 103
tanahashi 0:3fb5ae3480ae 104 mission_hour = mission_time / 3600;
tanahashi 0:3fb5ae3480ae 105 mission_time %= 3600;
tanahashi 0:3fb5ae3480ae 106 mission_min = mission_time / 60;
tanahashi 0:3fb5ae3480ae 107 mission_time %= 60;
tanahashi 0:3fb5ae3480ae 108 mission_sec = mission_time;
tanahashi 0:3fb5ae3480ae 109
tanahashi 0:3fb5ae3480ae 110 pc.printf(" mission time:\t%02d:%02d:%02d\r\n", mission_hour, mission_min, mission_sec);
tanahashi 0:3fb5ae3480ae 111 pc.printf(" flight time:\t%.3f[s]\r\n", flight_time);
tanahashi 0:3fb5ae3480ae 112 pc.printf(" phase:\t%s\r\n", phase_names[phase]);
tanahashi 0:3fb5ae3480ae 113 pc.printf(" flags:\tLAUNCH\tBURNING\tAPOGEE\tMISSION\tRELAY\tFLIGHT\tSEP\tBUZZER\r\n");
tanahashi 0:3fb5ae3480ae 114 pc.printf(" \t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n", f_launched, f_burning, f_apogee, f_mission, f_relay, f_flight_pin, f_sep, f_buzzer);
tanahashi 0:3fb5ae3480ae 115 pc.printf(" flags:\tSD\tGPS\tADXL\tINA_in\tINA_ex\tLPS\tMPU\tMPU_AK\r\n");
tanahashi 0:3fb5ae3480ae 116 pc.printf(" \t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n", f_sd, f_gps, f_adxl, f_ina_in, f_ina_ex, f_lps, f_mpu, f_mpu_ak);
tanahashi 0:3fb5ae3480ae 117 pc.printf("\r\n");
tanahashi 0:3fb5ae3480ae 118 pc.printf(" lat:\t\t%.6f\r\n", lat);
tanahashi 0:3fb5ae3480ae 119 pc.printf(" lon:\t\t%.6f\r\n", lon);
tanahashi 0:3fb5ae3480ae 120 pc.printf(" alt:\t\t%.1f[m]\r\n", alt);
tanahashi 0:3fb5ae3480ae 121 pc.printf("\r\n");
tanahashi 0:3fb5ae3480ae 122 pc.printf(" internal:\tvoltage\t\tcurrent\r\n");
tanahashi 0:3fb5ae3480ae 123 pc.printf(" \t%.2f[V]\t\t%.0f[mA]\r\n", voltage_in / 1000.0f, current_in);
tanahashi 0:3fb5ae3480ae 124 pc.printf(" external:\tvoltage\t\tcurrent\r\n");
tanahashi 0:3fb5ae3480ae 125 pc.printf(" \t%.2f[V]\t\t%.0f[mA]\r\n", voltage_ex / 1000.0f, current_ex);
tanahashi 0:3fb5ae3480ae 126 pc.printf("\r\n");
tanahashi 0:3fb5ae3480ae 127 pc.printf(" press:\t\t%.2f[hPa]\r\n", press);
tanahashi 0:3fb5ae3480ae 128 pc.printf(" temp:\t\t%.2f[C]\r\n", temp);
tanahashi 0:3fb5ae3480ae 129 pc.printf("\r\n");
tanahashi 0:3fb5ae3480ae 130 pc.printf(" high_accel:\tx\t\ty\t\tz\r\n");
tanahashi 0:3fb5ae3480ae 131 pc.printf(" \t\t%.2f\t\t%.2f\t\t%.2f\t[G]\r\n", high_accel[0], high_accel[1], high_accel[2]);
tanahashi 0:3fb5ae3480ae 132 pc.printf(" accel:\t\tx\t\ty\t\tz\r\n");
tanahashi 0:3fb5ae3480ae 133 pc.printf(" \t\t%.2f\t\t%.2f\t\t%.2f\t[G]\r\n", accel[0], accel[1], accel[2]);
tanahashi 0:3fb5ae3480ae 134 pc.printf(" gyro:\t\tx\t\ty\t\tz\r\n");
tanahashi 0:3fb5ae3480ae 135 pc.printf(" \t\t%.2f\t\t%.2f\t\t%.2f\t[rad/s]\r\n", gyro[0], gyro[1], gyro[2]);
tanahashi 0:3fb5ae3480ae 136 }
tanahashi 0:3fb5ae3480ae 137 }