Log.pde : Updated Flash Logging to log Floats properly vs scaled integers.

This commit is contained in:
Jason Short 2012-04-21 15:25:53 -07:00
parent e22832a832
commit 9c19138fb8
1 changed files with 27 additions and 18 deletions

View File

@ -291,26 +291,21 @@ static void Log_Write_Raw()
Vector3f accel = imu.get_accel(); Vector3f accel = imu.get_accel();
//Vector3f accel_filt = imu.get_accel_filtered(); //Vector3f accel_filt = imu.get_accel_filtered();
gyro *= t7; // Scale up for storage as long integers //gyro *= t7; // Scale up for storage as long integers
accel *= t7; //accel *= t7;
//accel_filt *= t7; //accel_filt *= t7;
DataFlash.WriteByte(HEAD_BYTE1); DataFlash.WriteByte(HEAD_BYTE1);
DataFlash.WriteByte(HEAD_BYTE2); DataFlash.WriteByte(HEAD_BYTE2);
DataFlash.WriteByte(LOG_RAW_MSG); DataFlash.WriteByte(LOG_RAW_MSG);
DataFlash.WriteLong(gyro.x); DataFlash.WriteLong(get_int(gyro.x));
DataFlash.WriteLong(gyro.y); DataFlash.WriteLong(get_int(gyro.y));
DataFlash.WriteLong(gyro.z); DataFlash.WriteLong(get_int(gyro.z));
DataFlash.WriteLong(get_int(accel.x));
//DataFlash.WriteLong(accels_rot.x * t7); DataFlash.WriteLong(get_int(accel.y));
//DataFlash.WriteLong(accels_rot.y * t7); DataFlash.WriteLong(get_int(accel.z));
//DataFlash.WriteLong(accels_rot.z * t7);
DataFlash.WriteLong(accel.x);
DataFlash.WriteLong(accel.y);
DataFlash.WriteLong(accel.z);
DataFlash.WriteByte(END_BYTE); DataFlash.WriteByte(END_BYTE);
} }
@ -321,9 +316,9 @@ static void Log_Read_Raw()
float logvar; float logvar;
Serial.printf_P(PSTR("RAW,")); Serial.printf_P(PSTR("RAW,"));
for (int y = 0; y < 6; y++) { for (int y = 0; y < 6; y++) {
logvar = (float)DataFlash.ReadLong() / t7; logvar = get_float(DataFlash.ReadLong());
Serial.print(logvar); Serial.print(logvar);
Serial.print(","); Serial.print(", ");
} }
Serial.println(" "); Serial.println(" ");
} }
@ -777,7 +772,13 @@ static void Log_Read_Startup()
static void Log_Write_Data(int8_t _type, float _data) static void Log_Write_Data(int8_t _type, float _data)
{ {
Log_Write_Data(_type, (int32_t)(_data * 1000)); DataFlash.WriteByte(HEAD_BYTE1);
DataFlash.WriteByte(HEAD_BYTE2);
DataFlash.WriteByte(LOG_DATA_MSG);
DataFlash.WriteByte(_type);
DataFlash.WriteByte(1);
DataFlash.WriteLong(get_int(_data));
DataFlash.WriteByte(END_BYTE);
} }
static void Log_Write_Data(int8_t _type, int32_t _data) static void Log_Write_Data(int8_t _type, int32_t _data)
@ -786,6 +787,7 @@ static void Log_Write_Data(int8_t _type, int32_t _data)
DataFlash.WriteByte(HEAD_BYTE2); DataFlash.WriteByte(HEAD_BYTE2);
DataFlash.WriteByte(LOG_DATA_MSG); DataFlash.WriteByte(LOG_DATA_MSG);
DataFlash.WriteByte(_type); DataFlash.WriteByte(_type);
DataFlash.WriteByte(0);
DataFlash.WriteLong(_data); DataFlash.WriteLong(_data);
DataFlash.WriteByte(END_BYTE); DataFlash.WriteByte(END_BYTE);
} }
@ -794,8 +796,15 @@ static void Log_Write_Data(int8_t _type, int32_t _data)
static void Log_Read_Data() static void Log_Read_Data()
{ {
int8_t temp1 = DataFlash.ReadByte(); int8_t temp1 = DataFlash.ReadByte();
int32_t temp2 = DataFlash.ReadLong(); int8_t temp2 = DataFlash.ReadByte();
Serial.printf_P(PSTR("DATA: %d, %ld\n"), temp1, temp2);
if(temp2 == 1){
float temp3 = get_float(DataFlash.ReadLong());
Serial.printf_P(PSTR("DATA: %d, %1.6f\n"), temp1, temp3);
}else{
int32_t temp3 = DataFlash.ReadLong();
Serial.printf_P(PSTR("DATA: %d, %ld\n"), temp1, temp3);
}
} }
// Write an PID packet. Total length : 28 bytes // Write an PID packet. Total length : 28 bytes