finished adding 48 bit int support
This commit is contained in:
+19
-21
@@ -13,9 +13,6 @@ print(BitArray(test).bin[:1])
|
||||
def chunker(seq, size):
|
||||
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
|
||||
|
||||
test = [16, -12, 1, 0, 3, 2, 999,0, -1277, -1, 1, 0]
|
||||
# accelerom_string = b"".join([struct.pack("h", x) for x in test])
|
||||
# print(b"".join([struct.pack("h", x) for x in test]))
|
||||
def test_bin_float_converstion():
|
||||
val = 100
|
||||
test = struct.pack(">f", val)
|
||||
@@ -27,22 +24,28 @@ def test_bin_float_converstion():
|
||||
print(struct.unpack("f", test))
|
||||
|
||||
def test_bin_int_converstion():
|
||||
print()
|
||||
val = 100
|
||||
test = struct.pack(">i", val)
|
||||
print("VAL IS ", val)
|
||||
test = struct.pack("i", val)
|
||||
binary = float_to_bin(val)
|
||||
print(binary)
|
||||
print(BinToInt().process(test))
|
||||
print(struct.unpack(">i", test))
|
||||
print(BinToInt().process(test, True))
|
||||
print(struct.unpack("i", test))
|
||||
print(BinToInt().process(test, True))
|
||||
print(struct.unpack(">i", test))
|
||||
|
||||
print()
|
||||
|
||||
val = -100
|
||||
test = struct.pack(">i", val)
|
||||
print("VAL IS ", val)
|
||||
test = struct.pack("i", val)
|
||||
binary = float_to_bin(val)
|
||||
print(binary)
|
||||
print(BinToInt().process(test))
|
||||
print(struct.unpack(">i", test))
|
||||
print(BinToInt().process(test, True))
|
||||
print(struct.unpack("i", test))
|
||||
print(BinToInt().process(test, True))
|
||||
print(struct.unpack(">i", test))
|
||||
|
||||
|
||||
def float_to_bin(num):
|
||||
@@ -51,23 +54,18 @@ def float_to_bin(num):
|
||||
|
||||
def convert_row_to_bytes(row):
|
||||
row = b"".join([struct.pack("h", x) for x in row])
|
||||
b2f = BinToFloat(15, 32)
|
||||
print([b2f.process(x) for x in chunker(row, 6)])
|
||||
|
||||
# structure = "q"
|
||||
# i = 8
|
||||
# print(len(accelerom_string))
|
||||
# print(struct.unpack(structure, accelerom_string[:i]), struct.unpack(structure, accelerom_string[i:2*i]),
|
||||
# struct.unpack(structure, accelerom_string[2*i:]))
|
||||
# b2f = BinToFloat(15, 32)
|
||||
b2i = BinToInt(48)
|
||||
print([b2i.process(x, True) for x in chunker(row, 6)])
|
||||
|
||||
|
||||
data = pd.read_csv("accelerometer.data")
|
||||
print(data)
|
||||
|
||||
test_bin_float_converstion()
|
||||
test_bin_int_converstion()
|
||||
# test_bin_float_converstion()
|
||||
# test_bin_int_converstion()
|
||||
|
||||
# for index, row in data.iterrows():
|
||||
# convert_row_to_bytes(row)
|
||||
for index, row in data.iterrows():
|
||||
convert_row_to_bytes(row)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user