Пример #1
0
def createDatasetWithCompoundType(h5file):

    # component name -> (offset, size, type)

    ht = { 'a_name': (0, 4, H5T_NATIVE_INT),
           'b_name': (4, 4, H5T_NATIVE_FLOAT),
           'c_name': (8, 8, H5T_NATIVE_DOUBLE) }

    sizeof = 0
    for k in ht.keys():
        sizeof  += ht[k][1]

    dtype = H5T.create(H5T.CreateClass.COMPOUND, sizeof)
    for k in ht.keys():
        H5T.insert(dtype, k, ht[k][0], ht[k][2])

    npoints = 10
    shape = Array[Int64]((npoints,))
    dspace = H5S.create_simple(shape.Length, shape)

    dset = H5D.create(h5file, 'ArrayOfStructures', dtype, dspace)

    # create an array of Byte
    # use BitConverter to get Byte representations

    shape = Array[Int64]((npoints*sizeof,))
    byteArray = Array.CreateInstance(Byte, shape)

    for i in range(npoints):

        offset = i*sizeof

        a = Int32(i)
        Array.Copy(BitConverter.GetBytes(a), 0, byteArray,
                   offset+ht['a_name'][0], ht['a_name'][1])
        b = Single(i*i)
        Array.Copy(BitConverter.GetBytes(b), 0, byteArray,
                   offset+ht['b_name'][0], ht['b_name'][1])
        c = Double(1.0/(i+1.0))
        Array.Copy(BitConverter.GetBytes(c), 0, byteArray,
                   offset+ht['c_name'][0], ht['c_name'][1])

    H5D.write(dset, dtype, H5Array[Byte](byteArray))

    H5S.close(dspace)
    H5T.close(dtype)

    return dset
Пример #2
0
def PrintChunk(p, Addr):
    pHeader = p.xStructInfo("_POOL_HEADER", Addr)
    prevSize = pHeader.PreviousSize.Value << 4
    Size = pHeader.BlockSize.Value << 4
    Addr = pHeader.vAddress
    print "Address: " + Addr.ToString("X") + " Size: " + Size.ToString("X"),
    print " previous size: " + prevSize.ToString("X") + " Tag: " + Encoding.ASCII.GetString(BitConverter.GetBytes(pHeader.PoolTag.Value))
    return Size
Пример #3
0
	def parseString(json, index, success):
		s = StringBuilder()
		index = JsonDecoder.skipWhitespace(json, index)
		c = json[index] # "
		index += 1
		complete = False
		
		while not complete:
			if index == json.Length:
				break

			c = json[index]
			index += 1

			if c == '"':
				complete = True
				break

			elif c == '\\':
				if index == json.Length:
					break

				c = json[index]
				index += 1

				if c == '"':
					s.Append('"')
				elif c == '\\':
					s.Append('\\')
				elif c == '/':
					s.Append('/')
				elif c == 'b':
					s.Append('\b')
				elif c == 'f':
					s.Append('\f')
				elif c == 'n':
					s.Append('\n')
				elif c == 'r':
					s.Append('\r')
				elif c == 't':
					s.Append('\t')
				elif c == 'u':
					remainingLength = json.Length - index

					if remainingLength >= 4:
						sb = StringBuilder()
						
						for i in range(4):
							sb.Append(json[index + i])

						success, codePoint = UInt32.TryParse(sb.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture)
						
						if not success:
							return String.Empty, index, success

						s.Append(Encoding.UTF32.GetString(BitConverter.GetBytes(codePoint)))
						index += 4

					else:
						break

			else:
				s.Append(c)

		if not complete:
			return None, index, False

		return s.ToString(), index, success
from AntPlus.Profiles.Components import DataPage
from AntPlus.Profiles.BikePower import BikePowerDisplay, SetCustomCalibrationParameterPage
from AntPlus.Types import BindableByteArray
from System import Array, Byte, BitConverter, Int32
from System.Collections.Generic import List
import System


def stopScript():
    simulator.TurnOff()


simulator.TurnOn()
page = SetCustomCalibrationParameterPage()

# byte 0
# 1 = SCALE
# 2 = ?
byte_0 = Byte(1)

# bytes 1-4 : values (little endian 32 bits int)
bytes_value = BitConverter.GetBytes(Int32(-2300))

# byte 5 : reserved future use
byte_5 = Byte(0)

x = List[Byte]([byte_0] + [Byte(b) for b in bytes_value] + [byte_5])
array = BindableByteArray(x)
# page.Encode(array)
page.ManufacturerSpecificData = array
simulator.SendSetCustomCalibrationParameterPage(page)