Changeset - 8bad90087cda
[Not reviewed]
default
0 1 0
Ethan Zonca - 7 years ago 2019-09-04 21:11:14
ez@ethanzonca.com
Wspr transmissions now timed off of RTC directly
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/main.c
Show inline comments
 
@@ -55,43 +55,43 @@ int main(void)
 
    led_blink(4);
 
 
    uint16_t blink_rate = BLINK_FAST;
 
    uint8_t state = SYSTEM_GPSACQ;
 
 
    // DEBUG EMZ FIXME
 
//    state = SYSTEM_IDLE;
 
 
    uint32_t gps_polltimer = 0;
 
    uint32_t fix_acq_starttime = 0;
 
    uint32_t nextwspr_time = 0;
 
    uint8_t nextwspr_time_valid = 0;
 
    uint32_t last_wspr_tx_time = 0;
 
    uint64_t last_wspr_tx_time = 0;
 
    uint64_t idle_blink_last = 0;
 
 
    uint8_t packet_type = 0;
 
 
    // Transmit pilot tone to test TX on bootup
 
    HAL_Delay(1000);
 
    wspr_pilot_tone();
 
    adc_stop();
 
    HAL_Delay(1000);
 
 
//    __DBGMCU_CLK_ENABLE() ; // (RCC->APB2ENR |= (RCC_APB2ENR_DBGMCUEN))
 
//    HAL_EnableDBGStopMode();  //  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
 
 
 
    while (1)
 
    {
 
    	// Every 10 minutes, wake up and try to wspr
 
    	if(state == SYSTEM_IDLE && (HAL_GetTick() - last_wspr_tx_time > 60000 * 10))
 
    	if(state == SYSTEM_IDLE && (rtc_timestamp() - last_wspr_tx_time > 60000 * 10))
 
    	{
 
    		state = SYSTEM_GPSACQ;
 
    	}
 
 
        // Update fix status every 2 seconds, only if the GPS is powered on
 
        if(HAL_GetTick() - gps_polltimer > 2000)
 
        {
 
            if(gps_ison())
 
            {
 
            	HAL_GPIO_WritePin(LED_BLUE, 1);
 
            	HAL_Delay(50);
 
            	HAL_GPIO_WritePin(LED_BLUE, 0);
 
@@ -173,25 +173,25 @@ int main(void)
 
                    // TODO: Set wspr countdown timer for this transmission!
 
                    fix_acq_starttime = 0;
 
                    state = SYSTEM_WSPRTX;
 
                    adc_start();
 
                }
 
                // If no decent fix in 3 minutes
 
                else if(HAL_GetTick() - fix_acq_starttime > 60000 * 3)
 
                {
 
                	// Flash error code and go to idle, try again next time
 
                	led_blink(4);
 
                    gps_poweroff();
 
                    fix_acq_starttime = 0;
 
                    last_wspr_tx_time = HAL_GetTick(); // repeat acq/tx cycle after big time delay
 
                    last_wspr_tx_time = rtc_timestamp(); // repeat acq/tx cycle after big time delay
 
                	state = SYSTEM_IDLE;
 
                }
 
                else
 
                {
 
                	// We're waiting for a GPS fix, might as well sleep and let the GPS get a fix.
 
            		// Enter stop mode for 1 second. Blink in the GPS code above.
 
                    __sleep_enter_stop();
 
                }
 
 
            } break;
 
 
 
@@ -207,32 +207,32 @@ int main(void)
 
            	{
 
            		if(HAL_GetTick() < nextwspr_time + 2000)
 
            		{
 
            			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);
 
 
                        // TODO: Switch between alternate and standard packet
 
						wspr_transmit(grid_locator, packet_type);
 
                        packet_type = !packet_type; // alternate packet type
 
						last_wspr_tx_time = HAL_GetTick();
 
						last_wspr_tx_time = rtc_timestamp();
 
						state = SYSTEM_IDLE;
 
                        adc_stop();
 
            		}
 
            		else
 
            		{
 
            			// Window was missed, go back to idle, and try again after time delay
 
						last_wspr_tx_time = HAL_GetTick();
 
						last_wspr_tx_time = rtc_timestamp();
 
            			state = SYSTEM_IDLE;
 
                        adc_stop();
 
            		}
 
                    nextwspr_time_valid = 0; // invalidate wspr time
 
                }
 
            	else
 
            	{
 
                	HAL_GPIO_WritePin(LED_BLUE, 1);
 
                	HAL_Delay(50);
 
                	HAL_GPIO_WritePin(LED_BLUE, 0);
 
                	HAL_Delay(50);
 
                	HAL_GPIO_WritePin(LED_BLUE, 1);
0 comments (0 inline, 0 general)