Skip to content
Snippets Groups Projects
Commit 844ac8a4167c authored by jfp's avatar jfp
Browse files

ptd.write: split string uing SYI__TTY_TYPAHDSZ (-8 to keep some margin)

parent b0c87cce625d
Branches
No related tags found
No related merge requests found
......@@ -18,6 +18,6 @@
import re
from ovms.ssdef import SS__TIMEOUT
from . import _vmsptd
from ovms.rtl.lib import getdvi, spawn
from ovms.rtl.lib import getdvi, spawn, getsyi
from ovms.clidef import CLI_M_NOWAIT
from ovms.dvidef import DVI__UNIT
......@@ -22,5 +22,6 @@
from ovms.clidef import CLI_M_NOWAIT
from ovms.dvidef import DVI__UNIT
from ovms.syidef import SYI__TTY_TYPAHDSZ
theNULL = chr(0)
ESC = chr(27)
......@@ -193,6 +194,7 @@
row: int
column: int
_screen: List[List[str]]
tty_typahdsz: int = 0
def __init__(
self,
......@@ -236,6 +238,7 @@
flags=CLI_M_NOWAIT,
prompt=prompt,
)
Ptd.tty_typahdsz = getsyi(SYI__TTY_TYPAHDSZ)[1]
def close(self):
"""Forces the pseudoterminal to be deleted and frees the channel"""
......@@ -269,8 +272,11 @@
def write(self, string: bytes | str) -> str:
"""Write to the pseudo terminal, return the echo string"""
_, res = _vmsptd.write(self.ptd, string)
wres = ""
n = Ptd.tty_typahdsz - 8
for i in range(0, len(string), n):
_, res = _vmsptd.write(self.ptd, string[i:i+n])
if isinstance(res, bytes):
res = res.decode("iso-8859-15")
elif not isinstance(res, str):
raise ValueError("Argument should be bytes or str")
......@@ -273,5 +279,6 @@
if isinstance(res, bytes):
res = res.decode("iso-8859-15")
elif not isinstance(res, str):
raise ValueError("Argument should be bytes or str")
wres += res
self._to_screen(res)
......@@ -277,5 +284,5 @@
self._to_screen(res)
return res
return wres
def writeln(self, string: bytes | str):
"""Write to the pseudo terminal the command and send a '\\r' character"""
......
......@@ -282,6 +282,7 @@
def create(unsigned int acmode=0, DeviceCharacteristics charbuff=None):
"status, handler = create(acmode=0, charbuff=None)"
cdef unsigned short s;
cdef char* inadr[2]
cdef int pgsize = sysconf(_SC_PAGE_SIZE)
cdef int nbpages = <int>(6 * pgsize / 512) # 4 + 1 data + 1 guard pages
......@@ -336,6 +337,7 @@
def readw(PtdHandler handler):
"status, res = readw(handler)"
cdef int efn = EFN_C_ENF
cdef unsigned short s
# if a read is already pending, wait for completion
if handler.handler.read_status != 0:
while handler.handler.read_status != 2:
......@@ -347,6 +349,8 @@
handler.handler.inadr.va_range_ps_start_va,
handler.handler.buflen - 4)
checkStatus(s)
s = (<unsigned short *>(handler.handler.inadr.va_range_ps_start_va))[0]
checkStatus(s)
handler.handler.read_status = 0
cdef char* buf = <char *>(handler.handler.inadr.va_range_ps_start_va) + 4
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
......@@ -360,6 +364,7 @@
the command interprets the number as hundredths of a second. \
For example, timeout=-20 specifies an interval of 20/100 or 1/5 of a second."
cdef char ascTime[10]
cdef unsigned short s
cdef dsc_descriptor_s ascTimeD
DESCSTR(ascTimeD, ascTime)
cdef unsigned long long binTime
......@@ -399,6 +404,7 @@
wrtstr = getstr(wrtstr)
cdef char* wrtstrPtr = wrtstr
cdef int wlen = len(wrtstr)
cdef unsigned short s;
if wlen > 1024:
raise ValueError('Invalid wrtstr length, maximum is 1024')
cdef char* wrtbuf = <char *>(handler.handler.inadr.va_range_ps_start_va)
......@@ -413,9 +419,11 @@
handler.handler.inadr.va_range_ps_start_va, wlen, readbuf,
handler.handler.buflen - 1024 - 4)
checkStatus(s)
s = (<unsigned short *>(handler.handler.inadr.va_range_ps_start_va))[0]
checkStatus(s)
cdef char* buf = <char *>(handler.handler.inadr.va_range_ps_start_va) + 4
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
return s, buf[:retlenPtr[0]]
def set_event_notification(PtdHandler handler):
"status = set_event_notification(handler)"
......@@ -416,9 +424,10 @@
cdef char* buf = <char *>(handler.handler.inadr.va_range_ps_start_va) + 4
cdef unsigned short* retlenPtr = <unsigned short *>(buf - 2)
return s, buf[:retlenPtr[0]]
def set_event_notification(PtdHandler handler):
"status = set_event_notification(handler)"
cdef unsigned short s;
s = ptd_set_event_notification(handler.handler.channel, NULL, 0, 0, PTD_C_ENABLE_READ)
checkStatus(s)
s = ptd_set_event_notification(handler.handler.channel,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment