Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

moved FDD code to a module

  • Loading branch information...
commit a05871c03d057086440099ec7af9ec729f542913 1 parent bf19118
Steve Conklin authored

Showing 1 changed file with 2 additions and 304 deletions. Show diff stats Hide diff stats

  1. +2 304 experimental/driveread.py
306 experimental/driveread.py
@@ -24,309 +24,7 @@
24 24 import time
25 25 import serial
26 26
27   -FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
28   -
29   -def dump(src, length=16):
30   - result=[]
31   - for i in xrange(0, len(src), length):
32   - s = src[i:i+length]
33   - hexa = ' '.join(["%02X"%ord(x) for x in s])
34   - printable = s.translate(FILTER)
35   - result.append("%04X %-*s %s\n" % (i, length*3, hexa, printable))
36   - return ''.join(result)
37   -
38   -class PDD1():
39   -
40   - def __init__(self):
41   - self.verbose = True
42   - self.commport = ''
43   - self.ser = None
44   - return
45   -
46   - def __del__(self):
47   - return
48   -
49   - def open(self, cport='/dev/ttyUSB0', rate = 9600, par = 'N', stpbts=1, tmout=1, xx=0):
50   - #self.ser = serial.Serial(port = cport, baudrate = rate, parity = par, stopbits = stpbts, timeout = tmout, xonxoff=0)
51   - self.ser = serial.Serial(port = cport, baudrate = rate, parity = par, stopbits = stpbts, timeout = tmout, xonxoff=0, rtscts=1, dsrdtr=0)
52   - if self.ser == None:
53   - print 'Unable to open serial device %s' % cport
54   - raise IOError
55   - self.commtimeout = tmout
56   - # Sometimes on powerup there are some characters in the buffer, purge them
57   - self.dumpchars()
58   - return
59   -
60   - def close(self):
61   - if self.ser is not None:
62   - self.ser.close()
63   - self.ser = None
64   - return
65   -
66   - def dumpchars(self):
67   - num = 1
68   - while self.ser.inWaiting():
69   - inc = self.ser.read()
70   - if len(inc) != 0:
71   - print 'flushed 0x%02X (%d)' % (ord(inc), num)
72   - num = num + 1
73   - else:
74   - break
75   - return
76   -
77   - def getFDCresponse(self):
78   - sch = self.ser.read(8)
79   - if self.verbose:
80   - print "Got FDC response:"
81   - if (sch[0] == '0') and (sch[1] == '0'):
82   - print " SUCCESS"
83   - print " Physical Sector = %c%c" % (sch[2], sch[3])
84   - print " Logical Sector = %c%c%c%c" % (sch[4], sch[5],sch[6], sch[7])
85   - else:
86   - print " ***** ERROR ***** : %c%c" % (sch[0], sch[1])
87   - print " Physical Sector = %c%c" % (sch[2], sch[3])
88   - print " Logical Sector = %c%c%c%c" % (sch[4], sch[5],sch[6], sch[7])
89   - return sch
90   -
91   - def isSuccess(self, FDCstatus):
92   - if self.verbose:
93   - print "isSuccess checking:"
94   - print dump(FDCstatus)
95   - if len(FDCstatus) != 8:
96   - print "Status Bad Len"
97   - return False
98   - for sb in FDCstatus[0:2]:
99   - if sb != '0':
100   - return False
101   - return True
102   -
103   -# def readchar(self):
104   -# inc = ''
105   -# while len(inc) == 0:
106   -# inc = self.ser.read()
107   -# return inc
108   -
109   - def writebytes(self, bytes):
110   - self.ser.write(bytes)
111   - return
112   -
113   - def calcChecksum(self, string):
114   - sum = 0
115   - for schr in string:
116   - sum = sum + ord(schr)
117   - sum = sum % 0x100
118   - sum = sum ^ 0xFF
119   - return chr(sum)
120   -
121   -# def __commandResponse(self, command):
122   -# if self.verbose:
123   -# pcmd = command.strip()
124   -# print 'writing command ===> <%s>' % pcmd
125   -# self.dumpchars()
126   -# ds_string = command
127   -# cs = self.calcChecksum(ds_string)
128   -# ds_string = ds_string + cs
129   -# print "cR sending . . ."
130   -# print dump(ds_string)
131   -# self.writebytes(ds_string)
132   -# response = self.readsomechars()
133   -# print 'Command got a response of ', response
134   -# return response
135   -
136   - def __FDCcommandResponse(self, command):
137   - if self.verbose:
138   - pcmd = command.strip()
139   - print '-------------------------------------\nwriting FDC command ===> <%s>' % pcmd
140   - self.dumpchars()
141   - self.writebytes(command)
142   - response = self.getFDCresponse()
143   - return response
144   - #
145   - # Begin Op Mode commands
146   - #
147   -
148   - def EnterFDCMode(self):
149   - if False:
150   - command = "ZZ" + chr(0x08) + chr(0)
151   - cs = self.calcChecksum(command)
152   - command = command + cs + "\r"
153   - else:
154   - command = "ZZ" + chr(0x08) + chr(0) + chr(0xF7) + "\r"
155   - if self.verbose:
156   - print "Entering FDC Mode, sending:"
157   - print dump(command),
158   - self.writebytes(command)
159   - # There's no response to this command, so allow time to complete
160   - time.sleep(.010)
161   - if self.verbose:
162   - print "Done entering FDC Mode\n"
163   - return
164   -
165   - #
166   - # Begin FDC mode commands
167   - #
168   -
169   - def FDCChangeMode(self, mode = '1'):
170   - """
171   - Change the disk drive mode. Default to changing from FDC
172   - emulation mode back to Operational Mode.
173   - """
174   - command = "M " + mode
175   - result = self.__FDCcommandResponse(command)
176   - if not self.isSuccess(result):
177   - raise IOError
178   - return
179   -
180   - def FDCcheckDeviceCondition(self):
181   - """
182   - Send the 'D' command and return the result
183   - """
184   - command = "D\r"
185   - result = self.__FDCcommandResponse(command)
186   - if self.verbose:
187   - # third byte:
188   - # 30 - Normal
189   - # 45 - Door open or no disk
190   - # 32 - write protected
191   - print "third byte = 0x%X" % ord(result[2])
192   - return result
193   -
194   - def FDCformat(self, sectorSize='5', verify=True):
195   - """
196   - Format the floppy with the requested
197   - """
198   - if verify:
199   - command = "F"
200   - else:
201   - command = "G"
202   - command = command + sectorSize + "\r"
203   - result = self.__FDCcommandResponse(command)
204   - if not self.isSuccess(result):
205   - raise IOError
206   - return
207   -
208   - def FDCreadIdSection(self, psn = '0'):
209   - """
210   - Read the ID section of a physical sector, and return
211   - the ID, which should be 12 bytes long
212   - """
213   - if self.verbose:
214   - print "FDCreadIdSection: Enter"
215   - command = "A " + psn + "\r"
216   - result = self.__FDCcommandResponse(command)
217   - #if not self.isSuccess(result):
218   - # raise IOError
219   - result = self.__FDCcommandResponse("\r")
220   - if self.verbose:
221   - print "FDCreadIdSection data:"
222   - print dump(result)
223   - print "FDCreadIdSection: Exit"
224   - return result
225   -
226   - def FDCreadSector(self, psn = '0', lsn = '1'):
227   - """
228   - Read the data from a logical sector.
229   - psn is Physical sector number, in the range 0-79
230   - lsn is the logical sector number, in range of 1
231   - to the max for the physical sector size
232   - """
233   - if self.verbose:
234   - print "FDCreadSector: Enter"
235   - command = "R " + psn + ","+ lsn + "\r"
236   - result = self.__FDCcommandResponse(command)
237   - #if not self.isSuccess(result):
238   - # raise IOError
239   - result = self.__FDCcommandResponse("\r")
240   - if self.verbose:
241   - print "FDCreadSector data:"
242   - print dump(result)
243   - print "FDCreadSector: Exit"
244   - return result
245   -
246   - def FDCsearchIdSection(self, data, psn = '0'):
247   - """
248   - Compare the data to the sector ID
249   - psn is Physical sector number, in the range 0-79
250   - Data length must be 12 bytes
251   - """
252   - if len(data) != 12:
253   - raise ValueError("ID data must be 12 characters long")
254   - if self.verbose:
255   - print "FDCsearchIdSection: Enter"
256   - command = "S" + psn + "\r"
257   - result = self.__FDCcommandResponse(command)
258   - if not self.isSuccess(result):
259   - raise IOError
260   - if self.verbose:
261   - print "FDCsearchIdSection data:"
262   - print dump(data)
263   - result = self.__FDCcommandResponse(data)
264   - if self.verbose:
265   - print "FDCsearchIdSection: Exit"
266   - print "NOT SURE WHAT WE EXPECT HERE"
267   - print "FDCsearchIdSection status is:"
268   - print dump(result)
269   - if not self.isSuccess(result):
270   - raise IOError
271   - return
272   -
273   - def FDCwriteIdSection(self, data, psn = '0', verify = True):
274   - """
275   - Write the data to the sector ID
276   - psn is Physical sector number, in the range 0-79
277   - Data length must be 12 bytes
278   - """
279   - if len(data) != 12:
280   - raise ValueError("ID data must be 12 characters long")
281   - if verify:
282   - command = "B"
283   - else:
284   - command = "C"
285   - if self.verbose:
286   - print "FDCwriteIdSection: Enter"
287   - command = command + psn + "\r"
288   - result = self.__FDCcommandResponse(command)
289   - if not self.isSuccess(result):
290   - raise IOError
291   - if self.verbose:
292   - print "FDCwriteIdSection data:"
293   - print dump(data)
294   - result = self.__FDCcommandResponse(data)
295   - if self.verbose:
296   - print "FDCwriteIdSection: Exit"
297   - if not self.isSuccess(result):
298   - raise IOError
299   - return
300   -
301   -#W Write log sector w/verify
302   -# (two stages - second stage send data to be written)
303   -#X Write log sector w/o vfy
304   -# (two stages - second stage send data to be written)
305   - def FDCwriteSector(self, data, psn = '0', lsn = '1', verify = True):
306   - """
307   - Write the data to the sector
308   - psn is Physical sector number, in the range 0-79, defaults to 0
309   - lsn is logical sector number, defaults to 1
310   - """
311   - if verify:
312   - command = "W"
313   - else:
314   - command = "X"
315   - if self.verbose:
316   - print "FDCwriteSector: Enter"
317   - command = command + psn + "," + lsn + "\r"
318   - result = self.__FDCcommandResponse(command)
319   - if not self.isSuccess(result):
320   - raise IOError
321   - if self.verbose:
322   - print "FDCwriteSector data:"
323   - print dump(data)
324   - result = self.__FDCcommandResponse(data)
325   - if self.verbose:
326   - print "FDCwriteSector: Exit"
327   - if not self.isSuccess(result):
328   - raise IOError
329   - return
  27 +from FDif import PDD1, dump
330 28
331 29 # meat and potatos here
332 30
@@ -344,7 +42,7 @@ def FDCwriteSector(self, data, psn = '0', lsn = '1', verify = True):
344 42 #stat = drive.FDCformat() # FDC Mode
345 43 #stat = drive.FDCcheckDeviceCondition() # FDC Mode
346 44 #stat = drive.FDCsendS()
347   -for sector in range(79):
  45 +for sector in range(2):
348 46 sid = drive.FDCreadIdSection(psn = '%d' % sector)
349 47 print "Sector ID: "
350 48 print dump(sid)

0 comments on commit a05871c

Please sign in to comment.
Something went wrong with that request. Please try again.