diff --git a/CLOCK.CFG b/CLOCK.CFG deleted file mode 100755 index c6ed75d754e2d9387ccebd64c6d8c9955eb554d2..0000000000000000000000000000000000000000 --- a/CLOCK.CFG +++ /dev/null @@ -1,2 +0,0 @@ -//System Configuration File -CLOCKTIME= 01/12/2020 14:30:00; \ No newline at end of file diff --git a/JConfig.CFG b/JConfig.CFG deleted file mode 100755 index 8c49eb4f2c8b8348eb16315502871611cf7e7816..0000000000000000000000000000000000000000 --- a/JConfig.CFG +++ /dev/null @@ -1,21 +0,0 @@ -//System Configuration File - -Sampling_Resolution=16; // 16 = Resolution in bits (8 or 16) -Sampling_Freq=256000; // 256000 = Sampling frequency(in sample //per sec). Possibles values are //512000,256000, 128000,64000 With WidBand //Filters, or 512000, //128000,32000,8000 With Low Latency //filter -Filter_Selection=1; // = 1 ; filter selection. Possibles //values are: - //0->Wideband1 (0.45 to0.55)�fDATA - //1->Wideband2 (0.40 to0.50)�fDATA - //2->LowLatency - -AutoStart=true; // = true = Auto record at boot -FILE_Size_Limit=150000000;//File Size limitation (in bytes) = //150000000 for 5 minutes -Record_Use_TimeInterval=true; //Set or unset the discrete recording -Shutdown_Duration=5; //Time period of wait time between each record (in seconds) -Preparing_Duration=5; //Time to boot and prepare Pic 32 (SD Card or HDD is not the same) -Recording_Duration=5; //Time period of record (in seconds) -Stopping_Duration=5; //Time to stop Pic 32 (SD Card or HDD is not the same) -Channel_Count=2; //Number of channels to record -Storage_Target=SD; //Storage target (SD for SD card, HDD for hard disk drive or USB for Device mode) -CNN_Detection_Timeout_Duration=30; -GSM_Data_Send_Timeout_Duration=3; -Nb_Remontes_Par_Jour=10; diff --git a/Rapport2wavs.py b/Rapport2wavs.py deleted file mode 100644 index 6239431be8678004707105a1fbab9032a06302d9..0000000000000000000000000000000000000000 --- a/Rapport2wavs.py +++ /dev/null @@ -1,43 +0,0 @@ -import numpy as np -import soundfile as sf -import argparse - -parser = argparse.ArgumentParser() -parser.add_argument('filename') -args = parser.parse_args() - -RORQUAL_HOPSIZE, RORQUAL_WINSIZE, RORQUAL_FE, RORQUAL_SAMPLEPERSAMPLE, RORQUAL_LENSIG = 256, 4096, 4000, 25600, 60 -CACHA_HOPSIZE, CACHA_WINSIZE, CACHA_FE, CACHA_SAMPLEPERSAMPLE, CACHA_LENSIG = 256, 512, 64000, 12800, 60 -CACHA_RAPPORT_FE, RORQUAL_RAPPORT_FE, RAPPORT_N_CHANNELS = 128_000, 128_00, 5 -CACHA_NUM_DETEC, RORQUAL_NUM_DETEC = 10, 3 -rorqual_predPos = lambda p: int(((p * RORQUAL_HOPSIZE + (RORQUAL_WINSIZE/2 + RORQUAL_HOPSIZE * 13) / 2) / RORQUAL_FE - 1) * RORQUAL_RAPPORT_FE) -cacha_predPos = lambda p: int(((p * CACHA_HOPSIZE * 8 + (CACHA_WINSIZE + CACHA_HOPSIZE * 7 * 6) / 4 ) / CACHA_FE - 0.05) * CACHA_RAPPORT_FE) - -file = open(args.filename, 'r') -lines = iter(file.readlines()) - -for l in lines: - if l == ' rorqual predPeaks\n': - l = next(lines) - if ',' in l: - sig = np.zeros((RORQUAL_LENSIG * RORQUAL_RAPPORT_FE, RAPPORT_N_CHANNELS), dtype='int16') - peaks = np.array(l[:-2].split(',')).astype(int) - l = next(lines) - for p in peaks[:RORQUAL_NUM_DETEC]: - l = next(lines) - samples = np.array(l[:-2].split(',')).astype('int16').reshape(-1, RAPPORT_N_CHANNELS) - sig[rorqual_predPos(p):rorqual_predPos(p)+RORQUAL_SAMPLEPERSAMPLE] = samples[:min(rorqual_predPos(p)+RORQUAL_SAMPLEPERSAMPLE, len(sig))-rorqual_predPos(p)] - sf.write(f'{args.filename[:-8]}_rorqual.wav', sig, RORQUAL_RAPPORT_FE) - if l == ' cacha predPeaks\n': - l = next(lines) - if ',' in l: - sig = np.zeros((CACHA_LENSIG * CACHA_RAPPORT_FE, RAPPORT_N_CHANNELS), dtype='int16') - peaks = np.array(l[:-2].split(',')).astype(int) - l = next(lines) - for p in peaks[:CACHA_NUM_DETEC]: - l = next(lines) - samples = np.array(l[:-2].split(',')).astype('int16').reshape(-1, RAPPORT_N_CHANNELS) - sig[cacha_predPos(p):cacha_predPos(p)+CACHA_SAMPLEPERSAMPLE] = samples - sf.write(f'{args.filename[:-8]}_cacha.wav', sig, CACHA_RAPPORT_FE) - -file.close() diff --git a/RapportIMU2txt b/RapportIMU2txt deleted file mode 100755 index 8247fd7cd7a3fa4b67b80eb790c6d10c7cbb191e..0000000000000000000000000000000000000000 Binary files a/RapportIMU2txt and /dev/null differ diff --git a/RapportIMU2txt.c b/RapportIMU2txt.c deleted file mode 100755 index bed0582743e03447827ff07f2c6513479176e319..0000000000000000000000000000000000000000 --- a/RapportIMU2txt.c +++ /dev/null @@ -1,130 +0,0 @@ -// by paul -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <math.h> - -#define NTOAS_MAX 200 - -#define RORQUAL_SAMPLE_RATE 4000 -#define RORQUAL_LENSIG RORQUAL_SAMPLE_RATE*60 // load 60sec -#define RORQUAL_WINSIZE 4096 -#define RORQUAL_LENSPEC (RORQUAL_LENSIG - RORQUAL_WINSIZE)/RORQUAL_HOPSIZE -#define RORQUAL_HOPSIZE 256 -#define RORQUAL_LENPRED RORQUAL_LENSPEC - (5-1)*3 //3 layers of kernel size 5 -#define RORQUAL_RAPPORT_NSAMPLESTOSEND 3 // see cacha -#define RORQUAL_RAPPORT_SAMPLE_RATE 12800 -#define RORQUAL_RAPPORT_SAMPLESPERSAMPLE 25600 // see cacha - -#define CACHA_SAMPLE_RATE 64000 -#define CACHA_LENSIG CACHA_SAMPLE_RATE*60 // load 10sec -#define CACHA_WINSIZE 512 -#define CACHA_LENSPEC (CACHA_LENSIG - CACHA_WINSIZE)/CACHA_HOPSIZE -#define CACHA_HOPSIZE 256 -#define CACHA_LENPRED (((CACHA_LENSPEC - 6)/2 - 6)/2 -6)/2 // 3 layers hopsize 2 kernel 7 -#define CACHA_RAPPORT_NSAMPLESTOSEND 10 // a sample is positionned at a high pred from the cnn, we extract the audio signal arround to send back via network -#define CACHA_RAPPORT_SAMPLE_RATE 128000 -#define CACHA_RAPPORT_SAMPLESPERSAMPLE 12800// number of audio samples per high pred sample to send back - -#define RAPPORT_CHANNELS 5 // number of channels recorded to include in the report -#define ADDITIONNAL_DATA_SIZE 736 -#define trameSize 31 - -typedef struct{ - float predsC[CACHA_LENPRED]; //len of preds for 10sec signal - short numDetectionsCachalot; - float predsR[RORQUAL_LENPRED]; //len of preds for 60sec signal - short numDetectionsRorqual; - char fileName[50]; //Nom du fichier concerne - // int ToAs_cacha[NTOAS_MAX]; - // unsigned char hydros_ToAs_cacha[NTOAS_MAX]; - short predPeaksR[RORQUAL_RAPPORT_NSAMPLESTOSEND]; //indices of predPeaks for rorqual - short predPeaksC[CACHA_RAPPORT_NSAMPLESTOSEND]; //indices of predPeaks for cachalot - unsigned char imuR[RORQUAL_RAPPORT_NSAMPLESTOSEND][ADDITIONNAL_DATA_SIZE]; - unsigned char imuC[RORQUAL_RAPPORT_NSAMPLESTOSEND][ADDITIONNAL_DATA_SIZE]; - int16_t samplesR[RORQUAL_RAPPORT_NSAMPLESTOSEND][RORQUAL_RAPPORT_SAMPLESPERSAMPLE][RAPPORT_CHANNELS]; // samples to send back for rorqual - int16_t samplesC[CACHA_RAPPORT_NSAMPLESTOSEND][CACHA_RAPPORT_SAMPLESPERSAMPLE][RAPPORT_CHANNELS]; // samples to send back for cachalot -}RAPPORT; -int main(int argc, char* argv[]){ -// printf("Have you checked rorqual and cacha lensigs and config ?? (needs to match with pic32\'s)"); - FILE* infile = fopen(argv[1], "rb"); - if(infile==NULL){ - printf("Failed to open input file\n"); - return 0; - } - static RAPPORT rapport; - int i, j, timestamp; - unsigned char* curData; - short int val; - fread(&rapport, sizeof(RAPPORT), 1, infile); - printf("%d cacha and %d rorqual", rapport.numDetectionsCachalot, rapport.numDetectionsRorqual); - - strcpy(argv[1] + strlen(argv[1])-5, "_imuC.txt\0"); - FILE* outfile = fopen(argv[1], "w+"); - if(outfile==NULL){ - printf("Failed to open output file\n"); - return 0; - } - for(j=0; j<rapport.numDetectionsCachalot; j++){ - curData = rapport.imuC[j] + 6; - while(curData + trameSize + 6 < rapport.imuC[j] + ADDITIONNAL_DATA_SIZE){ - if(!(curData[0]==0xFE && curData[1]==0x0A && curData[2]==0x0A && curData[5]==0x08)){ - // skip trame if header is incorrect - curData += trameSize + 6; - continue; - } - curData += 3 + 2; // skip trame header, trame length - timestamp = *((int*) (curData + 9)); - timestamp = ((timestamp & 0xFF000000)>>24) | ((timestamp & 0x00FF0000)>>8) | ((timestamp & 0x0000FF00)<<8) | ((timestamp & 0x000000FF)<<24); - fprintf(outfile, "%d,", timestamp); - for(i=13; i<31; i+=2){ - val = *((short int*) (curData + i)); - val = ((val & 0x00FF)<<8) | ((val & 0xFF00)>>8); - if(i<29){ - fprintf(outfile, "%hd,", val); - }else{ - fprintf(outfile, "%hd\n", val); - } - } - curData += trameSize + 1; - } - fprintf(outfile, "\n"); - } - fclose(outfile); - - strcpy(argv[1] + strlen(argv[1])-5, "R.txt\0"); - outfile = fopen(argv[1], "w+"); - if(outfile==NULL){ - printf("Failed to open output file\n"); - return 0; - } - for(j=0; j<rapport.numDetectionsRorqual; j++){ - curData = rapport.imuR[j] + 6; - while(curData + trameSize + 6 < rapport.imuR[j] + ADDITIONNAL_DATA_SIZE){ - if(!(curData[0]==0xFE && curData[1]==0x0A && curData[2]==0x0A && curData[5]==0x08)){ - // skip trame if header is incorrect - curData += trameSize + 6; - continue; - } - curData += 3 + 2; // skip trame header, trame length - timestamp = *((int*) (curData + 9)); - timestamp = ((timestamp & 0xFF000000)>>24) | ((timestamp & 0x00FF0000)>>8) | ((timestamp & 0x0000FF00)<<8) | ((timestamp & 0x000000FF)<<24); - fprintf(outfile, "%d,", timestamp); - for(i=13; i<31; i+=2){ - val = *((short int*) (curData + i)); - val = ((val & 0x00FF)<<8) | ((val & 0xFF00)>>8); - if(i<29){ - fprintf(outfile, "%hd,", val); - }else{ - fprintf(outfile, "%hd\n", val); - } - } - curData += trameSize + 1; - } - fprintf(outfile, "\n"); - } - fclose(outfile); - fclose(infile); - return 0; -} diff --git a/RapportInfo2txt b/RapportInfo2txt deleted file mode 100755 index 5c219b675b4d844bca1774f3c33385fe0afaf5ab..0000000000000000000000000000000000000000 Binary files a/RapportInfo2txt and /dev/null differ diff --git a/RapportInfo2txt.c b/RapportInfo2txt.c deleted file mode 100755 index 39d7c5dabe32e3959aa607f267562c284e333952..0000000000000000000000000000000000000000 --- a/RapportInfo2txt.c +++ /dev/null @@ -1,112 +0,0 @@ -// by paul -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <math.h> - -#define NTOAS_MAX 200 - -#define RORQUAL_SAMPLE_RATE 4000 -#define RORQUAL_LENSIG RORQUAL_SAMPLE_RATE*60 // load 60sec -#define RORQUAL_WINSIZE 4096 -#define RORQUAL_LENSPEC (RORQUAL_LENSIG - RORQUAL_WINSIZE)/RORQUAL_HOPSIZE -#define RORQUAL_HOPSIZE 256 -#define RORQUAL_LENPRED RORQUAL_LENSPEC - (5-1)*3 //3 layers of kernel size 5 -#define RORQUAL_RAPPORT_NSAMPLESTOSEND 3 // see cacha -#define RORQUAL_RAPPORT_SAMPLE_RATE 12800 -#define RORQUAL_RAPPORT_SAMPLESPERSAMPLE 25600 // see cacha - -#define CACHA_SAMPLE_RATE 64000 -#define CACHA_LENSIG CACHA_SAMPLE_RATE*60 // load 10sec -#define CACHA_WINSIZE 512 -#define CACHA_LENSPEC (CACHA_LENSIG - CACHA_WINSIZE)/CACHA_HOPSIZE -#define CACHA_HOPSIZE 256 -#define CACHA_LENPRED (((CACHA_LENSPEC - 6)/2 - 6)/2 -6)/2 // 3 layers hopsize 2 kernel 7 -#define CACHA_RAPPORT_NSAMPLESTOSEND 10 // a sample is positionned at a high pred from the cnn, we extract the audio signal arround to send back via network -#define CACHA_RAPPORT_SAMPLE_RATE 128000 -#define CACHA_RAPPORT_SAMPLESPERSAMPLE 12800// number of audio samples per high pred sample to send back - -#define RAPPORT_CHANNELS 5 // number of channels recorded to include in the report -#define ADDITIONNAL_DATA_SIZE 736 - -typedef struct{ - float predsC[CACHA_LENPRED]; //len of preds for 10sec signal - short numDetectionsCachalot; - float predsR[RORQUAL_LENPRED]; //len of preds for 60sec signal - short numDetectionsRorqual; - char fileName[50]; //Nom du fichier concerne - // int ToAs_cacha[NTOAS_MAX]; - // unsigned char hydros_ToAs_cacha[NTOAS_MAX]; - short predPeaksR[RORQUAL_RAPPORT_NSAMPLESTOSEND]; //indices of predPeaks for rorqual - short predPeaksC[CACHA_RAPPORT_NSAMPLESTOSEND]; //indices of predPeaks for cachalot - unsigned char imuR[RORQUAL_RAPPORT_NSAMPLESTOSEND][ADDITIONNAL_DATA_SIZE]; - unsigned char imuC[CACHA_RAPPORT_NSAMPLESTOSEND][ADDITIONNAL_DATA_SIZE]; - int16_t samplesR[RORQUAL_RAPPORT_NSAMPLESTOSEND][RORQUAL_RAPPORT_SAMPLESPERSAMPLE][RAPPORT_CHANNELS]; // samples to send back for rorqual - int16_t samplesC[CACHA_RAPPORT_NSAMPLESTOSEND][CACHA_RAPPORT_SAMPLESPERSAMPLE][RAPPORT_CHANNELS]; // samples to send back for cachalot -}RAPPORT; - -int main(int argc, char* argv[]){ -// printf("Have you checked rorqual and cacha lensigs and config ?? (needs to match with pic32\'s)"); - FILE* infile = fopen(argv[1], "rb"); - if(infile==NULL){ - printf("Failed to open input file\n"); - return 0; - } - strcpy(argv[1] + strlen(argv[1])-4, "txt\0"); - FILE* outfile = fopen(argv[1], "w+"); - if(outfile==NULL){ - printf("Failed to open output file\n"); - return 0; - } - static RAPPORT rapport; - fread(&rapport, sizeof(RAPPORT), 1, infile); - printf("Writing into %s with %d fin whale pulses and %d sperm whale clicks \n", argv[1], rapport.numDetectionsRorqual, rapport.numDetectionsCachalot); - int i, j, k; - fprintf(outfile, "Filename : %s \n", rapport.fileName); - fprintf(outfile, "\n rorqual preds\n"); - for(i=0; i<RORQUAL_LENPRED; i++){ - fprintf(outfile, "%f,", rapport.predsR[i]); - } - fprintf(outfile, "\n rorqual predPeaks\n"); - for(i=0; i<rapport.numDetectionsRorqual; i++){ - fprintf(outfile, "%hd,", rapport.predPeaksR[i]); - printf("%f ", rapport.predsR[rapport.predPeaksR[i]]); - } - if(rapport.numDetectionsRorqual > 0){ - printf("\n"); - } - fprintf(outfile, "\n rorqual samples\n"); - for(i=0; i<rapport.numDetectionsRorqual; i++){ - for(j=0; j<RORQUAL_RAPPORT_SAMPLESPERSAMPLE; j++){ - for(k=0; k<RAPPORT_CHANNELS; k++){ - fprintf(outfile, "%hd,", rapport.samplesR[i][j][k]); - } - } - fprintf(outfile, "\n"); - } - fprintf(outfile, "cacha preds\n"); - for(i=0; i<CACHA_LENPRED; i++){ - fprintf(outfile, "%f,", rapport.predsC[i]); - } - fprintf(outfile, "\n cacha predPeaks\n"); - for(i=0; i<rapport.numDetectionsCachalot; i++){ - fprintf(outfile, "%hd,", rapport.predPeaksC[i]); - printf("%f ", rapport.predsC[rapport.predPeaksC[i]]); - } - if(rapport.numDetectionsCachalot > 0){ - printf("\n"); - } - fprintf(outfile, "\n cacha samples\n"); - for(i=0; i < fmin(rapport.numDetectionsCachalot, CACHA_RAPPORT_NSAMPLESTOSEND); i++){ - for(j=0; j<CACHA_RAPPORT_SAMPLESPERSAMPLE; j++){ - for(k=0; k<RAPPORT_CHANNELS; k++){ - fprintf(outfile, "%hd,", rapport.samplesC[i][j][k]); - } - } - fprintf(outfile, "\n"); - } - fclose(infile); - fclose(outfile); - return 0; -} diff --git a/log2wav b/log2wav deleted file mode 100755 index 948f72d1c49145a50b4ea4fef4e846c1afee5eb6..0000000000000000000000000000000000000000 Binary files a/log2wav and /dev/null differ diff --git a/log2wav.c b/log2wav.c deleted file mode 100755 index 0e1363fceb3d6ffcc161404788d82ca9a8502144..0000000000000000000000000000000000000000 --- a/log2wav.c +++ /dev/null @@ -1,231 +0,0 @@ -// Jan. 2021 -// by paul, inspired / recycled from microchip code by SMIOT -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdbool.h> -#include <math.h> - -#define MAX_PERIPHERAL 5 //Nombre max de peripheriques externes - -typedef struct{ - char Type; //type du peripherique (0x01 accel, 0x02 gyro, 0x03 magneto, 0x04 temperature, 0x05 pressure, 0x06 light,...) - char ID; //ID du peripherique - char Range; //Range de la mesure (ex: 2G, 4G, 6G, 8G, 16G pour un accel) - char Resolution; //Resolution de mesure du peripherique - short Frequency; //Frequence d'echantillonage du peripherique -}PERIPHERAL_CONFIGURATION; - -typedef struct{ - int headerSize; //Taille du header ce champ exclu - int versionNumber; - char numberOfChan; - char resolutionBits; - int samplingFrequency; - int dmaBlockSize; - int sizeOfAdditionnalDataBuffer; - char numberOfExternalPeripheral; - int timeStampOfStart; - PERIPHERAL_CONFIGURATION periphConfig[MAX_PERIPHERAL]; -}HighBlueHeader; - -struct WaveHeader_s { - char chunkId[4]; // Riff Wave Header - int chunkSize; - char format[4]; - char subChunk1Id[4]; // Format Subchunk - int subChunk1Size; - short int audioFormat; - short int numChannels; - int sampleRate; - int byteRate; - short int blockAlign; - short int bitsPerSample; - //short int extraParamSize; - char subChunk2Id[4]; // Data Subchunk - int subChunk2Size; -} WaveHeader_default = {{'R','I','F','F'}, 36, {'W','A','V','E'}, {'f','m','t',' '}, 16, 1, 0, 0, 0, 0, 0, {'d','a','t','a'}, 0}; -typedef struct WaveHeader_s WaveHeader; - - -void parseLogFileHeader(FILE* logfile, HighBlueHeader* hdr, int verbose){ - // header parse - fread(&hdr->headerSize, 4, 1, logfile); - fread(&hdr->versionNumber, 2, 1, logfile); - fread(&hdr->numberOfChan, 1, 1, logfile); - fread(&hdr->resolutionBits, 1, 1, logfile); - fread(&hdr->samplingFrequency, 4, 1, logfile); - fread(&hdr->dmaBlockSize, 4, 1, logfile); - fread(&hdr->sizeOfAdditionnalDataBuffer, 4, 1, logfile); - fread(&hdr->numberOfExternalPeripheral, 1, 1, logfile); - fread(&hdr->timeStampOfStart, 4, 1, logfile); - if(verbose){ - printf("header size : %d\n", hdr->headerSize); - printf("version number : %d\n", hdr->versionNumber); - printf("number of chans : %d\n", hdr->numberOfChan); - printf("resolutionBits : %d\n", hdr->resolutionBits); - printf("samplingFrequency : %d\n", hdr->samplingFrequency); - printf("dmaBlockSize : %d\n", hdr->dmaBlockSize); - printf("sizeOfAdditionnalDataBuffer : %d\n", hdr->sizeOfAdditionnalDataBuffer); - printf("numberOfExternalPeripheral : %d\n", hdr->numberOfExternalPeripheral); - printf("timeStampOfStart : %d\n", hdr->timeStampOfStart); - } - // load external periph config - for(int i=0; i<hdr->numberOfExternalPeripheral; i++){ - fread(&hdr->periphConfig[i].Type, 1, 1, logfile); - fread(&hdr->periphConfig[i].ID, 1, 1, logfile); - fread(&hdr->periphConfig[i].Range, 1, 1, logfile); - fread(&hdr->periphConfig[i].Resolution, 1, 1, logfile); - fread(&hdr->periphConfig[i].Frequency, 2, 1, logfile); - } - return; -} - -short int toLittleEndian(short int val){ - return val = ((val & 0x00FF)<<8) | ((val & 0xFF00)>>8); -} - -void parseMPU(unsigned char* additionnalDataBlock, int size, bool verbose, FILE* mpuFile){ - static int maxtimeStamp = 0; - int i, timestamp; - short int trameSize = 31, val; // fixed for now - unsigned char* curData = additionnalDataBlock + 6; // first 6 bytes are for usb device - if(verbose){ - printf("MPU Range : %hdG\n", *(curData + 5 + 3)); - printf("MPU Resolution : %hd\n", *(curData + 5 + 3 + 1)); - printf("MPU Sampling Frequency : %hd\n", *(curData + 5 + 3 + 3)); - } - while(curData + trameSize + 6 < additionnalDataBlock + size){ - if(!(curData[0]==0xFE && curData[1]==0x0A && curData[2]==0x0A && curData[5]==0x08)){ - // skip trame if header is incorrect - curData += trameSize + 6; - continue; - } - curData += 3 + 2; // skip trame header, trame length - timestamp = *((int*) (curData + 9)); - timestamp = ((timestamp & 0xFF000000)>>24) | ((timestamp & 0x00FF0000)>>8) | ((timestamp & 0x0000FF00)<<8) | ((timestamp & 0x000000FF)<<24); - if(timestamp > maxtimeStamp){ - fprintf(mpuFile, "%d,", timestamp); - //printf("%d\n", timestamp); - // treat payload - for(i=13; i<31; i+=2){ - val = *((short int*) (curData + i)); - val = ((val & 0x00FF)<<8) | ((val & 0xFF00)>>8); - //printf("curData %x %x %hd", *(curData+i), *(curData + i +1), val); - if(i<29){ - fprintf(mpuFile, "%hd,", val); - }else{ - fprintf(mpuFile, "%hd\n", val); - } - } - maxtimeStamp = timestamp; - } - curData += trameSize + 1; // shift of trame size + 1 byte of checksum - } -} - -int main(int argc, char* argv[]){ - if(argc < 2){ - printf("Script needs to be called with at least 1 arguments :\n\t input file name (.log file)\n\t(optionnal) output filename (.wav file)\n\t(optionnal) mpu filename (.csv file)\n\t(optionnal) verbose (1 / void)\n"); - return 0; - } - HighBlueHeader hdr; - FILE* logfile = fopen(argv[1], "rb"); - if(logfile==NULL){ - printf("Failed to open input file\n"); - return 0; - } - // get file size - fseek(logfile, 0, SEEK_END); - long filesize = ftell(logfile); - if(filesize == 0){ - printf("skipped empty file : %s\n", argv[1]); - return 0; - } - fseek(logfile, 0, SEEK_SET); - int verbose = 0; - if(argc==5){ - verbose = *argv[4]=='1'; - } - // file opened successfully, we read the header - parseLogFileHeader(logfile, &hdr, verbose); - int resolutionBytes = hdr.resolutionBits/8; - long dataBlockSampleSize = hdr.dmaBlockSize / ( hdr.numberOfChan * resolutionBytes); - if(verbose){ - printf("file size (bytes) %ld \n", filesize); - printf("dataBlockSampleSize %ld\n", dataBlockSampleSize); - } - if(hdr.resolutionBits!=16 && hdr.resolutionBits!=24 && hdr.resolutionBits!=32){ - printf("resolution %d not supported yet sorry\n", hdr.resolutionBits); - return 0; - } - // move to start of the data - fseek(logfile, hdr.headerSize + 4, SEEK_SET); - - FILE* wavfile;// open wav file - if(argc>2){ - wavfile = fopen(argv[2], "wb"); - }else{ - strcpy(argv[1] + strlen(argv[1])-3, "wav\0"); - wavfile = fopen(argv[1], "wb"); - } - if(wavfile==NULL){ - printf("Failed to open wav output file\n"); - return 0; - } - WaveHeader whdr = WaveHeader_default; - whdr.numChannels = hdr.numberOfChan; - whdr.sampleRate = hdr.samplingFrequency; - whdr.bitsPerSample = hdr.resolutionBits; - whdr.byteRate = whdr.sampleRate * whdr.numChannels * resolutionBytes; - whdr.blockAlign = whdr.numChannels * resolutionBytes; - whdr.chunkSize = 36 + (filesize - hdr.headerSize - 4) / (hdr.dmaBlockSize + hdr.sizeOfAdditionnalDataBuffer) * hdr.numberOfChan * dataBlockSampleSize * resolutionBytes; - whdr.subChunk2Size = whdr.chunkSize-36; - fwrite(&whdr, sizeof(WaveHeader), 1, wavfile); - - FILE* mpuFile = NULL; // open mpu file - if(argc>3){ - mpuFile = fopen(argv[3], "w+"); - if(mpuFile==NULL){ - printf("Failed to open mpu output file\n"); - return 0; - } - } - // }else{ - // strcpy(argv[1] + strlen(argv[1])-4, "_mpu.csv\0"); - // mpuFile = fopen(argv[1], "w+"); - // argv[1][strlen(argv[1])-8] = '\0'; - // } - - char* dmaBlock = (char*) malloc(hdr.dmaBlockSize); - char* additionnalDataBlock = (char*) malloc(hdr.sizeOfAdditionnalDataBuffer); - char* samples = (char*) malloc(hdr.numberOfChan * resolutionBytes); - int ichan, isample; - long pos = 0; - bool isFirst = true; - // read each dataBlock - do{ - fread(additionnalDataBlock, hdr.sizeOfAdditionnalDataBuffer, 1, logfile); - if(mpuFile != NULL){ - parseMPU(additionnalDataBlock, hdr.sizeOfAdditionnalDataBuffer, isFirst && verbose, mpuFile); - isFirst = false; - } - fread(dmaBlock, hdr.dmaBlockSize, 1, logfile); - for(isample=0; isample<dataBlockSampleSize; isample++){ - for(ichan=0; ichan<hdr.numberOfChan; ichan++){ - memcpy(samples + ichan * resolutionBytes, dmaBlock + (ichan * dataBlockSampleSize + isample) * resolutionBytes, resolutionBytes); - } - fwrite(samples, resolutionBytes, hdr.numberOfChan, wavfile); - } - printf("\r %s : ", argv[1]); - pos = ftell(logfile); - printf(" %ld%%", pos*100/filesize); - }while(pos < filesize - 1); - printf("\r\n"); - fclose(wavfile); - fclose(logfile); - if(mpuFile!=NULL){ - fclose(mpuFile); - } - return 0; -} diff --git a/plot_mpu.py b/plot_mpu.py deleted file mode 100755 index de164d64fc054a2990ed48b17f1c56352ceb95d3..0000000000000000000000000000000000000000 --- a/plot_mpu.py +++ /dev/null @@ -1,30 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -import os - - -time, accelX, accelY, accelZ, gyroX, gyroY, gyroZ, magX, magY, magZ = [], [], [], [], [], [], [], [], [], [] - -for f in os.listdir('./'): - if not f.endswith('mpu.csv'): - continue - print(f) - plt.figure() - plt.title(f) - a = np.loadtxt('./'+f, delimiter=',') - time.extend(a[:,0]) - accelX.extend(a[:,1]) - accelY.extend(a[:,2]) - accelZ.extend(a[:,3]) - gyroX.extend(a[:,4]) - gyroY.extend(a[:,5]) - gyroZ.extend(a[:,6]) - magX.extend(a[:,7]) - magY.extend(a[:,8]) - magZ.extend(a[:,9]) - -plt.scatter(time, magX, label='x') -plt.scatter(time, magY, label='y') -plt.scatter(time, magZ, label='z') -plt.legend() -plt.show() diff --git a/stdc2txt.py b/stdc2txt.py deleted file mode 100755 index bb54fe469089d1d4a863ea089e15e0f7c9b12a3a..0000000000000000000000000000000000000000 --- a/stdc2txt.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -import argparse -import torch -import numpy as np - -parser = argparse.ArgumentParser() -parser.add_argument("stdc") -args = parser.parse_args() - -os.system('rm output_stdc.txt') - -f = open('output_stdc.txt', 'a') -m = torch.load(args.stdc) - -for k in m.keys(): - m[k] = m[k].squeeze().cpu() - f.write(k+'\n') - if len(m[k].shape) == 0: - f.write(str(m[k].item())+'\n') - elif len(m[k].shape) == 1: - f.write(",".join(m[k].numpy().astype(str))+'\n') - else : - for l in m[k].squeeze(): - f.write(",".join(l.numpy().astype(str))+'\n') - f.write('\n') - diff --git a/trame IMU.txt b/trame IMU.txt deleted file mode 100755 index 6cf00b858dca64a0bed8747af9f0dff8bacc3362..0000000000000000000000000000000000000000 --- a/trame IMU.txt +++ /dev/null @@ -1,36 +0,0 @@ - commandSPISentUART = HS_DATA_PACKET_FULL_TIMESTAMP; - indexpayloadSPISentUART = 0; -// uint16_t payloadLength = SET_RTCC_DU_RECORDER_AUDIO_LENGHT; -// uint8_t payload[payloadLength]; - uint32_t timstampNow = GetFullTimestamp(); - payloadSPISentUART[indexpayloadSPISentUART++] = 0x08;//Type IMU - payloadSPISentUART[indexpayloadSPISentUART++] = 0x01;//Sensor ID - payloadSPISentUART[indexpayloadSPISentUART++] = 9;//Sensor ID - payloadSPISentUART[indexpayloadSPISentUART++] = 4;//Range 4G - payloadSPISentUART[indexpayloadSPISentUART++] = 16;//16 bits resolution - payloadSPISentUART[indexpayloadSPISentUART++] = 0;//Sampling freq 100 Hz - payloadSPISentUART[indexpayloadSPISentUART++] = 100;//Sampling freq 100 Hz - payloadSPISentUART[indexpayloadSPISentUART++] = 0;//Nb samples - payloadSPISentUART[indexpayloadSPISentUART++] = 1;//Nb samples - payloadSPISentUART[indexpayloadSPISentUART++] = BREAK_UINT32(timstampNow, 3);//supervisorState.localTime.year; - payloadSPISentUART[indexpayloadSPISentUART++] = BREAK_UINT32(timstampNow, 2);//supervisorState.localTime.month; - payloadSPISentUART[indexpayloadSPISentUART++] = BREAK_UINT32(timstampNow, 1);//supervisorState.localTime.day; - payloadSPISentUART[indexpayloadSPISentUART++] = BREAK_UINT32(timstampNow, 0);//supervisorState.localTime.hour; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subAccel.Accel_X_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subAccel.Accel_X_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subAccel.Accel_Y_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subAccel.Accel_Y_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subAccel.Accel_Z_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subAccel.Accel_Z_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subGyro.Gyro_X_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subGyro.Gyro_X_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subGyro.Gyro_Y_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subGyro.Gyro_Y_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subGyro.Gyro_Z_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subGyro.Gyro_Z_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subMag.Mag_X_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subMag.Mag_X_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subMag.Mag_Y_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subMag.Mag_Y_Low; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subMag.Mag_Z_High; - payloadSPISentUART[indexpayloadSPISentUART++] = ICM20948_subMag.Mag_Z_Low;