/** * @brief Entry point function for accessing option values. * @param Selected option code. * @retval void* - should be casted to appr. type. */ void* GetOption(option_types opt_code) { void* ret_val = NULL; switch (opt_code) { case OPT_CONS_SPEED: { ret_val = GetConsSpeed(); break; } case OPT_GPS_SPEED: { ret_val = GetGPSSpeed(); break; } case OPT_ACFT_ID: { ret_val = GetAcftID(); break; } case OPT_TX_POWER: { ret_val = GetTxPower(); break; } case OPT_XTAL_CORR: { ret_val = GetXtalCorr(); break; } case OPT_FREQ_OFS: { ret_val = GetFreqOfs(); break; } case OPT_IWDG: { ret_val = GetIWDGDis(); break; } case OPT_OPER_MODE: { ret_val = GetOperMode(); break; } case OPT_CHANNEL: { ret_val = GetChannel(); break; } case OPT_GPSDUMP: { ret_val = GetGPSDump(); break; } case OPT_MAX_TX_PWR: { ret_val = GetMaxTxPower(); break;} case OPT_GPS_ALW_ON: { ret_val = GetGPSAlwON(); break; } case OPT_GPS_ANT: { ret_val = GetGPSAnt(); break; } case OPT_JAM_RATIO: { ret_val = GetJamRatio(); break; } case OPT_MIN_BAT_LVL:{ ret_val = GetMinBatLvl(); break; } case OPT_GPS_WDG_TIME:{ ret_val = GetGPSWdgTime(); break; } default: break; } return ret_val; }
/* ISR for serial interrupt */ void rt_hw_serial_isr(rt_device_t device) { struct stm32_serial_device* uart = (struct stm32_serial_device*) device->user_data; static unsigned char checksum = 0; static uint16_t lenth; // static unsigned char gprmcbuf[400]; static unsigned char isgprmc=0; static unsigned short gprmccnt = 0; if(USART_GetITStatus(uart->uart_device, USART_IT_RXNE) != RESET) { /* interrupt mode receive */ RT_ASSERT(device->flag & RT_DEVICE_FLAG_INT_RX); /* save on rx buffer */ while (uart->uart_device->SR & USART_FLAG_RXNE) { rt_base_t level; /* disable interrupt */ level = rt_hw_interrupt_disable(); /* save character */ if((&uart2_device )== device) { uartcount++; uart->int_rx->rx_buffer[uart->int_rx->save_index] = uart->uart_device->DR & 0xff; rt_device_write(&uart2_device, 0,&(uart->int_rx->rx_buffer[uart->int_rx->save_index]), 1); checksum = checksum^(uart->int_rx->rx_buffer[uart->int_rx->save_index]); switch (Uart2PackStatus ) { case Get_sync_head: if ((uart->int_rx->rx_buffer[uart->int_rx->save_index])== 0xaa) { checksum = uart->int_rx->rx_buffer[uart->int_rx->save_index]; Uart2PackStatus = Start_head_end; } else { uart->int_rx->getcmd = 0x7f; } break; case Start_head_end: if((uart->int_rx->rx_buffer[uart->int_rx->save_index])== 0x75) { Uart2PackStatus = Get_the_Command; //rt_device_write(&uart2_device, 0,&(uart->int_rx->rx_buffer[uart->int_rx->save_index]), 1); } else { uart->int_rx->getcmd = 0x7f; Uart2PackStatus = Get_sync_head; } break; case Get_the_Command: if(((uart->int_rx->rx_buffer[uart->int_rx->save_index]) <0x16) ||((uart->int_rx->rx_buffer[uart->int_rx->save_index])>0x81 &&(uart->int_rx->rx_buffer[uart->int_rx->save_index])<0x85 ) ||((uart->int_rx->rx_buffer[uart->int_rx->save_index])>0x81 &&(uart->int_rx->rx_buffer[uart->int_rx->save_index])<0x85 ) ||((uart->int_rx->rx_buffer[uart->int_rx->save_index])>0xc1 &&(uart->int_rx->rx_buffer[uart->int_rx->save_index])<0xc5 )) { Uart2PackStatus = Get_the_lenth_high; } else { uart->int_rx->getcmd = 0x7f; Uart2PackStatus = Get_sync_head; } break; case Get_the_lenth_high: lenth = uart->int_rx->rx_buffer[uart->int_rx->save_index]; Uart2PackStatus = Get_the_lenth_low; break; case Get_the_lenth_low: lenth = ((lenth<<8)&0xff00)+(uart->int_rx->rx_buffer[uart->int_rx->save_index]); Uart2PackStatus = Get_the_reserve; break; case Get_the_reserve: if (lenth != 0) { Uart2PackStatus = Get_the_data; } else Uart2PackStatus = Get_the_checksum; break; case Get_the_data: if(lenth ) lenth--; if(lenth == 0) Uart2PackStatus = Get_the_checksum; break; case Get_the_checksum: if(checksum == 0) { uart->int_rx->getcmd ++; } else { uart->int_rx->getcmd = 0x7f; } Uart2PackStatus = Get_sync_head; break; default: break; } uart->int_rx->save_index ++; if (uart->int_rx->save_index >= UART_RX_BUFFER_SIZE) uart->int_rx->save_index = 0; /* if the next position is read index, discard this 'read char' */ if (uart->int_rx->save_index == uart->int_rx->read_index) { uart->int_rx->read_index ++; if (uart->int_rx->read_index >= UART_RX_BUFFER_SIZE) uart->int_rx->read_index = 0; } } if((&uart3_device)== device) { if((uart->uart_device->DR & 0xff) == '$') { SectionID=0; isgprmc = 0; gprmccnt =0; uart3flag =1; } else if((uart->uart_device->DR & 0xff)==',') { if((isgprmc == 1)&&(SectionID== FIELD_NIGHT)) { //get the time GetGPSLocation3(gprmcbuf,gprmccnt); } else if((isgprmc == 2) &&(SectionID == FIELD_SEVEN )) { GetGPSSpeed(gprmcbuf,gprmccnt); } SectionID++; gprmccnt = 0; uart3flag =2; } else { if(gprmccnt == 400) { gprmccnt = 0; } gprmcbuf[gprmccnt] = uart->uart_device->DR & 0xff; gprmccnt++; switch(SectionID) { case FIELD_NONE: if(gprmccnt == 5) { uart3flag =2; gprmccnt =0 ; if ( (gprmcbuf[0] == 'G') &&(gprmcbuf[1] == 'P')&&(gprmcbuf[2] =='G') &&(gprmcbuf[3] =='G')&&(gprmcbuf[4] == 'A')) { isgprmc =1;//位置信息 } if ( (gprmcbuf[0] == 'G') &&(gprmcbuf[1] == 'P')&&(gprmcbuf[2] =='V') &&(gprmcbuf[3] == 'T')&&(gprmcbuf[4] == 'G')) { isgprmc =2;//速度信息 uart3flag =2; } } break; case FIELD_ONE://提取时间 uart3flag =1; if(isgprmc == 1) { if(gprmccnt == 10 ) { //get the time GetTheGPSTime(gprmcbuf); } } break; case FIELD_TWO: //判断数据是否可信(当GPS天线能接收到有3颗GPS卫星时为A,可信 if(isgprmc == 1) { if(gprmccnt == 9 ) { //get the time GetGPSLocation1(gprmcbuf); } } break; case FIELD_THREE://提取出纬度 break; case FIELD_FOUR://提取出速度 if(isgprmc == 1) { if(gprmccnt == 10 ) { //get the time GetGPSLocation2(gprmcbuf); } } break; case FIELD_FIVE://提取出经度 break; case FIELD_SEVEN: if(isgprmc == 1) { if(gprmccnt == 2 ) { //get the singal GettheSinaldata(gprmcbuf); } } break; case FIELD_NIGHT://提取高度 break; default: break; } } } if((&uart4_device )== device) { gprmcbuf[gprmccnt] = uart->uart_device->DR & 0xff; gprmccnt++; } /* enable interrupt */ rt_hw_interrupt_enable(level); } /* clear interrupt */ USART_ClearITPendingBit(uart->uart_device, USART_IT_RXNE); /* invoke callback */ if (device->rx_indicate != RT_NULL) { rt_size_t rx_length; /* get rx length */ rx_length = uart->int_rx->read_index > uart->int_rx->save_index ? UART_RX_BUFFER_SIZE - uart->int_rx->read_index + uart->int_rx->save_index : uart->int_rx->save_index - uart->int_rx->read_index; device->rx_indicate(device, rx_length); } } if (USART_GetITStatus(uart->uart_device, USART_IT_TC) != RESET) { /* clear interrupt */ USART_ClearITPendingBit(uart->uart_device, USART_IT_TC); } }