DataMuseum.dk

Presents historical artifacts from the history of:

Rational R1000/400

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Rational R1000/400

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦c67e1d914⟧ Ada Source

    Length: 12288 (0x3000)
    Types: Ada Source
    Notes: 03_class, FILE, R1k_Segment, e3_tag, package body Cl_35_Protocole, seg_0423a9

Derivation

└─⟦8527c1e9b⟧ Bits:30000544 8mm tape, Rational 1000, Arrival backup of disks in PAM's R1000
    └─ ⟦5a81ac88f⟧ »Space Info Vol 1« 
        └─⟦this⟧ 

E3 Source Code



with Cl_35;
with Serial_Port;
with Conversion;
with Text_Io;

package body Cl_35_Protocole is


    Packet_Header : constant System.Byte_String (0 .. 0) := (0 => 16#01#);

    End_Of_Packet : constant System.Byte_String (0 .. 1) :=
       (0 => 16#F1#, 1 => 16#F2#);

    Ack_String : constant System.Byte_String (0 .. 0) := (0 => 16#06#);

    Sum_Length : constant Natural := 2;

    Error_Description : String (1 .. 40);

    Read_Error : exception;


    function "&" (Left : System.Byte_String; Right : System.Byte_String)
                 return System.Byte_String is
        Left_Length : constant Natural := Left'Length;
        Right_Length : constant Natural := Right'Length;
        Result : System.Byte_String (0 .. Left_Length + Right'Length - 1);
    begin
        for I in 0 .. Left_Length - 1 loop
            Result (I) := Left (I);
        end loop;
        for I in 0 .. Right_Length - 1 loop
            Result (I + Left_Length) := Right (I);
        end loop;
        return Result;
    end "&";


    function Sum_String (Of_String : System.Byte_String)
                        return System.Byte_String is
        String_Length : Natural := Of_String'Length + 1;
        Result : System.Byte_String (0 .. 1) :=
           (0 => Conversion.In_System_Byte (Of_Object => (String_Length / 100)),
            1 => Conversion.In_System_Byte
                    (Of_Object => (String_Length mod 100)));
    begin
        return Result;
    end Sum_String;


    function Build_Packet (With_Message : System.Byte_String)
                          return System.Byte_String is
        Message_Length : Natural := With_Message'Length;
        Result_Length : constant Natural :=
           Cl_35_Protocole.Packet_Header'Length + Cl_35_Protocole.Sum_Length +
              With_Message'Length + Cl_35_Protocole.End_Of_Packet'Length;
        Result : System.Byte_String (0 .. Result_Length - 1);
        Adress_Byte : System.Byte_String (0 .. 0) := (0 => With_Message (0));
        Message_Header : System.Byte_String (0 .. 0) := (0 => With_Message (1));
        Message_Data : System.Byte_String (0 .. With_Message'Length - 3);
    begin
        for I in 2 .. Message_Length - 1 loop
            Message_Data (I - 2) := With_Message (I);
        end loop;
        Result := Packet_Header & Adress_Byte &
                     Sum_String (Of_String => Message_Data) & Message_Header &
                     Message_Data & End_Of_Packet;
        return Result;
    end Build_Packet;


    procedure Read_Header is
        A_Byte : System.Byte;
        Max : Natural := Packet_Header'Length - 1;
    begin
        for I in 0 .. Max loop
            Serial_Port.Get (A_Byte);
            if Natural (A_Byte) /= Natural (Packet_Header (0)) then
                Error_Description := "Invalid Header";
                raise Read_Error;
            end if;
        end loop;
    end Read_Header;


    procedure Read_Adress (With_Control_Adress : Cl_35.Adress) is
        A_Byte : System.Byte;
    begin
        Serial_Port.Get (A_Byte);
        if Natural (A_Byte) /= Natural (With_Control_Adress) then
            Error_Description := "Invalid Adress";
            raise Read_Error;
        end if;
    end Read_Adress;


    procedure Read_Sum (Result : in out Natural) is
        A_Byte : System.Byte;
    begin
        Serial_Port.Get (A_Byte);
        Result := Natural (A_Byte);
        for I in 1 .. Sum_Length loop
            Serial_Port.Get (A_Byte);
            Result := Result + (Natural (A_Byte) * 100 * I);
        end loop;
    end Read_Sum;


    procedure Read_Data (Number_Of_Bytes : Natural;
                         Result : in out System.Byte_String) is
        A_Byte : System.Byte;
    begin
        for I in 1 .. Number_Of_Bytes loop
            Serial_Port.Get (A_Byte);
            Result (I) := A_Byte;       end loop;
    end Read_Data;


    procedure Read_End_Of_Packet is
        Max : Natural := End_Of_Packet'Length - 1;
        A_Byte : System.Byte;
    begin
        for I in 0 .. Max loop
            Serial_Port.Get (A_Byte);
            if Natural (A_Byte) /= Natural (End_Of_Packet (I)) then
                Error_Description := "Invalid End Packet";
                raise Read_Error;
            end if;
        end loop;
    end Read_End_Of_Packet;

    procedure Read_Answer (Of_Adress : Cl_35.Adress;
                           Result_String : in out System.Byte_String) is
        Sum : Natural;
    begin
        Serial_Port.Open (With_Mode => "Read");
        Read_Header;
        Read_Adress (With_Control_Adress => Of_Adress);
        Read_Sum (Result => Sum);
        Read_Data (Number_Of_Bytes => Sum, Result => Result_String);
        Read_End_Of_Packet;
        Serial_Port.Close;
    exception
        when Read_Error =>
            Text_Io.Put_Line ("READ ERROR : " & Error_Description);
            Serial_Port.Close;
    end Read_Answer;


    procedure Send (The_Message : System.Byte_String;
                    Error_Status : in out Boolean) is
        A_Byte : System.Byte;
        Answer_String : System.Byte_String (0 .. Ack_String'Length - 1);
        Adress : constant System.Byte := The_Message (0);
    begin
        Serial_Port.Open (With_Mode => "Write");
        Serial_Port.Put (The_Byte_String =>
                            Build_Packet (With_Message => The_Message));
        Serial_Port.Close;
        Read_Answer (Of_Adress => Adress, Result_String => Answer_String);
        --if Answer_String /= Ack_String then
        --    Text_Io.Put_Line ("Ack Error...");
        --end if;
    end Send;


    procedure Send (The_Request : System.Byte_String;
                    With_Answer : in out System.Byte_String;
                    Error_Status : in out Boolean) is
        A_Byte : System.Byte;
        Sum : Natural := 0;
    begin
        Serial_Port.Open (With_Mode => "Write");
        Serial_Port.Put (The_Byte_String =>
                            Build_Packet (With_Message => The_Request));
        Serial_Port.Close;
        Serial_Port.Open (With_Mode => "Read");
        Read_Header (Status => Error_Status);
        if Error_Status = False then
            Read_Adress (Status => Error_Status);
        end if;
        if Error_Status = False then
            Read_Sum (Status => Error_Status, Result => Sum);
        end if;
        if Error_Status = False then
            Read_Data (Status => Error_Status,
                       Number_Of_Bytes => Sum,
                       Result => With_Answer);
        end if;
        if Error_Status = False then
            Read_End_Of_Packet (Status => Error_Status);
        end if;
        Serial_Port.Close;
    end Send;


end Cl_35_Protocole;

E3 Meta Data

    nblk1=b
    nid=a
    hdr6=e
        [0x00] rec0=22 rec1=00 rec2=01 rec3=04c
        [0x01] rec0=19 rec1=00 rec2=07 rec3=014
        [0x02] rec0=19 rec1=00 rec2=06 rec3=00e
        [0x03] rec0=21 rec1=00 rec2=04 rec3=002
        [0x04] rec0=1e rec1=00 rec2=03 rec3=018
        [0x05] rec0=19 rec1=00 rec2=09 rec3=018
        [0x06] rec0=1d rec1=00 rec2=05 rec3=000
        [0x07] rec0=11 rec1=00 rec2=08 rec3=000
        [0x08] rec0=13 rec1=00 rec2=03 rec3=001
        [0x09] rec0=5d rec1=0c rec2=06 rec3=5d1
        [0x0a] rec0=04 rec1=a1 rec2=30 rec3=000
    tail 0x2153cd7d88628605f1407 0x42a00088462060003
Free Block Chain:
  0xa: 0000  00 0b 03 eb 00 1d 20 20 20 20 20 20 20 20 41 5f  ┆              A_┆
  0xb: 0000  00 08 00 0e 80 07 63 65 70 74 69 6f 6e 07 00 01  ┆      ception   ┆
  0x8: 0000  00 02 00 1b 80 0b 20 52 69 67 68 74 20 28 49 29  ┆       Right (I)┆
  0x2: 0000  00 00 00 04 80 01 72 01 02 03 04 05 06 07 08 09  ┆      r         ┆