Add OOK example to simulate Ventus/alecto wind station, reduce granularity to 100Khz
This commit is contained in:
parent
1be11a70e3
commit
ff8fa74517
3 changed files with 437 additions and 199 deletions
|
@ -45,7 +45,6 @@ void SimpleTest(uint64_t Freq)
|
|||
padgpio pad;
|
||||
pad.setlevel(7);
|
||||
|
||||
|
||||
clkgpio clk;
|
||||
clk.print_clock_tree();
|
||||
clk.SetPllNumber(clk_pllc, 0);
|
||||
|
@ -78,7 +77,8 @@ void SimpleTest(uint64_t Freq)
|
|||
static int Ki = 4, Kp = 0, Ka = 0;
|
||||
Kp = Kp + 1;
|
||||
if (Kp > 15)
|
||||
{ Kp=0;
|
||||
{
|
||||
Kp = 0;
|
||||
Ki = Ki + 1;
|
||||
}
|
||||
//Ki=Ki+1;
|
||||
|
@ -108,13 +108,11 @@ void SimpleTest(uint64_t Freq)
|
|||
usleep(1000);
|
||||
}*/
|
||||
clk.disableclk(4);
|
||||
|
||||
}
|
||||
|
||||
void SimpleTestDMA(uint64_t Freq)
|
||||
{
|
||||
|
||||
|
||||
int SR = 200000;
|
||||
int FifoSize = 4096;
|
||||
ngfmdmasync ngfmtest(Freq, SR, 14, FifoSize);
|
||||
|
@ -132,24 +130,20 @@ void SimpleTestDMA(uint64_t Freq)
|
|||
//ngfmtest.SetFrequencySample(Index,((i%10000)>5000)?1000:0);
|
||||
ngfmtest.SetFrequencySample(Index + j, (i % SR) / 10.0);
|
||||
i++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
fprintf(stderr, "End\n");
|
||||
|
||||
ngfmtest.stop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimpleTestFileIQ(uint64_t Freq)
|
||||
{
|
||||
FILE *iqfile = NULL;
|
||||
iqfile = fopen("../ssbtest.iq", "rb");
|
||||
if (iqfile==NULL) printf("input file issue\n");
|
||||
if (iqfile == NULL)
|
||||
printf("input file issue\n");
|
||||
|
||||
#define IQBURST 1280
|
||||
bool stereo = true;
|
||||
|
@ -167,7 +161,6 @@ void SimpleTestFileIQ(uint64_t Freq)
|
|||
{
|
||||
|
||||
CIQBuffer[i] = std::complex<float>(IQBuffer[i * 2] / 32768.0, IQBuffer[i * 2 + 1] / 32768.0);
|
||||
|
||||
}
|
||||
iqtest.SetIQSamples(CIQBuffer, nbread / 2, 1);
|
||||
}
|
||||
|
@ -175,8 +168,6 @@ void SimpleTestFileIQ(uint64_t Freq)
|
|||
{
|
||||
printf("End of file\n");
|
||||
fseek(iqfile, 0, SEEK_SET);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,11 +177,9 @@ void SimpleTestFileIQ(uint64_t Freq)
|
|||
void SimpleTestbpsk(uint64_t Freq)
|
||||
{
|
||||
|
||||
|
||||
clkgpio clk;
|
||||
clk.print_clock_tree();
|
||||
|
||||
|
||||
int SR = 250000;
|
||||
int FifoSize = 10000;
|
||||
int NumberofPhase = 2;
|
||||
|
@ -208,12 +197,10 @@ void SimpleTestbpsk(uint64_t Freq)
|
|||
PhaseBuffer[i] = phase;
|
||||
}
|
||||
biphase.SetPhaseSamples(PhaseBuffer, BURST_SIZE);
|
||||
|
||||
}
|
||||
biphase.stop();
|
||||
}
|
||||
|
||||
|
||||
void SimpleTestSerial()
|
||||
{
|
||||
|
||||
|
@ -232,15 +219,11 @@ void SimpleTestSerial()
|
|||
{
|
||||
int Index = testserial.GetUserMemIndex();
|
||||
|
||||
|
||||
for (int i = 0; i < Available; i++)
|
||||
{
|
||||
|
||||
|
||||
testserial.SetSample(Index + i, i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
testserial.stop();
|
||||
|
@ -250,8 +233,8 @@ void SimpleTestAm(uint64_t Freq)
|
|||
{
|
||||
FILE *audiofile = NULL;
|
||||
audiofile = fopen("../ssbaudio48.wav", "rb");
|
||||
if (audiofile==NULL) printf("input file issue\n");
|
||||
|
||||
if (audiofile == NULL)
|
||||
printf("input file issue\n");
|
||||
|
||||
bool Stereo = true;
|
||||
int SR = 48000;
|
||||
|
@ -283,9 +266,7 @@ void SimpleTestAm(uint64_t Freq)
|
|||
{
|
||||
float x = ((AudioBuffer[i] / 32768.0) / 2.0) * 8.0;
|
||||
amtest.SetAmSample(Index + i, x);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -308,17 +289,230 @@ void SimpleTestOOK(uint64_t Freq)
|
|||
|
||||
unsigned char TabSymbol[FifoSize] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0};
|
||||
|
||||
/*for(size_t i=0;i<FifoSize;i++)
|
||||
{
|
||||
TabSymbol[i]=i%2;
|
||||
}*/
|
||||
|
||||
//while(running)
|
||||
{
|
||||
ook.SetSymbols(TabSymbol, FifoSize);
|
||||
|
||||
}
|
||||
|
||||
void SimpleTestOOKTiming(uint64_t Freq)
|
||||
{
|
||||
|
||||
// 30ms max message
|
||||
ookbursttiming ooksender(Freq, 300000);
|
||||
ookbursttiming::SampleOOKTiming Message[100];
|
||||
|
||||
for (size_t i = 0; i < 100; i += 2)
|
||||
{
|
||||
Message[i].value = 1;
|
||||
Message[i].duration = 50;
|
||||
Message[i + 1].value = 0;
|
||||
Message[i + 1].duration = 2000;
|
||||
}
|
||||
ooksender.SendMessage(Message, 100);
|
||||
}
|
||||
|
||||
uint8_t SetCRC8(uint8_t *addr)
|
||||
{
|
||||
char nibble[8];
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
|
||||
nibble[i * 2] = 0;
|
||||
nibble[i * 2 + 1] = 0;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
nibble[i * 2] |= addr[i * 8 + j] << (j);
|
||||
nibble[i * 2 + 1] |= addr[i * 8 + j + 4] << (j);
|
||||
}
|
||||
fprintf(stderr, "nibble[%d]=%x\nnibble[%d]=%x\n", i * 2, nibble[i * 2], i * 2 + 1, nibble[i * 2 + 1]);
|
||||
}
|
||||
int8_t checksumcalc = 0;
|
||||
if ((nibble[2] & 0x6) != 6)
|
||||
{ // temperature packet
|
||||
fprintf(stderr, "Temp\n");
|
||||
checksumcalc = (0xf - nibble[0] - nibble[1] - nibble[2] - nibble[3] - nibble[4] - nibble[5] - nibble[6] - nibble[7]) & 0xf;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((nibble[3] & 0x7) == 3)
|
||||
{ // Rain packet
|
||||
fprintf(stderr, "Rain\n");
|
||||
checksumcalc = (0x7 + nibble[0] + nibble[1] + nibble[2] + nibble[3] + nibble[4] + nibble[5] + nibble[6] + nibble[7]) & 0xf;
|
||||
}
|
||||
else
|
||||
{ // Wind packet
|
||||
fprintf(stderr, "wind\n");
|
||||
checksumcalc = (0xf - nibble[0] - nibble[1] - nibble[2] - nibble[3] - nibble[4] - nibble[5] - nibble[6] - nibble[7]) & 0xf;
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
addr[32 + i] = (checksumcalc >> (i)) & 1;
|
||||
}
|
||||
fprintf(stderr, "CRC=%x", checksumcalc);
|
||||
return checksumcalc;
|
||||
}
|
||||
|
||||
void AlectoOOK(uint64_t Freq)
|
||||
{
|
||||
|
||||
// 30ms max message
|
||||
ookbursttiming ooksender(Freq, 1200000);
|
||||
ookbursttiming::SampleOOKTiming Message[50 * 6 * 2]; // 46 exactly * 6 times
|
||||
|
||||
ookbursttiming::SampleOOKTiming pulse;
|
||||
pulse.value = 1;
|
||||
pulse.duration = 450;//468
|
||||
|
||||
ookbursttiming::SampleOOKTiming Sync;
|
||||
Sync.value = 0;
|
||||
Sync.duration = 9000;//8956
|
||||
|
||||
ookbursttiming::SampleOOKTiming Zero;
|
||||
Zero.value = 0;
|
||||
Zero.duration = 2000;//2016
|
||||
|
||||
ookbursttiming::SampleOOKTiming One;
|
||||
One.value = 0;
|
||||
One.duration = 4000;
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
//Widn average
|
||||
unsigned char AlectoProtocol[] = {0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0};
|
||||
// Wind gust direction
|
||||
unsigned char AlectoProtocol1[] = {0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
// Temperature
|
||||
unsigned char AlectoProtocolT[] = {0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0};
|
||||
//ID
|
||||
|
||||
/*AlectoProtocol[0]=1;
|
||||
unsigned char LowBattery=0;
|
||||
AlectoProtocol[8]=LowBattery;
|
||||
AlectoProtocol[9]=1;//Wind
|
||||
AlectoProtocol[10]=1;//Wind
|
||||
*/
|
||||
//AlectoProtocol[11] = 1; //Button generated
|
||||
//AlectoProtocol[28] = 1; //Wind
|
||||
//AlectoProtocol1[28] = 1; //Wind
|
||||
|
||||
|
||||
|
||||
//CheckSum n8 = ( 0xf - n0 - n1 - n2 - n3 - n4 - n5 - n6 - n7 ) & 0xf
|
||||
|
||||
|
||||
for (size_t h = 0; h < 6; h++)
|
||||
{
|
||||
|
||||
|
||||
int direction = h*45;
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
AlectoProtocol1[15 + i] = (direction >> (i)) & 0x1;
|
||||
}
|
||||
int Speed = h*10;
|
||||
Speed=Speed/0.2;
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
AlectoProtocol[24 + i] = (direction >> (i)) & 0x1;
|
||||
AlectoProtocol1[24 + i] = (direction >> (i)) & 0x1;
|
||||
}
|
||||
SetCRC8(AlectoProtocol1);
|
||||
SetCRC8(AlectoProtocol);
|
||||
n=0;
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = One;
|
||||
}
|
||||
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = Sync;
|
||||
for (size_t k = 0; k < 6; k++)
|
||||
{
|
||||
for (size_t i = 0; i < 36; i++)
|
||||
{
|
||||
Message[n++] = pulse;
|
||||
if (k % 2 == 0)
|
||||
{
|
||||
if (AlectoProtocol[i] == 0)
|
||||
Message[n++] = Zero;
|
||||
else
|
||||
Message[n++] = One;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AlectoProtocol1[i] == 0)
|
||||
Message[n++] = Zero;
|
||||
else
|
||||
Message[n++] = One;
|
||||
}
|
||||
//Message[n++]=(AlectoProtocol[i]==0)?Zero:One;
|
||||
}
|
||||
|
||||
if (k < 5) // Not last one
|
||||
{
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = Sync;
|
||||
}
|
||||
}
|
||||
}
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = Sync;
|
||||
Message[n++] = pulse;
|
||||
|
||||
fprintf(stderr, "N=%d\n", n);
|
||||
ooksender.SendMessage(Message, n);
|
||||
sleep(10);
|
||||
|
||||
int Temperature = h * 100+200;
|
||||
for (size_t i = 0; i < 12; i++)
|
||||
{
|
||||
AlectoProtocolT[12 + i] = (Temperature >> (i)) & 0x1;
|
||||
}
|
||||
//AlectoProtocolT[11] = 1;
|
||||
//AlectoProtocolT[8] = 1;
|
||||
SetCRC8(AlectoProtocolT);
|
||||
fprintf(stderr, "Temperature sending\n");
|
||||
n = 0;
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = One;
|
||||
}
|
||||
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = Sync;
|
||||
for (size_t k = 0; k < 6; k++)
|
||||
{
|
||||
for (size_t i = 0; i < 36; i++)
|
||||
{
|
||||
Message[n++] = pulse;
|
||||
|
||||
if (AlectoProtocolT[i] == 0)
|
||||
Message[n++] = Zero;
|
||||
else
|
||||
Message[n++] = One;
|
||||
}
|
||||
if (k < 5) // Not last one
|
||||
{
|
||||
//for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = Sync;
|
||||
}
|
||||
}
|
||||
}
|
||||
Message[n++] = pulse;
|
||||
Message[n++] = Sync;
|
||||
Message[n++] = pulse;
|
||||
|
||||
ooksender.SendMessage(Message, n);
|
||||
//sleep(5);
|
||||
sleep(20);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleTestBurstFsk(uint64_t Freq)
|
||||
|
@ -332,13 +526,10 @@ void SimpleTestBurstFsk(uint64_t Freq)
|
|||
|
||||
unsigned char TabSymbol[FifoSize] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0};
|
||||
|
||||
|
||||
//while(running)
|
||||
{
|
||||
|
||||
fsktest.SetSymbols(TabSymbol, FifoSize);
|
||||
|
||||
|
||||
}
|
||||
fsktest.stop();
|
||||
}
|
||||
|
@ -347,10 +538,8 @@ terminate(int num)
|
|||
{
|
||||
running = false;
|
||||
fprintf(stderr, "Caught signal - Terminating\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
|
@ -358,7 +547,8 @@ int main(int argc, char* argv[])
|
|||
if (argc > 1)
|
||||
Freq = atof(argv[1]);
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
std::memset(&sa, 0, sizeof(sa));
|
||||
|
@ -372,7 +562,7 @@ int main(int argc, char* argv[])
|
|||
//SimpleTestDMA(Freq);
|
||||
//SimpleTestAm(Freq);
|
||||
//SimpleTestOOK(Freq);
|
||||
SimpleTestBurstFsk(Freq);
|
||||
|
||||
//SimpleTestBurstFsk(Freq);
|
||||
//SimpleTestOOKTiming(Freq);
|
||||
AlectoOOK(Freq);
|
||||
}
|
||||
|
||||
|
|
|
@ -132,8 +132,8 @@ This program is free software: you can redistribute it and/or modify
|
|||
dma_cb_t *cbp=cbarray;
|
||||
cbp++; // Skip the first which is the Fiiling of Fifo
|
||||
|
||||
unsigned i=0;
|
||||
for(i=0;i<Size;i++)
|
||||
|
||||
for(unsigned i=0;i<Size;i++)
|
||||
{
|
||||
|
||||
sampletab[i]=(Symbols[i]==0)?((Originfsel & ~(7 << 12)) | (0 << 12)):((Originfsel & ~(7 << 12)) | (4 << 12));
|
||||
|
@ -162,3 +162,34 @@ This program is free software: you can redistribute it and/or modify
|
|||
|
||||
}
|
||||
|
||||
//****************************** OOK BURST TIMING *****************************************
|
||||
// SampleRate is set to 0.1MHZ,means 10us granularity, MaxMessageDuration in us
|
||||
ookbursttiming::ookbursttiming(uint64_t TuneFrequency,size_t MaxMessageDuration):ookburst(TuneFrequency,1e5,14,MaxMessageDuration/10)
|
||||
{
|
||||
m_MaxMessage=MaxMessageDuration;
|
||||
ookrenderbuffer=new unsigned char[m_MaxMessage];
|
||||
}
|
||||
|
||||
ookbursttiming::~ookbursttiming()
|
||||
{
|
||||
if(ookrenderbuffer!=nullptr)
|
||||
delete []ookrenderbuffer;
|
||||
}
|
||||
|
||||
void ookbursttiming::SendMessage(SampleOOKTiming *TabSymbols,size_t Size)
|
||||
{
|
||||
size_t n=0;
|
||||
for (size_t i=0;i<Size;i++)
|
||||
{
|
||||
for(size_t j=0;j<TabSymbols[i].duration/10;j++)
|
||||
{
|
||||
ookrenderbuffer[n++]=TabSymbols[i].value;
|
||||
if(n>=m_MaxMessage)
|
||||
{
|
||||
fprintf(stderr,"OOK Message too long abort time(%d/%d)\n",n,m_MaxMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
SetSymbols(ookrenderbuffer,n);
|
||||
}
|
||||
|
|
|
@ -20,4 +20,21 @@ class ookburst:public bufferdma,public clkgpio,public pwmgpio,public pcmgpio
|
|||
void SetSymbols(unsigned char *Symbols,uint32_t Size);
|
||||
};
|
||||
|
||||
class ookbursttiming:public ookburst
|
||||
{
|
||||
protected:
|
||||
unsigned char *ookrenderbuffer=nullptr;
|
||||
size_t m_MaxMessage=0;
|
||||
public:
|
||||
typedef struct SampleOOKTiming
|
||||
{
|
||||
unsigned char value;
|
||||
size_t duration;
|
||||
} SampleOOKTiming;
|
||||
|
||||
ookbursttiming(uint64_t TuneFrequency,size_t MaxMessageDuration);
|
||||
~ookbursttiming();
|
||||
void SendMessage(SampleOOKTiming *TabSymbols,size_t Size);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue