Improved code style and added Doxygen

This commit is contained in:
Christoph Niemann
2012-03-03 23:56:26 +01:00
parent 63157dcd12
commit 470599265e
4 changed files with 66 additions and 71 deletions
+1 -1
View File
@@ -941,7 +941,7 @@
<field name="snapshot_image_number" type="uint16"/> <field name="snapshot_image_number" type="uint16"/>
</message> </message>
<message name="OPENLOG_TIMESTAMP" id="129"> <message name="TIMESTAMP" id="129">
<field name="timestamp" type="uint32"/> <field name="timestamp" type="uint32"/>
</message> </message>
-3
View File
@@ -7,9 +7,6 @@
<init fun="init_openlog()"/> <init fun="init_openlog()"/>
<periodic fun="periodic_2Hz_openlog()" freq="2." autorun="TRUE"/> <periodic fun="periodic_2Hz_openlog()" freq="2." autorun="TRUE"/>
<makefile> <makefile>
<raw>
#Exemple of RAW makefile part
</raw>
<file name="openlog.c"/> <file name="openlog.c"/>
</makefile> </makefile>
</module> </module>
+3 -3
View File
@@ -22,7 +22,7 @@
* *
*/ */
/* /**
* This module provides a timestamp-message, allowing * This module provides a timestamp-message, allowing
* sw/logalizer/openlog2tlm to convert a recorded dumpfile, * sw/logalizer/openlog2tlm to convert a recorded dumpfile,
* created by openlog into the pprz-tlm format, to be converted into * created by openlog into the pprz-tlm format, to be converted into
@@ -38,12 +38,12 @@
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif #endif
uint32_t timestamp = 0; //max flighttime = 49 days :-) uint32_t timestamp = 0; ///< Timestamp to be incremented during operation
void init_openlog(void) { void init_openlog(void) {
} }
void periodic_2Hz_openlog(void) { void periodic_2Hz_openlog(void) {
timestamp=timestamp+500; timestamp=timestamp+500;
DOWNLINK_SEND_OPENLOG_TIMESTAMP(DefaultChannel, &timestamp); DOWNLINK_SEND_TIMESTAMP(DefaultChannel, &timestamp);
} }
+62 -64
View File
@@ -22,80 +22,78 @@
* the Free Software Foundation, 59 Temple Place - Suite 330, * the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
* *
*
Description : Converts a Paparazzi Message dump, containing a timestamp,
to Paparazzi TLM, wich can be converted to .data and .log by
sw/logalizer/sd2log
The openlog Module has to be loaded for use
*/ */
/** Converts a Paparazzi Message dump, containing a timestamp,
to Paparazzi TLM, wich can be converted to .data and .log by
sw/logalizer/sd2log .
The openlog Module has to be loaded for use
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
//define the message id for the OPENLOG_TIMESTAMP message (default is 59) /* define the message id for the TIMESTAMP message (default is 129) */
#define MSG_NUMBER 129 #define MSG_NUMBER 129
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
FILE *in,*out; FILE *in,*out;
int current_timestamp = 0; int current_timestamp = 0;
int timestamp_bytes[4] = {0,0,0,0}; int timestamp_bytes[4] = {0,0,0,0};
int temp = 0; int temp = 0;
if(argc != 3){ if(argc != 3){
puts("wrong number of parameters!\n" puts("wrong number of parameters!\n"
"usage is openlog2tlm <inuptfile> <outputfile>"); "usage is openlog2tlm <inuptfile> <outputfile>");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if((in=fopen(argv[1],"rb"))==NULL){ if((in=fopen(argv[1],"rb"))==NULL){
puts("openlog2tlm wasn't able to open the inputfile\n"); puts("openlog2tlm wasn't able to open the inputfile\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if((out=fopen(argv[2],"wb"))==NULL){ if((out=fopen(argv[2],"wb"))==NULL){
puts("openlog2tlm wasn't able to open the outputfile\n"); puts("openlog2tlm wasn't able to open the outputfile\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf("converting %s to %s\n",argv[1],argv[2]); printf("converting %s to %s\n",argv[1],argv[2]);
temp = fgetc(in); temp = fgetc(in);
while(!feof(in)){
if(temp==0x99){//if a message starts
int length=fgetc(in); //determining the length of the message
int message[length-2]; // allocate an array that fits for the message
int i;
for(i = 0; i<(length-2); i++){//read the complete message first
message[i]=fgetc(in);
}
temp = fgetc(in);
if(message[1]==MSG_NUMBER){
current_timestamp = message[2]+(message[3]<<8)+(message[4]<<16)+(message[5]<<24);
//printf("hooray openlog message! the time is %i now (in ms)\n", current_timestamp);
current_timestamp = current_timestamp*10; //now according to 100 microsecond grid for tlm
//splitting the timestamp into bytes again, to use it for the messages
timestamp_bytes[0] = current_timestamp & 0xff;
timestamp_bytes[1] = ( current_timestamp >> 8 ) & 0xff;
timestamp_bytes[2] = ( current_timestamp >> 16 ) & 0xff;
timestamp_bytes[3] = ( current_timestamp >> 24 ) & 0xff;
}
//start to write the message to the tlm-file
fputc(0x99,out);//write PPRZ_STX
fputc(length-4,out);//write LENGTH, recalculated for TLM
fputc(0,out); //write SOURCE, defaults to uart0
fputc(timestamp_bytes[0],out); //write TIMESTAMP_LSB
fputc(timestamp_bytes[1],out); //write TIMESTAMP
fputc(timestamp_bytes[2],out); //write TIMESTAMP
fputc(timestamp_bytes[3],out); //write TIMESTAMP_MSB
int checksum = length-4+timestamp_bytes[0]+timestamp_bytes[1]+timestamp_bytes[2]+timestamp_bytes[3];
for(i = 0; i<(length-4); i++){//write payload
fputc(message[i],out);
checksum+=message[i];
}
fputc(checksum,out);//write checksum, recalculated for tlm
}
}
return EXIT_SUCCESS;
}
while(!feof(in)){
if(temp==0x99){/// if a message starts
int length=fgetc(in); /// determining the length of the message
int message[length-2]; /// allocate an array that fits for the message
int i;
for(i = 0; i<(length-2); i++){/// read the complete message first
message[i]=fgetc(in);
}
temp = fgetc(in);
if(message[1]==MSG_NUMBER){
current_timestamp = message[2]+(message[3]<<8)+(message[4]<<16)+(message[5]<<24);
current_timestamp = current_timestamp*10; /// now according to 100 microsecond grid for tlm
/// splitting the timestamp into bytes again, to use it for the messages
timestamp_bytes[0] = current_timestamp & 0xff;
timestamp_bytes[1] = ( current_timestamp >> 8 ) & 0xff;
timestamp_bytes[2] = ( current_timestamp >> 16 ) & 0xff;
timestamp_bytes[3] = ( current_timestamp >> 24 ) & 0xff;
}
/// start to write the message to the tlm-file
fputc(0x99,out);/// write PPRZ_STX
fputc(length-4,out);/// write LENGTH, recalculated for TLM
fputc(0,out); /// write SOURCE, defaults to uart0
fputc(timestamp_bytes[0],out); /// write TIMESTAMP_LSB
fputc(timestamp_bytes[1],out); /// write TIMESTAMP
fputc(timestamp_bytes[2],out); /// write TIMESTAMP
fputc(timestamp_bytes[3],out); /// write TIMESTAMP_MSB
int checksum = length-4+timestamp_bytes[0]+timestamp_bytes[1]+timestamp_bytes[2]+timestamp_bytes[3];
for(i = 0; i<(length-4); i++){/// write payload
fputc(message[i],out);
checksum+=message[i];
}
fputc(checksum,out);/// write checksum, recalculated for tlm
}
}
return EXIT_SUCCESS;
}