Hello,
I would like to modify the diagnostics information, in the provided Segger project pdoa_node, to print out whether or not the tag is line of sight. I referred to the dw1000 user manual (pages 45 and 46) for the calculation. In json_2pc.c, the diagnostics functions get passed a rx_mail_t, which has a diag_v5_t, which has the necessary registers for the calculation. unfortunately, the upper byte and a half of r10 is zero. any idea why this would happen?
for reference, i’ll provide the code and output
output:
DMM207B 1B fp1: 5805, fp2: 5794, fp3: 5423, pac: 0, cir: 1250 pac3: 00, pac2: 00 fpp: , rxp: , los: 20000000
DMM207C 1C fp1: 5286, fp2: 5343, fp3: 5357, pac: 0, cir: 1144 pac3: 00, pac2: 00 fpp: , rxp: , los: E0000000
note that the tag and node were less than 1 meter apart and line of sight.
code:
#include <math.h>
#define JSON2PC_PRF64MHZ (121.74)
#define JSON2PC_SFD (8.0)
#define JSON2PC_FPP_THRESHOLD (82)
#define JSON2PC_FPP_RXP_THRESHOLD (6)
static void parse_diag( diag_v5_t* diag, dwt_rxdiag_t * out)
{
out->firstPathAmp1 = (diag->r15[8] << 8) | diag->r15[7];
out->firstPathAmp2 = (diag->r12[3] << 8) | diag->r12[2];
out->firstPathAmp3 = (diag->r12[5] << 8) | diag->r12[4];
out->maxGrowthCIR = ( diag->r12[7] << 8) | diag->r12[6];
out->rxPreamCount = (diag->r10[3] << 4) | ((diag->r10[2] >> 4) & 0x0F);
}
static void send_los_diag(char str,
uint16_t maxLen,
diag_v5_t diagv5)
{
if ((strlen(str)+ 2*sizeof(diag_v5_t) + 1 + 10 + 6) < maxLen)
{
dwt_rxdiag_t diag;
parse_diag(diagv5, &diag);
float fpp = (10.0f * log10( (pow(diag.firstPathAmp1, 2.0) + pow(diag.firstPathAmp2, 2.0) + pow(diag.firstPathAmp3, 2.0)) / (pow(diag.rxPreamCount - JSON2PC_SFD,
2.0)) )) - JSON2PC_PRF64MHZ;
float rxp = (10.0f * log10( (diag.maxGrowthCIR * 131072.0f) / (pow(diag.rxPreamCount - JSON2PC_SFD, 2.0)) )) - JSON2PC_PRF64MHZ;
uint8_t los = 0;
if (fpp < JSON2PC_FPP_THRESHOLD && abs(fpp - rxp) < JSON2PC_FPP_RXP_THRESHOLD)
los = 1;
if (fpp == 0 && rxp == 0)
los = 0xFF;
sprintf(&str[strlen(str)], " fp1: %d, fp2: %d, fp3: %d, pac: %d, cir: %d pac3: %02x, pac2: %02x ", diag.firstPathAmp1, diag.firstPathAmp2, diag.firstPathAmp3, diag.rxPreamCount, diag.maxGrowthCIR, diagv5->r10[3], diagv5->r10[2]);
sprintf(&str[strlen(str)], " Fpp: %.3f, Rxp: %.3f, los: %02X \r\n", (float)fpp, (float)rxp, los);
while(port_tx_msg((uint8_t*)str, strlen(str)) !=_NO_ERR)
{
osThreadYield(); //force switch content
osDelay(5); //wait 5ms for Flush thread freed the buffer
}
}
}