mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-09 17:34:01 -04:00
AP_Common: moved map_baudrate() into AP_Common
this version supports a much wider range of baudrates
This commit is contained in:
parent
7d712f90bf
commit
42c1501563
56
libraries/AP_Common/AP_Common.cpp
Normal file
56
libraries/AP_Common/AP_Common.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||||
|
/*
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* AP_Common.cpp - common utility functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <AP_HAL.h>
|
||||||
|
#include <AP_Common.h>
|
||||||
|
|
||||||
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* map from a 16 bit EEPROM baud rate to a real baud rate
|
||||||
|
* The practical rates for APM1/APM2 are up to 500kbaud, although
|
||||||
|
* beyond 115200 isn't recommended. For PX4 we can do 1.5MBit,
|
||||||
|
* although 921600 is more reliable
|
||||||
|
*/
|
||||||
|
uint32_t map_baudrate(int16_t rate)
|
||||||
|
{
|
||||||
|
if (rate <= 0) {
|
||||||
|
rate = 57;
|
||||||
|
}
|
||||||
|
switch (rate) {
|
||||||
|
case 1: return 1200;
|
||||||
|
case 2: return 2400;
|
||||||
|
case 4: return 4800;
|
||||||
|
case 9: return 9600;
|
||||||
|
case 19: return 19200;
|
||||||
|
case 38: return 38400;
|
||||||
|
case 57: return 57600;
|
||||||
|
case 111: return 111100;
|
||||||
|
case 115: return 115200;
|
||||||
|
case 230: return 230400;
|
||||||
|
case 460: return 460800;
|
||||||
|
case 500: return 500000;
|
||||||
|
case 921: return 921600;
|
||||||
|
case 1500: return 1500000;
|
||||||
|
}
|
||||||
|
// allow any other kbaud rate
|
||||||
|
return rate*1000;
|
||||||
|
}
|
||||||
|
|
@ -143,4 +143,7 @@ struct PACKED Location {
|
|||||||
#define AP_PRODUCT_ID_L3G4200D 0x101 // Linux with L3G4200D and ADXL345
|
#define AP_PRODUCT_ID_L3G4200D 0x101 // Linux with L3G4200D and ADXL345
|
||||||
#define AP_PRODUCT_ID_VRBRAIN 0x150 // VRBRAIN on NuttX
|
#define AP_PRODUCT_ID_VRBRAIN 0x150 // VRBRAIN on NuttX
|
||||||
|
|
||||||
|
// map from kbaud rate to baudrate
|
||||||
|
uint32_t map_baudrate(int16_t rate);
|
||||||
|
|
||||||
#endif // _AP_COMMON_H
|
#endif // _AP_COMMON_H
|
||||||
|
Loading…
Reference in New Issue
Block a user