Beispiel #1
0
 def __init__(self, mode, sensitivity: list = [0, 0, 0]):
     self._modes = {
         "text": {
             "name": "Text Mode",
             "code": TAPInputMode.Text()
         },
         "controller": {
             "name": "Controller Mode",
             "code": TAPInputMode.Controller()
         },
         "controller_text": {
             "name": "Controller and Text Mode",
             "code": TAPInputMode.ControllerWithMouseHID()
         },
         "raw": {
             "name":
             "Raw sensors Mode",
             "code":
             TAPInputMode.RawSensor(
                 RawSensorSensitivity(System.Byte(0), System.Byte(0),
                                      System.Byte(0)))
         }
     }
     self.sensitivity = sensitivity
     if mode in self._modes.keys():
         self.mode = mode
         if mode == "raw":
             self._register_sensitivity(sensitivity)
     else:
         logging.warning("Invalid mode \"%s\". Set to \"text\"" % mode)
         self.mode = "text"
Beispiel #2
0
def hex_string_to_color(hex_str):
    """Получения цвета из HEX"""
    hex_str = hex_str.lstrip('##')
    r, g, b = (int(hex_str[i:i + 2], 16) for i in (0, 2, 4))
    color = DB.Color(System.Byte(r), System.Byte(g), System.Byte(b))

    logger.debug('Color was created')
    return color
Beispiel #3
0
def cont_to_itemloc(container):
    """Converts a container object to an ItemLocation. Makes the ItemLocation
    the last square in the container
    """
    iloc = Tibia.Objects.ItemLocation()
    iloc.FromContainer(
        System.Byte(container.Number),
        System.Byte(container.Volume - 1)
        )

    return iloc
 def loopbackfromrx2tx(self,channelMsk,enable): 
     data = self.Link.SpiRead(System.UInt16(0x101))&0xFF
     if   channelMsk&1 and enable:
         self.Link.SpiWrite(System.UInt16(0x101),System.Byte(data | 0x40))
     elif channelMsk&2 and enable:	
         self.Link.SpiWrite(System.UInt16(0x101),System.Byte(data | 0x80))
     elif channelMsk&1 and enable == 0:	
         self.Link.SpiWrite(System.UInt16(0x101),System.Byte(data & 0xBF))
     elif channelMsk&2 and enable == 0:	
         self.Link.SpiWrite(System.UInt16(0x101),System.Byte(data & 0x7F))
     else:
         print ('Invalid Tx channel for Talise')
Beispiel #5
0
    def stream_data_available(self, rxType, rxId):
        result = self._server.StreamDataAvailable(System.Byte(rxType),
                                                  System.Byte(rxId))

        # Is any data available
        if result[0]:
            # Is it data from the desired stream?
            if result[1] != rxType or result[2] != rxId:
                return False

        # Return result
        return result[0]
Beispiel #6
0
 def _register_sensitivity(self, sensitivity):
     if isinstance(sensitivity, list) and len(sensitivity) == 3:
         sensitivity[0] = max(0,
                              min(4,
                                  sensitivity[0]))  # fingers accelerometers
         sensitivity[1] = max(0, min(5, sensitivity[1]))  # imu gyro
         sensitivity[2] = max(0, min(4,
                                     sensitivity[2]))  # imu accelerometer
         self.sensitivity = sensitivity
         self._modes["raw"]["code"] = TAPInputMode.RawSensor(
             RawSensorSensitivity(System.Byte(sensitivity[0]),
                                  System.Byte(sensitivity[1]),
                                  System.Byte(sensitivity[2])))
