|
| 1 | +/* |
| 2 | + * D1090Helper.cpp |
| 3 | + * Copyright (C) 2016-2026 Linar Yusupov |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <adsb_encoder.h> |
| 20 | +#include <TimeLib.h> |
| 21 | +#include <protocol.h> |
| 22 | + |
| 23 | +#include "SoCHelper.h" |
| 24 | +#include "D1090Helper.h" |
| 25 | +#include "GNSSHelper.h" |
| 26 | +#include "EEPROMHelper.h" |
| 27 | +#include "TrafficHelper.h" |
| 28 | +#include "WiFiHelper.h" |
| 29 | + |
| 30 | +static unsigned long D1090_Data_TimeMarker = 0; |
| 31 | + |
| 32 | +static void D1090_Parse_Character(char c) |
| 33 | +{ |
| 34 | + /* TODO */ |
| 35 | +} |
| 36 | + |
| 37 | +void D1090_setup() |
| 38 | +{ |
| 39 | + if (settings->m.protocol == PROTOCOL_D1090) { |
| 40 | + |
| 41 | + switch (settings->m.connection) |
| 42 | + { |
| 43 | + case CON_SERIAL_MAIN: |
| 44 | + case CON_SERIAL_AUX: |
| 45 | + uint32_t SerialBaud; |
| 46 | + |
| 47 | + switch (settings->m.baudrate) |
| 48 | + { |
| 49 | + case B4800: |
| 50 | + SerialBaud = 4800; |
| 51 | + break; |
| 52 | + case B9600: |
| 53 | + SerialBaud = 9600; |
| 54 | + break; |
| 55 | + case B19200: |
| 56 | + SerialBaud = 19200; |
| 57 | + break; |
| 58 | + case B57600: |
| 59 | + SerialBaud = 57600; |
| 60 | + break; |
| 61 | + case B115200: |
| 62 | + SerialBaud = 115200; |
| 63 | + break; |
| 64 | + case B2000000: |
| 65 | + SerialBaud = 2000000; |
| 66 | + break; |
| 67 | + case B38400: |
| 68 | + default: |
| 69 | + SerialBaud = 38400; |
| 70 | + break; |
| 71 | + } |
| 72 | + |
| 73 | + SoC->swSer_begin(SerialBaud); |
| 74 | + break; |
| 75 | + case CON_BLUETOOTH: |
| 76 | +#if 0 |
| 77 | + if (SoC->Bluetooth_ops) { |
| 78 | + SoC->Bluetooth_ops->setup(); |
| 79 | + } |
| 80 | +#endif |
| 81 | + break; |
| 82 | + case CON_USB: |
| 83 | + case CON_NONE: |
| 84 | + case CON_WIFI_UDP: |
| 85 | + default: |
| 86 | + break; |
| 87 | + } |
| 88 | + |
| 89 | + D1090_Data_TimeMarker = millis(); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +void D1090_loop() |
| 94 | +{ |
| 95 | + size_t size; |
| 96 | + |
| 97 | + switch (settings->m.connection) |
| 98 | + { |
| 99 | + case CON_SERIAL_MAIN: |
| 100 | + while (SerialInput.available() > 0) { |
| 101 | + char c = SerialInput.read(); |
| 102 | +// Serial.print(c); |
| 103 | + D1090_Parse_Character(c); |
| 104 | + D1090_Data_TimeMarker = millis(); |
| 105 | + } |
| 106 | + break; |
| 107 | + case CON_SERIAL_AUX: |
| 108 | + /* read data from Type-C USB port */ |
| 109 | + while (Serial.available() > 0) { |
| 110 | + char c = Serial.read(); |
| 111 | +// Serial.print(c); |
| 112 | + D1090_Parse_Character(c); |
| 113 | + D1090_Data_TimeMarker = millis(); |
| 114 | + } |
| 115 | + break; |
| 116 | + case CON_USB: |
| 117 | + /* read data from Type-C USB port in Host mode */ |
| 118 | + if (SoC->USB_ops) { |
| 119 | + while (SoC->USB_ops->available() > 0) { |
| 120 | + char c = SoC->USB_ops->read(); |
| 121 | +// Serial.print(c); |
| 122 | + D1090_Parse_Character(c); |
| 123 | + D1090_Data_TimeMarker = millis(); |
| 124 | + } |
| 125 | + } |
| 126 | + break; |
| 127 | + case CON_WIFI_UDP: |
| 128 | + size = SoC->WiFi_Receive_UDP((uint8_t *) UDPpacketBuffer, sizeof(UDPpacketBuffer)); |
| 129 | + if (size > 0) { |
| 130 | + for (size_t i=0; i < size; i++) { |
| 131 | +// Serial.print(UDPpacketBuffer[i]); |
| 132 | + D1090_Parse_Character(UDPpacketBuffer[i]); |
| 133 | + } |
| 134 | + D1090_Data_TimeMarker = millis(); |
| 135 | + } |
| 136 | + break; |
| 137 | + case CON_BLUETOOTH: |
| 138 | + if (SoC->Bluetooth_ops) { |
| 139 | + while (SoC->Bluetooth_ops->available() > 0) { |
| 140 | + char c = SoC->Bluetooth_ops->read(); |
| 141 | +// Serial.print(c); |
| 142 | + D1090_Parse_Character(c); |
| 143 | + D1090_Data_TimeMarker = millis(); |
| 144 | + } |
| 145 | + } |
| 146 | + break; |
| 147 | + case CON_NONE: |
| 148 | + default: |
| 149 | + break; |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +void D1090_Out(byte *buf, size_t size) |
| 154 | +{ |
| 155 | + if (size > 0) { |
| 156 | + switch(settings->m.data_dest) |
| 157 | + { |
| 158 | + case D1090_UART: |
| 159 | + case D1090_USB: |
| 160 | + Serial.write(buf, size); |
| 161 | + break; |
| 162 | + case D1090_BLUETOOTH: |
| 163 | + { |
| 164 | + if (SoC->Bluetooth_ops) { |
| 165 | + SoC->Bluetooth_ops->write(buf, size); |
| 166 | + } |
| 167 | + } |
| 168 | + break; |
| 169 | + case D1090_UDP: |
| 170 | + { |
| 171 | + SoC->WiFi_transmit_UDP(D1090_DST_PORT, buf, size); |
| 172 | + } |
| 173 | + break; |
| 174 | + case D1090_TCP: |
| 175 | + case D1090_OFF: |
| 176 | + default: |
| 177 | + break; |
| 178 | + } |
| 179 | + } |
| 180 | +} |
0 commit comments