Make this code more readable please, fix all the naming convention issues too
import time
import os
import struct
import ctypes 
from queue import Queue
from datetime import datetime, timedelta, timezone

GPS_TIME_TO_UTC_LEAP_SECONDS = 18
ACCELEROMETER_DEVICE_INDEX = 0
GYROSCOPE_DEVICE_INDEX = 1
ACCEL_FSR_2G = GYRO_FSR_250DPS = 0
ACCEL_FSR_4G = GYRO_FSR_500DPS = 1
ACCEL_FSR_8G = GYRO_FSR_1000DPS = 2
ACCEL_FSR_16G = GYRO_FSR_2000DPS = 3
ACCEL_ODR_12_5Hz = GYRO_ODR_12_5Hz = 12
ACCEL_ODR_25Hz = GYRO_ODR_25Hz = 25
ACCEL_ODR_50Hz = GYRO_ODR_50Hz = 50
ACCEL_ODR_100Hz = GYRO_ODR_100Hz = 100
ACCEL_ODR_200Hz = GYRO_ODR_200Hz = 200
ACCEL_ODR_400Hz = GYRO_ODR_400Hz = 400
ACCEL_ODR_800Hz = GYRO_ODR_800Hz = 800
ACCEL_ODR_1600Hz = GYRO_ODR_1600Hz = 1600
ACCEL_HDR = 1
GYRO_HDR = 2
EMPTY_MARKER = 17
END_MARKER = 18
ACCEL_DATA_SZ = 24
GYRO_DATA_SZ = 24
EMPTY_MARKER_SZ = 8
END_MARKER_SZ = 8
def getParameter(path):
	try:
		with open(path, 'r') as param:
			return param.read()
	except Exception:
		return False      
def setParameter(path, value):
	value = str(value)
	try:
		with open(path,'w') as param:
			param.write(value)
		with open(path, 'r') as param:
			updatedValue = param.read()
			if updatedValue.strip() != value:
				return False
	except Exception:
		return False
	return True
def setParameterNoCheck(path, value):
	value = str(value)
	try:
		with open(path,'w') as param:
			param.write(value)
	except Exception:
		print("Errore di I/O durante la scrittura del parametro")
		return False
	return True
def getSensorOrientationMatrix(sensor):
	if str(sensor) == str(ACCELEROMETER_DEVICE_INDEX):
		orientationMatrix = getParameter('/sys/bus/iio/devices/iio:device0/info_accel_matrix')
	if str(sensor) == str(GYROSCOPE_DEVICE_INDEX): 
		orientationMatrix = getParameter('/sys/bus/iio/devices/iio:device0/info_anglvel_matrix')
	if orientationMatrix is False: 
		return False
	return [int(x) for x in orientationMatrix.split(",")]
def setBufferEnabledState(state):
	if state not in [0, 1]:
		return False
	state = str(state)
	return setParameter('/sys/bus/iio/devices/iio:device0/buffer/enable', state)
def setBufferSampleSize(sampleSize):
	if sampleSize < 0 or sampleSize > 32768:
		return False
	state = str(sampleSize)
	return setParameter('/sys/bus/iio/devices/iio:device0/buffer/length', sampleSize)
def setTimestampEnabledState(state):
	if state not in [0, 1]:
		return False
	state = str(state)
	return setParameter('/sys/bus/iio/devices/iio:device0/scan_elements/in_timestamp_en', state)
def setSensorEnabledState(sensor, state):
	state = str(state)
	if str(sensor) == str(ACCELEROMETER_DEVICE_INDEX):
		success = setParameter('/sys/bus/iio/devices/iio:device0/in_accel_enable', state)
	elif str(sensor) == str(GYROSCOPE_DEVICE_INDEX):
		success = setParameter('/sys/bus/iio/devices/iio:device0/in_anglvel_enable', state)
	else: 
		success = False
	return success
def getSensorUpdateRate(sensor):
	if str(sensor) == str(ACCELEROMETER_DEVICE_INDEX): 
		return getParameter('/sys/bus/iio/devices/iio:device0/in_accel_rate')
	elif str(sensor) == str(GYROSCOPE_DEVICE_INDEX): 
		return getParameter('/sys/bus/iio/devices/iio:device0/in_anglvel_rate')
	else: 
		return False
def setSensorUpdateRate(sensor, hz):
	allowedInputParametersList = ['12', '25', '50', '100', '200', '400', '800', '1600']
	if str(hz) not in allowedInputParametersList:
		return False
	if sensor == ACCELEROMETER_DEVICE_INDEX:
		return setParameter('/sys/bus/iio/devices/iio:device0/in_accel_rate', hz)
	elif sensor == GYROSCOPE_DEVICE_INDEX:
		return setParameter('/sys/bus/iio/devices/iio:device0/in_anglvel_rate', hz)
	else: 
		return False
def getSensorFullScaleRange(sensor):
	if str(sensor) == str(ACCELEROMETER_DEVICE_INDEX):
		return getParameter('/sys/bus/iio/devices/iio:device0/in_accel_scale')
	elif str(sensor) == str(GYROSCOPE_DEVICE_INDEX):
		return getParameter('/sys/bus/iio/devices/iio:device0/in_anglvel_scale')
	else:
		return False
def setSensorFullScaleRange(sensor, scaleRange):
	allowedInputParametersList = ['0', '1', '2', '3']
	expectedAccelParametersList = ['2', '4', '8', '16']
	expectedGyroParametersList = ['250', '500', '1000', '2000']
	if (sensor == ACCELEROMETER_DEVICE_INDEX) and (str(scaleRange) in allowedInputParametersList):
		return setParameterNoCheck('/sys/bus/iio/devices/iio:device0/in_accel_scale', scaleRange)
	elif (sensor == GYROSCOPE_DEVICE_INDEX) and (str(scaleRange) in allowedInputParametersList): 
		return setParameterNoCheck('/sys/bus/iio/devices/iio:device0/in_anglvel_scale', scaleRange)
	else:
		return False
def getSensorBatchTimeout():
	return getParameter('/sys/bus/iio/devices/iio:device0/misc_batchmode_timeout')
def setSensorBatchTimeout(msTimeout):
	return setParameter('/sys/bus/iio/devices/iio:device0/misc_batchmode_timeout', msTimeout)
def setHighResMode(enabled):
	if enabled==True:
		success = setParameter('/sys/bus/iio/devices/iio:device0/in_high_res_mode', 1)
	elif enabled==False:
		success = setParameter('/sys/bus/iio/devices/iio:device0/in_high_res_mode', 0)
	else:
		return False
	return success
def setupIIO():
	status = True
	if not setBufferEnabledState(0):
		status = False
	if not setTimestampEnabledState(1):
		status = False
	if not setBufferSampleSize(32768):
		status = False
	if not setBufferEnabledState(1):
		status = False
	return status
def setupAccelerometer(fullScaleRange, outputDataRate):
	if not setSensorEnabledState(ACCELEROMETER_DEVICE_INDEX,0):
		return False
	if not setSensorFullScaleRange(ACCELEROMETER_DEVICE_INDEX, fullScaleRange):
		return False
	if not setSensorUpdateRate(ACCELEROMETER_DEVICE_INDEX, outputDataRate):
		return False
	if not setSensorEnabledState(ACCELEROMETER_DEVICE_INDEX,1):
		return False
	return True
def setupGyroscope(fullScaleRange, outputDataRate):
	if not setSensorEnabledState(GYROSCOPE_DEVICE_INDEX,0):
		return False
	if not setSensorFullScaleRange(GYROSCOPE_DEVICE_INDEX, fullScaleRange):
		return False
	if not setSensorUpdateRate(GYROSCOPE_DEVICE_INDEX, outputDataRate):
		return False
	if not setSensorEnabledState(GYROSCOPE_DEVICE_INDEX,1):
		return False
	return True
def closeSensors():
	setSensorEnabledState(ACCELEROMETER_DEVICE_INDEX, 0)
	setSensorEnabledState(GYROSCOPE_DEVICE_INDEX, 0)
	setBufferEnabledState(0)
def computeAccelScalingFactor():
	currentFSR = int(getSensorFullScaleRange(ACCELEROMETER_DEVICE_INDEX))
	currentResMode = int(getParameter('/sys/bus/iio/devices/iio:device0/in_high_res_mode'))
	if currentResMode == 1: 
		return currentFSR/524288
	if currentResMode == 0:
		return currentFSR/32768
def computeGyroScalingFactor():
	currentFSR = int(getSensorFullScaleRange(GYROSCOPE_DEVICE_INDEX))
	currentResMode = int(getParameter('/sys/bus/iio/devices/iio:device0/in_high_res_mode'))
	pi = 3.14159265358979323846
	if currentResMode == 1:
		return currentFSR/524288 * pi / 180
	if currentResMode == 0:
		return currentFSR/32768 * pi / 180