Beispiel #7
0
    def __init__(self, ip, port, ttl, type_, id_):
        handler = UDP_Communications.UDP_Server.SenderHandler(
            self.__packet_received)
        self._server = UDP_Communications.UDP_Server(handler)
        # debug=True for more outputs in the Python command line.
        self._server.debug = False
        # Turn off local adapter filter; Let it switched off
        self._server.adapter_filter(False)
        self._server.init_udp(ip, port, ttl, System.Byte(type_),
                              System.Byte(id_), True)

        if not self._server.udp_active():
            raise RuntimeError("Server is not running!")
        pass
    def testByteConversion(self):
        """Test byte conversion."""
        self.failUnless(System.Byte.MaxValue == 255)
        self.failUnless(System.Byte.MinValue == 0)

        object = ConversionTest()
        self.failUnless(object.ByteField == 0)

        object.ByteField = 255
        self.failUnless(object.ByteField == 255)

        object.ByteField = 0
        self.failUnless(object.ByteField == 0)

        object.ByteField = System.Byte(255)
        self.failUnless(object.ByteField == 255)

        object.ByteField = System.Byte(0)
        self.failUnless(object.ByteField == 0)

        def test():
            ConversionTest().ByteField = "spam"
            
        self.failUnlessRaises(TypeError, test)

        def test():
            ConversionTest().ByteField = None
            
        self.failUnlessRaises(TypeError, test)

        def test():
            ConversionTest().ByteField = 256
            
        self.failUnlessRaises(OverflowError, test)

        def test():
            ConversionTest().ByteField = -1
            
        self.failUnlessRaises(OverflowError, test)

        def test():
            value = System.Byte(256)
            
        self.failUnlessRaises(OverflowError, test)

        def test():
            value = System.Byte(-1)
            
        self.failUnlessRaises(OverflowError, test)
Beispiel #9
0
    def get_stream_data(self, rxType, rxId):
        streamData = self._server.getStreamData(System.Byte(rxType),
                                                System.Byte(rxId))
        if streamData is None:
            return
        dataArray = []
        # NOTE: This is very inefficient; Has to be improved
        # The problem is conversion from System.Byte to e.g. numpy data type
        #for x in streamData:
        #    dataArray.append(x)
        # NOTE: For now we just convert the first 10 elements. However, everything is received.
        for x in range(9):
            dataArray.append(streamData[x])

        return dataArray
Beispiel #10
0
    def loot_logic0(self):
        """Placeholder for future implementation
        5 is reserved for corpses
        15 for rares.
        Will ignore stackables and commons for now.
        Return after every statement
        """
        corpse_items = list(self.corpse_cont.GetItems())

        for i in corpse_items:
            # print 'Scanning Corpse @ Item.Id: ', i.Id
            if i.Id in tid.loot_gold:
                bpmain_item = inven.GetItemInSlot(3)
                self.loot_enq_move(i, bpmain_item.Location.ToLocation())
                print 'Looting: ', tid.loot_list[i.Id]

                return

            elif i.Id in tid.loot_list: # and not in loot_gold

                if (i.Id in tid.loot_rares) or (i.Id in tid.loot_commons):
                    cntr = self.loot_cont_rares
                    if cntr.Amount == cntr.Volume:
                        self.idx_rare += 1
                        bp = self.loot_bps[self.idx_rare]
                        loc = bp.Location.ToLocation()
                        self.pqi.enq(2, ['use',
                                [[loc.X, loc.Y, loc.Z], bp.Id, 0, 15]])
                        # mk_itemuse([loc.X, loc.Y, loc.Z], bp.Id, 0, 15).Send()]
                        return
                    lootbp = self.loot_bps[self.idx_rare]
                    # print 'LOOT BP SET 722'
                elif i.Id in tid.loot_stack:
                    lootbp = self.loot_bps[self.idx_stk]
                    # print 'LOOT BP SET 725'

                # set_trace()
                self.loot_enq_move(i, lootbp.Location.ToLocation())
                # i.Move(lootbp.Location, System.Byte(i.Count)) # IMPLEMENT PACKET!
                print 'Looting: ', tid.loot_list[i.Id]

                return

            elif i == corpse_items[-1]: # At last item, and not in tid.loot_list
                for j in corpse_items:
                    if j.Id in tid.loot_subcont:
                        # PQI Implementation should not be needed here
                        j.OpenAsContainer(System.Byte(self.corpse_cont.Number))
                        return

                # No subcont
                # PQI Implementation should not be needed here
                self.pqi.tryct[2] = 0
                self.corpse_cont.Close()
                # Consider using an 'islooting' flag

        self.corpse_cont.Close() # Should only occur if corpse is empty
