Vorlage für Projekt
Dependencies: EthernetInterface mbed-rtos
Fork of Telemetrie_eth_h2m by
Telemetry.cpp@12:f34b079ae15c, 2016-07-20 (annotated)
- Committer:
- HMFK03LST1
- Date:
- Wed Jul 20 14:14:11 2016 +0000
- Revision:
- 12:f34b079ae15c
- Parent:
- 11:ad8346bafe5e
first
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HMFK03LST1 | 3:94a735c744ff | 1 | /** Ethernet Interface for send/receive Datastructs over udp |
HMFK03LST1 | 3:94a735c744ff | 2 | * |
HMFK03LST1 | 3:94a735c744ff | 3 | * |
HMFK03LST1 | 3:94a735c744ff | 4 | * By Sebastian Donner |
HMFK03LST1 | 3:94a735c744ff | 5 | * |
HMFK03LST1 | 3:94a735c744ff | 6 | * Permission is hereby granted, free of charge, to any person |
HMFK03LST1 | 3:94a735c744ff | 7 | * obtaining a copy of this software and associated documentation |
HMFK03LST1 | 3:94a735c744ff | 8 | * files (the "Software"), to deal in the Software without |
HMFK03LST1 | 3:94a735c744ff | 9 | * restriction, including without limitation the rights to use, |
HMFK03LST1 | 3:94a735c744ff | 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell |
HMFK03LST1 | 3:94a735c744ff | 11 | * copies of the Software, and to permit persons to whom the |
HMFK03LST1 | 3:94a735c744ff | 12 | * Software is furnished to do so, subject to the following |
HMFK03LST1 | 3:94a735c744ff | 13 | * conditions: |
HMFK03LST1 | 3:94a735c744ff | 14 | * |
HMFK03LST1 | 3:94a735c744ff | 15 | * The above copyright notice and this permission notice shall be |
HMFK03LST1 | 3:94a735c744ff | 16 | * included in all copies or substantial portions of the Software. |
HMFK03LST1 | 3:94a735c744ff | 17 | * |
HMFK03LST1 | 3:94a735c744ff | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
HMFK03LST1 | 3:94a735c744ff | 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
HMFK03LST1 | 3:94a735c744ff | 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
HMFK03LST1 | 3:94a735c744ff | 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
HMFK03LST1 | 3:94a735c744ff | 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
HMFK03LST1 | 3:94a735c744ff | 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
HMFK03LST1 | 3:94a735c744ff | 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
HMFK03LST1 | 3:94a735c744ff | 25 | * OTHER DEALINGS IN THE SOFTWARE. |
HMFK03LST1 | 3:94a735c744ff | 26 | */ |
HMFK03LST1 | 0:c0179f2ad295 | 27 | |
HMFK03LST1 | 0:c0179f2ad295 | 28 | #include "Telemetry.h" |
HMFK03LST1 | 0:c0179f2ad295 | 29 | |
HMFK03LST1 | 3:94a735c744ff | 30 | /**Debug Schnittstelle |
HMFK03LST1 | 3:94a735c744ff | 31 | */ |
HMFK03LST1 | 0:c0179f2ad295 | 32 | #ifdef DEBUG |
HMFK03LST1 | 2:e19b937a29c1 | 33 | Serial debug(USBTX, USBRX); |
HMFK03LST1 | 3:94a735c744ff | 34 | debug.baud(115200); |
HMFK03LST1 | 0:c0179f2ad295 | 35 | #endif |
HMFK03LST1 | 0:c0179f2ad295 | 36 | |
HMFK03LST1 | 3:94a735c744ff | 37 | /**Konstruktoren |
HMFK03LST1 | 3:94a735c744ff | 38 | */ |
HMFK03LST1 | 2:e19b937a29c1 | 39 | EthernetInterface eth; |
HMFK03LST1 | 0:c0179f2ad295 | 40 | TCPSocketConnection sock_tcp; |
HMFK03LST1 | 7:a269ac8c3259 | 41 | UDPSocket sock_udp_client; //send socket |
HMFK03LST1 | 11:ad8346bafe5e | 42 | UDPSocket sock_udp_server; //receive socket |
HMFK03LST1 | 2:e19b937a29c1 | 43 | |
HMFK03LST1 | 2:e19b937a29c1 | 44 | |
HMFK03LST1 | 0:c0179f2ad295 | 45 | |
HMFK03LST1 | 0:c0179f2ad295 | 46 | |
HMFK03LST1 | 3:94a735c744ff | 47 | /** Create a new Ethernet interface |
HMFK03LST1 | 3:94a735c744ff | 48 | * |
HMFK03LST1 | 3:94a735c744ff | 49 | */ |
HMFK03LST1 | 7:a269ac8c3259 | 50 | Telemetry::Telemetry(PinName ora, PinName gre):orange(ora),green(gre) |
HMFK03LST1 | 7:a269ac8c3259 | 51 | { |
HMFK03LST1 | 3:94a735c744ff | 52 | InitSucceed = false; |
HMFK03LST1 | 7:a269ac8c3259 | 53 | green = 0; |
HMFK03LST1 | 7:a269ac8c3259 | 54 | orange = 0; |
HMFK03LST1 | 0:c0179f2ad295 | 55 | } |
HMFK03LST1 | 0:c0179f2ad295 | 56 | |
HMFK03LST1 | 3:94a735c744ff | 57 | |
HMFK03LST1 | 3:94a735c744ff | 58 | /** Init a Serial Debug interface |
HMFK03LST1 | 3:94a735c744ff | 59 | * |
HMFK03LST1 | 3:94a735c744ff | 60 | */ |
HMFK03LST1 | 0:c0179f2ad295 | 61 | #ifdef DEBUG |
HMFK03LST1 | 0:c0179f2ad295 | 62 | void Telemetry::InitUSBSerialConnection() |
HMFK03LST1 | 0:c0179f2ad295 | 63 | { |
HMFK03LST1 | 0:c0179f2ad295 | 64 | serial.baud(115200); |
HMFK03LST1 | 0:c0179f2ad295 | 65 | } |
HMFK03LST1 | 0:c0179f2ad295 | 66 | #endif |
HMFK03LST1 | 0:c0179f2ad295 | 67 | |
HMFK03LST1 | 3:94a735c744ff | 68 | |
HMFK03LST1 | 3:94a735c744ff | 69 | |
HMFK03LST1 | 3:94a735c744ff | 70 | |
HMFK03LST1 | 3:94a735c744ff | 71 | /** Init Ethernet interface |
HMFK03LST1 | 3:94a735c744ff | 72 | * mit DHCP max. 10 Sekunden |
HMFK03LST1 | 3:94a735c744ff | 73 | */ |
HMFK03LST1 | 3:94a735c744ff | 74 | bool Telemetry::InitEthernetConnection() |
HMFK03LST1 | 3:94a735c744ff | 75 | { |
HMFK03LST1 | 3:94a735c744ff | 76 | bool ReturnValue = false; |
HMFK03LST1 | 3:94a735c744ff | 77 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 78 | debug.printf("Initalisiere LAN Verbindung mit DHCP\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 79 | #endif |
HMFK03LST1 | 3:94a735c744ff | 80 | |
HMFK03LST1 | 3:94a735c744ff | 81 | //Schnittstelle nur einmal initialisieren, sonst gibt es Fehler! |
HMFK03LST1 | 3:94a735c744ff | 82 | if (!InitSucceed) |
HMFK03LST1 | 3:94a735c744ff | 83 | { |
HMFK03LST1 | 3:94a735c744ff | 84 | if (eth.init()==0) //Init Interface |
HMFK03LST1 | 3:94a735c744ff | 85 | { |
HMFK03LST1 | 3:94a735c744ff | 86 | InitSucceed = true; |
HMFK03LST1 | 3:94a735c744ff | 87 | } |
HMFK03LST1 | 3:94a735c744ff | 88 | } |
HMFK03LST1 | 3:94a735c744ff | 89 | |
HMFK03LST1 | 3:94a735c744ff | 90 | //Nur wenn Initialisierung erfolgreich war! |
HMFK03LST1 | 3:94a735c744ff | 91 | if (InitSucceed) |
HMFK03LST1 | 3:94a735c744ff | 92 | { |
HMFK03LST1 | 3:94a735c744ff | 93 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 94 | serial.printf("Verbinde\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 95 | #endif |
HMFK03LST1 | 3:94a735c744ff | 96 | ip_self = eth.getIPAddress(); |
HMFK03LST1 | 3:94a735c744ff | 97 | |
HMFK03LST1 | 3:94a735c744ff | 98 | if (eth.connect(10000)==0) //CONNECT |
HMFK03LST1 | 3:94a735c744ff | 99 | { |
HMFK03LST1 | 3:94a735c744ff | 100 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 101 | printf("IP Adresse: %s\r\n\r\n", eth.getIPAddress()); |
HMFK03LST1 | 3:94a735c744ff | 102 | #endif |
HMFK03LST1 | 3:94a735c744ff | 103 | ReturnValue = true; |
HMFK03LST1 | 7:a269ac8c3259 | 104 | green = 1; |
HMFK03LST1 | 3:94a735c744ff | 105 | } |
HMFK03LST1 | 3:94a735c744ff | 106 | else |
HMFK03LST1 | 3:94a735c744ff | 107 | { |
HMFK03LST1 | 3:94a735c744ff | 108 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 109 | serial.printf("DHCP fail!\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 110 | #endif |
HMFK03LST1 | 3:94a735c744ff | 111 | ReturnValue = false; |
HMFK03LST1 | 3:94a735c744ff | 112 | } |
HMFK03LST1 | 3:94a735c744ff | 113 | } |
HMFK03LST1 | 3:94a735c744ff | 114 | |
HMFK03LST1 | 3:94a735c744ff | 115 | return ReturnValue; |
HMFK03LST1 | 3:94a735c744ff | 116 | } |
HMFK03LST1 | 3:94a735c744ff | 117 | |
HMFK03LST1 | 3:94a735c744ff | 118 | |
HMFK03LST1 | 3:94a735c744ff | 119 | /** Init Ethernet interface |
HMFK03LST1 | 4:5881695ba67a | 120 | * ohne DHCP max. 2.5 Sekunden |
HMFK03LST1 | 5:a96e4e59c710 | 121 | * @param IPAddress Interface IP |
HMFK03LST1 | 3:94a735c744ff | 122 | */ |
HMFK03LST1 | 4:5881695ba67a | 123 | bool Telemetry::InitEthernetConnection(const char* IPAddress, const char* SubNetMask, const char* GateWay) |
HMFK03LST1 | 3:94a735c744ff | 124 | { |
HMFK03LST1 | 3:94a735c744ff | 125 | bool ReturnValue = false; |
HMFK03LST1 | 3:94a735c744ff | 126 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 127 | printf("Initalisiere LAN Verbindung ohne DHCP\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 128 | printf("IP: %s - GateWay: %s - SubNetMask: %s\r\n\r\n",IPAdress, GateWay, SubNetMask); |
HMFK03LST1 | 3:94a735c744ff | 129 | #endif |
HMFK03LST1 | 3:94a735c744ff | 130 | |
HMFK03LST1 | 3:94a735c744ff | 131 | //Schnittstelle nur einmal initialisieren, sonst gibt es Fehler! |
HMFK03LST1 | 3:94a735c744ff | 132 | if (!InitSucceed) |
HMFK03LST1 | 3:94a735c744ff | 133 | { |
HMFK03LST1 | 4:5881695ba67a | 134 | if (eth.init(IPAddress, SubNetMask, GateWay)==0) //Init Interface |
HMFK03LST1 | 3:94a735c744ff | 135 | { |
HMFK03LST1 | 3:94a735c744ff | 136 | InitSucceed = true; |
HMFK03LST1 | 3:94a735c744ff | 137 | } |
HMFK03LST1 | 3:94a735c744ff | 138 | } |
HMFK03LST1 | 3:94a735c744ff | 139 | |
HMFK03LST1 | 3:94a735c744ff | 140 | //Nur wenn Initialisierung erfolgreich war! |
HMFK03LST1 | 3:94a735c744ff | 141 | if (InitSucceed) |
HMFK03LST1 | 3:94a735c744ff | 142 | { |
HMFK03LST1 | 3:94a735c744ff | 143 | if (eth.connect(2500)==0) //CONNECT |
HMFK03LST1 | 3:94a735c744ff | 144 | { |
HMFK03LST1 | 7:a269ac8c3259 | 145 | green = 1; |
HMFK03LST1 | 3:94a735c744ff | 146 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 147 | serial.printf("Init success!"); |
HMFK03LST1 | 3:94a735c744ff | 148 | #endif |
HMFK03LST1 | 12:f34b079ae15c | 149 | ip_self = eth.getIPAddress(); |
HMFK03LST1 | 3:94a735c744ff | 150 | ReturnValue = true; |
HMFK03LST1 | 3:94a735c744ff | 151 | } |
HMFK03LST1 | 3:94a735c744ff | 152 | else |
HMFK03LST1 | 3:94a735c744ff | 153 | { |
HMFK03LST1 | 3:94a735c744ff | 154 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 155 | serial.printf("Init fail!"); |
HMFK03LST1 | 3:94a735c744ff | 156 | #endif |
HMFK03LST1 | 3:94a735c744ff | 157 | ReturnValue = false; |
HMFK03LST1 | 3:94a735c744ff | 158 | } |
HMFK03LST1 | 3:94a735c744ff | 159 | } |
HMFK03LST1 | 3:94a735c744ff | 160 | |
HMFK03LST1 | 3:94a735c744ff | 161 | return ReturnValue; |
HMFK03LST1 | 3:94a735c744ff | 162 | } |
HMFK03LST1 | 3:94a735c744ff | 163 | |
HMFK03LST1 | 3:94a735c744ff | 164 | |
HMFK03LST1 | 3:94a735c744ff | 165 | //! Close Connection |
HMFK03LST1 | 3:94a735c744ff | 166 | void Telemetry::CloseEthernetConnection() |
HMFK03LST1 | 3:94a735c744ff | 167 | { |
HMFK03LST1 | 3:94a735c744ff | 168 | eth.disconnect(); |
HMFK03LST1 | 3:94a735c744ff | 169 | InitSucceed = false; |
HMFK03LST1 | 3:94a735c744ff | 170 | |
HMFK03LST1 | 3:94a735c744ff | 171 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 172 | serial.printf("LAN Stack close\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 173 | #endif |
HMFK03LST1 | 3:94a735c744ff | 174 | } |
HMFK03LST1 | 3:94a735c744ff | 175 | |
HMFK03LST1 | 3:94a735c744ff | 176 | |
HMFK03LST1 | 3:94a735c744ff | 177 | //! Connect Port TCP |
HMFK03LST1 | 7:a269ac8c3259 | 178 | void Telemetry::ConnectSocket_TCP(Endpoint Host) |
HMFK03LST1 | 3:94a735c744ff | 179 | { |
HMFK03LST1 | 3:94a735c744ff | 180 | sock_tcp.connect(Host.get_address(), Host.get_port()); |
HMFK03LST1 | 3:94a735c744ff | 181 | sock_tcp.set_blocking(false, 0); |
HMFK03LST1 | 3:94a735c744ff | 182 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 183 | serial.printf("Open TCP Socket to IP: %s:%d.\r\n\r\n",Host.get_address(), Host.get_port()); |
HMFK03LST1 | 3:94a735c744ff | 184 | #endif |
HMFK03LST1 | 3:94a735c744ff | 185 | } |
HMFK03LST1 | 3:94a735c744ff | 186 | |
HMFK03LST1 | 3:94a735c744ff | 187 | |
HMFK03LST1 | 3:94a735c744ff | 188 | //! Connect Port UDP receive |
HMFK03LST1 | 7:a269ac8c3259 | 189 | void Telemetry::ConnectSocket_UDP_Client() |
HMFK03LST1 | 3:94a735c744ff | 190 | { |
HMFK03LST1 | 7:a269ac8c3259 | 191 | sock_udp_client.init(); |
HMFK03LST1 | 7:a269ac8c3259 | 192 | sock_udp_client.set_blocking(false, 0); |
HMFK03LST1 | 3:94a735c744ff | 193 | |
HMFK03LST1 | 3:94a735c744ff | 194 | #ifdef DEBUG |
HMFK03LST1 | 7:a269ac8c3259 | 195 | serial.printf("Open UDP_Client Socket\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 196 | #endif |
HMFK03LST1 | 3:94a735c744ff | 197 | } |
HMFK03LST1 | 3:94a735c744ff | 198 | |
HMFK03LST1 | 3:94a735c744ff | 199 | |
HMFK03LST1 | 3:94a735c744ff | 200 | //! Connect Port UDP send |
HMFK03LST1 | 7:a269ac8c3259 | 201 | void Telemetry::ConnectSocket_UDP_Server(int Port) |
HMFK03LST1 | 3:94a735c744ff | 202 | { |
HMFK03LST1 | 7:a269ac8c3259 | 203 | sock_udp_server.init(); |
HMFK03LST1 | 7:a269ac8c3259 | 204 | sock_udp_server.bind(Port); |
HMFK03LST1 | 3:94a735c744ff | 205 | #ifdef DEBUG |
HMFK03LST1 | 7:a269ac8c3259 | 206 | serial.printf("Open UDP_Server on Port: %d.\r\n\r\n",Port); |
HMFK03LST1 | 3:94a735c744ff | 207 | #endif |
HMFK03LST1 | 3:94a735c744ff | 208 | } |
HMFK03LST1 | 3:94a735c744ff | 209 | |
HMFK03LST1 | 3:94a735c744ff | 210 | |
HMFK03LST1 | 3:94a735c744ff | 211 | //! Close Port TCP |
HMFK03LST1 | 7:a269ac8c3259 | 212 | void Telemetry::CloseSocket_TCP() |
HMFK03LST1 | 3:94a735c744ff | 213 | { |
HMFK03LST1 | 3:94a735c744ff | 214 | sock_tcp.close(); |
HMFK03LST1 | 3:94a735c744ff | 215 | |
HMFK03LST1 | 3:94a735c744ff | 216 | #ifdef DEBUG |
HMFK03LST1 | 3:94a735c744ff | 217 | serial.printf("TCP Socket closed.\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 218 | #endif |
HMFK03LST1 | 3:94a735c744ff | 219 | } |
HMFK03LST1 | 3:94a735c744ff | 220 | |
HMFK03LST1 | 3:94a735c744ff | 221 | |
HMFK03LST1 | 3:94a735c744ff | 222 | //! Close Port UDP receive |
HMFK03LST1 | 7:a269ac8c3259 | 223 | void Telemetry::CloseSocket_UDP_Client() |
HMFK03LST1 | 3:94a735c744ff | 224 | { |
HMFK03LST1 | 7:a269ac8c3259 | 225 | sock_udp_client.close(); |
HMFK03LST1 | 3:94a735c744ff | 226 | #ifdef DEBUG |
HMFK03LST1 | 7:a269ac8c3259 | 227 | serial.printf("UDP Client Socket closed.\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 228 | #endif |
HMFK03LST1 | 3:94a735c744ff | 229 | } |
HMFK03LST1 | 3:94a735c744ff | 230 | |
HMFK03LST1 | 3:94a735c744ff | 231 | |
HMFK03LST1 | 3:94a735c744ff | 232 | //! Close Port UDP send |
HMFK03LST1 | 7:a269ac8c3259 | 233 | void Telemetry::CloseSocket_UDP_Server() |
HMFK03LST1 | 3:94a735c744ff | 234 | { |
HMFK03LST1 | 7:a269ac8c3259 | 235 | sock_udp_server.close(); |
HMFK03LST1 | 3:94a735c744ff | 236 | |
HMFK03LST1 | 3:94a735c744ff | 237 | #ifdef DEBUG |
HMFK03LST1 | 7:a269ac8c3259 | 238 | serial.printf("UDP Server Socket closed.\r\n\r\n"); |
HMFK03LST1 | 3:94a735c744ff | 239 | #endif |
HMFK03LST1 | 3:94a735c744ff | 240 | } |
HMFK03LST1 | 3:94a735c744ff | 241 | |
HMFK03LST1 | 3:94a735c744ff | 242 | |
HMFK03LST1 | 3:94a735c744ff | 243 | //! Struct Check Sum calc |
HMFK03LST1 | 6:abadad863420 | 244 | uint8_t Telemetry::do_cs(uint8_t* buffer) |
HMFK03LST1 | 2:e19b937a29c1 | 245 | { |
HMFK03LST1 | 5:a96e4e59c710 | 246 | uint8_t ck_a=0; |
HMFK03LST1 | 5:a96e4e59c710 | 247 | uint8_t ck_b=0; |
HMFK03LST1 | 2:e19b937a29c1 | 248 | |
HMFK03LST1 | 2:e19b937a29c1 | 249 | for(int i=0; i < (buffer[0]-1); i++) |
HMFK03LST1 | 2:e19b937a29c1 | 250 | { |
HMFK03LST1 | 2:e19b937a29c1 | 251 | ck_a += buffer[i]; |
HMFK03LST1 | 2:e19b937a29c1 | 252 | ck_b += ck_a; |
HMFK03LST1 | 2:e19b937a29c1 | 253 | } |
HMFK03LST1 | 2:e19b937a29c1 | 254 | |
HMFK03LST1 | 2:e19b937a29c1 | 255 | return ck_b; |
HMFK03LST1 | 2:e19b937a29c1 | 256 | } |
HMFK03LST1 | 2:e19b937a29c1 | 257 | |
HMFK03LST1 | 2:e19b937a29c1 | 258 | |
HMFK03LST1 | 7:a269ac8c3259 | 259 | //! Read UDP Packet on Client Port |
HMFK03LST1 | 7:a269ac8c3259 | 260 | int Telemetry::Rec_Data_UDP_Client(char *buffer, int size) |
HMFK03LST1 | 0:c0179f2ad295 | 261 | { |
HMFK03LST1 | 7:a269ac8c3259 | 262 | return sock_udp_client.receiveFrom(input_Client, buffer, size); |
HMFK03LST1 | 2:e19b937a29c1 | 263 | } |
HMFK03LST1 | 2:e19b937a29c1 | 264 | |
HMFK03LST1 | 7:a269ac8c3259 | 265 | //! Read UDP Packet on Server Port |
HMFK03LST1 | 7:a269ac8c3259 | 266 | int Telemetry::Rec_Data_UDP_Server(char *buffer, int size) |
HMFK03LST1 | 7:a269ac8c3259 | 267 | { |
HMFK03LST1 | 7:a269ac8c3259 | 268 | return sock_udp_server.receiveFrom(input_Server, buffer, size); |
HMFK03LST1 | 7:a269ac8c3259 | 269 | } |
HMFK03LST1 | 2:e19b937a29c1 | 270 | |
HMFK03LST1 | 7:a269ac8c3259 | 271 | |
HMFK03LST1 | 3:94a735c744ff | 272 | //! Check UDP Packet of containing Struct |
HMFK03LST1 | 7:a269ac8c3259 | 273 | bool Telemetry::Rec_Struct(uint8_t *buffer) |
HMFK03LST1 | 7:a269ac8c3259 | 274 | { |
HMFK03LST1 | 7:a269ac8c3259 | 275 | orange = !orange; |
HMFK03LST1 | 2:e19b937a29c1 | 276 | if (buffer[buffer[0]-1] == do_cs(buffer)) return true; |
HMFK03LST1 | 2:e19b937a29c1 | 277 | else return false; |
HMFK03LST1 | 2:e19b937a29c1 | 278 | } |
HMFK03LST1 | 2:e19b937a29c1 | 279 | |
HMFK03LST1 | 2:e19b937a29c1 | 280 | |
HMFK03LST1 | 3:94a735c744ff | 281 | //! Read TCP Packet |
HMFK03LST1 | 2:e19b937a29c1 | 282 | int Telemetry::Rec_Data_TCP(char *buffer,int size) |
HMFK03LST1 | 2:e19b937a29c1 | 283 | { |
HMFK03LST1 | 7:a269ac8c3259 | 284 | orange = !orange; |
HMFK03LST1 | 2:e19b937a29c1 | 285 | return sock_tcp.receive(buffer, size); |
HMFK03LST1 | 2:e19b937a29c1 | 286 | } |
HMFK03LST1 | 2:e19b937a29c1 | 287 | |
HMFK03LST1 | 2:e19b937a29c1 | 288 | |
HMFK03LST1 | 7:a269ac8c3259 | 289 | //! Send UDP Packet as Client |
HMFK03LST1 | 7:a269ac8c3259 | 290 | void Telemetry::Send_Data_UDP_Client(Endpoint Server, char* Daten, int size ) |
HMFK03LST1 | 3:94a735c744ff | 291 | { |
HMFK03LST1 | 7:a269ac8c3259 | 292 | sock_udp_client.sendTo(Server, Daten, size); |
HMFK03LST1 | 7:a269ac8c3259 | 293 | orange = !orange; |
HMFK03LST1 | 0:c0179f2ad295 | 294 | #ifdef DEBUG |
HMFK03LST1 | 0:c0179f2ad295 | 295 | serial.printf("UDP Paket gesendet.\r\n\r\n"); |
HMFK03LST1 | 0:c0179f2ad295 | 296 | #endif |
HMFK03LST1 | 0:c0179f2ad295 | 297 | } |
HMFK03LST1 | 0:c0179f2ad295 | 298 | |
HMFK03LST1 | 7:a269ac8c3259 | 299 | //! Send UDP Packet as Server |
HMFK03LST1 | 7:a269ac8c3259 | 300 | void Telemetry::Send_Data_UDP_Server(Endpoint Client, char* Daten, int size ) |
HMFK03LST1 | 7:a269ac8c3259 | 301 | { |
HMFK03LST1 | 7:a269ac8c3259 | 302 | sock_udp_server.sendTo(Client, Daten, size); |
HMFK03LST1 | 7:a269ac8c3259 | 303 | orange = !orange; |
HMFK03LST1 | 7:a269ac8c3259 | 304 | #ifdef DEBUG |
HMFK03LST1 | 7:a269ac8c3259 | 305 | serial.printf("UDP Paket gesendet.\r\n\r\n"); |
HMFK03LST1 | 7:a269ac8c3259 | 306 | #endif |
HMFK03LST1 | 7:a269ac8c3259 | 307 | } |
HMFK03LST1 | 2:e19b937a29c1 | 308 | |
HMFK03LST1 | 7:a269ac8c3259 | 309 | //! Send Struct as UDP Client |
HMFK03LST1 | 7:a269ac8c3259 | 310 | void Telemetry::Send_Struct_UDP_Client(Endpoint Server, uint8_t* Daten) |
HMFK03LST1 | 2:e19b937a29c1 | 311 | { |
HMFK03LST1 | 2:e19b937a29c1 | 312 | Daten[(*Daten - 1)] = do_cs(Daten); |
HMFK03LST1 | 7:a269ac8c3259 | 313 | sock_udp_client.sendTo(Server, (char*)Daten, *Daten); |
HMFK03LST1 | 7:a269ac8c3259 | 314 | orange = !orange; |
HMFK03LST1 | 2:e19b937a29c1 | 315 | } |
HMFK03LST1 | 2:e19b937a29c1 | 316 | |
HMFK03LST1 | 7:a269ac8c3259 | 317 | //! Send Struct as UDP Server |
HMFK03LST1 | 7:a269ac8c3259 | 318 | void Telemetry::Send_Struct_UDP_Server(Endpoint Client, uint8_t* Daten) |
HMFK03LST1 | 7:a269ac8c3259 | 319 | { |
HMFK03LST1 | 7:a269ac8c3259 | 320 | Daten[(*Daten - 1)] = do_cs(Daten); |
HMFK03LST1 | 7:a269ac8c3259 | 321 | sock_udp_server.sendTo(Client, (char*)Daten, *Daten); |
HMFK03LST1 | 7:a269ac8c3259 | 322 | orange = !orange; |
HMFK03LST1 | 7:a269ac8c3259 | 323 | } |
HMFK03LST1 | 2:e19b937a29c1 | 324 | |
HMFK03LST1 | 3:94a735c744ff | 325 | //! Send TCP Packet |
HMFK03LST1 | 3:94a735c744ff | 326 | void Telemetry::Send_Data_TCP(char* Host, char* Buffer) |
HMFK03LST1 | 0:c0179f2ad295 | 327 | { |
HMFK03LST1 | 0:c0179f2ad295 | 328 | |
HMFK03LST1 | 3:94a735c744ff | 329 | /* Umwandeln in char* |
HMFK03LST1 | 0:c0179f2ad295 | 330 | const char *DataBuf = datenpaket.c_str(); |
HMFK03LST1 | 0:c0179f2ad295 | 331 | char DataPaket[datenpaket.length()]; |
HMFK03LST1 | 0:c0179f2ad295 | 332 | strcpy(DataPaket,DataBuf); |
HMFK03LST1 | 3:94a735c744ff | 333 | */ |
HMFK03LST1 | 0:c0179f2ad295 | 334 | #ifdef DEBUG |
HMFK03LST1 | 0:c0179f2ad295 | 335 | serial.printf("----\r\n%s----\r\n\r\n",DataPaket); |
HMFK03LST1 | 0:c0179f2ad295 | 336 | serial.printf("Sende Paket.\r\n\r\n"); |
HMFK03LST1 | 0:c0179f2ad295 | 337 | #endif |
HMFK03LST1 | 0:c0179f2ad295 | 338 | |
HMFK03LST1 | 3:94a735c744ff | 339 | sock_tcp.send_all(Buffer, sizeof(Buffer)-1); |
HMFK03LST1 | 0:c0179f2ad295 | 340 | |
HMFK03LST1 | 0:c0179f2ad295 | 341 | #ifdef DEBUG |
HMFK03LST1 | 0:c0179f2ad295 | 342 | serial.printf("Paket gesendet.\r\n\r\n"); |
HMFK03LST1 | 0:c0179f2ad295 | 343 | #endif |
HMFK03LST1 | 0:c0179f2ad295 | 344 | } |
HMFK03LST1 | 0:c0179f2ad295 | 345 | |
HMFK03LST1 | 2:e19b937a29c1 | 346 | |
HMFK03LST1 | 0:c0179f2ad295 | 347 | |
HMFK03LST1 | 2:e19b937a29c1 | 348 | |
HMFK03LST1 | 0:c0179f2ad295 | 349 |