Changeset - f126c64d1202
[Not reviewed]
default
0 3 0
Ethan Zonca - 9 years ago 2016-10-11 22:54:04
ez@ethanzonca.com
Actually fill in the correct grid locator!
3 files changed with 45 insertions and 5 deletions:
0 comments (0 inline, 0 general)
inc/wspr.h
Show inline comments
 
@@ -5,7 +5,7 @@
 
void wspr_init(void);
 
void wspr_sleep(void);
 
void wspr_wakeup(void);
 
void wspr_transmit(void);
 
void wspr_transmit(uint8_t* grid_locator);
 

	
 

	
 
#endif
src/main.c
Show inline comments
 
@@ -23,6 +23,8 @@ enum _state
 
    SYSTEM_WSPRTX, // Wait for timeslot and actually transmit the message
 
};
 
 
static void __calc_gridloc(char *dst, double lat, double lon);
 
 
 
int main(void)
 
{
 
@@ -124,12 +126,12 @@ int main(void)
 
                    fix_acq_starttime = 0;
 
                    state = SYSTEM_WSPRTX;
 
                }
 
                else if(HAL_GetTick() - fix_acq_starttime > 60000)
 
                // If no fix in 2 minutes
 
                else if(HAL_GetTick() - fix_acq_starttime > 120000)
 
                {
 
                	  // Flash error code and go to idle probably? or just try forever?
 
                	led_blink(4);
 
                }
 
 
            } break;
 
 
            
 
@@ -146,7 +148,13 @@ int main(void)
 
            	{
 
            		if(HAL_GetTick() < nextwspr_time + 2000)
 
            		{
 
						wspr_transmit();
 
            			volatile double latitude_flt = (double)gps_getdata()->latitude / 10000000.0;
 
            			volatile double longitude_flt = (double)gps_getdata()->longitude / 10000000.0;
 
            			volatile uint8_t grid_locator[7];
 
 
            			__calc_gridloc(grid_locator, latitude_flt, longitude_flt);
 
 
						wspr_transmit(grid_locator);
 
						last_wspr_tx_time = HAL_GetTick();
 
						state = SYSTEM_IDLE;
 
            		}
 
@@ -176,5 +184,32 @@ int main(void)
 
}
 
 
 
static void __calc_gridloc(char *dst, double lat, double lon)
 
{
 
	int o1, o2, o3;
 
	int a1, a2, a3;
 
	double remainder;
 
	// longitude
 
	remainder = lon + 180.0;
 
	o1 = (int)(remainder / 20.0);
 
	remainder = remainder - (double)o1 * 20.0;
 
	o2 = (int)(remainder / 2.0);
 
	remainder = remainder - 2.0 * (double)o2;
 
	o3 = (int)(12.0 * remainder);
 
 
	// latitude
 
	remainder = lat + 90.0;
 
	a1 = (int)(remainder / 10.0);
 
	remainder = remainder - (double)a1 * 10.0;
 
	a2 = (int)(remainder);
 
	remainder = remainder - (double)a2;
 
	a3 = (int)(24.0 * remainder);
 
	dst[0] = (char)o1 + 'A';
 
	dst[1] = (char)a1 + 'A';
 
	dst[2] = (char)o2 + '0';
 
	dst[3] = (char)a2 + '0';
 
	dst[4] = (char)o3 + 'A';
 
	dst[5] = (char)a3 + 'A';
 
	dst[6] = (char)0;
 
}
 
src/wspr.c
Show inline comments
 
@@ -61,8 +61,13 @@ void wspr_wakeup(void)
 

	
 

	
 
// Bring up TCXO and oscillator IC
 
void wspr_transmit(void)
 
void wspr_transmit(uint8_t* grid_locator)
 
{
 
	// Copy 4 digit grid locator to local buffer; null terminate
 
	for(uint8_t i=0; i<4; i++)
 
		loc[i] = grid_locator[i];
 
	loc[4] = '\0';
 

	
 
    HAL_GPIO_WritePin(OSC_NOTEN, 0);
 
    HAL_GPIO_WritePin(TCXO_EN, 1);
 
    HAL_Delay(100);
0 comments (0 inline, 0 general)