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 : Simulator for the NMEA Serial rangefinder 17 : */ 18 : 19 : #include "SIM_RF_NMEA.h" 20 : 21 : #include <GCS_MAVLink/GCS.h> 22 : 23 : #include <stdio.h> 24 : #include <string.h> 25 : 26 : using namespace SITL; 27 : 28 1583 : uint32_t RF_NMEA::packet_for_alt(float alt_m, uint8_t *buffer, uint8_t buflen) 29 : { 30 : // Format 2 DBT NMEA mode (e.g. $SMDBT,5.94,f,1.81,M,67) 31 : // Format 3 DPT NMEA mode (e.g. $SMDPT,1.81,0.066) 32 : 33 1583 : ssize_t ret = snprintf((char*)buffer, buflen, "$SMDPT,%f,%f", alt_m, 0.01f); 34 1583 : uint8_t checksum = 0; 35 38319 : for (uint8_t i=1; i<ret; i++) { // 1 because the initial $ is skipped 36 36736 : checksum ^= buffer[i]; 37 : } 38 1583 : ret += snprintf((char*)&buffer[ret], buflen-ret, "*%02X\r\n", checksum); 39 1583 : return ret; 40 : } 41 : 42 1583 : uint32_t RF_NMEA::packet_for_temperature(float temperature, uint8_t *buffer, uint8_t buflen) 43 : { 44 1583 : ssize_t ret = snprintf((char*)buffer, buflen, "$SMMTW,%f %f", temperature, 0.01); 45 1583 : uint8_t checksum = 0; 46 39575 : for (uint8_t i=1; i<ret; i++) { // 1 because the initial $ is skipped 47 37992 : checksum ^= buffer[i]; 48 : } 49 1583 : ret += snprintf((char*)&buffer[ret], buflen-ret, "*%02X\r\n", checksum); 50 1583 : return ret; 51 : }