Commit f16596a0 authored by Antoine Lemasson's avatar Antoine Lemasson
Browse files

Correct Byte swap pb

parent 891c47ed
......@@ -429,8 +429,9 @@ string MFMCommonFrame::GetHeaderDisplay(char* infotext) const{
unsigned char MFMCommonFrame::GetFrameEndianness() const{
/// Return BIG_ENDIAN or LITTLE_ENDIAN value of current computer for metaType format
unsigned char tmp = pHeader->hd.metaType & MFM_ENDIANNESS_MSK;
return (tmp);
unsigned char tmp = (pHeader->hd.metaType & MFM_ENDIANNESS_MSK);
//cout << "Mask " << hex << MFM_ENDIANNESS_MSK << " " << pHeader->hd.metaType << " " << (pHeader->hd.metaType & MFM_ENDIANNESS_MSK) << dec << endl;
return (tmp);
}
//_______________________________________________________________________________
......@@ -534,9 +535,10 @@ void MFMCommonFrame::SetPointers(void * pt) {
}
pHeader = (MFM_topcommon_header*) pData;
fFrameIsBigEndian = (GetFrameEndianness() == MFM_BIG_ENDIAN);
//cout << "Endianness " << GetFrameEndianness() << endl;
pData_char = (char*) pData;
SetUnitBlockSizeFromFrameData();
//SetUserDataPointer();
//SetUserDataPointer();
}
//_______________________________________________________________________________
void MFMCommonFrame::SetAttributs(void * pt) {
......@@ -550,7 +552,7 @@ void MFMCommonFrame::SetAttributs(void * pt) {
SetFrameSizeFromFrameData();
SetTimeStampFromFrameData();
SetEventNumberFromFrameData();
SetUserDataPointer();
SetUserDataPointer();
}
//_______________________________________________________________________________
void MFMCommonFrame::CopyFrameAndResizeFrameIfNecessary(MFMCommonFrame* frame){
......@@ -789,7 +791,7 @@ int MFMCommonFrame::ReadInFileold(int *lun, char** vector, int * vectorsize) {
/// lun : descriptor of file (given by a previous open)
/// vector : pointer on pointer will contain frame . if size isn't big, a new value of pointer
/// vectorsize of this pointer
/// return size of read frame.
/// return size of read frame.
int count = 0;
int framesize = 0;
char* vectornew = NULL;
......@@ -804,7 +806,7 @@ int MFMCommonFrame::ReadInFileold(int *lun, char** vector, int * vectorsize) {
cout << " Error in read file\n";
return count;
}
MFMCommonFrame::SetAttributs((*vector));
MFMCommonFrame::SetAttributs((*vector));
framesize = GetFrameSize();
if (framesize > 1000000000)
fError.TreatError(2, framesize, "Crazy Frame size > 1000000000");
......
......@@ -26,6 +26,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <byteswap.h>
#pragma pack(push, 1)// allow strict alignment
#define MFM_ENDIANNESS_MSK 0x80
......@@ -288,7 +290,9 @@ inline void SwapInt64(uint64_t *Buf, int nbByte =8, int repeat=1) {
tmp1 = (unsigned char*) Bufloc;
for (int i = 0; i < nbByte; i++) {
tempo = ((tempo) << 8);
memcpy(tmp2, tmp1 + i, 1);
// memcpy(tmp2, tmp1 + i, 1);
*tmp2 = tmp1[i];
}
*Bufloc = tempo;
}
......@@ -299,19 +303,26 @@ inline void SwapInt16(uint16_t *Buf, int repeat=1) {
/// Swap a 16 bits(2 Bytes) integer to do endianess conversion
/// Buf : pointer on integer to convert
/// repeat: nb of repeat in case of a vector to convert. default =1
typedef struct mot16 {
unsigned char Byte1;
unsigned char Byte2;
} SW_MOT16;
SW_MOT16 Temp, *Mot16;
Mot16 = (SW_MOT16 *) Buf;
for (int i = 0; i < repeat; i++, Mot16++) {
Temp.Byte1 = Mot16->Byte2;
Temp.Byte2 = Mot16->Byte1;
*Mot16 = Temp;
}
// typedef struct mot16 {
// unsigned char Byte1;
// unsigned char Byte2;
// } SW_MOT16;
// SW_MOT16 Temp, *Mot16;
//// cout << "Initial Buf " << *Buf << hex << " " << *Buf << dec << endl;
// Mot16 = (SW_MOT16 *) Buf;
// for (int i = 0; i < repeat; i++, Mot16++) {
// Temp.Byte1 = Mot16->Byte2;
// Temp.Byte2 = Mot16->Byte1;
// *Mot16 = Temp;
//// cout << "swap " << endl;
//// cout << "Final Buf " << *Buf << hex << " " << *Buf<< dec << endl;
// }
// cout << "Initial Buf " << *Buf << hex << " 0x" << *Buf<< dec << endl;
for (int i = 0; i < repeat; i++)
*(Buf+i) = __bswap_16 (*(Buf+i));
// cout << (*Buf && 0xFF00) << endl;
// cout << "Final Buf " << *Buf << hex << " 0x" << *Buf<< dec << endl;
}
//_______________________________________________________________________________
inline uint64_t GenerateATimeStamp() {
......@@ -343,7 +354,8 @@ inline void SwapInt32(uint32_t *Buf, int nbByte=4, int repeat=1) {
tmp2 = (unsigned char*) (&tempo);
for (int i = 0; i < nbByte; i++) {
tempo = ((uint32_t) (tempo) << 8);
memcpy(tmp2, tmp1 + i, 1);
// memcpy(tmp2, tmp1 + i, 1);
*tmp2 = tmp1[i];
}
*Buf = tempo;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment