Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding demodulator for ARGOS 4 PTT-VLD-A4 (A4-SS-TER-SP-0079-CNES) #12

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
70 changes: 35 additions & 35 deletions ARGOS4VLDdemod/ByteSync.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ int FindSyncWords(unsigned char *bitStreamIn, double *bitStreamInTime, unsigned
static int oldest = 0, syncIndicator, frameByteIdx, packetShiftFlag=0, bitIdx;
static unsigned char zero=0, one=1;
static unsigned char byte=0;

int packetsFound=0;
unsigned long idx;

if(firstTime == 1)
{
firstTime = 0;
Expand All @@ -37,26 +37,26 @@ int FindSyncWords(unsigned char *bitStreamIn, double *bitStreamInTime, unsigned
}
memset(historyBufferCirc, 48, sizeof(char) * syncWordLength);
}

//loop through samples

for(idx = 0; idx < nSamples; idx++)
{
//Enter this loop if we found a syncword last time around
if(packetShiftFlag == 1)
{
if(bitStreamIn[idx]=='0')
if(bitStreamIn[idx]=='0')
{
byte = byte << 1; //This is a zero, just shift
byte = byte | zero;
}
else
{
byte = byte << 1; //This is a one, set the bit then shift
byte = byte << 1; //This is a one, set the bit then shift
byte = byte | one;
}
bitIdx++;

bitIdx++;
if(bitIdx > 7)
{
//minorFrame[frameByteIdx]=byte;
Expand All @@ -65,40 +65,40 @@ int FindSyncWords(unsigned char *bitStreamIn, double *bitStreamInTime, unsigned
byte = 0;
bitIdx = 0;
frameByteIdx++;
if(frameByteIdx > 8)
if(frameByteIdx > 24)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me what this change does ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. It took me a while to find where the longer ARGOS 4 VLD Long messages were being truncated - and its there. That change just lets 24 bytes of data through instead of 8. Actually I think we only need 18 bytes, not 24. It might be nice to add the expected message length as an arg?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, good call. The best way would be to detect the end of the packet.... not so easy though!!

Is there a payload length byte we could read in to make a guess on??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed:
The sync is 24 bits: 0xAC5353
The two bits after that define the length. If they are 0b00 then the total number of encoded data bits after that is 68. If the two length bits are 0b11 then 3*68 encoded data bits follow.
Note: this is only true for ARGOS 4 VLD. The other PTT formats use quite different length fields.
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but... The encoding process reduces the 68 bits down to 45. So, the true answer, in terms of how many bits to process, is:

  • 0b00 indicates that 45 bits follow
  • 0b11 indicates that 3*45 bits follow

{
packetShiftFlag = 0;
fprintf(packetFile,"\n");
printf("\n");
}
}
}
//overwrite oldest bit in cir buffer with newest bit
historyBufferCirc[oldest] = bitStreamIn[idx];
}

//overwrite oldest bit in cir buffer with newest bit
historyBufferCirc[oldest] = bitStreamIn[idx];
//printf("h[%d]=%c\n",oldest, historyBufferCirc[oldest]);
syncIndicator = 1; //set to 1 to enable, any other to disable
//Look for syncword
for (idx2 = 0; idx2 < syncWordLength; idx2++)


syncIndicator = 1; //set to 1 to enable, any other to disable

//Look for syncword
for (idx2 = 0; idx2 < syncWordLength; idx2++)
{
//compare syncword bytes to appropriate circular buffer bytes

if (syncWord[idx2] != historyBufferCirc[(oldest + idx2 + 1) % syncWordLength])
{
syncIndicator = 0;
break;
}
}

if(syncIndicator == 1 && packetShiftFlag == 0)
{
fprintf(packetFile,"%.5f ",bitStreamInTime[idx]);
//fprintf(packetFile,"%.2X ",0b11100010);
//fprintf(packetFile,"%.2X ",0b11110000);

printf("%.5f ",bitStreamInTime[idx]);
frameByteIdx = 2;
packetShiftFlag = 1;
Expand All @@ -108,29 +108,29 @@ int FindSyncWords(unsigned char *bitStreamIn, double *bitStreamInTime, unsigned
zero = 0;
one = 1;
//bitIdx=;
}
}

//Look for Inverse Syncword
syncIndicator = 0; //set to 1 to enable, any other to disable
for (idx2 = 0; idx2 < syncWordLength; idx2++)
syncIndicator = 1; //set to 1 to enable, any other to disable
for (idx2 = 0; idx2 < syncWordLength; idx2++)
{
//compare syncword bytes to appropriate circular buffer bytes
//printf("sw[%d] == hst[%d] , %c == %c, ", idx2,(oldest + idx2 + 1) % syncWordLength,syncWord[idx2],historyBufferCirc[(oldest + idx2) % syncWordLength]);

if (syncWord[idx2] == historyBufferCirc[(oldest + idx2 + 1) % syncWordLength])
{
syncIndicator = 0;
//printf("NO\n\n");
break;
}
}
}

if(syncIndicator == 1 && packetShiftFlag == 0)
{
fprintf(packetFile,"%.5fi ",bitStreamInTime[idx]);
//fprintf(packetFile,"%.2X ",0b11100010);
//fprintf(packetFile,"%.2X ",0b11110000);

printf("\t%.5fi ",bitStreamInTime[idx]);
frameByteIdx = 2;
packetShiftFlag = 1;
Expand All @@ -140,10 +140,10 @@ int FindSyncWords(unsigned char *bitStreamIn, double *bitStreamInTime, unsigned
zero = 1;
one = 0;
//bitIdx=;
}
//advance oldest bit pointer
}

//advance oldest bit pointer
oldest = (oldest + 1) % syncWordLength;
}
return packetsFound;
}
return packetsFound;
}
2 changes: 1 addition & 1 deletion ARGOS4VLDdemod/RAW_Plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
break

fig, ax = plt.subplots()
ax.plot(x, y)
ax.plot(x, y, 'o-')

ax.set(xlabel='sample', ylabel='signal',
title=sys.argv[1])
Expand Down
Binary file modified ARGOS4VLDdemod/demodARGOS.exe
Binary file not shown.
28 changes: 14 additions & 14 deletions ARGOS4VLDdemod/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, char **argv)
double dspMaxCarrierDeviation = DSP_MAX_CARRIER_DEVIATION;

//unsigned int CheckSum1=0, CheckSum2=0, CheckSum3=0;
int nFrames=0, totalFrames=0,c;
int nFrames=0, totalFrames=0, c;

unsigned char *dataStreamBits=NULL;
char *inFileName=NULL;
Expand Down Expand Up @@ -303,25 +303,25 @@ int main(int argc, char **argv)
//nSymbols = MMClockRecovery(dataStreamReal, waveDataTime, nSamples, dataStreamSymbols, Fs, 3, 0.15);
nSymbols = GardenerClockRecovery(dataStreamReal, waveDataTime, nSamples, dataStreamSymbols, Fs, DSP_BAUD, DSP_GDNR_ERR_LIM, DSP_GDNR_GAIN);

if(outputRawFiles == 1)
{
for(idx=0; idx < nSymbols; idx++)
{
fwrite(&dataStreamSymbols[idx],sizeof(double),1,rawOutFilePtr);
}
}

//nBits = ManchesterDecode(dataStreamSymbols, waveDataTime, nSymbols, dataStreamBits, DSP_MCHSTR_RESYNC_LVL);
nBits = ManchesterDecode(dataStreamSymbols, waveDataTime, nSymbols, dataStreamBits, dspManchesterResyncLevel);

// if(outputRawFiles == 1)
// {
// for(idx=0; idx < nBits; idx++)
// for(idx=0; idx < nSymbols; idx++)
// {
// fwrite(&dataStreamBits[idx],sizeof(char),1,rawOutFilePtr);
// fwrite(&dataStreamSymbols[idx],sizeof(double),1,rawOutFilePtr);
// }
// }

//nBits = ManchesterDecode(dataStreamSymbols, waveDataTime, nSymbols, dataStreamBits, DSP_MCHSTR_RESYNC_LVL);
nBits = ManchesterDecode(dataStreamSymbols, waveDataTime, nSymbols, dataStreamBits, dspManchesterResyncLevel);

if(outputRawFiles == 1)
{
for(idx=0; idx < nBits; idx++)
{
fwrite(&dataStreamBits[idx],sizeof(char),1,rawOutFilePtr);
}
}

// There's no need to invert the data. FindSyncWords automatically checks for the sync word and its inverse.

// ARGOS 4 PTT-VLD-A4 A4-SS-TER-SP-0079-CNES defines a sync pattern of 0xAC5353
Expand Down