comp.lang.ada
 help / color / mirror / Atom feed
* Serial port configuration
@ 2014-04-06 16:22 hreba
  2014-04-06 18:57 ` Simon Wright
  0 siblings, 1 reply; 6+ messages in thread
From: hreba @ 2014-04-06 16:22 UTC (permalink / raw)


The problem
-----------
I am trying to communicate with an Arduino using 
GNAT.Serial_Communications, which I will abbreviate as "Serial". The 
"Set" procedure isn't detailed enough, I need "fcntl", "tcgetattr" and 
"tcsetattr" which are private in Serial. To call them, I need the file 
descriptor which is a private component of the type "Port".

The Idea
--------
1. Create a new package "SerAux"
2. declare "fcntl", "tcgetattr" and "tcsetattr" the same way as in
    "Serial", but public
3. define a new type "Port" the same way as in "Serial", but public,
    and do the conversion somehow.

The obstacles
-------------
Creating the new Port requires to override its methods "Read" and 
"Write", but even doing that the same way as in "Serial" gets me a lot 
of error messages. The SerAux.adb begins like this (reproduced from 
original line # 4 on):

--------------------------------------------------------------
...
package body SerAux is

    type Port_Data is new int;
    type Port_Data_Access is access Port_Data;
    type Port is new Ada.Streams.Root_Stream_Type with record
       H : Port_Data_Access;
    end record;


    overriding procedure Read
      (--Port   : in out Serial_Port;
       Port   : in out Port;
       Buffer : out Ada.Streams.Stream_Element_Array;
       Last   : out Ada.Streams.Stream_Element_Offset)
    is
    begin
       Read (Serial.Serial_Port(Port), Buffer, Last);
    end Read;

    ...
----------------------------------------------------------------

The error messages for this fragment are:

seraux.adb:8:09: type must be declared abstract or "Read" overridden
seraux.adb:8:09: "Read" has been inherited at line 8
seraux.adb:8:09: "Read" has been inherited from subprogram at 
a-stream.ads:54
seraux.adb:13:15: subprogram "Read" is not overriding
seraux.adb:15:23: formal parameter "Port" cannot be used before end of 
specification
seraux.adb:20:07: warning: possible infinite recursion
seraux.adb:20:07: warning: Storage_Error may be raised at run time
...
-----------------------------------------------------------------

The questions
-------------
1. Why is all that an error here and not in "Serial"?
2. Am I on the right way or would you solve the problem completely 
different?

Please consider that I am a beginner.

--
hreba


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Serial port configuration
  2014-04-06 16:22 Serial port configuration hreba
@ 2014-04-06 18:57 ` Simon Wright
  2014-04-06 19:06   ` Shark8
  2014-04-07 11:44   ` Serial port configuration hreba
  0 siblings, 2 replies; 6+ messages in thread
From: Simon Wright @ 2014-04-06 18:57 UTC (permalink / raw)


hreba <hreba@terra.com.br> writes:

> package body SerAux is
>
>    type Port_Data is new int;
>    type Port_Data_Access is access Port_Data;
>    type Port is new Ada.Streams.Root_Stream_Type with record
>       H : Port_Data_Access;
>    end record;

The declaration of type Port needs to be in the spec; and you need to
have the spec of Read there also.

>    overriding procedure Read
>      (--Port   : in out Serial_Port;
>       Port   : in out Port;

You can't use the name Port twice like that. I'd suggest using
Serial_Port for the type name, like the original (why change?).

In fact, why not just copy the contents of the GNAT version and change
the bits you need to?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Serial port configuration
  2014-04-06 18:57 ` Simon Wright
@ 2014-04-06 19:06   ` Shark8
  2014-04-07 11:47     ` hreba
  2023-11-04 14:23     ` GNAT.SHA256 differs from Linux' sha256sum wvxvw
  2014-04-07 11:44   ` Serial port configuration hreba
  1 sibling, 2 replies; 6+ messages in thread
From: Shark8 @ 2014-04-06 19:06 UTC (permalink / raw)


On 06-Apr-14 12:57, Simon Wright wrote:
>> >    overriding procedure Read
>> >      (--Port   : in out Serial_Port;
>> >       Port   : in out Port;
> You can't use the name Port twice like that. I'd suggest using
> Serial_Port for the type name, like the original (why change?).

You can use the same name as the type if you fully qualify it:

Generic
   Type Element(<>) is private;
   Maximum_Size : Positive:=  1024;
Package Stack_Package is
   type Stack is private;

   Function Pop( Stack : Stack_Package.Stack ) return Element;

End;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Serial port configuration
  2014-04-06 18:57 ` Simon Wright
  2014-04-06 19:06   ` Shark8
@ 2014-04-07 11:44   ` hreba
  1 sibling, 0 replies; 6+ messages in thread
From: hreba @ 2014-04-07 11:44 UTC (permalink / raw)


On 04/06/2014 03:57 PM, Simon Wright wrote:
> hreba <hreba@terra.com.br> writes:
>
>> package body SerAux is
>>
>>     type Port_Data is new int;
>>     type Port_Data_Access is access Port_Data;
>>     type Port is new Ada.Streams.Root_Stream_Type with record
>>        H : Port_Data_Access;
>>     end record;
>
> The declaration of type Port needs to be in the spec; and you need to
> have the spec of Read there also.
>
>>     overriding procedure Read
>>       (--Port   : in out Serial_Port;
>>        Port   : in out Port;
>
> You can't use the name Port twice like that. I'd suggest using
> Serial_Port for the type name, like the original (why change?).

Thanks for the hints.
>
> In fact, why not just copy the contents of the GNAT version and change
> the bits you need to?
>
This might not be the most elegant solution, but the one with the least 
effort. I think I'll try that.
-- 
hreba

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Serial port configuration
  2014-04-06 19:06   ` Shark8
@ 2014-04-07 11:47     ` hreba
  2023-11-04 14:23     ` GNAT.SHA256 differs from Linux' sha256sum wvxvw
  1 sibling, 0 replies; 6+ messages in thread
From: hreba @ 2014-04-07 11:47 UTC (permalink / raw)


On 04/06/2014 04:06 PM, Shark8 wrote:
> On 06-Apr-14 12:57, Simon Wright wrote:
>>> >    overriding procedure Read
>>> >      (--Port   : in out Serial_Port;
>>> >       Port   : in out Port;
>> You can't use the name Port twice like that. I'd suggest using
>> Serial_Port for the type name, like the original (why change?).
>
> You can use the same name as the type if you fully qualify it:
>
> Generic
>    Type Element(<>) is private;
>    Maximum_Size : Positive:=  1024;
> Package Stack_Package is
>    type Stack is private;
>
>    Function Pop( Stack : Stack_Package.Stack ) return Element;
>
> End;

Ok, thanks.

-- 
hreba

^ permalink raw reply	[flat|nested] 6+ messages in thread

* GNAT.SHA256 differs from Linux' sha256sum
  2014-04-06 19:06   ` Shark8
  2014-04-07 11:47     ` hreba
@ 2023-11-04 14:23     ` wvxvw
  1 sibling, 0 replies; 6+ messages in thread
From: wvxvw @ 2023-11-04 14:23 UTC (permalink / raw)


Hello.

I'm learning Ada as well as how to use Usenet, so don't be too harsh.
As a learning exercise, I want to write a program that, beside other
things, needs to compute SHA256 hashes.  I discovered GNAT.SHA256
library and was able to use it (by calling Digest(<some string>)),
however the result is different from what I'd get for the same string
with running sha256sum.

Eg, with GNAT.SHA256 for string "foo" I get:

❯ ./bin/test_sha --arg foo
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
❯ echo foo | sha256sum -
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c  -

My Ada code looks (with some unrelated stuff removed) like this:

with GNAT.Command_Line;   use GNAT.Command_Line;
with GNAT.SHA256;         use GNAT.SHA256;

procedure Main is
   loop
      case Getopt ("-arg=") is
         when '-' =>
            if Full_Switch = "-arg" then
               Put_Line (Digest (Parameter));
            end if;
      end case;
   end loop;
end Main;

My understanding is that there are plenty of configuration settings to
how the checksum is computed, but I know very little about it.  My goal
is to produce the same checksum as would be produced by sha256sum
though, as the checksums are to be used outside of my program.

Finally: is GNAT.SHA256 a good way to go if I need this functionality (I
don't care about portability, if that's a concern)?

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-04 14:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-06 16:22 Serial port configuration hreba
2014-04-06 18:57 ` Simon Wright
2014-04-06 19:06   ` Shark8
2014-04-07 11:47     ` hreba
2023-11-04 14:23     ` GNAT.SHA256 differs from Linux' sha256sum wvxvw
2014-04-07 11:44   ` Serial port configuration hreba

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