📄 src.txt
字号:
//---------------------------------------------------------------------------
// The SmartPropo project is concerned with reading out the
// transmitter via the trainer port to a computer.
// We found several weird things that seem to mismatch with what we know
// about PCM
// Therefore I conclude that the trainer port data format as decoded here
// is NOT PCM 1024Z.
// ProcessPulse is called for every high-low and low-high flank in the samples
// width is the length to the previous flank (#samples) and input is
// FALSE if the transition is low2high and TRUE if the transition is high2low.
// sampling rate is always 44.1kHz or T=22.6757us.
#ifdef FUTABA_PCM
static void __fastcall ProcessPulse(int width, BOOL input)
{
static int sync = 0;
static unsigned int bit = 0; // last received bit since sync.
// should be equal to input variable I think.
static unsigned int bitcount = 0;
static unsigned int bitstream = 0;
static int data[32]; // 6bit packets received. Don't know why this isn't just byte but int.
static int datacount = 0;
width = (int)floor(width / PW_FUTABA + 0.5);
if (sync == 0 && width == 18) { // more than 18 pulsewidths is sync
sync = 1;
bit = 0;
bitstream = 0;
bitcount = 0;
datacount = 0;
return;
}
if (!sync) return;
// now if width>1 we received more than 1 bit.
// add equal bits to right of the the bitstream
// bitcount keeps track of #bits in bitstream
bitstream = (bitstream << width) | (bit >> (32 - width));
bit ^= 0xFFFFFFFF;
bitcount += width;
// bitstream is an int and so it could overflow if not emptied in time
// so they gonna check if enough bits gathered to continue processing
// bitcount will be lowered as bits are taken out.
if (sync == 1)
{
if (bitcount >= 6)
{
bitcount -= 6;
if (((bitstream >> bitcount) & 0x3F) == 0x03) {
sync = 2;
datacount = 0;
} else if (((bitstream >> bitcount) & 0x3F) == 0x00) {
sync = 2;
datacount = 16;
bitcount -= 2;
} else {
sync = 0;
}
}
return;
}
// if we have 10 bits we have received a new symbol.
// This is a 6B10B block code as they call it,
// which means every 10 bits encode a 6 bit value.
// Why this is useful is still to be figured out.
if (bitcount >= 10)
{
bitcount -= 10;
// look up the corresponding symbol from the table and store it in data array.
if ((data[datacount++] = futaba_symbol[(bitstream >> bitcount) & 0x3FF]) < 0)
{
// only 2^6 out of the 2^10 symbols are valid.
// If we get here we received an illegal symbol and cancel processing.
sync = 0;
return;
}
}
// check if we can calculate some channel positions.
// To do that we join parts of two 6-bit values to make a 10 bit number.
// Today (5nov2003) FredericG found the contents for this data
//
Quote
--------------------------------------------------------------------------------
Every 24bits data contains 2bits of auxilialy data,
// 4bits of difference data, 10bits ofposition data, and 8 bits of error correcting data.
--------------------------------------------------------------------------------
// NOTE that this is quite far from the radio PCM format:
// for one, PCM has NO error correcting data but a CRC
// second, we miss failsafe info here
// and there are a few more difference.
// I CONCLUDE THAT THIS MUST BE THE TRAINER PORT FORMAT WHEN PCM IS SELECTED
// AND NOT THE PCM RADIO FORMAT.
switch (datacount) {
case 3: if ((data[0] >> 4) != 0) Position[2] = (data[1] << 4) | (data[2] >> 2); break;
case 7: Position[3] = (data[5] << 4) | (data[6] >> 2); break;
case 11: if ((data[0] >> 4) != 0) Position[4] = (data[9] << 4) | (data[10] >> 2); break;
case 15: sync = 0;
case 19: Position[1] = (data[17] << 4) | (data[18] >> 2); break;
case 23: if ((data[16] >> 4) != 1) Position[0] = (data[21] << 4) | (data[22] >> 2); break;
case 27: Position[5] = (data[25] << 4) | (data[26] >> 2); break;
case 31: break;
case 32: sync = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -