dashera_0.14.0_ee112420/src/xmodem.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--  Copyright ©2022 Steve Merrony
--
--  Permission is hereby granted, free of charge, to any person obtaining a copy
--  of this software and associated documentation files (the "Software"), to deal
--  in the Software without restriction, including without limitation the rights
--  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
--  copies of the Software, and to permit persons to whom the Software is
--  furnished to do so, subject to the following conditions:
--  The above copyright notice and this permission notice shall be included in
--  all copies or substantial portions of the Software.
--
--  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
--  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
--  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
--  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
--  THE SOFTWARE.

with Ada.Containers;             use Ada.Containers;
with Ada.Containers.Vectors;
with Ada.Streams.Stream_IO;      use Ada.Streams.Stream_IO;
with Ada.Unchecked_Conversion;

with Interfaces;  use Interfaces;

package Xmodem is

   type Packet_Size is (Short, Long);
   for Packet_Size use (Short => 128, Long => 1024);

   package Char_Vectors is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => Character);
   use Char_Vectors;

   task type Receiver is
      entry Start (RX_Stream : Stream_Access);
      entry Accept_Data (Char : Character);
      entry Done;
      --  entry Stop;
   end Receiver;
   type Receiver_Acc is access Receiver;

   Receiver_Task : Receiver_Acc;

   procedure Receive (Filename : String; Trace_Flag : Boolean);

   task type Sender is
      entry Start (TX_Stream : Stream_Access; Pkt_Len : Packet_Size);
      entry Accept_Data (Char : Character);
      entry Done;
   end Sender;
   type Sender_Acc is access Sender;

   Sender_Task : Sender_Acc;

   procedure Send (Filename : String; Pkt_Len : Packet_Size; Trace_Flag : Boolean);

   Already_Exists,
   File_Does_Not_Exist,
   File_Access_Error,
   Protocol_Error,
   Sender_Cancelled,
   Timeout,
   Too_Many_Retries  : exception;

private

   function Char_To_U8   is new Ada.Unchecked_Conversion (Character, Unsigned_8);
   function Byte_To_Char is new Ada.Unchecked_Conversion (Unsigned_8, Character);

   function CRC_16 (Data : Vector) return Unsigned_16;
   --  Calculate the CRC-16 value of the provided block of data

   function CRC_16_Fixed_Len (Data : Vector; FL : Positive) return Unsigned_16;
   --  Calculate the CRC-16 Constant for the provided block of data

   procedure Send_Block (Data : in out Vector; Block_Num : Natural; Block_Size : Packet_Size);

   Tracing : Boolean;

end Xmodem;