2018-03-16 22:03:06 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include "../src/librpitx.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "stdio.h"
|
|
|
|
#include <cstring>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
bool running = true;
|
2018-06-14 21:49:20 +08:00
|
|
|
/*int
|
|
|
|
gcd ( int a, int b )
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
while ( a != 0 ) {
|
|
|
|
c = a; a = b%a; b = c;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}*/
|
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
uint64_t gcd(uint64_t x, uint64_t y)
|
2018-06-14 21:49:20 +08:00
|
|
|
{
|
|
|
|
return y == 0 ? x : gcd(y, x % y);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t lcm(uint64_t x, uint64_t y)
|
|
|
|
{
|
|
|
|
return x * y / gcd(x, y);
|
|
|
|
}
|
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
void SimpleTest(uint64_t Freq)
|
|
|
|
{
|
|
|
|
generalgpio genpio;
|
2018-12-20 23:40:16 +08:00
|
|
|
fprintf(stderr, "GPIOPULL =%x\n", genpio.gpioreg[GPPUDCLK0]);
|
|
|
|
|
|
|
|
#define PULL_OFF 0
|
|
|
|
#define PULL_DOWN 1
|
|
|
|
#define PULL_UP 2
|
|
|
|
genpio.gpioreg[GPPUD] = 1; //PULL_DOWN;
|
|
|
|
usleep(150);
|
|
|
|
genpio.gpioreg[GPPUDCLK0] = (1 << 4); //GPIO CLK is GPIO 4
|
|
|
|
usleep(150);
|
|
|
|
genpio.gpioreg[GPPUDCLK0] = (0); //GPIO CLK is GPIO 4
|
|
|
|
|
2018-06-14 21:49:20 +08:00
|
|
|
//genpio.setpulloff(4);
|
|
|
|
|
|
|
|
padgpio pad;
|
|
|
|
pad.setlevel(7);
|
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
clkgpio clk;
|
|
|
|
clk.print_clock_tree();
|
2018-12-20 23:40:16 +08:00
|
|
|
clk.SetPllNumber(clk_pllc, 0);
|
|
|
|
|
2018-06-14 21:49:20 +08:00
|
|
|
//clk.SetAdvancedPllMode(true);
|
|
|
|
//clk.SetPLLMasterLoop(0,4,0);
|
2018-03-30 16:23:20 +08:00
|
|
|
//clk.Setppm(+7.7);
|
2018-12-20 23:40:16 +08:00
|
|
|
clk.SetCenterFrequency(Freq, 1000);
|
|
|
|
double freqresolution = clk.GetFrequencyResolution();
|
|
|
|
double RealFreq = clk.GetRealFrequency(0);
|
|
|
|
fprintf(stderr, "Frequency resolution=%f Error freq=%f\n", freqresolution, RealFreq);
|
|
|
|
int Deviation = 0;
|
2018-03-16 22:03:06 +08:00
|
|
|
clk.SetFrequency(000);
|
2018-12-20 23:40:16 +08:00
|
|
|
|
2018-06-14 21:49:20 +08:00
|
|
|
clk.enableclk(4);
|
|
|
|
usleep(100);
|
|
|
|
//clk.SetClkDivFrac(100,0); // If mash!=0 update doesnt seem to work
|
2018-12-20 23:40:16 +08:00
|
|
|
int count = 0;
|
|
|
|
while (running)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-06-14 21:49:20 +08:00
|
|
|
//clk.SetMasterMultFrac(44,(1<<count));
|
|
|
|
//uint32_t N=(1<<18);
|
2018-12-20 23:40:16 +08:00
|
|
|
uint32_t N = (1 << 13) * count;
|
2018-06-14 21:49:20 +08:00
|
|
|
|
|
|
|
//clk.SetMasterMultFrac(34,N);
|
2018-12-20 23:40:16 +08:00
|
|
|
printf("count =%d gcd%d spurious%f N=%x %f\n", count, lcm(N, 1 << 20), (double)gcd(1 << 20, N) * 19.2e6 / (double)(1 << 20), N, N / (float)(1 << 20));
|
|
|
|
count = (count + 1) % 128;
|
2018-06-14 21:49:20 +08:00
|
|
|
//usleep(10000000);
|
2018-12-20 23:40:16 +08:00
|
|
|
int a = getc(stdin);
|
|
|
|
static int Ki = 4, Kp = 0, Ka = 0;
|
|
|
|
Kp = Kp + 1;
|
|
|
|
if (Kp > 15)
|
|
|
|
{
|
|
|
|
Kp = 0;
|
|
|
|
Ki = Ki + 1;
|
2018-06-14 21:49:20 +08:00
|
|
|
}
|
|
|
|
//Ki=Ki+1;
|
2018-12-20 23:40:16 +08:00
|
|
|
if (Ki > 11)
|
2018-06-14 21:49:20 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
Ki = 4;
|
|
|
|
Ka++;
|
2018-06-14 21:49:20 +08:00
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
Ki = Kp;
|
|
|
|
|
|
|
|
clk.SetClkDivFrac(count, count);
|
|
|
|
|
2018-06-14 21:49:20 +08:00
|
|
|
//clk.SetPLLMasterLoop(Ki,4,Ka);
|
|
|
|
//clk.SetPLLMasterLoop(2,4,0);
|
|
|
|
//clk.SetPLLMasterLoop(3,4,0); //best one
|
2018-12-20 23:40:16 +08:00
|
|
|
|
2018-06-14 21:49:20 +08:00
|
|
|
//printf("Ki=%d :Kp %d Ka %d\n ",Ki,Kp,Ka);
|
|
|
|
/*clk.SetFrequency(000);
|
2018-03-21 18:26:47 +08:00
|
|
|
sleep(5);
|
|
|
|
clk.SetFrequency(freqresolution);
|
2018-06-14 21:49:20 +08:00
|
|
|
sleep(5);*/
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
2018-03-30 16:23:20 +08:00
|
|
|
/*
|
|
|
|
for(int i=0;i<100000;i+=1)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-03-30 16:23:20 +08:00
|
|
|
clk.SetFrequency(0);
|
2018-03-16 22:03:06 +08:00
|
|
|
usleep(1000);
|
|
|
|
}*/
|
|
|
|
clk.disableclk(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTestDMA(uint64_t Freq)
|
|
|
|
{
|
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
int SR = 200000;
|
|
|
|
int FifoSize = 4096;
|
|
|
|
ngfmdmasync ngfmtest(Freq, SR, 14, FifoSize);
|
|
|
|
for (int i = 0; running;)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
|
|
|
//usleep(10);
|
2018-12-20 23:40:16 +08:00
|
|
|
usleep(FifoSize * 1000000.0 * 3.0 / (4.0 * SR));
|
|
|
|
int Available = ngfmtest.GetBufferAvailable();
|
|
|
|
if (Available > FifoSize / 2)
|
|
|
|
{
|
|
|
|
int Index = ngfmtest.GetUserMemIndex();
|
2018-03-16 22:03:06 +08:00
|
|
|
//printf("GetIndex=%d\n",Index);
|
2018-12-20 23:40:16 +08:00
|
|
|
for (int j = 0; j < Available; j++)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
|
|
|
//ngfmtest.SetFrequencySample(Index,((i%10000)>5000)?1000:0);
|
2018-12-20 23:40:16 +08:00
|
|
|
ngfmtest.SetFrequencySample(Index + j, (i % SR) / 10.0);
|
2018-03-16 22:03:06 +08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
fprintf(stderr, "End\n");
|
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
ngfmtest.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTestFileIQ(uint64_t Freq)
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
FILE *iqfile = NULL;
|
|
|
|
iqfile = fopen("../ssbtest.iq", "rb");
|
|
|
|
if (iqfile == NULL)
|
|
|
|
printf("input file issue\n");
|
|
|
|
|
|
|
|
#define IQBURST 1280
|
|
|
|
bool stereo = true;
|
|
|
|
int SR = 48000;
|
|
|
|
int FifoSize = 512;
|
|
|
|
iqdmasync iqtest(Freq, SR, 14, FifoSize, MODE_IQ);
|
|
|
|
short IQBuffer[IQBURST * 2];
|
|
|
|
std::complex<float> CIQBuffer[IQBURST];
|
|
|
|
while (running)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
int nbread = fread(IQBuffer, sizeof(short), IQBURST * 2, iqfile);
|
|
|
|
if (nbread > 0)
|
2018-03-21 18:26:47 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
for (int i = 0; i < nbread / 2; i++)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
CIQBuffer[i] = std::complex<float>(IQBuffer[i * 2] / 32768.0, IQBuffer[i * 2 + 1] / 32768.0);
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
iqtest.SetIQSamples(CIQBuffer, nbread / 2, 1);
|
2018-03-21 18:26:47 +08:00
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
else
|
2018-03-21 18:26:47 +08:00
|
|
|
{
|
|
|
|
printf("End of file\n");
|
2018-12-20 23:40:16 +08:00
|
|
|
fseek(iqfile, 0, SEEK_SET);
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
}
|
2018-03-21 18:26:47 +08:00
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
iqtest.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTestbpsk(uint64_t Freq)
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
clkgpio clk;
|
|
|
|
clk.print_clock_tree();
|
2018-10-03 22:05:01 +08:00
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
int SR = 250000;
|
|
|
|
int FifoSize = 10000;
|
|
|
|
int NumberofPhase = 2;
|
|
|
|
phasedmasync biphase(Freq, SR, NumberofPhase, 14, FifoSize);
|
2018-10-03 22:05:01 +08:00
|
|
|
padgpio pad;
|
2018-12-20 23:40:16 +08:00
|
|
|
pad.setlevel(7);
|
|
|
|
int lastphase = 0;
|
|
|
|
#define BURST_SIZE 100
|
2018-10-03 22:05:01 +08:00
|
|
|
int PhaseBuffer[BURST_SIZE];
|
2018-12-20 23:40:16 +08:00
|
|
|
while (running)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
for (int i = 0; i < BURST_SIZE; i++)
|
2018-10-03 22:05:01 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
int phase = (rand() % NumberofPhase);
|
|
|
|
PhaseBuffer[i] = phase;
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
biphase.SetPhaseSamples(PhaseBuffer, BURST_SIZE);
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
biphase.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTestSerial()
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
bool stereo = true;
|
|
|
|
int SR = 10000;
|
|
|
|
int FifoSize = 1024;
|
|
|
|
bool dualoutput = true;
|
|
|
|
serialdmasync testserial(SR, 14, FifoSize, dualoutput);
|
|
|
|
|
|
|
|
while (running)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
usleep(10);
|
2018-12-20 23:40:16 +08:00
|
|
|
int Available = testserial.GetBufferAvailable();
|
|
|
|
if (Available > 256)
|
|
|
|
{
|
|
|
|
int Index = testserial.GetUserMemIndex();
|
|
|
|
|
|
|
|
for (int i = 0; i < Available; i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
testserial.SetSample(Index + i, i);
|
|
|
|
}
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
testserial.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTestAm(uint64_t Freq)
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
FILE *audiofile = NULL;
|
|
|
|
audiofile = fopen("../ssbaudio48.wav", "rb");
|
|
|
|
if (audiofile == NULL)
|
|
|
|
printf("input file issue\n");
|
2018-03-16 22:03:06 +08:00
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
bool Stereo = true;
|
|
|
|
int SR = 48000;
|
|
|
|
int FifoSize = 512;
|
|
|
|
amdmasync amtest(Freq, SR, 14, FifoSize);
|
2018-03-16 22:03:06 +08:00
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
short AudioBuffer[128 * 2];
|
2018-03-21 18:26:47 +08:00
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
while (running)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
|
|
|
//usleep(FifoSize*1000000.0*1.0/(8.0*SR));
|
|
|
|
usleep(100);
|
2018-12-20 23:40:16 +08:00
|
|
|
int Available = amtest.GetBufferAvailable();
|
|
|
|
if (Available > 256)
|
|
|
|
{
|
|
|
|
int Index = amtest.GetUserMemIndex();
|
|
|
|
int nbread = fread(AudioBuffer, sizeof(short), 128 * 2, audiofile);
|
|
|
|
if (nbread > 0)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < nbread / 2; i++)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
if (!Stereo)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
float x = ((AudioBuffer[i * 2] / 32768.0) + (AudioBuffer[i * 2 + 1] / 32768.0)) / 4.0;
|
|
|
|
amtest.SetAmSample(Index + i, x);
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
float x = ((AudioBuffer[i] / 32768.0) / 2.0) * 8.0;
|
|
|
|
amtest.SetAmSample(Index + i, x);
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
else
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
|
|
|
printf("End of file\n");
|
2018-12-20 23:40:16 +08:00
|
|
|
fseek(audiofile, 0, SEEK_SET);
|
2018-03-16 22:03:06 +08:00
|
|
|
//break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
amtest.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTestOOK(uint64_t Freq)
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
int SR = 1000;
|
|
|
|
int FifoSize = 21; //24
|
|
|
|
ookburst ook(Freq, SR, 14, FifoSize);
|
|
|
|
|
|
|
|
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};
|
|
|
|
|
|
|
|
ook.SetSymbols(TabSymbol, FifoSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleTestOOKTiming(uint64_t Freq)
|
|
|
|
{
|
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
// 300ms max message
|
2018-12-20 23:40:16 +08:00
|
|
|
ookbursttiming ooksender(Freq, 300000);
|
|
|
|
ookbursttiming::SampleOOKTiming Message[100];
|
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
for (size_t i = 0; i < 10; i += 2)
|
2018-12-20 23:40:16 +08:00
|
|
|
{
|
|
|
|
Message[i].value = 1;
|
2018-12-23 03:58:11 +08:00
|
|
|
Message[i].duration = 5000;
|
2018-12-20 23:40:16 +08:00
|
|
|
Message[i + 1].value = 0;
|
2018-12-23 03:58:11 +08:00
|
|
|
Message[i + 1].duration = 15000;
|
2018-12-20 23:40:16 +08:00
|
|
|
}
|
2018-12-23 03:58:11 +08:00
|
|
|
ooksender.SendMessage(Message, 10);
|
2018-12-20 23:40:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2018-12-23 03:58:11 +08:00
|
|
|
pulse.duration = 450; //468
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming Sync;
|
|
|
|
Sync.value = 0;
|
2018-12-23 03:58:11 +08:00
|
|
|
Sync.duration = 9000; //8956
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming Zero;
|
|
|
|
Zero.value = 0;
|
2018-12-23 03:58:11 +08:00
|
|
|
Zero.duration = 2000; //2016
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
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++)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
int direction = h * 45;
|
|
|
|
for (size_t i = 0; i < 9; 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;
|
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
Message[n++] = pulse;
|
2018-12-23 03:58:11 +08:00
|
|
|
Message[n++] = Sync;
|
|
|
|
for (size_t k = 0; k < 6; k++)
|
2018-12-20 23:40:16 +08:00
|
|
|
{
|
2018-12-23 03:58:11 +08:00
|
|
|
for (size_t i = 0; i < 36; i++)
|
2018-12-20 23:40:16 +08:00
|
|
|
{
|
2018-12-23 03:58:11 +08:00
|
|
|
Message[n++] = pulse;
|
|
|
|
if (k % 2 == 0)
|
|
|
|
{
|
|
|
|
if (AlectoProtocol[i] == 0)
|
|
|
|
Message[n++] = Zero;
|
|
|
|
else
|
|
|
|
Message[n++] = One;
|
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
else
|
2018-12-23 03:58:11 +08:00
|
|
|
{
|
|
|
|
if (AlectoProtocol1[i] == 0)
|
|
|
|
Message[n++] = Zero;
|
|
|
|
else
|
|
|
|
Message[n++] = One;
|
|
|
|
}
|
|
|
|
//Message[n++]=(AlectoProtocol[i]==0)?Zero:One;
|
2018-12-20 23:40:16 +08:00
|
|
|
}
|
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
if (k < 5) // Not last one
|
2018-12-20 23:40:16 +08:00
|
|
|
{
|
2018-12-23 03:58:11 +08:00
|
|
|
for (size_t i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
Message[n++] = pulse;
|
|
|
|
Message[n++] = Sync;
|
|
|
|
}
|
2018-12-20 23:40:16 +08:00
|
|
|
}
|
|
|
|
}
|
2018-12-23 03:58:11 +08:00
|
|
|
Message[n++] = pulse;
|
|
|
|
Message[n++] = Sync;
|
|
|
|
Message[n++] = pulse;
|
2018-12-20 23:40:16 +08:00
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
fprintf(stderr, "N=%d\n", n);
|
|
|
|
ooksender.SendMessage(Message, n);
|
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
int Temperature = h * 100 + 200;
|
2018-12-20 23:40:16 +08:00
|
|
|
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);
|
2018-12-23 03:58:11 +08:00
|
|
|
sleep(2);
|
2018-12-20 23:40:16 +08:00
|
|
|
}
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
void RfSwitchOOK(uint64_t Freq)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* From http://elektronikforumet.com/wiki/index.php/RF_Protokoll_-_Proove_self_learning
|
|
|
|
* Proove packet structure (32 bits):
|
|
|
|
* HHHH HHHH HHHH HHHH HHHH HHHH HHGO CCEE
|
|
|
|
* H = The first 26 bits are transmitter unique codes, and it is this code that the receiver “learns” to recognize.
|
|
|
|
* G = Group code. Set to 0 for on, 1 for off.
|
|
|
|
* O = On/Off bit. Set to 0 for on, 1 for off.
|
|
|
|
* C = Channel bits.
|
|
|
|
* E = Unit bits. Device to be turned on or off. Unit #1 = 00, #2 = 01, #3 = 10.
|
|
|
|
* Physical layer.
|
|
|
|
* Every bit in the packets structure is sent as two physical bits.
|
|
|
|
* Where the second bit is the inverse of the first, i.e. 0 -> 01 and 1 -> 10.
|
|
|
|
* Example: 10101110 is sent as 1001100110101001
|
|
|
|
* The sent packet length is thus 64 bits.
|
|
|
|
* A message is made up by a Sync bit followed by the Packet bits and ended by a Pause bit.
|
|
|
|
* Every message is repeated four times.
|
|
|
|
* */
|
|
|
|
ookbursttiming ooksender(Freq, 1200000);
|
2019-01-02 05:45:37 +08:00
|
|
|
ookbursttiming::SampleOOKTiming Message[50 * 6 * 2];
|
2018-12-23 03:58:11 +08:00
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming pulse;
|
|
|
|
pulse.value = 1;
|
|
|
|
pulse.duration = 200; //468
|
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming Sync;
|
|
|
|
Sync.value = 0;
|
|
|
|
Sync.duration = 10700; //8956
|
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming Zero;
|
|
|
|
Zero.value = 0;
|
|
|
|
Zero.duration = 1300; //2016
|
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming One;
|
|
|
|
One.value = 0;
|
|
|
|
One.duration = 300;
|
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming preamble;
|
|
|
|
preamble.value = 0;
|
|
|
|
preamble.duration = 2600;
|
|
|
|
|
2019-01-02 05:45:37 +08:00
|
|
|
unsigned int ID = 32288767;
|
|
|
|
|
|
|
|
ID = ID << 6;
|
2018-12-23 03:58:11 +08:00
|
|
|
|
|
|
|
unsigned char MessageTx[4];
|
2019-01-02 05:45:37 +08:00
|
|
|
|
|
|
|
int group = 1;
|
|
|
|
int Channel = 3;
|
|
|
|
int unit = 2;
|
|
|
|
int power = 1;
|
2018-12-23 03:58:11 +08:00
|
|
|
|
|
|
|
ookbursttiming::SampleOOKTiming MessageOOK[200];
|
2019-01-02 05:45:37 +08:00
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
for (int times = 0; times < 20; times++)
|
|
|
|
{
|
2019-01-02 05:45:37 +08:00
|
|
|
power = times % 2;
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
MessageTx[i] = ID >> (8 * (3 - i));
|
|
|
|
MessageTx[3] |= (group & 0x1) << 5;
|
|
|
|
MessageTx[3] |= (~power & 0x1) << 4;
|
|
|
|
MessageTx[3] |= (Channel & 0x3) << 2;
|
|
|
|
MessageTx[3] |= (unit & 0x3);
|
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
MessageOOK[n++] = pulse;
|
|
|
|
MessageOOK[n++] = preamble;
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
{
|
2019-01-02 05:45:37 +08:00
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
for (int k = 0; k < 8; k++)
|
|
|
|
{
|
|
|
|
if (((MessageTx[j] >> (7 - k)) & 1) == 0)
|
|
|
|
{
|
|
|
|
MessageOOK[n++] = pulse;
|
|
|
|
MessageOOK[n++] = Zero;
|
|
|
|
MessageOOK[n++] = pulse;
|
|
|
|
MessageOOK[n++] = One;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MessageOOK[n++] = pulse;
|
|
|
|
MessageOOK[n++] = One;
|
|
|
|
MessageOOK[n++] = pulse;
|
|
|
|
MessageOOK[n++] = Zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-02 05:45:37 +08:00
|
|
|
|
2018-12-23 03:58:11 +08:00
|
|
|
MessageOOK[n++] = pulse;
|
|
|
|
MessageOOK[n++] = Sync;
|
|
|
|
|
|
|
|
ooksender.SendMessage(MessageOOK, n);
|
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
void SimpleTestBurstFsk(uint64_t Freq)
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
//int SR=40625;
|
2018-12-20 23:40:16 +08:00
|
|
|
int SR = 1000;
|
|
|
|
float Deviation = 2000;
|
|
|
|
int FifoSize = 21;
|
|
|
|
fskburst fsktest(Freq, SR, Deviation, 14, FifoSize);
|
|
|
|
|
|
|
|
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};
|
|
|
|
|
2018-12-19 18:16:40 +08:00
|
|
|
//while(running)
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
|
|
|
|
fsktest.SetSymbols(TabSymbol, FifoSize);
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
fsktest.stop();
|
|
|
|
}
|
2018-12-23 22:25:11 +08:00
|
|
|
|
|
|
|
void SimpleTestAtv(uint64_t Freq)
|
|
|
|
{
|
|
|
|
|
2019-01-03 20:06:15 +08:00
|
|
|
//int SR = 1000000;
|
2018-12-23 22:25:11 +08:00
|
|
|
int SR = 1000000;
|
2019-01-02 05:45:37 +08:00
|
|
|
int FifoSize = 625 * 52;
|
|
|
|
unsigned char samples[FifoSize];
|
|
|
|
|
|
|
|
|
|
|
|
atv atvtest(Freq, SR, 14, 625);
|
2019-01-02 06:56:02 +08:00
|
|
|
atvtest.start();
|
2019-01-03 20:06:15 +08:00
|
|
|
enum {patern_grey,patern_square,patern_move,patern_point};
|
|
|
|
int Mode=patern_move;
|
|
|
|
bool random_patern=true;
|
2019-01-02 06:56:02 +08:00
|
|
|
for(int frame=0;running;frame++)
|
|
|
|
{
|
2019-01-03 20:06:15 +08:00
|
|
|
int x,y;
|
|
|
|
y=rand()%625;
|
|
|
|
x=rand()%52;
|
|
|
|
if((frame%50==0)&&(random_patern))
|
|
|
|
Mode=rand()%(patern_point+1);
|
2019-01-02 06:56:02 +08:00
|
|
|
for(int i=0;i<625;i++)
|
2018-12-24 00:35:55 +08:00
|
|
|
{
|
2019-01-02 06:56:02 +08:00
|
|
|
for (int j = 0; j < 52; j++)
|
2019-01-02 05:45:37 +08:00
|
|
|
{
|
2019-01-03 20:06:15 +08:00
|
|
|
switch(Mode)
|
|
|
|
{
|
|
|
|
case patern_grey:
|
|
|
|
{
|
|
|
|
samples[i*52+j]=255*(j/52.0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case patern_square:
|
|
|
|
{
|
|
|
|
if(i%64<(frame%64))
|
|
|
|
samples[i*52+j]=(j%16<8)?255*(j/52.0):255*(1-(j/52.0));
|
|
|
|
else
|
|
|
|
samples[i*52+j]=(j%16<8)?255:0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case patern_move:
|
|
|
|
{
|
|
|
|
samples[i*52+j]=((i+j*frame)%255);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case patern_point:
|
|
|
|
{
|
|
|
|
if((i==y)&&(j==x))
|
|
|
|
samples[i*52+j]=255;
|
|
|
|
else
|
|
|
|
samples[i*52+j]=0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-02 05:45:37 +08:00
|
|
|
}
|
2019-01-02 06:56:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-02 05:45:37 +08:00
|
|
|
//atvtest.SetTvSamples(samples,FifoSize/4);
|
2019-01-03 20:06:15 +08:00
|
|
|
|
|
|
|
atvtest.SetFrame(samples,625);
|
2019-01-02 06:56:02 +08:00
|
|
|
usleep(40000);
|
2018-12-23 22:25:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 22:03:06 +08:00
|
|
|
static void
|
|
|
|
terminate(int num)
|
|
|
|
{
|
2018-12-20 23:40:16 +08:00
|
|
|
running = false;
|
|
|
|
fprintf(stderr, "Caught signal - Terminating\n");
|
2018-03-16 22:03:06 +08:00
|
|
|
}
|
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
int main(int argc, char *argv[])
|
2018-03-16 22:03:06 +08:00
|
|
|
{
|
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
uint64_t Freq = 144200000;
|
|
|
|
if (argc > 1)
|
|
|
|
Freq = atof(argv[1]);
|
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
2018-03-16 22:03:06 +08:00
|
|
|
|
2018-12-20 23:40:16 +08:00
|
|
|
std::memset(&sa, 0, sizeof(sa));
|
|
|
|
sa.sa_handler = terminate;
|
|
|
|
sigaction(i, &sa, NULL);
|
|
|
|
}
|
2018-03-16 22:03:06 +08:00
|
|
|
|
2018-08-06 17:29:26 +08:00
|
|
|
//SimpleTest(Freq);
|
2018-12-17 20:46:17 +08:00
|
|
|
//SimpleTestbpsk(Freq);
|
2018-03-26 15:46:59 +08:00
|
|
|
//SimpleTestFileIQ(Freq);
|
2018-10-03 22:05:01 +08:00
|
|
|
//SimpleTestDMA(Freq);
|
2018-03-16 22:03:06 +08:00
|
|
|
//SimpleTestAm(Freq);
|
2018-12-19 18:16:40 +08:00
|
|
|
//SimpleTestOOK(Freq);
|
2018-12-20 23:40:16 +08:00
|
|
|
//SimpleTestBurstFsk(Freq);
|
|
|
|
//SimpleTestOOKTiming(Freq);
|
2018-12-23 03:58:11 +08:00
|
|
|
//AlectoOOK(Freq);
|
2018-12-23 22:25:11 +08:00
|
|
|
//RfSwitchOOK(Freq);
|
|
|
|
SimpleTestAtv(Freq);
|
2018-12-20 23:40:16 +08:00
|
|
|
}
|