Refactoring Ironcup 2020
Dependencies: mbed mbed-rtos MotionSensor EthernetInterface
Protocol/Protocol/receiver.h@0:8f5db5085df7, 2020-09-21 (annotated)
- Committer:
- starling
- Date:
- Mon Sep 21 21:42:07 2020 +0000
- Revision:
- 0:8f5db5085df7
12 mar 2020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
starling | 0:8f5db5085df7 | 1 | /** |
starling | 0:8f5db5085df7 | 2 | @file receiver.h |
starling | 0:8f5db5085df7 | 3 | @brief Receiver side functions declarations. |
starling | 0:8f5db5085df7 | 4 | */ |
starling | 0:8f5db5085df7 | 5 | |
starling | 0:8f5db5085df7 | 6 | /* |
starling | 0:8f5db5085df7 | 7 | Copyright 2016 Erik Perillo <erik.perillo@gmail.com> |
starling | 0:8f5db5085df7 | 8 | |
starling | 0:8f5db5085df7 | 9 | This file is part of piranha-ptc. |
starling | 0:8f5db5085df7 | 10 | |
starling | 0:8f5db5085df7 | 11 | This is free software: you can redistribute it and/or modify |
starling | 0:8f5db5085df7 | 12 | it under the terms of the GNU General Public License as published by |
starling | 0:8f5db5085df7 | 13 | the Free Software Foundation, either version 3 of the License, or |
starling | 0:8f5db5085df7 | 14 | (at your option) any later version. |
starling | 0:8f5db5085df7 | 15 | |
starling | 0:8f5db5085df7 | 16 | This is distributed in the hope that it will be useful, |
starling | 0:8f5db5085df7 | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
starling | 0:8f5db5085df7 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
starling | 0:8f5db5085df7 | 19 | See the GNU General Public License for more details. |
starling | 0:8f5db5085df7 | 20 | |
starling | 0:8f5db5085df7 | 21 | You should have received a copy of the GNU General Public License |
starling | 0:8f5db5085df7 | 22 | along with this. If not, see <http://www.gnu.org/licenses/>. |
starling | 0:8f5db5085df7 | 23 | */ |
starling | 0:8f5db5085df7 | 24 | |
starling | 0:8f5db5085df7 | 25 | |
starling | 0:8f5db5085df7 | 26 | #ifndef __PIRANHA_RCV_PROTOCOL_H__ |
starling | 0:8f5db5085df7 | 27 | #define __PIRANHA_RCV_PROTOCOL_H__ |
starling | 0:8f5db5085df7 | 28 | |
starling | 0:8f5db5085df7 | 29 | #include "protocol.h" |
starling | 0:8f5db5085df7 | 30 | #include "mbed.h" |
starling | 0:8f5db5085df7 | 31 | #include "EthernetInterface.h" |
starling | 0:8f5db5085df7 | 32 | |
starling | 0:8f5db5085df7 | 33 | #define TEST |
starling | 0:8f5db5085df7 | 34 | |
starling | 0:8f5db5085df7 | 35 | class Receiver |
starling | 0:8f5db5085df7 | 36 | { |
starling | 0:8f5db5085df7 | 37 | |
starling | 0:8f5db5085df7 | 38 | #ifdef TEST |
starling | 0:8f5db5085df7 | 39 | public: |
starling | 0:8f5db5085df7 | 40 | #else |
starling | 0:8f5db5085df7 | 41 | protected: |
starling | 0:8f5db5085df7 | 42 | #endif |
starling | 0:8f5db5085df7 | 43 | UDPSocket sock; |
starling | 0:8f5db5085df7 | 44 | char message[MSG_BUF_LEN]; |
starling | 0:8f5db5085df7 | 45 | Endpoint sender_addr; |
starling | 0:8f5db5085df7 | 46 | |
starling | 0:8f5db5085df7 | 47 | float un_scale(uint16_t value, float min, float max); |
starling | 0:8f5db5085df7 | 48 | uint8_t get_header(); |
starling | 0:8f5db5085df7 | 49 | uint16_t get_raw_val(int pos=0); |
starling | 0:8f5db5085df7 | 50 | float get_val(float min, float max, int pos=0); |
starling | 0:8f5db5085df7 | 51 | void get_vals(float min, float max, float* vals, int size); |
starling | 0:8f5db5085df7 | 52 | |
starling | 0:8f5db5085df7 | 53 | public: |
starling | 0:8f5db5085df7 | 54 | Receiver(); |
starling | 0:8f5db5085df7 | 55 | Receiver(Endpoint sender_addr, const UDPSocket& sock); |
starling | 0:8f5db5085df7 | 56 | Receiver(Endpoint sender_addr, int sock_port=RECEIVER_PORT, int timeout=1); |
starling | 0:8f5db5085df7 | 57 | |
starling | 0:8f5db5085df7 | 58 | void set_sender_addr(const Endpoint& sender_addr); |
starling | 0:8f5db5085df7 | 59 | void set_socket(const UDPSocket& sock); |
starling | 0:8f5db5085df7 | 60 | void set_socket(int port=RECEIVER_PORT, int timeout=1); |
starling | 0:8f5db5085df7 | 61 | Endpoint get_sender_addr(); |
starling | 0:8f5db5085df7 | 62 | UDPSocket get_socket(); |
starling | 0:8f5db5085df7 | 63 | |
starling | 0:8f5db5085df7 | 64 | bool receive(); |
starling | 0:8f5db5085df7 | 65 | uint8_t get_msg(); |
starling | 0:8f5db5085df7 | 66 | float get_abs_ang_ref(); |
starling | 0:8f5db5085df7 | 67 | float get_rel_ang_ref(); |
starling | 0:8f5db5085df7 | 68 | float get_mag_ang_ref(); |
starling | 0:8f5db5085df7 | 69 | float get_gnd_vel(); |
starling | 0:8f5db5085df7 | 70 | void get_brake(float* intensity, float* period); |
starling | 0:8f5db5085df7 | 71 | void get_jog_vel(float* period, float* ratio); |
starling | 0:8f5db5085df7 | 72 | void get_pid_params(float* params); |
starling | 0:8f5db5085df7 | 73 | void get_mag_calib(float* params); |
starling | 0:8f5db5085df7 | 74 | }; |
starling | 0:8f5db5085df7 | 75 | |
starling | 0:8f5db5085df7 | 76 | #endif |
starling | 0:8f5db5085df7 | 77 |