Beispiel #11
0
def test_byte_conversion():
    """Test byte conversion."""
    assert System.Byte.MaxValue == 255
    assert System.Byte.MinValue == 0

    ob = ConversionTest()
    assert ob.ByteField == 0

    ob.ByteField = 255
    assert ob.ByteField == 255

    ob.ByteField = 0
    assert ob.ByteField == 0

    ob.ByteField = System.Byte(255)
    assert ob.ByteField == 255

    ob.ByteField = System.Byte(0)
    assert ob.ByteField == 0

    with pytest.raises(TypeError):
        ConversionTest().ByteField = "spam"

    with pytest.raises(TypeError):
        ConversionTest().ByteField = None

    with pytest.raises(OverflowError):
        ConversionTest().ByteField = 256

    with pytest.raises(OverflowError):
        ConversionTest().ByteField = -1

    with pytest.raises(OverflowError):
        _ = System.Byte(256)

    with pytest.raises(OverflowError):
        _ = System.Byte(-1)
Beispiel #12
0
    def loot_logic1(self):
        """Looting works by moving items into a variety of crown BP's
        Needs: self.corpse_cont, self.loot_cont, self.loot_bps
        """

        # self.statusflag = 'looting'
        corpse_items = list(self.corpse_cont.GetItems())
        precount = len(corpse_items)

        for i in corpse_items:
            # print 'Scanning Corpse @ Item.Id: ', i.Id
            if i.Id in tid.loot_gold:
                bpmain_item = inven.GetItemInSlot(3)
                # i.Move(bpmain_item.Location, System.Byte(i.Count))
                # sleep(0.3)
                self.loot_enq_move(i, bpmain_item.Location.ToLocation())
                print 'Looting: ', tid.loot_list[i.Id]

                # Can Also try putting into into last slot of container.
                # toloc = list(bpmain.GetItems())[0].Location... change Z to Volume-1
                #  (0, +1, ID, containerid+64, +1)
                return

            elif i.Id in tid.loot_list: # and not in loot_gold
                if i.Id in tid.loot_rares:
                    lootbp = self.loot_bps[self.idx_rare]
                elif i.Id in tid.loot_commons:
                    lootbp = self.loot_bps[self.idx_com]
                elif i.Id in tid.loot_stack:
                    lootbp = self.loot_bps[self.idx_stk]
                elif i.Id in tid.loot_test: # Test
                    lootbp = self.loot_bps[self.idx_rare]

                # i.Move(lootbp.Location, System.Byte(i.Count)) # IMPLEMENT PACKET!
                # sleep(0.3)
                self.loot_enq_move(i, lootbp.Location.ToLocation())
                print 'Looting: ', tid.loot_list[i.Id]

                # Check for completion:
                postcount = len(list(self.corpse_cont.GetItems()))
                if postcount == precount: # Item did not move
                        pass
                elif postcount < precount:
                    if i.Id in tid.loot_rares:
                        self.ct_rare += 1
                        if self.ct_rare == 20:
                            self.idx_rare += 1
                            print 'changing bp'
                    elif i.Id in tid.loot_commons:
                        self.ct_com += 1
                        if self.ct_com == 20:
                            self.idx_com -= 1
                    elif i.Id in tid.loot_stack:
                        self.ct_stk += 1
                        if self.ct_stk == 20:
                            self.idx_stk -= 1
                    elif i.Id in tid.loot_test: # Test
                        self.ct_rare += 1
                        if self.ct_rare == 20:
                            self.idx_rare += 1

                return

            elif i == corpse_items[-1]: # At last item, and not in tid.loot_list
                for j in corpse_items:
                    if j.Id in tid.loot_subcont:
                        # PQI Implementation should not be needed here
                        j.OpenAsContainer(System.Byte(self.corpse_cont.Number))
                        return

                # No subcont
                # PQI Implementation should not be needed here
                self.pqi.tryct[2] = 0
                self.corpse_cont.Close()
                # Consider using an 'islooting' flag

        # PQI Implementation should not be needed here
        self.pqi.tryct[2] = 0
        self.corpse_cont.Close() # Should only occur if corpse is empty
 def spiWrite(self,address,data):
     self.Link.SpiWrite( System.UInt16(address), System.Byte(data) )
     print ("SPI Write Address " + hex(address) + ": " + hex(data))   
