cd33c7fc71
#### Why I did it Update scripts in sonic-buildimage from py-swsssdk to swsscommon #### How I did it Remove unused swsssdk import from accton device code #### How to verify it Pass all E2E test case #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 201811 - [ ] 201911 - [ ] 202006 - [ ] 202012 - [ ] 202106 - [ ] 202111 - [ ] 202205 #### Description for the changelog Remove unused swsssdk import from accton device code #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md --> #### A picture of a cute animal (not mandatory but encouraged)
55 lines
1.5 KiB
Python
Executable File
55 lines
1.5 KiB
Python
Executable File
# led_control.py
|
|
#
|
|
# Platform-specific LED control functionality for SONiC
|
|
#
|
|
|
|
try:
|
|
from sonic_led.led_control_base import LedControlBase
|
|
import threading
|
|
import os
|
|
import logging
|
|
import struct
|
|
import time
|
|
import syslog
|
|
from socket import *
|
|
from select import *
|
|
from minipack.pimutil import PimUtil
|
|
except ImportError as e:
|
|
raise ImportError(str(e) + " - required module not found")
|
|
|
|
|
|
class LedControl(LedControlBase):
|
|
"""Platform specific LED control class"""
|
|
SONIC_PORT_NAME_PREFIX = "Ethernet"
|
|
|
|
def __init__(self):
|
|
pim = PimUtil()
|
|
pim.init_pim_fpga()
|
|
|
|
def _port_name_to_index(self, port_name):
|
|
# Strip "Ethernet" off port name
|
|
if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX):
|
|
return -1
|
|
|
|
port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
|
|
return port_idx
|
|
|
|
def _port_state_to_mode(self, port_idx, state):
|
|
if state == "up":
|
|
return 1, 4 # port linkup, led is green
|
|
else:
|
|
return 0, 0 # port linkdown, led is off
|
|
|
|
def port_link_state_change(self, portname, state):
|
|
pim = PimUtil()
|
|
port_idx = self._port_name_to_index(portname)
|
|
new_control, led_mode = self._port_state_to_mode(port_idx, state)
|
|
color, control = pim.get_port_led(port_idx)
|
|
|
|
if color == led_mode:
|
|
if control == new_control:
|
|
return
|
|
|
|
pim.set_port_led(port_idx, led_mode, new_control) # port linkup, led is green
|
|
# port linkdown, led is off
|