Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [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 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 17 | package devices |
| 18 | |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 19 | import ( |
| 20 | "github.com/looplab/fsm" |
| 21 | "github.com/opencord/voltha-protos/go/openolt" |
| 22 | "strconv" |
| 23 | ) |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 24 | |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 25 | var newFSM = fsm.NewFSM |
| 26 | |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 27 | func getOperStateFSM(cb fsm.Callback) *fsm.FSM { |
Matteo Scandolo | 1100699 | 2019-08-28 11:29:46 -0700 | [diff] [blame] | 28 | return newFSM( |
Matteo Scandolo | 9a3518c | 2019-08-13 14:36:01 -0700 | [diff] [blame] | 29 | "down", |
| 30 | fsm.Events{ |
| 31 | {Name: "enable", Src: []string{"down"}, Dst: "up"}, |
| 32 | {Name: "disable", Src: []string{"up"}, Dst: "down"}, |
| 33 | }, |
| 34 | fsm.Callbacks{ |
| 35 | "enter_state": func(e *fsm.Event) { |
| 36 | cb(e) |
| 37 | }, |
| 38 | }, |
| 39 | ) |
| 40 | } |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 41 | |
Matteo Scandolo | 40e067f | 2019-10-16 16:59:41 -0700 | [diff] [blame^] | 42 | // deprecated |
Matteo Scandolo | 4b3fc7e | 2019-09-17 16:49:54 -0700 | [diff] [blame] | 43 | func onuSnToString(sn *openolt.SerialNumber) string { |
| 44 | s := string(sn.VendorId) |
| 45 | for _, i := range sn.VendorSpecific { |
| 46 | s = s + strconv.FormatInt(int64(i/16), 16) + strconv.FormatInt(int64(i%16), 16) |
| 47 | } |
| 48 | return s |
| 49 | } |