44import sys
55import struct
66import select
7+ import posix
78
89DEVICE = '/dev/ttyd2'
910
11+ class UnixFile :
12+ def open (self , name , mode ):
13+ self .fd = posix .open (name , mode )
14+ return self
15+
16+ def read (self , len ):
17+ return posix .read (self .fd , len )
18+
19+ def write (self , data ):
20+ dummy = posix .write (self .fd , data )
21+
22+ def flush (self ):
23+ pass
24+
25+ def fileno (self ):
26+ return self .fd
27+
28+ def close (self ):
29+ dummy = posix .close (self .fd )
30+
1031def packttyargs (* args ):
1132 if type (args ) <> type (()):
1233 raise 'Incorrect argtype for packttyargs'
@@ -39,8 +60,8 @@ def unpackttyargs(str):
3960 return (iflag , oflag , cflag , lflag , line , chars )
4061
4162def initline (name ):
42- fp = open (name , 'r' )
43- ofp = open ( name , 'w' )
63+ fp = UnixFile (). open (name , 2 )
64+ ofp = fp
4465 fd = fp .fileno ()
4566 rv = fcntl .ioctl (fd , IOCTL .TCGETA , nullttyargs ())
4667 iflag , oflag , cflag , lflag , line , chars = unpackttyargs (rv )
@@ -92,21 +113,40 @@ def initline(name):
92113FF = '\xab '
93114REW = '\xac '
94115STILL = '\x4f '
95- STEP_FWD = '\xad '
116+ STEP_FWD = '\x2b ' # Was: '\ xad'
96117FM_SELECT = EXP_8 + '\xc8 '
97118FM_STILL = EXP_8 + '\xcd '
98119DM_OFF = EXP_8 + '\xc9 '
99120DM_SET = EXP_8 + '\xc4 '
100121FWD_SHUTTLE = '\xb5 '
101122REV_SHUTTLE = '\xb6 '
123+ EM_SELECT = EXP_8 + '\xc0 '
124+ N_FRAME_REC = EXP_8 + '\x92 '
125+
126+ IN_ENTRY = EXP_7 + '\x90 '
127+ IN_ENTRY_RESET = EXP_7 + '\x91 '
128+ IN_ENTRY_SET = EXP_7 + '\x98 '
129+ IN_ENTRY_INC = EXP_7 + '\x94 '
130+ IN_ENTRY_DEC = EXP_7 + '\x95 '
131+ IN_ENTRY_SENSE = EXP_7 + '\x9a '
132+
133+ OUT_ENTRY = EXP_7 + '\x92 '
134+ OUT_ENTRY_RESET = EXP_7 + '\x93 '
135+ OUT_ENTRY_SET = EXP_7 + '\x99 '
136+ OUT_ENTRY_INC = EXP_7 + '\x96 '
137+ OUT_ENTRY_DEC = EXP_7 + '\x98 '
138+ OUT_ENTRY_SENSE = EXP_7 + '\x9b '
139+
140+ DEBUG = 0
102141
103142class VCR :
104143 def init (self ):
105144 self .ifp , self .ofp = initline (DEVICE )
106145 return self
107146
108147 def _cmd (self , cmd ):
109- ## print '>>>',`cmd`
148+ if DEBUG :
149+ print '>>>' ,`cmd`
110150 self .ofp .write (cmd )
111151 self .ofp .flush ()
112152
@@ -118,8 +158,10 @@ def _waitdata(self, len, tout):
118158## if rep:
119159## print 'FLUSHED:', `rep`
120160 return None
161+ # XXXX Niet goed: er is meer gebufferd!
121162 data = self .ifp .read (1 )
122- ## print '<<<',`data`
163+ if DEBUG :
164+ print '<<<' ,`data`
123165 if data == NAK :
124166 return NAK
125167 rep = rep + data
@@ -143,11 +185,12 @@ def _getnumber(self, len):
143185 return number
144186
145187 def _iflush (self ):
146- dummy = self ._waitdata (10000 , 1 )
188+ dummy = self ._waitdata (10000 , 0 )
147189## if dummy:
148190## print 'IFLUSH:', dummy
149191
150192 def simplecmd (self ,cmd ):
193+ self ._iflush ()
151194 for ch in cmd :
152195 self ._cmd (ch )
153196 rep = self ._reply (1 )
@@ -157,6 +200,11 @@ def simplecmd(self,cmd):
157200 raise error , 'Unexpected reply:' + `rep`
158201 return 1
159202
203+ def replycmd (self , cmd ):
204+ if not self .simplecmd (cmd [:- 1 ]):
205+ return 0
206+ self ._cmd (cmd [- 1 ])
207+
160208 def _number (self , number , digits ):
161209 if number < 0 :
162210 raise error , 'Unexpected negative number:' + `number`
@@ -258,6 +306,41 @@ def fmmode(self, mode):
258306 return 0
259307 return 1
260308
309+ def editmode (self , mode ):
310+ if mode == 'off' :
311+ a0 = a1 = a2 = 0
312+ elif mode == 'format' :
313+ a0 = 4
314+ a1 = 7
315+ a2 = 4
316+ elif mode == 'asmbl' :
317+ a0 = 1
318+ a1 = 7
319+ a2 = 4
320+ elif mode == 'insert-video' :
321+ a0 = 2
322+ a1 = 4
323+ a2 = 0
324+ else :
325+ raise 'editmode should be off,format,asmbl or insert-video'
326+ if not self .simplecmd (EM_SELECT ):
327+ return 0
328+ self ._number (a0 , 1 )
329+ self ._number (a1 , 1 )
330+ self ._number (a2 , 1 )
331+ if not self .simplecmd (ENTER ):
332+ return 0
333+ return 1
334+
335+ def nframerec (self , num ):
336+ if not self .simplecmd (N_FRAME_REC ):
337+ return 0
338+ self ._number (num , 4 )
339+ if not self .simplecmd (ENTER ):
340+ return 0
341+ self .waitready ()
342+ return 1
343+
261344 def fmstill (self ):
262345 if not self .simplecmd (FM_STILL ):
263346 return 0
@@ -295,3 +378,51 @@ def revshuttle(self, num):
295378 return 0
296379 self ._number (num , 1 )
297380 return 1
381+
382+ def getentry (self , which ):
383+ if which == 'in' :
384+ cmd = IN_ENTRY_SENSE
385+ elif which == 'out' :
386+ cmd = OUT_ENTRY_SENSE
387+ self .replycmd (cmd )
388+ h = self ._getnumber (2 )
389+ print 'h=' ,h
390+ m = self ._getnumber (2 )
391+ print 'm=' ,m
392+ s = self ._getnumber (2 )
393+ print 's=' ,s
394+ f = self ._getnumber (2 )
395+ print 'f=' ,f
396+ return (h , m , s , f )
397+
398+ def inentry (self , arg ):
399+ return self .ioentry (arg , (IN_ENTRY , IN_ENTRY_RESET , \
400+ IN_ENTRY_SET , IN_ENTRY_INC , IN_ENTRY_DEC ))
401+
402+ def outentry (self , arg ):
403+ return self .ioentry (arg , (OUT_ENTRY , OUT_ENTRY_RESET , \
404+ OUT_ENTRY_SET , OUT_ENTRY_INC , OUT_ENTRY_DEC ))
405+
406+ def ioentry (self , arg , (Load , Clear , Set , Inc , Dec )):
407+ if type (arg ) == type (()):
408+ h , m , s , f = arg
409+ if not self .simplecmd (Set ):
410+ return 0
411+ self ._number (h ,2 )
412+ self ._number (m ,2 )
413+ self ._number (s ,2 )
414+ self ._number (f ,2 )
415+ if not self .simplecmd (ENTER ):
416+ return 0
417+ return 1
418+ elif arg == 'reset' :
419+ cmd = Clear
420+ elif arg == 'load' :
421+ cmd = Load
422+ elif arg == '+' :
423+ cmd = Inc
424+ elif arg == '-' :
425+ cmd = Dec
426+ else :
427+ raise error , 'Arg should be +,-,reset,load or (h,m,s,f)'
428+ return self .simplecmd (cmd )
0 commit comments