What you could possibly do for floating point data, is sprintf() it into
a string, and then transmit the string. All char data is sent / received
in order - always.
When sending ints, you will always need to perform hton and similar
functions when sending, and ntohl or ntohs when receiving, etc.
see 'man hton'
An excellent primer is "beej's guide to internet programming with
sockets" available free online. (I believe) he specifically says that
structs do not work at all reliably through sockets.
~/Chris
Yan Seiner wrote:
> --- In "Oguz Dilmac" <> wrote:
>> Hi all,
>>
>> I'm trying to pass some data from my pc to ts7300 via Ethernet.
>> It seems floating point formats of EP9302 and PC are different from
>> each other.
>>
>> In my program, I have a struct with both floating point and integer
>> variables. I simply send this data to ethernet from PC. On the arm
>> side, a user program gets the data from socket and put it to a FIFO to
>> pass to a kernel module. Then I print them with rt_printk.
>>
>> When I dmesg, Integer parts are OK. But float parts are garbage.
>>
>
> I looked at doing this. I even had a discussion of this on either the
> gcc list or the general C list; I forget.
>
> The gist of the issue is this:
>
> While in theory you could get it to work, in practice it is
> unmaintainable.
>
> Structs are created by the compiler, and as such, the various byte
> padding schemes and memory alignment schemes can vary from compiler to
> compiler, between compiler versions, and possibly even between
> compiler runs, so there's no guarantee that it will work even on the
> same hardware platform.
>
> Now throw in the problem of endiannes, and the different float
> formats, and the fact that on some architectures ints are 2 bytes, on
> some 4 bytes, and if you're really using off-the-wall stuff, 36 bits.
>
> In other words, it cannot be done.
>
> I ended up normalizing everything into 2 byte big-endian ints, and
> writing routines that pack and unpack the data. (See PHP's
> pack/unpack functions.)
>
> Look into the modbus spec for a truly portable (but not easy to
> implement) way to transfer data between arbitrary architectures.
>
> --Yan
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|