Changeset - b113d7d76caf
[Not reviewed]
default
0 3 0
Ethan Zonca - 9 years ago 2016-10-09 14:19:08
ez@ethanzonca.com
Implementation of faster baud rate and new message
3 files changed with 65 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/gps.c
Show inline comments
 
@@ -40,7 +40,6 @@ void gps_init()
 
   // done in poweron uart_init();
 

	
 
	gps_poweron();
 
	HAL_Delay(500);
 

	
 
//	// uart1 ubx only
 
//
 
@@ -212,36 +211,61 @@ void gps_update_time(uint8_t* hour, uint
 
void gps_check_lock(uint8_t* lock, uint8_t* sats)
 
{
 
    // Construct the request to the GPS
 
    uint8_t request[8] = {0xB5, 0x62, 0x01, 0x06, 0x00, 0x00, 0x07, 0x16};
 
    uint8_t request[8] = {0xB5, 0x62, 0x01, 0x07, 0x00, 0x00, 0xFF, 0xFF};
 

	
 

	
 
    volatile uint8_t check_a = 0;
 
    volatile uint8_t check_b = 0;
 
    for(uint8_t i = 2; i<6; i++)
 
    {
 
    	check_a += request[i];
 
    	check_b += check_a;
 
    }
 
    request[6] = check_a;
 
    request[7] = check_b;
 

	
 
    uint8_t flushed = uart_gethandle()->Instance->RDR;
 
    HAL_UART_Transmit(uart_gethandle(), request, 8, 100);
 

	
 

	
 

	
 
    // Get the message back from the GPS
 
    uint8_t buf[60];
 
    for(uint8_t i=0; i<60; i++)
 
    uint8_t buf[100];
 
    for(uint8_t i=0; i<100; i++)
 
    	buf[i] = 0xaa;
 
    volatile HAL_StatusTypeDef res = HAL_UART_Receive(uart_gethandle(), buf, 60, 3000);
 

	
 
    // Verify the sync and header bits
 
//    if( buf[0] != 0xB5 || buf[1] != 0x62 )
 
//        led_set(LED_RED, 1);
 
//    if( buf[2] != 0x01 || buf[3] != 0x06 )
 
//        led_set(LED_RED, 1);
 
    volatile HAL_StatusTypeDef res = HAL_UART_Receive(uart_gethandle(), buf, 100, 3000);
 

	
 
    // Check 60 bytes minus SYNC and CHECKSUM (4 bytes)
 
    if( !_gps_verify_checksum(&buf[2], 56) )
 
    if( !_gps_verify_checksum(&buf[2], 96) )
 
        led_blink(2);
 

	
 

	
 
    // Return the value if GPSfixOK is set in 'flags'
 
    if( buf[17] & 0x01 )
 
        *lock = buf[16];
 
    else
 
        *lock = 0;
 
    //volatile uint32_t gpstime_ms = (buf[6+0] << 24) | (buf[6+1] << 16) | buf[6+2] << 8) | (buf[6+3]);
 

	
 
    volatile uint8_t month = buf[6+6];
 
    volatile uint8_t day = buf[6+7];
 
    volatile uint8_t hour = buf[6+8];
 
    volatile uint8_t minute = buf[6+9];
 
    volatile uint8_t second = buf[6+10];
 
    volatile uint8_t valid = buf[6+11] & 0b1111;
 
    volatile uint8_t fixtype = buf[6+20];
 

	
 
    volatile uint8_t sats_in_solution = buf[6+23];
 

	
 
    *sats = buf[53];
 
    volatile uint32_t longitude = (buf[6+24] << 24) | (buf[6+25] << 16) | (buf[6+26] << 8) | (buf[6+27]);
 
    volatile uint32_t latitude = (buf[6+28] << 24) | (buf[6+29] << 16) | (buf[6+30] << 8) | (buf[6+31]);
 
    volatile uint32_t altitude_sealevel = (buf[6+36] << 24) | (buf[6+37] << 16) | (buf[6+38] << 8) | (buf[6+39]);
 
    volatile uint32_t groundspeed = (buf[6+60] << 24) | (buf[6+61] << 16) | (buf[6+62] << 8) | (buf[6+63]);
 
    volatile uint16_t pdop = (buf[6+76] << 8) | (buf[6+77]);
 
//
 
//    // Return the value if GPSfixOK is set in 'flags'
 
//    if( buf[17] & 0x01 )
 
//        *lock = buf[16];
 
//    else
 
//        *lock = 0;
 
    *lock = fixtype;
 

	
 
    *sats = sats_in_solution;
 
}
 

	
 
/**
src/main.c
Show inline comments
 
@@ -43,6 +43,9 @@ int main(void)
 
    uint16_t blink_rate = BLINK_FAST;
 
    uint8_t state = SYSTEM_GPSACQ;
 
 
    uint32_t fixinfo_timer = 0;
 
    uint8_t fix_ok = 0;
 
    uint8_t numsats = 0;
 
 
    while (1)
 
    {
 
@@ -58,7 +61,7 @@ int main(void)
 
                //enter_sleep();
 
 
                // Somehow go to another state when we get an interrupt
 
                state = SYSTEM_GPSACQ;
 
//                state = SYSTEM_GPSACQ;
 
            } break;
 
 
 
@@ -70,17 +73,19 @@ int main(void)
 
                // TODO: probably don't power on all the time, just on state transition
 
//                gps_poweron();
 
//                HAL_Delay(100);
 
                HAL_Delay(1000);
 
//                gps_update_position();
 
                
 
                uint8_t fix_ok = 0;
 
                uint8_t numsats = 0;
 
                gps_check_lock(&fix_ok, &numsats);
 
                // Update fix status every 2 seconds
 
                if(HAL_GetTick() - fixinfo_timer > 2000)
 
                {
 
                	gps_check_lock(&fix_ok, &numsats);
 
                	fixinfo_timer = HAL_GetTick();
 
                }
 
 
                if(fix_ok)
 
                if(fix_ok > 0)
 
                {
 
                    // Disable GPS module
 
                    gps_poweroff();
 
                    //gps_poweroff();
 
 
                    // TODO: Set RTC from GPS time
 
 
@@ -100,6 +105,7 @@ int main(void)
 
            // Wait for wspr timeslot and start transmitting
 
            case SYSTEM_WSPRTX:
 
            {
 
            	blink_rate = BLINK_SLOW;
 
                // Wait for wspr countdown timer to expire and go to tx
 
//                if(timeout_expired)
 
//                {
 
@@ -109,7 +115,7 @@ int main(void)
 
                // Schedule next wakeup (maybe 2mins prior ot timeslot if no osc trim)
 
                // Next wakeup should enter SYSTEM_GPSACQ state...
 
 
                state = SYSTEM_IDLE;
 
//                state = SYSTEM_IDLE;
 
 
            } break;
 
src/uart.c
Show inline comments
 
@@ -39,6 +39,15 @@ void uart_init(void)
 
    huart1.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;
 
    HAL_UART_Init(&huart1);
 
 
    HAL_Delay(100);
 
	uint8_t switch_baud[] = "$PUBX,41,1,0003,0001,115200,0*1E\r\n";
 
	HAL_UART_Transmit(uart_gethandle(), switch_baud, sizeof(switch_baud)/sizeof(uint8_t), 1000);
 
 
    HAL_UART_DeInit(&huart1);
 
    huart1.Init.BaudRate = 115200;
 
    HAL_UART_Init(&huart1);
 
 
 
//
 
//    __DMA1_CLK_ENABLE();
 
//
0 comments (0 inline, 0 general)