def readCharDeviceBenchmarkOnFile(): 
	boot_time = datetime.fromtimestamp(time.time() - time.monotonic(), timezone.utc)
	boot_time = boot_time + timedelta(seconds = GPS_TIME_TO_UTC_LEAP_SECONDS)
	iio_read_buf = bytearray(2048)
	iio_read_size = 0
	accel_scale = computeAccelScalingFactor()
	gyro_scale = computeGyroScalingFactor()
	iio_fd = os.open("/dev/iio:device0", os.O_RDONLY) 
	start_time = time.perf_counter()
	tempString = []
	while time.perf_counter()-start_time < 10:
		nbytes = len(iio_read_buf) - iio_read_size
		data = os.read(iio_fd, nbytes)
		if not data:
			print("no data in buffer")
			exit()
		iio_read_buf[iio_read_size:iio_read_size+len(data)] = data
		iio_read_size += len(data)
		ptr = 0
		left_over = 0
		while ptr < iio_read_size:
			rdata = iio_read_buf[ptr:]
			header = struct.unpack("<H", rdata[:2])[0]
			if header == END_MARKER:
				if (iio_read_size - ptr) < END_MARKER_SZ:
					left_over = iio_read_size - ptr
					break
				ptr += END_MARKER_SZ
			elif header == EMPTY_MARKER:
				if (iio_read_size - ptr) < EMPTY_MARKER_SZ:
					left_over = iio_read_size - ptr
					break
				ptr += EMPTY_MARKER_SZ
			elif header == GYRO_HDR:
				if (iio_read_size - ptr) < GYRO_DATA_SZ:
					left_over = iio_read_size - ptr
					break
				gyro = struct.unpack("<3i", rdata[4:16])
				gyro_ts = struct.unpack("<q", rdata[16:24])[0]
				timestamp = (
					boot_time + timedelta(microseconds=round(gyro_ts / 100))
				).strftime("%Y%m%d%H%M%S.%f")
				tempString.append(f"G | {timestamp} | {tuple(g * gyro_scale for g in gyro)}")
				ptr += GYRO_DATA_SZ
			elif header == ACCEL_HDR:
				if (iio_read_size - ptr) < ACCEL_DATA_SZ:
					left_over = iio_read_size - ptr
					break
				accel = struct.unpack("<3i", rdata[4:16])
				accel_ts = struct.unpack("<q", rdata[16:24])[0]
				timestamp = (
					boot_time + timedelta(microseconds=round(accel_ts / 100))
				).strftime("%Y%m%d%H%M%S.%f")
				tempString.append(f"A | {timestamp} | {tuple(a * accel_scale for a in accel)}")
				ptr += ACCEL_DATA_SZ
			else:
				ptr += 1
		if left_over > 0:
			iio_read_buf_ctypes = (ctypes.c_char * len(iio_read_buf)).from_buffer_copy(iio_read_buf)
			ctypes.memmove(ctypes.cast(iio_read_buf_ctypes, ctypes.c_void_p).value, ctypes.cast(ctypes.addressof(iio_read_buf_ctypes) + ptr, ctypes.c_void_p).value, left_over)
			iio_read_buf[:] = bytearray(iio_read_buf_ctypes)
			iio_read_size = left_over
		else:
			iio_read_size = 0
	with open("datalog.txt", "wt") as log:
		for sample in tempString:
			log.write(f"{sample}\n")
def testMain():
	DESIRED_ACCEL_FSR = ACCEL_FSR_16G
	DESIRED_GYRO_FSR = GYRO_FSR_2000DPS
	HIGH_RES_MODE_SETTING = True
	accelOrientationMatrix = getSensorOrientationMatrix(ACCELEROMETER_DEVICE_INDEX)
	gyroOrientationMatrix = getSensorOrientationMatrix(GYROSCOPE_DEVICE_INDEX)
	setupIIO()
	setSensorEnabledState(ACCELEROMETER_DEVICE_INDEX,0)
	setSensorEnabledState(GYROSCOPE_DEVICE_INDEX,0)
	setSensorBatchTimeout(0)
	setHighResMode(HIGH_RES_MODE_SETTING)
	setupAccelerometer(DESIRED_ACCEL_FSR, ACCEL_ODR_400Hz)
	setupGyroscope(DESIRED_GYRO_FSR, GYRO_ODR_400Hz)
	readCharDeviceBenchmarkOnFile()
	closeSensors()
testMain()