import struct

from seabreeze.pyseabreeze.communication import USBCommOOI, USBCommOBP
from seabreeze.pyseabreeze.features._base import SeaBreezeFeature


# Definition
# ==========
#
class SeaBreezeNonlinearityCoefficientsFeature(SeaBreezeFeature):
    identifier = 'nonlinearity_coefficients'

    def get_nonlinearity_coefficients(self):
        raise NotImplementedError("implement in derived class")


# OOI implementation
# ==================
#
class NonlinearityCoefficientsEEPromFeatureOOI(SeaBreezeNonlinearityCoefficientsFeature):
    required_interface_cls = USBCommOOI
    required_features = ('eeprom',)

    def get_nonlinearity_coefficients(self):
        # The spectrometers store the wavelength calibration in slots 6..13
        coeffs = []
        order = int(float(self.device.f.eeprom.read_eeprom_slot(14)))
        for i in range(6, 6 + order + 1):
            coeffs.append(float(self.device.f.eeprom.read_eeprom_slot(i)))
        return coeffs


# OBP implementation
# ==================
#
class NonlinearityCoefficientsFeatureOBP(SeaBreezeNonlinearityCoefficientsFeature):
    required_interface_cls = USBCommOBP

    def get_nonlinearity_coefficients(self):
        # get number of nonlinearity coefficients
        data = self.device.query(0x00181100, "")
        N = struct.unpack("<B", data)[0]
        # now query the coefficients
        coeffs = []
        for i in range(N):
            data = self.device.query(0x00181101, struct.pack("<B", i))
            coeffs.append(struct.unpack("<f", data)[0])
        return coeffs

@@ -39,51 +39,48 @@
 eze.
-communication import USBCommOOI, USBCommOBP
+protocol import OOIProtocol, OBPProtocol
 %0Afro
@@ -142,16 +142,92 @@
 Feature%0A
+from seabreeze.pyseabreeze.features.eeprom import SeaBreezeEEPromFeatureOOI%0A
 %0A%0A# Defi
@@ -601,32 +601,33 @@
 tsFeature):%0A    
+_
 required_interfa
@@ -623,39 +623,40 @@
 red_
-interface_cls = USBCommOOI
+protocol_cls = OOIProtocol
 %0A    
+_
 requ
@@ -681,16 +681,17 @@
 eeprom',
+ 
 )%0A%0A    d
@@ -838,182 +838,320 @@
     
-order = int(float(self.device.f.eeprom.read_eeprom_slot(14)))%0A        for i in range(6, 6 + order + 1):%0A            coeffs.append(float(self.device.f.eeprom.read_eeprom_slot(
+# noinspection PyProtectedMember%0A        order = int(float(SeaBreezeEEPromFeatureOOI._func_eeprom_read_slot(self.protocol, 14)))%0A        for i in range(6, 6 + order + 1):%0A            # noinspection PyProtectedMember%0A            coeffs.append(float(SeaBreezeEEPromFeatureOOI._func_eeprom_read_slot(self.protocol, 
 i)))
@@ -1307,16 +1307,17 @@
 e):%0A    
+_
 required
@@ -1321,34 +1321,34 @@
 red_
-interface_cls = USBCommOBP
+protocol_cls = OBPProtocol
 %0A%0A  
@@ -1452,38 +1452,40 @@
     data = self.
-device
+protocol
 .query(0x0018110
@@ -1489,12 +1489,8 @@
 1100
-, %22%22
 )%0A  
@@ -1640,14 +1640,16 @@
 elf.
-device
+protocol
 .que
@@ -1667,28 +1667,9 @@
 01, 
-struct.pack(%22%3CB%22, i)
+i
 )%0A  

update after refactor