Orhan Kupusoglu | ec57af0 | 2021-05-12 12:38:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef TRX_EEPROM_READER_H |
| 18 | #define TRX_EEPROM_READER_H |
| 19 | |
| 20 | /** |
| 21 | * RSSI - Received Signal Strength Indication |
| 22 | * see: |
| 23 | * https://en.wikipedia.org/wiki/Received_signal_strength_indication |
| 24 | * |
| 25 | * per EC Ticket#7825 |
| 26 | * see: |
| 27 | * https://support.edge-core.com/hc/en-us/requests/7825 |
| 28 | */ |
| 29 | |
| 30 | class TrxEepromReader { |
| 31 | public: |
| 32 | enum device_type { |
| 33 | DEVICE_EITHER, |
| 34 | DEVICE_GPON, |
| 35 | DEVICE_XGSPON |
| 36 | }; |
| 37 | |
| 38 | enum power_type { |
| 39 | RX_POWER, |
| 40 | TX_POWER, |
| 41 | RX_AND_TX_POWER |
| 42 | }; |
| 43 | |
| 44 | TrxEepromReader(device_type dev_type, const power_type read_type, const int port); |
| 45 | TrxEepromReader() = delete; |
| 46 | |
| 47 | static std::pair<std::string, bool> read_txt_file(const std::string& file_name); |
| 48 | static std::string get_board_name(); |
| 49 | |
| 50 | int read_binary_file(char* buffer); |
| 51 | bool is_valid_port() const; |
| 52 | void set_port_path(); |
| 53 | unsigned long get_value_from_pointer_u(unsigned char *ptr, int size); |
| 54 | double raw_rx_to_mw(int raw); |
| 55 | double raw_tx_to_mw(int raw); |
| 56 | double mw_to_dbm(double mw); |
| 57 | std::pair<std::pair<int, int>, bool> read_power_raw(); |
| 58 | std::pair<std::pair<double, double>, bool> read_power_mean_dbm(); |
| 59 | std::string dump_data(); |
| 60 | int get_buf_size() const; |
| 61 | int get_read_offset() const; |
| 62 | int get_read_num_bytes() const; |
| 63 | int get_max_ports() const; |
| 64 | const char* get_node_path() const; |
| 65 | |
| 66 | private: |
| 67 | int _port; |
| 68 | power_type _read_type; |
| 69 | std::string _dev_name; |
| 70 | int _buf_size; |
| 71 | int _read_offset; |
| 72 | int _read_num_bytes; |
| 73 | int _port_addr; |
| 74 | std::string _name_eeprom; |
| 75 | const int* _bus_index; |
| 76 | size_t _max_ports; |
| 77 | |
| 78 | char _node_format[64] = {0}; |
| 79 | char _node_path[64] = {0}; |
| 80 | |
| 81 | const char* _master_format = "/sys/bus/i2c/devices/%s-00%d/%s"; |
| 82 | const int _gpon_bus_index[74] = { |
| 83 | 41, 42, 56, 55, 43, 44, 54, 53, |
| 84 | 45, 46, 52, 51, 47, 48, 50, 49, |
| 85 | 57, 58, 72, 71, 59, 60, 70, 69, |
| 86 | 61, 62, 68, 67, 63, 64, 66, 65, |
| 87 | 73, 74, 88, 87, 75, 76, 86, 85, |
| 88 | 77, 78, 84, 83, 79, 80, 82, 81, |
| 89 | 89, 90, 104, 103, 91, 92, 102, 101, |
| 90 | 93, 94, 100, 99, 95, 96, 98, 97, |
| 91 | 20, 21, 25, 26, 27, 28, 29, 30, |
| 92 | 31, 32 |
| 93 | }; |
| 94 | const int _xgspon_bus_index[20] = { |
| 95 | 47, 48, 37, 38, 35, 36, 33, 34, |
| 96 | 39, 40, 41, 42, 43, 44, 45, 46, |
| 97 | 49, 50, 51, 52 |
| 98 | }; |
| 99 | }; |
| 100 | |
| 101 | #endif |