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 simulator for the NoopLoop TOFSense-F/P Serial RangeFinders 17 : */ 18 : 19 : #include "SIM_RF_JRE.h" 20 : 21 : using namespace SITL; 22 : 23 0 : uint32_t RF_JRE::packet_for_alt(float alt_m, uint8_t *buffer, uint8_t buflen) 24 : { 25 0 : uint16_t status = 0; 26 0 : if (alt_m > 500) { 27 0 : status |= 0x2; // NTRK, whatever that means... 28 : } 29 : 30 0 : const uint16_t alt_cm = alt_m * 100; 31 : 32 0 : buffer[0] = 'R'; 33 0 : buffer[1] = 'A'; 34 0 : buffer[2] = 0x01; 35 0 : buffer[3] = frame_count++; 36 0 : buffer[4] = alt_cm >> 8; // altitide low 37 0 : buffer[5] = alt_cm & 0xff; // Altitude-High, LSB 38 0 : buffer[6] = 0x00; // reserved 39 0 : buffer[7] = 0x00; // reserved 40 0 : buffer[8] = 0x00; // reserved 41 0 : buffer[9] = 0x00; // reserved 42 0 : buffer[10] = 0x00; // FFT 43 0 : buffer[11] = 0x00; // FFT 44 0 : buffer[12] = status >> 8; // FFT 45 0 : buffer[13] = status & 0xff; // FFT 46 : 47 0 : const uint16_t crc = crc16_ccitt_r(&buffer[0], 14, 0xffff, 0xffff); 48 0 : buffer[14] = crc & 0xff; 49 0 : buffer[15] = crc >> 8; 50 : 51 0 : return 16; 52 : }