comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@callnetuk.com>
Subject: Re: S'Write and How To Count Bytes
Date: 2000/10/11
Date: 2000-10-11T00:00:00+00:00	[thread overview]
Message-ID: <8s2bf1$j1v4d$1@ID-25716.news.cis.dfn.de> (raw)
In-Reply-To: 39D8EF78.27E5649F@acm.org

I would honestly suggest you abandon the use of Ada's streams totally
(except, at least, within the internals of a small package), and define your
own package which formalises the entire message protocol. E.g. (inventing
fictitious commands etc.):


package SCSI is

   type Device_Type is tagged limited private;

   type Device_Status is (Ready, Busy, Spun_Down, Down);

   function Status (Device: in Device_Type) return Device_Status;

   procedure Reset (Device: in out Device_Type);

   ...

   type Block_List is array (Positive range <>) of Block_Number;

   procedure Get_Bad_Sector_Map (
      Device: in out Device_Type;
      Map: out Block_List;
      Last: out Natural);

   ...

   Operation_Not_Supported: exception;

private

   ...

end SCSI;


package body SCSI is

   ...

   type Byte_List is array (Positive range <>) of Unsigned_8;

   procedure Send_Bytes (Device: in out Device_Type; Bytes: in Byte_Array)
is
   begin
      ...
   end;

   procedure Read_Bytes (Device: in out Device_Type; Bytes: out Byte_Array)
is
   begin
      ...
   end;

   ...

   procedure Get_Bad_Sector_Map (
      Device: in out Device_Type;
      Map: out Block_List;
      Last: out Natural) is

      Prelude: Byte_Array(1..1);
      Data: Byte_Array(1..4);

   begin
      Send_Bytes(Device,(1=>16#0A#)); -- fictitious code for 'GETBSMAP'
      Read_Bytes(Device,Prelude);
      -- TBD: check Prelude(1) byte
      Last := Map'First-1;
      loop
         Read_Bytes(Device,Data);
         if Data = (0,0,0,0) then return; end if;
         Last := Last+1;
         Map(Last) := (
            Head_Number(Data(1)),
            Cylinder_Number(Integer(Data(2))*256+Integer(Data(3))),
            Sector_Number(Data(4)));
      end loop;
   end Get_Bad_Sector_Map;

   ...

end SCSI;


You can then allocate memory at exactly the points that make the best sense.
The message protocol itself will determine how efficiently this can be done.
Note how I've illustrated a solution to the unknown length problem similar
to that adopted by Ada.Text_IO.Get_Line on a String. Also note how
SCSI.Device_Type operations can be overridden and extended, neatly
accommodating irregular devices. (Not quite so butt-ugly? ;-)


--
Nick Roberts
http://www.AdaOS.org


----- Original Message -----
From: "Marin David Condic" <mcondic.nospam@acm.org>
Newsgroups: comp.lang.ada
Sent: Monday, October 02, 2000 9:26 PM
Subject: Re: S'Write and How To Count Bytes


> tmoran@bix.com wrote:
>
> > How about dropping the initial byte count and use an end-of-record
> > indicator instead, like LF in Text_IO?
>
> Clearly, one could do that. You could build your whole protocol as if it
> were trading lines of text.
>
> The bad news is that for the particular app I'm looking at, I've got an
> already defined set of messages. What I am hoping to do is find a nice,
> tidy way of using Ada95 to get at that message catalog and build support
> tools that connect to the existing system. If the answer is really good,
> I might even be able to sell the notion of changing the existing system
> and eliminate some really butt-ugly code.







  reply	other threads:[~2000-10-11  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-30  0:00 S'Write and How To Count Bytes Marin David Condic
2000-10-01  0:00 ` David C. Hoos, Sr.
2000-10-02  0:00   ` Marin David Condic
2000-10-02  0:00     ` Ted Dennison
2000-10-02  0:00       ` tmoran
2000-10-02  0:00         ` tmoran
2000-10-02  0:00           ` Ted Dennison
2000-10-02  0:00           ` Marin David Condic
2000-10-11  0:00             ` Nick Roberts [this message]
2000-10-11  0:00               ` Marin David Condic
2000-10-02  0:00         ` Marin David Condic
2000-10-03  0:00       ` Robert A Duff
2000-10-06  0:00         ` Randy Brukardt
2000-10-07  0:11           ` Ted Dennison
2000-10-06  0:00             ` Randy Brukardt
2000-10-07  0:00             ` Marin David Condic
2000-10-08  0:00               ` Jean-Pierre Rosen
2000-10-09  0:00                 ` Randy Brukardt
2000-10-11  0:00                 ` Marin David Condic
2000-10-02  0:00   ` Dr. Joachim Schr�er
2000-10-02  0:00     ` Marin David Condic
2000-10-06  0:00       ` Charles Hixson
2000-10-02  0:00 ` David C. Hoos, Sr.
2000-10-02  6:58 ` tmoran
2000-10-02  0:00   ` Marin David Condic
  -- strict thread matches above, loose matches on Subject: below --
2000-10-02  0:00 tmoran
2000-10-03  5:21 ` Marin David Condic
2000-10-03  0:00 Mario Amado Alves
2000-10-03  0:00 ` Marin David Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox