add initial autoEncodeing
This commit is contained in:
parent
d6c5c8a791
commit
06e80017a9
@ -117,7 +117,7 @@ panSizeHorizontal=0
|
|||||||
|
|
||||||
[screen]
|
[screen]
|
||||||
driver=vcsaDriver
|
driver=vcsaDriver
|
||||||
encoding=UTF-8
|
encoding=auto
|
||||||
screenUpdateDelay=0.05
|
screenUpdateDelay=0.05
|
||||||
suspendingScreen=
|
suspendingScreen=
|
||||||
autodetectSuspendingScreen=True
|
autodetectSuspendingScreen=True
|
||||||
|
@ -119,7 +119,7 @@ panSizeHorizontal=0
|
|||||||
|
|
||||||
[screen]
|
[screen]
|
||||||
driver=vcsaDriver
|
driver=vcsaDriver
|
||||||
encoding=cp850
|
encoding=auto
|
||||||
screenUpdateDelay=0.05
|
screenUpdateDelay=0.05
|
||||||
suspendingScreen=
|
suspendingScreen=
|
||||||
autodetectSuspendingScreen=True
|
autodetectSuspendingScreen=True
|
||||||
|
@ -76,7 +76,7 @@ panSizeHorizontal=0
|
|||||||
|
|
||||||
[screen]
|
[screen]
|
||||||
driver=vcsaDriver
|
driver=vcsaDriver
|
||||||
encoding=cp850
|
encoding=auto
|
||||||
screenUpdateDelay=0.05
|
screenUpdateDelay=0.05
|
||||||
suspendingScreen=
|
suspendingScreen=
|
||||||
autodetectSuspendingScreen=True
|
autodetectSuspendingScreen=True
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import time
|
import time
|
||||||
from fcntl import ioctl
|
from fcntl import ioctl
|
||||||
from array import array
|
from array import array
|
||||||
import struct
|
from struct import unpack_from
|
||||||
|
from struct import unpack
|
||||||
|
from struct import pack
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import sys
|
||||||
charmap = {}
|
charmap = {}
|
||||||
@ -14,13 +16,13 @@ def updateCharMap(screen):
|
|||||||
VT_GETHIFONTMASK = 0x560D
|
VT_GETHIFONTMASK = 0x560D
|
||||||
himask = array("H", (0,))
|
himask = array("H", (0,))
|
||||||
ioctl(tty, VT_GETHIFONTMASK, himask)
|
ioctl(tty, VT_GETHIFONTMASK, himask)
|
||||||
hichar, = struct.unpack_from("@H", himask)
|
hichar, = unpack_from("@H", himask)
|
||||||
sz = 512
|
sz = 512
|
||||||
line = ''
|
line = ''
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
unipairs = array("H", [0]*(2*sz))
|
unipairs = array("H", [0]*(2*sz))
|
||||||
unimapdesc = array("B", struct.pack("@HP", sz, unipairs.buffer_info()[0]))
|
unimapdesc = array("B", pack("@HP", sz, unipairs.buffer_info()[0]))
|
||||||
ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
|
ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
|
||||||
break
|
break
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
@ -28,8 +30,8 @@ def updateCharMap(screen):
|
|||||||
raise
|
raise
|
||||||
sz *= 2
|
sz *= 2
|
||||||
tty.close()
|
tty.close()
|
||||||
ncodes, = struct.unpack_from("@H", unimapdesc)
|
ncodes, = unpack_from("@H", unimapdesc)
|
||||||
utable = struct.unpack_from("@%dH" % (2*ncodes), unipairs)
|
utable = unpack_from("@%dH" % (2*ncodes), unipairs)
|
||||||
for u, b in zip(utable[::2], utable[1::2]):
|
for u, b in zip(utable[::2], utable[1::2]):
|
||||||
if charmap.get(b) is None:
|
if charmap.get(b) is None:
|
||||||
charmap[b] = chr(u)
|
charmap[b] = chr(u)
|
||||||
@ -53,7 +55,7 @@ def autoDecodeVCSA(allData, rows, cols):
|
|||||||
lineAttrib.append(7)
|
lineAttrib.append(7)
|
||||||
lineText += ' '
|
lineText += ' '
|
||||||
continue
|
continue
|
||||||
(sh,) = struct.unpack("=H", data)
|
(sh,) = unpack("=H", data)
|
||||||
attr = (sh >> 8) & 0xFF
|
attr = (sh >> 8) & 0xFF
|
||||||
ch = sh & 0xFF
|
ch = sh & 0xFF
|
||||||
if hichar == 0x100:
|
if hichar == 0x100:
|
||||||
@ -63,8 +65,8 @@ def autoDecodeVCSA(allData, rows, cols):
|
|||||||
paper = (attr>>4) & 0x0F
|
paper = (attr>>4) & 0x0F
|
||||||
#if (ink != 7) or (paper != 0):
|
#if (ink != 7) or (paper != 0):
|
||||||
# print(ink,paper)
|
# print(ink,paper)
|
||||||
#if sh & hichar:
|
if sh & hichar:
|
||||||
# ch |= 0x100
|
ch |= 0x100
|
||||||
try:
|
try:
|
||||||
lineText += charmap[ch]
|
lineText += charmap[ch]
|
||||||
except:
|
except:
|
||||||
@ -73,11 +75,11 @@ def autoDecodeVCSA(allData, rows, cols):
|
|||||||
allAttrib.append(lineAttrib)
|
allAttrib.append(lineAttrib)
|
||||||
return allText, allAttrib
|
return allText, allAttrib
|
||||||
|
|
||||||
def m():
|
def m(screen):
|
||||||
s = time.time()
|
s = time.time()
|
||||||
updateCharMap('4')
|
updateCharMap(str(screen))
|
||||||
print(time.time() -s )
|
print(time.time() -s )
|
||||||
vcsa = open('/dev/vcsa' + '4', 'rb')
|
vcsa = open('/dev/vcsa' + str(screen), 'rb')
|
||||||
head = vcsa.read(4)
|
head = vcsa.read(4)
|
||||||
rows = int(head[0])
|
rows = int(head[0])
|
||||||
cols = int(head[1])
|
cols = int(head[1])
|
||||||
|
@ -15,91 +15,27 @@ import difflib
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import glob, os
|
import glob, os
|
||||||
import fcntl
|
|
||||||
import termios
|
import termios
|
||||||
import time
|
import time
|
||||||
import select
|
import select
|
||||||
import dbus
|
import dbus
|
||||||
import fcntl
|
import fcntl
|
||||||
from array import array
|
from array import array
|
||||||
import struct
|
|
||||||
import errno
|
import errno
|
||||||
import sys
|
import sys
|
||||||
|
from utils import screen_utils
|
||||||
|
from fcntl import ioctl
|
||||||
|
from struct import unpack_from, unpack, pack
|
||||||
from core import debug
|
from core import debug
|
||||||
from core.eventData import fenrirEventType
|
from core.eventData import fenrirEventType
|
||||||
from utils import screen_utils
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
ttyno = 4
|
|
||||||
tty = open('/dev/tty%d' % ttyno, 'rb')
|
|
||||||
vcs = open('/dev/vcsa%d' % ttyno, 'rb')
|
|
||||||
|
|
||||||
head = vcs.read(4)
|
|
||||||
rows = int(head[0])
|
|
||||||
cols = int(head[1])
|
|
||||||
|
|
||||||
|
|
||||||
GIO_UNIMAP = 0x4B66
|
|
||||||
VT_GETHIFONTMASK = 0x560D
|
|
||||||
himask = array("H", (0,))
|
|
||||||
fcntl.ioctl(tty, VT_GETHIFONTMASK, himask)
|
|
||||||
hichar, = struct.unpack_from("@H", himask)
|
|
||||||
|
|
||||||
sz = 512
|
|
||||||
line = ''
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
unipairs = array("H", [0]*(2*sz))
|
|
||||||
unimapdesc = array("B", struct.pack("@HP", sz, unipairs.buffer_info()[0]))
|
|
||||||
fcntl.ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
|
|
||||||
break
|
|
||||||
except IOError as e:
|
|
||||||
if e.errno != errno.ENOMEM:
|
|
||||||
raise
|
|
||||||
sz *= 2
|
|
||||||
|
|
||||||
tty.close()
|
|
||||||
|
|
||||||
ncodes, = struct.unpack_from("@H", unimapdesc)
|
|
||||||
utable = struct.unpack_from("@%dH" % (2*ncodes), unipairs)
|
|
||||||
|
|
||||||
charmap = {}
|
|
||||||
for u, b in zip(utable[::2], utable[1::2]):
|
|
||||||
if charmap.get(b) is None:
|
|
||||||
charmap[b] = u
|
|
||||||
|
|
||||||
allText = []
|
|
||||||
allAttrib = []
|
|
||||||
for y in range(rows):
|
|
||||||
lineText = ''
|
|
||||||
lineAttrib = []
|
|
||||||
for x in range(cols):
|
|
||||||
data = vcs.read(2)
|
|
||||||
(sh,) = struct.unpack("=H", data)
|
|
||||||
attr = (sh >> 8) & 0xFF
|
|
||||||
ch = sh & 0xFF
|
|
||||||
if hichar == 0x100:
|
|
||||||
attr >>= 1
|
|
||||||
lineAttrib.append(attr)
|
|
||||||
ink = attr & 0x0F
|
|
||||||
paper = (attr>>4) & 0x0F
|
|
||||||
if (ink != 7) or (paper != 0):
|
|
||||||
print(ink,paper)
|
|
||||||
if sh & hichar:
|
|
||||||
ch |= 0x100
|
|
||||||
lineText += chr(charmap.get(ch, u'?'))
|
|
||||||
allText.append(lineText)
|
|
||||||
allAttrib.append(lineAttrib)
|
|
||||||
|
|
||||||
print(allText)
|
|
||||||
print(allAttrib)
|
|
||||||
'''
|
|
||||||
|
|
||||||
class driver():
|
class driver():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.vcsaDevicePath = '/dev/vcsa'
|
self.vcsaDevicePath = '/dev/vcsa'
|
||||||
self.ListSessions = None
|
self.ListSessions = None
|
||||||
|
self.charmap = {}
|
||||||
|
self.hichar = None
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.env['runtime']['eventManager'].addCustomEventThread(self.updateWatchdog)
|
self.env['runtime']['eventManager'].addCustomEventThread(self.updateWatchdog)
|
||||||
@ -228,10 +164,73 @@ class driver():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR)
|
self.env['runtime']['debug'].writeDebugOut('VCSA:updateWatchdog:' + str(e),debug.debugLevel.ERROR)
|
||||||
|
|
||||||
|
def updateCharMap(self, screen):
|
||||||
|
tty = open('/dev/tty' + screen, 'rb')
|
||||||
|
GIO_UNIMAP = 0x4B66
|
||||||
|
VT_GETHIFONTMASK = 0x560D
|
||||||
|
himask = array("H", (0,))
|
||||||
|
ioctl(tty, VT_GETHIFONTMASK, himask)
|
||||||
|
self.hichar, = unpack_from("@H", himask)
|
||||||
|
sz = 512
|
||||||
|
line = ''
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
unipairs = array("H", [0]*(2*sz))
|
||||||
|
unimapdesc = array("B", pack("@HP", sz, unipairs.buffer_info()[0]))
|
||||||
|
ioctl(tty.fileno(), GIO_UNIMAP, unimapdesc)
|
||||||
|
break
|
||||||
|
except IOError as e:
|
||||||
|
if e.errno != errno.ENOMEM:
|
||||||
|
raise
|
||||||
|
sz *= 2
|
||||||
|
tty.close()
|
||||||
|
ncodes, = unpack_from("@H", unimapdesc)
|
||||||
|
utable = unpack_from("@%dH" % (2*ncodes), unipairs)
|
||||||
|
for u, b in zip(utable[::2], utable[1::2]):
|
||||||
|
if self.charmap.get(b) is None:
|
||||||
|
self.charmap[b] = chr(u)
|
||||||
|
|
||||||
|
def autoDecodeVCSA(self, allData, rows, cols):
|
||||||
|
allText = ''
|
||||||
|
allAttrib = b''
|
||||||
|
i = 0
|
||||||
|
for y in range(rows):
|
||||||
|
lineText = ''
|
||||||
|
lineAttrib = b''
|
||||||
|
for x in range(cols):
|
||||||
|
data = allData[i: i + 2]
|
||||||
|
i += 2
|
||||||
|
if data == b' \x07':
|
||||||
|
#attr = 7
|
||||||
|
#ink = 7
|
||||||
|
#paper = 0
|
||||||
|
#ch = ' '
|
||||||
|
lineAttrib += b'7'
|
||||||
|
lineText += ' '
|
||||||
|
continue
|
||||||
|
(sh,) = unpack("=H", data)
|
||||||
|
attr = (sh >> 8) & 0xFF
|
||||||
|
ch = sh & 0xFF
|
||||||
|
if self.hichar == 0x100:
|
||||||
|
attr >>= 1
|
||||||
|
lineAttrib += bytes(attr)
|
||||||
|
ink = attr & 0x0F
|
||||||
|
paper = (attr>>4) & 0x0F
|
||||||
|
#if (ink != 7) or (paper != 0):
|
||||||
|
# print(ink,paper)
|
||||||
|
if sh & self.hichar:
|
||||||
|
ch |= 0x100
|
||||||
|
try:
|
||||||
|
lineText += self.charmap[ch]
|
||||||
|
except:
|
||||||
|
lineText += chr('?')
|
||||||
|
allText += lineText + '\n'
|
||||||
|
allAttrib += lineAttrib
|
||||||
|
return str(allText), allAttrib
|
||||||
|
|
||||||
def update(self, trigger='onUpdate'):
|
def update(self, trigger='onUpdate'):
|
||||||
if trigger == 'onInput': # no need for an update on input for VCSA
|
if trigger == 'onInput': # no need for an update on input for VCSA
|
||||||
return
|
return
|
||||||
#print(self.env['screen']['newTTY'], self.env['screen']['oldTTY'])
|
|
||||||
newContentBytes = b''
|
newContentBytes = b''
|
||||||
try:
|
try:
|
||||||
# read screen
|
# read screen
|
||||||
@ -261,11 +260,18 @@ class driver():
|
|||||||
self.env['screen']['newCursor']['x'] = int( self.env['screen']['newContentBytes'][2])
|
self.env['screen']['newCursor']['x'] = int( self.env['screen']['newContentBytes'][2])
|
||||||
self.env['screen']['newCursor']['y'] = int( self.env['screen']['newContentBytes'][3])
|
self.env['screen']['newCursor']['y'] = int( self.env['screen']['newContentBytes'][3])
|
||||||
# analyze content
|
# analyze content
|
||||||
|
s = time.time()
|
||||||
|
if screenEncoding.upper() == 'AUTO':
|
||||||
|
self.updateCharMap(str(self.env['screen']['newTTY']))
|
||||||
|
self.env['screen']['newContentText'], \
|
||||||
|
self.env['screen']['newContentAttrib'] =\
|
||||||
|
self.autoDecodeVCSA(self.env['screen']['newContentBytes'][4:], self.env['screen']['lines'], self.env['screen']['columns'])
|
||||||
|
else:
|
||||||
self.env['screen']['newContentText'] = self.env['screen']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
|
self.env['screen']['newContentText'] = self.env['screen']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8')
|
||||||
self.env['screen']['newContentText'] = screen_utils.removeNonprintable(self.env['screen']['newContentText'])
|
self.env['screen']['newContentText'] = screen_utils.removeNonprintable(self.env['screen']['newContentText'])
|
||||||
self.env['screen']['newContentAttrib'] = self.env['screen']['newContentBytes'][5:][::2]
|
self.env['screen']['newContentAttrib'] = self.env['screen']['newContentBytes'][5:][::2]
|
||||||
self.env['screen']['newContentText'] = screen_utils.insertNewlines(self.env['screen']['newContentText'], self.env['screen']['columns'])
|
self.env['screen']['newContentText'] = screen_utils.insertNewlines(self.env['screen']['newContentText'], self.env['screen']['columns'])
|
||||||
|
print(time.time() -s, self.env['screen']['newTTY'] )
|
||||||
if self.env['screen']['newTTY'] != self.env['screen']['oldTTY']:
|
if self.env['screen']['newTTY'] != self.env['screen']['oldTTY']:
|
||||||
self.env['screen']['oldContentBytes'] = b''
|
self.env['screen']['oldContentBytes'] = b''
|
||||||
self.env['screen']['oldContentAttrib'] = b''
|
self.env['screen']['oldContentAttrib'] = b''
|
||||||
|
Loading…
Reference in New Issue
Block a user