kesavand | 0c06492 | 2020-12-15 15:36:25 +0530 | [diff] [blame] | 1 | // Copyright 2018 Open Networking Foundation |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | //Package utils gives type conversion helpers |
| 15 | package utils |
| 16 | |
| 17 | import ( |
| 18 | "encoding/hex" |
| 19 | "gerrit.opencord.org/kafka-topic-exporter/common/logger" |
| 20 | "strings" |
| 21 | ) |
| 22 | |
| 23 | var OnuSNhex bool |
| 24 | |
| 25 | //OnuSnHexEncode converts ONU sn from human readable format like 'SCOM00001B6D' to hex like '53434F4D00001B6D' |
| 26 | func OnuSnHexEncode(onuSn string) ( string) { |
| 27 | if len(onuSn) != 12 { |
| 28 | logger.Warn("ignoring serial to hex encode, 12 chars are expected for onuSn but %d are provided", len(onuSn)) |
| 29 | return onuSn |
| 30 | } |
| 31 | |
| 32 | output := hex.EncodeToString([]byte(onuSn[0:4])) + onuSn[4:12] |
| 33 | return strings.ToUpper(output) |
| 34 | } |
| 35 | |
| 36 | func GetOnuSN(onuSN string) (string) { |
| 37 | if OnuSNhex { |
| 38 | return OnuSnHexEncode(onuSN) |
| 39 | } else { |
| 40 | return onuSN |
| 41 | } |
| 42 | } |