Beispiel #14
0
    print('Ouch! ' + __name__)


button.Click += onClick

clr.AddReference("DLT698_45.OOP")

from DLT698_45.OOP import *
from DLT698_45.OOP.DataType import DT_OAD, DT_OI, DT_LONG_UNSIGNED, DT_UNSIGNED
from DLT698_45.OOP.DataType import DT_Data, DT_OCTET_STRING
#from DLT698_45.OOP.APDUType import *
from DLT698_45.OOP.Frame import *

HData_remain = DT_OCTET_STRING('')
value = String("68170043050100000000001026F605010060120200001085166666")

frame1 = OOPFrame(DT_OCTET_STRING(value), HData_remain)

if frame1 != None:
    str = frame1.HValue
    print(str)
frame1.A.SA.Addr = '000000000002'
frame1.A.SA.AddrLogic = DT_UNSIGNED(System.Byte(1))  #DT_UNSIGNED('1')
frame1.A.CA = 16
oad = DT_OAD(DT_OCTET_STRING('60130200'))

frame1.UserDataRegion.UserData.APDUGetRequest.OAD = oad
frame1.UserDataRegion.UserData.APDUGetRequest.PIID.ServiceID = 1
str = frame1.HValue
print(str)
Beispiel #15
0
def test_pep3141():
    '''
    This is already well covered by CPython's test_abstract_numbers.py. Just 
    check a few .NET interop cases as well to see what happens.
    '''
    import System
    from numbers import Complex, Real, Rational, Integral, Number
    
    #--Complex
    for x in [
                System.Double(9), System.Int32(4), System.Boolean(1), 
                ]:
        Assert(isinstance(x, Complex))
    
    for x in [
                #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=23147
                System.Char.MaxValue, 
                System.Single(8), System.Decimal(10),
                System.SByte(0), System.Byte(1),
                System.Int16(2), System.UInt16(3), System.UInt32(5), System.Int64(6), System.UInt64(7),
                ]:
        Assert(not isinstance(x, Complex), x)
        
    #--Real
    for x in [
                System.Double(9), System.Int32(4), System.Boolean(1), 
                ]:
        Assert(isinstance(x, Real))
    
    for x in [
                #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=23147
                System.Char.MaxValue, 
                System.Single(8), System.Decimal(10),
                System.SByte(0), System.Byte(1),
                System.Int16(2), System.UInt16(3), System.UInt32(5), System.Int64(6), System.UInt64(7),
                ]:
        Assert(not isinstance(x, Real))
    
    
    #--Rational
    for x in [
                System.Int32(4), System.Boolean(1), 
                ]:
        Assert(isinstance(x, Rational))
    
    for x in [
                System.Double(9), 
                #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=23147
                System.Char.MaxValue, 
                System.Single(8), System.Decimal(10),
                System.SByte(0), System.Byte(1),
                System.Int16(2), System.UInt16(3), System.UInt32(5), System.Int64(6), System.UInt64(7),
                ]:
        Assert(not isinstance(x, Rational))
    
    #--Integral
    for x in [
                System.Int32(4), System.Boolean(1), 
                ]:
        Assert(isinstance(x, Integral))
    
    for x in [
                System.Double(9), 
                #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=23147
                System.Char.MaxValue, 
                System.Single(8), System.Decimal(10),
                System.SByte(0), System.Byte(1),
                System.Int16(2), System.UInt16(3), System.UInt32(5), System.Int64(6), System.UInt64(7),
                ]:
        Assert(not isinstance(x, Integral))

    #--Number
    for x in [ 
                System.Double(9), System.Int32(4), System.Boolean(1), 
                ]:
        Assert(isinstance(x, Number))
    
    for x in [  
                #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=23147
                System.Char.MaxValue, 
                System.Single(8), System.Decimal(10),
                System.SByte(0), System.Byte(1),
                System.Int16(2), System.UInt16(3), System.UInt32(5), System.Int64(6), System.UInt64(7),
                ]:
        Assert(not isinstance(x, Number))
