Line data Source code
1 : /* 2 : This program is free software: you can redistribute it and/or modify 3 : it under the terms of the GNU General Public License as published by 4 : the Free Software Foundation, either version 3 of the License, or 5 : (at your option) any later version. 6 : 7 : This program is distributed in the hope that it will be useful, 8 : but WITHOUT ANY WARRANTY; without even the implied warranty of 9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 : GNU General Public License for more details. 11 : 12 : You should have received a copy of the GNU General Public License 13 : along with this program. If not, see <http://www.gnu.org/licenses/>. 14 : */ 15 : /* 16 : Base class for serial proximity sensors 17 : */ 18 : 19 : #include "SIM_SerialProximitySensor.h" 20 : 21 : #if AP_SIM_SERIALPROXIMITYSENSOR_ENABLED 22 : 23 : #include <AP_Math/AP_Math.h> 24 : 25 : #include <stdio.h> 26 : 27 : using namespace SITL; 28 : 29 0 : void SerialProximitySensor::update(const Location &location) 30 : { 31 : // just send a chunk of data at 5Hz: 32 0 : const uint32_t now = AP_HAL::millis(); 33 0 : if (now - last_sent_ms < reading_interval_ms()) { 34 0 : return; 35 : } 36 0 : last_sent_ms = now; 37 : 38 : uint8_t data[255]; 39 0 : const uint32_t packetlen = packet_for_location(location, 40 : data, 41 : ARRAY_SIZE(data)); 42 : 43 0 : write_to_autopilot((char*)data, packetlen); 44 : } 45 : 46 : #endif // AP_SIM_SERIALPROXIMITYSENSOR_ENABLED