Define RSSI value types and macro for conversions

pull/4/head
DiSlord 6 years ago
parent 1f234e18d2
commit bf5c624a79

@ -865,6 +865,15 @@ int plot_printf(char *str, int, const char *fmt, ...);
#define define_to_STR(x) STR1(x) #define define_to_STR(x) STR1(x)
// sa_core.c // sa_core.c
typedef uint8_t deviceRSSI_t;
typedef int16_t pureRSSI_t;
// RSSI values conversion macrp
#define DEVICE_TO_PURE_RSSI(rssi) ((rssi)<<4)
#define float_TO_PURE_RSSI(rssi) ((rssi)*32.0)
#define PURE_TO_float(rssi) ((rssi)/32.0)
int get_waterfall(void); int get_waterfall(void);
void toggle_tracking(void); void toggle_tracking(void);
void calibrate(void); void calibrate(void);

@ -1275,7 +1275,7 @@ static const int am_modulation[5] = { 4,0,1,5,7 }; // 5 step AM modulat
static const int nfm_modulation[5] = { 0, 2, 1, -1, -2}; // 5 step narrow FM modulation static const int nfm_modulation[5] = { 0, 2, 1, -1, -2}; // 5 step narrow FM modulation
static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wide FM modulation static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wide FM modulation
char age[POINTS_COUNT]; deviceRSSI_t age[POINTS_COUNT];
static float old_a = -150; static float old_a = -150;
static float correct_RSSI; static float correct_RSSI;
@ -1400,7 +1400,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
} }
// -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------
int16_t RSSI = (-150)*32; pureRSSI_t RSSI = float_TO_PURE_RSSI(-150.0);
int t = 0; int t = 0;
do { do {
int offs = 0,sm; int offs = 0,sm;
@ -1547,7 +1547,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
SI4432_Fill(MODE_SELECT(setting.mode), 0); SI4432_Fill(MODE_SELECT(setting.mode), 0);
} }
#endif #endif
int16_t pureRSSI; pureRSSI_t pureRSSI;
// if ( i < 3) // if ( i < 3)
// shell_printf("%d %.3f %.3f %.1f\r\n", i, local_IF/1000000.0, lf/1000000.0, subRSSI); // shell_printf("%d %.3f %.3f %.1f\r\n", i, local_IF/1000000.0, lf/1000000.0, subRSSI);
@ -1564,10 +1564,10 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
if (i == 0 && setting.frequency_step == 0 && setting.trigger != T_AUTO) { // if in zero span mode and wait for trigger to happen and NOT in trigger mode if (i == 0 && setting.frequency_step == 0 && setting.trigger != T_AUTO) { // if in zero span mode and wait for trigger to happen and NOT in trigger mode
register uint16_t t_mode; register uint16_t t_mode;
uint16_t trigger_lvl; pureRSSI_t trigger_lvl;
uint16_t data_level = T_LEVEL_UNDEF; uint16_t data_level = T_LEVEL_UNDEF;
// Calculate trigger level // Calculate trigger level
trigger_lvl = (setting.trigger_level - correct_RSSI) * 32; trigger_lvl = float_TO_PURE_RSSI(setting.trigger_level - correct_RSSI);
if (setting.trigger_direction == T_UP) if (setting.trigger_direction == T_UP)
t_mode = T_UP_MASK; t_mode = T_UP_MASK;
@ -1577,7 +1577,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
if (setting.sweep_time_us >= 100*ONE_MS_TIME) additional_delay = 20; if (setting.sweep_time_us >= 100*ONE_MS_TIME) additional_delay = 20;
SI4432_Sel = MODE_SELECT(setting.mode); SI4432_Sel = MODE_SELECT(setting.mode);
do{ // wait for trigger to happen do{ // wait for trigger to happen
pureRSSI = SI4432_Read_Byte(SI4432_REG_RSSI)<<4; pureRSSI = DEVICE_TO_PURE_RSSI((deviceRSSI_t)SI4432_Read_Byte(SI4432_REG_RSSI));
if (break_on_operation && operation_requested) // allow aborting a wait for trigger if (break_on_operation && operation_requested) // allow aborting a wait for trigger
return 0; // abort return 0; // abort
@ -1602,7 +1602,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
pureRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)); // Get RSSI, either from pre-filled buffer pureRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)); // Get RSSI, either from pre-filled buffer
#ifdef __SPUR__ #ifdef __SPUR__
static int16_t spur_RSSI = -1; static pureRSSI_t spur_RSSI = -1;
if (setting.spur == 1) { if (setting.spur == 1) {
if(spur_RSSI == -1) { // If first spur pass if(spur_RSSI == -1) { // If first spur pass
spur_RSSI = pureRSSI; // remember measure RSSI spur_RSSI = pureRSSI; // remember measure RSSI
@ -1620,7 +1620,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
if (break_on_operation && operation_requested) // break subscanning if requested if (break_on_operation && operation_requested) // break subscanning if requested
break; // abort break; // abort
} while (t < vbwSteps); // till all sub steps done } while (t < vbwSteps); // till all sub steps done
return(RSSI/32.0) + correct_RSSI; // add correction return PURE_TO_float(RSSI) + correct_RSSI; // add correction
} }
#define MAX_MAX 4 #define MAX_MAX 4

@ -82,7 +82,7 @@ static uint8_t shiftIn(void)
return value>>GPIO_SPI2_SDO; return value>>GPIO_SPI2_SDO;
} }
static inline void shiftInBuf(uint16_t sel, uint8_t addr, uint8_t *buf, uint16_t size, uint16_t delay) { static inline void shiftInBuf(uint16_t sel, uint8_t addr, deviceRSSI_t *buf, uint16_t size, uint16_t delay) {
uint8_t i = 0; uint8_t i = 0;
do{ do{
uint32_t value = addr; uint32_t value = addr;
@ -392,7 +392,7 @@ int SI4432_step_delay = 1500;
//extern int setting.repeat; //extern int setting.repeat;
#ifdef __FAST_SWEEP__ #ifdef __FAST_SWEEP__
extern char age[POINTS_COUNT]; extern deviceRSSI_t age[POINTS_COUNT];
static int buf_index = 0; static int buf_index = 0;
static bool buf_read = false; static bool buf_read = false;
@ -432,7 +432,7 @@ void SI4432_Fill(int s, int start)
my_microsecond_delay(t); my_microsecond_delay(t);
} while(1); } while(1);
#else #else
shiftInBuf(sel, SI4432_REG_RSSI, (uint8_t *)&age[start], sweep_points - start, t); shiftInBuf(sel, SI4432_REG_RSSI, &age[start], sweep_points - start, t);
#endif #endif
// __enable_irq(); // __enable_irq();
setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100; setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100;
@ -448,10 +448,10 @@ float getSI4432_RSSI_correction(void){
return SI4432_RSSI_correction; return SI4432_RSSI_correction;
}; };
int16_t SI4432_RSSI(uint32_t i, int s) pureRSSI_t SI4432_RSSI(uint32_t i, int s)
{ {
(void) i; (void) i;
int32_t RSSI_RAW; pureRSSI_t RSSI_RAW;
(void) i; (void) i;
// SEE DATASHEET PAGE 61 // SEE DATASHEET PAGE 61
#ifdef USE_SI4463 // Not used!!!!!!! #ifdef USE_SI4463 // Not used!!!!!!!
@ -464,7 +464,7 @@ int16_t SI4432_RSSI(uint32_t i, int s)
if (buf_read) { if (buf_read) {
if (buf_index == sweep_points-1) if (buf_index == sweep_points-1)
buf_read = false; buf_read = false;
return (unsigned char)age[buf_index++]<<4; return DEVICE_TO_PURE_RSSI(age[buf_index++]);
} }
#endif #endif
SI4432_Sel = s; SI4432_Sel = s;
@ -485,7 +485,7 @@ int16_t SI4432_RSSI(uint32_t i, int s)
i = setting.repeat; i = setting.repeat;
RSSI_RAW = 0; RSSI_RAW = 0;
do{ do{
RSSI_RAW += ((unsigned int)SI4432_Read_Byte(SI4432_REG_RSSI))<<4; RSSI_RAW += DEVICE_TO_PURE_RSSI((deviceRSSI_t)SI4432_Read_Byte(SI4432_REG_RSSI));
if (--i == 0) break; if (--i == 0) break;
my_microsecond_delay(100); my_microsecond_delay(100);
}while(1); }while(1);
@ -495,7 +495,8 @@ int16_t SI4432_RSSI(uint32_t i, int s)
// if (MODE_INPUT(setting.mode) && RSSI_RAW == 0) // if (MODE_INPUT(setting.mode) && RSSI_RAW == 0)
// SI4432_Init(); // SI4432_Init();
#ifdef __SIMULATION__ #ifdef __SIMULATION__
RSSI_RAW = Simulated_SI4432_RSSI(i,s)<<4; #error "Fixme!!! add correct simulation in pureRSSI_t type"
RSSI_RAW = Simulated_SI4432_RSSI(i,s);
#endif #endif
//STOP_PROFILE //STOP_PROFILE
// Serial.println(dBm,2); // Serial.println(dBm,2);

@ -115,7 +115,7 @@ void SI4432_Receive(void);
void SI4432_Init(void); void SI4432_Init(void);
void SI4432_Drive(int); void SI4432_Drive(int);
float getSI4432_RSSI_correction(void); float getSI4432_RSSI_correction(void);
int16_t SI4432_RSSI(uint32_t i, int s); pureRSSI_t SI4432_RSSI(uint32_t i, int s);
#ifdef __SIMULATION__ #ifdef __SIMULATION__
float Simulated_SI4432_RSSI(uint32_t i, int s); float Simulated_SI4432_RSSI(uint32_t i, int s);
#endif #endif

Loading…
Cancel
Save

Powered by TurnKey Linux.