YoyPa/isw

EC watcher

thebeerbaron2018 opened this issue · 1 comments

I wrote another little script which can help identify what changes in the EC over time - simply run the script and it monitors changes displaying them in red (hope this helps)

`

#!/usr/bin/python/env python
#sudo pip install pysensors
import os,time,subprocess,binascii

def getbgColorExact(r,g,b):
return '\033[{};2;{};{};{}m'.format(48, r, g, b)
def getfgColorExact(r,g,b):
return '\033[{};2;{};{};{}m'.format(38, r, g, b)
RESET = '\033[0m'

EC_IO_FILE="/sys/kernel/debug/ec/ec0/io"
if not os.path.exists(EC_IO_FILE):
subprocess.call(['modprobe','ec_sys','write_support=1'],stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

os.system('clear')

curvals = [None] *256
curchanged = [0] *256
curchanged2 = [1] *256

while True:

with open(EC_IO_FILE,"rb") as f:
	hexdata = binascii.hexlify(f.read()).decode('ascii')

for i in range(0,256,1):
	if curvals[i] == None:
		curvals[i]=hexdata[(i*2):(i*2)+2]
	elif curvals[i] != hexdata[(i*2):(i*2)+2] and curchanged[i]==0:
		curchanged[i]=1		
	elif curchanged[i]==1:
		if curvals[i] != hexdata[(i*2):(i*2)+2]:
			curchanged2[i]=1
		else:
			curchanged2[i]=0
	curvals[i]=hexdata[(i*2):(i*2)+2]

os.system('clear')
print('   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F')
for i in range(0,251,16):
	asciidata= ''
	linedata = '{:02x} '.format(i)
	for j in range(0,16,1):
		if int(curvals[i+j],16)>31 and int(curvals[i+j],16)<127:
			asciidata+= chr(int(curvals[i+j],16))
		else:
			asciidata+='.'
		if curchanged[i+j]==0:
			linedata+= curvals[i+j]
		else:
			if curchanged2[i+j]==0:
				linedata+= '%s%s%s' % (getfgColorExact(255,0,0),curvals[i+j],RESET)
			else:
				linedata+= '%s%s%s' % (getbgColorExact(255,0,0),curvals[i+j],RESET)

		linedata+= ' '		
	linedata += '>'
	linedata += asciidata
	linedata += '<'
	print(linedata)

time.sleep(1)

`

Screenshot:

screenie