Beispiel #16
0
 def send_stream(self, rxType, rxId, data):
     result = self._server.write(data.tobytes(), System.Byte(rxType),
                                 System.Byte(rxId))
     return result
 def loopbackfromdeframerA2framer(self,framer,enable):
     if framer == 1: address = 0x155A #Framer B
     else:           address = 0x1532 #Framer A
     data = self.Link.SpiRead(System.UInt16(address))&0xFF
     if enable:    self.Link.SpiWrite(System.UInt16(address),System.Byte(data | 0x80))
     else:         self.Link.SpiWrite(System.UInt16(address),System.Byte(data & 0x7F))
Beispiel #18
0
 def start_stream(self, rxType, rxId):
     result = self._server.startStream(System.Byte(rxType),
                                       System.Byte(rxId))
     return result
Beispiel #19
0
 def stop_stream(self, rxType, rxId):
     self._server.stopStream(System.Byte(rxType), System.Byte(rxId))
    def loadTxQecLolCalValues(self, txchannel, qecvals, lolvals):
        if qecvals == None or len(qecvals) != 22:    print('Invalid QEC cal values')
        elif txchannel == 1:
            # Load QEC Phase data
            for i in range(2):     self.Link.SpiWrite(System.UInt16(0xcc0+i), System.Byte(qecvals[i]))
            #Load QEC Gain Filter Coeffs
            for i in range(20):    self.Link.SpiWrite(System.UInt16(0xfe1+i), System.Byte(qecvals[2+i]))
            #Latch the bit to update QEC phase Data
            self.Link.SpiWrite(System.UInt16(0xcc1), System.Byte(qecvals[1] | 0x80))
            self.Link.SpiWrite(System.UInt16(0xcc1), System.Byte(qecvals[1] & 0x7F))
            #Latch the bit to update QEC Filter Coeffs
            self.Link.SpiWrite(System.UInt16(0xfe0), System.Byte(0x04))
        elif txchannel == 2:
            for i in range(2):     self.Link.SpiWrite(System.UInt16(0xcc2+i), System.Byte(qecvals[i]))
            for i in range(20):    self.Link.SpiWrite(System.UInt16(0x1001+i), System.Byte(qecvals[2+i]))
            self.Link.SpiWrite(System.UInt16(0xcc3), System.Byte(qecvals[1] | 0x80))
            self.Link.SpiWrite(System.UInt16(0xcc3), System.Byte(qecvals[1] & 0x7F))
            self.Link.SpiWrite(System.UInt16(0xfe0), System.Byte(0x08))
            
        if lolvals == None or len(lolvals) != 4:    print('Invalid LOL cal values')
        elif txchannel == 1:
            for i in range(4):    self.Link.SpiWrite(System.UInt16(0xff5+i), System.Byte(lolvals[i]))
            self.Link.SpiWrite(System.UInt16(0xfe0), System.Byte(0x01))
        elif txchannel == 2:
            for i in range(4):    self.Link.SpiWrite(System.UInt16(0x1015+i), System.Byte(lolvals[i]))        
            self.Link.SpiWrite(System.UInt16(0xfe0), System.Byte(0x02))





			
Beispiel #21
0
    def _emit_affix_body(il, s, inner_addr):  #s: specification
        #helpers
        c = System.Reflection.Emit.OpCodes
        Ldc_I4_ = lambda x: (getattr(c, "Ldc_I4_"+str(x)),) \
                            if (x in range(9)) else (c.Ldc_I4, x)
        Ldarg_ = lambda x: (getattr(c,"Ldarg_"+str(param_i)),) \
                           if (param_i in range(4)) else (c.Ldarg_S, param_i)
        methodinfo = lambda f: Harmony._get_target_info(f)['target']
        is_value_type = lambda t: System.Type.IsAssignableFrom(
            System.ValueType, t)

        #0  core python function return values
        il.DeclareLocal(System.Array[System.Object])
        #1  IDictionary assignments
        assdict_type = IronPython.Runtime.PythonDictionary
        il.DeclareLocal(assdict_type)
        #2  out object for TryGetValue
        il.DeclareLocal(System.Object)

        il.Emit(c.Nop)

        #get core python function
        il.Emit(c.Ldc_I8, System.Int64(inner_addr))
        il.Emit(c.Call, methodinfo(Python.AddressedStorage.Fetch))
        #stack: (core py func)

        #set up args
        il.Emit(*Ldc_I4_(len(s.core_param_list)))
        il.Emit(c.Newarr, System.Object)
        #stack: (core py func , arg array)
        _g = zip(range(len(s.core_param_list)), s.core_param_list)
        for array_i, coreparam in _g:
            #put array copy
            il.Emit(c.Dup)
            #put array index
            il.Emit(*Ldc_I4_(array_i))
            #put value from arg
            param_i = s.patch_param_list.index(coreparam)
            param_t = s.patch_param_types[param_i]
            il.Emit(*Ldarg_(param_i))
            if coreparam in s.refs:
                if is_value_type(param_t):
                    il.Emit(c.Ldobj, param_t)
                else:
                    il.Emit(c.Ldind_Ref)
            #save to array
            if is_value_type(param_t):
                il.Emit(c.Box, param_t)
            il.Emit(c.Stelem_Ref)
        #stack: (core py func , arg array)

        #call core (main) function
        _Call_targets = IronPython.Runtime.Operations.PythonCalls.Call.Overloads[
            System.Object, System.Array[System.Object]].Targets
        Call = dict((len(t.GetParameters()), t) for t in _Call_targets)[2]
        il.Emit(c.Call, Call)
        il.Emit(c.Castclass, System.Array[System.Object])
        il.Emit(c.Stloc_0)
        #stack: ()

        if s.refs:
            #try load assignments dictionary
            il.Emit(c.Ldloc_0)
            il.Emit(c.Ldc_I4_1)
            il.Emit(c.Ldelem_Ref)
            il.Emit(c.Isinst, assdict_type)
            il.Emit(c.Stloc_1)
            #stack: ()

            il.Emit(c.Nop)

            #jump to end if assignments dict is null
            il.Emit(c.Ldloc_1)
            label_assdict_null = il.DefineLabel()
            il.Emit(c.Brfalse_S, label_assdict_null)
            #stack: ()

            for ref in s.refs:
                param_i = s.patch_param_list.index(ref)
                param_t = s.patch_param_types[param_i]

                #trygetvalue
                il.Emit(c.Nop)
                il.Emit(c.Ldloc_1)
                il.Emit(c.Ldstr, ref)
                il.Emit(c.Ldloca_S, System.Byte(2))
                il.Emit(c.Callvirt, methodinfo(assdict_type.TryGetValue))
                label_skip_saveref = il.DefineLabel()
                #stack: ()
                #skip if key was not found
                il.Emit(c.Brfalse_S, label_skip_saveref)

                #set reference
                il.Emit(*Ldarg_(param_i))
                il.Emit(c.Ldloc_2)
                if is_value_type(param_t):
                    il.Emit(c.Unbox_Any, param_t)
                    il.Emit(c.Stobj, param_t)
                else:
                    il.Emit(c.Stind_Ref)

                il.MarkLabel(label_skip_saveref)

            il.MarkLabel(label_assdict_null)

        #return
        il.Emit(c.Nop)
        if s.patch_return_type is not None:
            il.Emit(c.Ldloc_0)
            il.Emit(c.Ldc_I4_0)
            il.Emit(c.Ldelem_Ref)
            if is_value_type(s.patch_return_type):
                il.Emit(c.Unbox_Any, s.patch_return_type)
            else:
                il.Emit(c.Isinst, s.patch_return_type)
        il.Emit(c.Ret)
 def test():
     value = System.Byte(-1)
 def test():
     value = System.Byte(256)
def IntsToBase64(ints):
    return System.Convert.ToBase64String([System.Byte(i) for i in ints].ToArray[System.Byte]())