Re: Question about GTK+ and timers
Hi, guys, On Sat, Apr 9, 2011 at 4:04 AM, Chris Vine ch...@cvine.freeserve.co.uk wrote: On Sat, 9 Apr 2011 00:14:45 -0700 Igor Korot ikoro...@gmail.com wrote: [snip] Is there any way to find out if the device is little- or big-endian? Which device are you referring to? You appear to be writing some code for a machine receiving data sent over a wire, and that machine's endianness can be tested by seeing whether G_BYTE_ORDER is defined as G_LITTLE_ENDIAN or G_BIG_ENDIAN, and then used for conditional compilation purposes. glib also has some built in byte-swapping macros: http://developer.gnome.org/glib/stable/glib-Byte-Order-Macros.html However the thing that puzzles me is that there are other issues here, apart from the byte order of data elements whose size is greater than 1. As another poster has pointed out, the format of the data stream requires specification somewhere. How do you know it is sent as structs with the potentially compiler-dependent layout that you referred to? As I mentioned (and others have mentioned) earlier, what is being sent is serialised data. What you need to know is how the data packet layout of the serialised data is specified and work from there. This is very simple. If I connect the device to the x86-based machine and run minicom I can see a string of numbers which is received from the device. By looking at the documentation I can find out that the first byte (let's say it's chr(3)) correspond to some particular data. However minicom will dispaly it as 03. And so forth. Now what I want to do is read those data in the m_data, grab some pieces, convert them to double and present them to the screen. Some data that I need are 2 bytes, some 3 bytes and some just 1 byte. I thought I could rely on the compiler to do the right thing in terms of endianess, however it looks like from my testing and what you all telling me I was wrong. And I need to take care of this by myself. I will look if I can compile serial port software to be run on this device to get a data dump from serial device and check if I need to do something additional. Thank you. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi Igor, On Fri, 8 Apr 2011 18:08:30 -0700 you wrote: So, what is the best course of action? I just tested the program on the device and on x86. On x86 it produced correct results, whereas on the ARM device it didn't. So it looks like I will have to switch the endianess when running on the ARM? When talking to a remote device over a serial port, what you are receiving is fundamentally a byte stream, so the best way to handle it is to admit that in your code. Read it into an array of (unsigned) char, do any formatting / alignment checks that you can, and then extract the data into the variables you want it in. If there are raw binary values of more than one byte, extract them explicitly: MyWordVal = buf[2] + ( buf[3] * 256 ); /* data stream is little endian */ This is portable and clear to any future maintainer. The efficiency loss is negligible. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Robert, On Fri, Apr 8, 2011 at 11:53 PM, Robert Pearce r...@bdt-home.demon.co.uk wrote: Hi Igor, On Fri, 8 Apr 2011 18:08:30 -0700 you wrote: So, what is the best course of action? I just tested the program on the device and on x86. On x86 it produced correct results, whereas on the ARM device it didn't. So it looks like I will have to switch the endianess when running on the ARM? When talking to a remote device over a serial port, what you are receiving is fundamentally a byte stream, so the best way to handle it is to admit that in your code. Read it into an array of (unsigned) char, do any formatting / alignment checks that you can, and then extract the data into the variables you want it in. If there are raw binary values of more than one byte, extract them explicitly: MyWordVal = buf[2] + ( buf[3] * 256 ); /* data stream is little endian */ This is portable and clear to any future maintainer. The efficiency loss is negligible. Is there any way to find out if the device is little- or big-endian? Also, I believe that the device spit out raw data in forms of characters. And I failed to produce the same result as I got on x86. But I want to know for sure. And the code for the big-endian will look like: MyWordVal = buf[3] + ( buf[2] * 256 ); right? Thank you. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi Igor, On Sat, 9 Apr 2011 00:14:45 -0700 you wrote: MyWordVal = buf[2] + ( buf[3] * 256 ); /* data stream is little endian */ This is portable and clear to any future maintainer. The efficiency loss is negligible. Is there any way to find out if the device is little- or big-endian? Well, if it's not your own device then one might hope it comes with a data sheet. Otherwise, you'll need to arrange to print out the raw hex data that arrives and reverse-engineer it. Also, I believe that the device spit out raw data in forms of characters. Raw data in what sense? I'd be surp... well, no, probably not surprised but definitely appalled if it's just dumping its internal data structure. For one thing, a serial link is not a reliable transport layer and needs to have some form of synchronisation protocol. And I failed to produce the same result as I got on x86. That may be surprising, but it may not. If you are relying on two different compiler back-ends for different processors generating the same exact layout of a struct then endian-ness isn't your only problem. But I want to know for sure. And the code for the big-endian will look like: MyWordVal = buf[3] + ( buf[2] * 256 ); right? Yes, that's right. But remember this is the _data_stream_ endian that you care about here, not the processor. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Sat, 9 Apr 2011 00:14:45 -0700 Igor Korot ikoro...@gmail.com wrote: [snip] Is there any way to find out if the device is little- or big-endian? Which device are you referring to? You appear to be writing some code for a machine receiving data sent over a wire, and that machine's endianness can be tested by seeing whether G_BYTE_ORDER is defined as G_LITTLE_ENDIAN or G_BIG_ENDIAN, and then used for conditional compilation purposes. glib also has some built in byte-swapping macros: http://developer.gnome.org/glib/stable/glib-Byte-Order-Macros.html However the thing that puzzles me is that there are other issues here, apart from the byte order of data elements whose size is greater than 1. As another poster has pointed out, the format of the data stream requires specification somewhere. How do you know it is sent as structs with the potentially compiler-dependent layout that you referred to? As I mentioned (and others have mentioned) earlier, what is being sent is serialised data. What you need to know is how the data packet layout of the serialised data is specified and work from there. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi, ALL, Apologies for possibly screwing up the threadding. I accidentally killed the messages in my INBOX. My (hopefully last) question here in this thread is: g_io_add_watch() should take a callback (i.e. static function) or just a regular function? Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Fri, 8 Apr 2011, Igor Korot ikoro...@gmail.com wrote : My (hopefully last) question here in this thread is: g_io_add_watch() should take a callback (i.e. static function) or just a regular function? Are you writing in C or C++? I assume you're using the straight Gtk for C as the function g_io_add_watch belongs to that and we're on the gtk-list rather than the gtkmm one. Anyway, the function you need to pass is a callback, so it needs to be a straight C function not a C++ class member. It doesn't need to be static in the C sense. -- Rob Pearce http://www.bdt-home.demon.co.uk The contents of | All power corrupts, but we need electricity. this message are| purely my opinion. | Don't believe a | word. | ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Robert, On Fri, Apr 8, 2011 at 1:03 PM, Robert Pearce r...@bdt-home.demon.co.uk wrote: On Fri, 8 Apr 2011, Igor Korot ikoro...@gmail.com wrote : My (hopefully last) question here in this thread is: g_io_add_watch() should take a callback (i.e. static function) or just a regular function? Are you writing in C or C++? I assume you're using the straight Gtk for C as the function g_io_add_watch belongs to that and we're on the gtk-list rather than the gtkmm one. Anyway, the function you need to pass is a callback, so it needs to be a straight C function not a C++ class member. It doesn't need to be static in the C sense. I decided to not to use GIOChannel. You can only use it if I need to read string, but I need to read data in a structure. Thank you. -- Rob Pearce http://www.bdt-home.demon.co.uk The contents of | All power corrupts, but we need electricity. this message are | purely my opinion. | Don't believe a | word. | ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Mikhail, On Fri, Apr 8, 2011 at 2:33 PM, Mikhail Titov m...@gmx.us wrote: As far as I understand it is possible to use it with NULL for encoding. It should just read bytes with no interpretation. http://www.mail-archive.com/gtk-list@gnome.org/msg29589.html Mikhail I understand this. However, what I want is to read data in: struct Data { char m_header[2]; char m_code; char m_voltageMask[2]; char m_highestVoltage[2]; char m_lowestVoltage[2]; char m_status; } m_data; I need to look at voltageMask, highestVoltage and lowestVoltage initially. Is it possible to use m_data with GIOChannel? Thank you. -Original Message- From: gtk-list-boun...@gnome.org [mailto:gtk-list-boun...@gnome.org] On Behalf Of Igor Korot Sent: Friday, April 08, 2011 3:54 PM To: gtk-list@gnome.org Subject: Re: Question about GTK+ and timers ... I decided to not to use GIOChannel. You can only use it if I need to read string, but I need to read data in a structure. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Fri, Apr 8, 2011 at 6:14 PM, Igor Korot ikoro...@gmail.com wrote: Mikhail, On Fri, Apr 8, 2011 at 2:33 PM, Mikhail Titov m...@gmx.us wrote: As far as I understand it is possible to use it with NULL for encoding. It should just read bytes with no interpretation. http://www.mail-archive.com/gtk-list@gnome.org/msg29589.html Mikhail I understand this. However, what I want is to read data in: struct Data { char m_header[2]; char m_code; char m_voltageMask[2]; char m_highestVoltage[2]; char m_lowestVoltage[2]; char m_status; } m_data; I need to look at voltageMask, highestVoltage and lowestVoltage initially. Is it possible to use m_data with GIOChannel? of course. but you'd better hope that the compiler packs that data structure in the same way the device is sending it. you'd be far better off not using a struct for this, but just reading (in your case) 10 bytes. sending raw C structs over any kind of wire protocol almost always turns out to be huge mistake unless its been very carefully thought about. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Paul, On Fri, Apr 8, 2011 at 3:28 PM, Paul Davis p...@linuxaudiosystems.com wrote: On Fri, Apr 8, 2011 at 6:14 PM, Igor Korot ikoro...@gmail.com wrote: Mikhail, On Fri, Apr 8, 2011 at 2:33 PM, Mikhail Titov m...@gmx.us wrote: As far as I understand it is possible to use it with NULL for encoding. It should just read bytes with no interpretation. http://www.mail-archive.com/gtk-list@gnome.org/msg29589.html Mikhail I understand this. However, what I want is to read data in: struct Data { char m_header[2]; char m_code; char m_voltageMask[2]; char m_highestVoltage[2]; char m_lowestVoltage[2]; char m_status; } m_data; I need to look at voltageMask, highestVoltage and lowestVoltage initially. Is it possible to use m_data with GIOChannel? of course. but you'd better hope that the compiler packs that data structure in the same way the device is sending it. you'd be far better off not using a struct for this, but just reading (in your case) 10 bytes. sending raw C structs over any kind of wire protocol almost always turns out to be huge mistake unless its been very carefully thought about. So best way is to use char m_data[10]? And then just get m_data[4], m_data[5], m_data[6], m_data[7], m_data[8] and m_data[9]? I am getting bytes over the wire thru the serial port and transfer is performed on the client side. read( handle, m_data, 10 ); I am just getting 10 bytes which are represented on the client as m_data members. Am I wrong here? It's possible there will be a packing issue, but I'm about to test this. Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Fri, 8 Apr 2011 21:03:47 +0100 Robert Pearce r...@bdt-home.demon.co.uk wrote: On Fri, 8 Apr 2011, Igor Korot ikoro...@gmail.com wrote : My (hopefully last) question here in this thread is: g_io_add_watch() should take a callback (i.e. static function) or just a regular function? Are you writing in C or C++? I assume you're using the straight Gtk for C as the function g_io_add_watch belongs to that and we're on the gtk-list rather than the gtkmm one. Anyway, the function you need to pass is a callback, so it needs to be a straight C function not a C++ class member. It doesn't need to be static in the C sense. But it should be made static in the C sense if you don't want to export it, and usually callbacks are local and don't need to be (and therefore shouldn't be) exported. Polluting global namespace/linkspace with functions with external linkage should be restricted to the cases where it is necessary. If the OP intended to refer to using C++ static member functions as callbacks, the best advice is not to, because C++ static member functions have C++ linkage specification and therefore might use a different calling convention from those with C linkage. (As it happens, with gcc this doesn't matter; but technically it is undefined behaviour.) Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Fri, 8 Apr 2011 15:43:17 -0700 Igor Korot ikoro...@gmail.com wrote: Paul, On Fri, Apr 8, 2011 at 3:28 PM, Paul Davis p...@linuxaudiosystems.com wrote: On Fri, Apr 8, 2011 at 6:14 PM, Igor Korot ikoro...@gmail.com wrote: Mikhail, On Fri, Apr 8, 2011 at 2:33 PM, Mikhail Titov m...@gmx.us wrote: As far as I understand it is possible to use it with NULL for encoding. It should just read bytes with no interpretation. http://www.mail-archive.com/gtk-list@gnome.org/msg29589.html Mikhail I understand this. However, what I want is to read data in: struct Data { char m_header[2]; char m_code; char m_voltageMask[2]; char m_highestVoltage[2]; char m_lowestVoltage[2]; char m_status; } m_data; I need to look at voltageMask, highestVoltage and lowestVoltage initially. Is it possible to use m_data with GIOChannel? of course. but you'd better hope that the compiler packs that data structure in the same way the device is sending it. you'd be far better off not using a struct for this, but just reading (in your case) 10 bytes. sending raw C structs over any kind of wire protocol almost always turns out to be huge mistake unless its been very carefully thought about. So best way is to use char m_data[10]? Why do you have this idea you need to use an aggregate, which then causes packing and layout issues to arise, leading to non-portability. Why not send them as individual entities, since you are guaranteed that they will be serialised? (I am not saying that you don't have a reason, but you have not given it.) Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
RE: Question about GTK+ and timers
Just use something like __attribute__ ((__packed__)) for your structure and you can always cast back and forth from the pointer to your structure to an array of bytes (char*). Just make sure that both systems have same ending (little or big) and that members' order is correct. Otherwise you'll have to swap data within let's say m_voltageMask . Mikhail -Original Message- From: gtk-list-boun...@gnome.org [mailto:gtk-list-boun...@gnome.org] On Behalf Of Igor Korot Sent: Friday, April 08, 2011 5:43 PM To: gtk-list@gnome.org Subject: Re: Question about GTK+ and timers Is it possible to use m_data with GIOChannel? of course. but you'd better hope that the compiler packs that data structure in the same way the device is sending it. you'd be far better off not using a struct for this, but just reading (in your case) 10 bytes. sending raw C structs over any kind of wire protocol almost always turns out to be huge mistake unless its been very carefully thought about. So best way is to use char m_data[10]? And then just get m_data[4], m_data[5], m_data[6], m_data[7], m_data[8] and m_data[9]? I am getting bytes over the wire thru the serial port and transfer is performed on the client side. read( handle, m_data, 10 ); I am just getting 10 bytes which are represented on the client as m_data members. Am I wrong here? It's possible there will be a packing issue, but I'm about to test this. Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Mikhail, On Fri, Apr 8, 2011 at 4:36 PM, Mikhail Titov m...@gmx.us wrote: Just use something like __attribute__ ((__packed__)) for your structure and you can always cast back and forth from the pointer to your structure to an array of bytes (char*). Just make sure that both systems have same ending (little or big) and that members' order is correct. Otherwise you'll have to swap data within let's say m_voltageMask . My intention is to run the program on the ARM architecture (armv4t) - S3C2440 mini2440 device from FriendlyARM. So I don't think the endianess will be the same here. I am building everything from the OpenEmbedded tree with the arm-angstrom-gnueabi gcc compiler. What would be the syntax with it? [code] __attribute__((__packed__)) struct Data { . } m_data; and what do you mean by swapping the order of the data? I am just relying on the cross-compiler to do the right thing for me in terms of endianess. Should I care about that? Thank you. Mikhail -Original Message- From: gtk-list-boun...@gnome.org [mailto:gtk-list-boun...@gnome.org] On Behalf Of Igor Korot Sent: Friday, April 08, 2011 5:43 PM To: gtk-list@gnome.org Subject: Re: Question about GTK+ and timers Is it possible to use m_data with GIOChannel? of course. but you'd better hope that the compiler packs that data structure in the same way the device is sending it. you'd be far better off not using a struct for this, but just reading (in your case) 10 bytes. sending raw C structs over any kind of wire protocol almost always turns out to be huge mistake unless its been very carefully thought about. So best way is to use char m_data[10]? And then just get m_data[4], m_data[5], m_data[6], m_data[7], m_data[8] and m_data[9]? I am getting bytes over the wire thru the serial port and transfer is performed on the client side. read( handle, m_data, 10 ); I am just getting 10 bytes which are represented on the client as m_data members. Am I wrong here? It's possible there will be a packing issue, but I'm about to test this. Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Fri, 8 Apr 2011 18:36:41 -0500 Mikhail Titov m...@gmx.us wrote: Just use something like __attribute__ ((__packed__)) for your structure and you can always cast back and forth from the pointer to your structure to an array of bytes (char*). Just make sure that both systems have same ending (little or big) and that members' order is correct. Otherwise you'll have to swap data within let's say m_voltageMask . This attribute is compiler specific. He would also have to be careful to avoid breaking strict aliasing with his casting, or he could have the compiler optimize away some of his code. It is relatively easy to avoid that (make sure you start with the type you finish with), but I am not convinced the OP is necessarily up to speed on how to do it defensively. Because this provides unaligned access (on gcc) it can also be significantly inefficient on particular architectures. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Fri, 8 Apr 2011 16:45:03 -0700 Igor Korot ikoro...@gmail.com wrote: Mikhail, On Fri, Apr 8, 2011 at 4:36 PM, Mikhail Titov m...@gmx.us wrote: Just use something like __attribute__ ((__packed__)) for your structure and you can always cast back and forth from the pointer to your structure to an array of bytes (char*). Just make sure that both systems have same ending (little or big) and that members' order is correct. Otherwise you'll have to swap data within let's say m_voltageMask . My intention is to run the program on the ARM architecture (armv4t) - S3C2440 mini2440 device from FriendlyARM. So I don't think the endianess will be the same here. I am building everything from the OpenEmbedded tree with the arm-angstrom-gnueabi gcc compiler. What would be the syntax with it? [code] __attribute__((__packed__)) struct Data { . } m_data; and what do you mean by swapping the order of the data? I am just relying on the cross-compiler to do the right thing for me in terms of endianess. Should I care about that? If the machine sending data over the wire has or might have a different idea of endianness than your ARM architecture receiving it (which actually is switchable bi-endian I think, but little endian by default), then you need to care about it. This might help: http://en.wikipedia.org/wiki/Endianness Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
RE: Question about GTK+ and timers
I guess the main point it should just work for x86 and certain ARM architecture. Everything else doesn't matter, including efficiency, especially if one side is already implemented in a particular way. Yes, structure packing is compiler-specific. In case of Visual C++ one uses #pragma, but I feel like OP uses gcc in both cases. So here comes the syntax http://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Type-Attributes.html#Type-Attrib utes I just learned that ARM is bi-endian and can be set up either way. Haven't ever had to deal with these creatures. And that is what endianness is usually about. If you are unlucky the order of 2 bytes of m_voltageMask may be incorrect, in this case you would receiver char[10] first, reverse it, and have a packed structure defined with the inverse order of members. See also http://linux.die.net/man/3/htons . Mikhail -Original Message- From: Chris Vine [mailto:ch...@cvine.freeserve.co.uk] Sent: Friday, April 08, 2011 7:02 PM To: Mikhail Titov Cc: 'Igor Korot'; gtk-list@gnome.org Subject: Re: Question about GTK+ and timers On Fri, 8 Apr 2011 18:36:41 -0500 Mikhail Titov m...@gmx.us wrote: Just use something like __attribute__ ((__packed__)) for your structure and you can always cast back and forth from the pointer to your structure to an array of bytes (char*). Just make sure that both systems have same ending (little or big) and that members' order is correct. Otherwise you'll have to swap data within let's say m_voltageMask . This attribute is compiler specific. He would also have to be careful to avoid breaking strict aliasing with his casting, or he could have the compiler optimize away some of his code. It is relatively easy to avoid that (make sure you start with the type you finish with), but I am not convinced the OP is necessarily up to speed on how to do it defensively. Because this provides unaligned access (on gcc) it can also be significantly inefficient on particular architectures. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Mikhail, On Fri, Apr 8, 2011 at 5:11 PM, Mikhail Titov m...@gmx.us wrote: I guess the main point it should just work for x86 and certain ARM architecture. Everything else doesn't matter, including efficiency, especially if one side is already implemented in a particular way. Yes, structure packing is compiler-specific. In case of Visual C++ one uses #pragma, but I feel like OP uses gcc in both cases. So here comes the syntax http://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Type-Attributes.html#Type-Attrib utes Yes, I'm using gcc. I just learned that ARM is bi-endian and can be set up either way. Haven't ever had to deal with these creatures. And that is what endianness is usually about. If you are unlucky the order of 2 bytes of m_voltageMask may be incorrect, in this case you would receiver char[10] first, reverse it, and have a packed structure defined with the inverse order of members. See also http://linux.die.net/man/3/htons . Does anybody know how to make ARM system to have the same endianess as with x86? I am using X11-GPE-IMAGE from OpenEmbedded. I just tested my program and it looks like I am not getting data properly, so I guess the image set as big endian by default. Thank you. Mikhail -Original Message- From: Chris Vine [mailto:ch...@cvine.freeserve.co.uk] Sent: Friday, April 08, 2011 7:02 PM To: Mikhail Titov Cc: 'Igor Korot'; gtk-list@gnome.org Subject: Re: Question about GTK+ and timers On Fri, 8 Apr 2011 18:36:41 -0500 Mikhail Titov m...@gmx.us wrote: Just use something like __attribute__ ((__packed__)) for your structure and you can always cast back and forth from the pointer to your structure to an array of bytes (char*). Just make sure that both systems have same ending (little or big) and that members' order is correct. Otherwise you'll have to swap data within let's say m_voltageMask . This attribute is compiler specific. He would also have to be careful to avoid breaking strict aliasing with his casting, or he could have the compiler optimize away some of his code. It is relatively easy to avoid that (make sure you start with the type you finish with), but I am not convinced the OP is necessarily up to speed on how to do it defensively. Because this provides unaligned access (on gcc) it can also be significantly inefficient on particular architectures. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Chris, On Fri, Apr 8, 2011 at 5:02 PM, Chris Vine ch...@cvine.freeserve.co.uk wrote: On Fri, 8 Apr 2011 18:36:41 -0500 Mikhail Titov m...@gmx.us wrote: Just use something like __attribute__ ((__packed__)) for your structure and you can always cast back and forth from the pointer to your structure to an array of bytes (char*). Just make sure that both systems have same ending (little or big) and that members' order is correct. Otherwise you'll have to swap data within let's say m_voltageMask . This attribute is compiler specific. He would also have to be careful to avoid breaking strict aliasing with his casting, or he could have the compiler optimize away some of his code. It is relatively easy to avoid that (make sure you start with the type you finish with), but I am not convinced the OP is necessarily up to speed on how to do it defensively. Yes, this is my first project with an Embedded development. ;-) Because this provides unaligned access (on gcc) it can also be significantly inefficient on particular architectures. So, what is the best course of action? I just tested the program on the device and on x86. On x86 it produced correct results, whereas on the ARM device it didn't. So it looks like I will have to switch the endianess when running on the ARM? No, Chris, what is the best way to do it? Thank you. Chris ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi Igor, On Wed, 6 Apr 2011 22:38:43 -0700 you wrote: Just one question: AFAIU this pair is polling the port for data and when they become available I need to drop them in the GUI. It's going to be something like MT, right? MT? It's not a threaded approach, if that's what you mean. Open the serial port and attach it to a g_io_channel: fd = open ( /dev/ttyS0, O_RDWR|O_NONBLOCK ); hFile = g_io_channel_unix_new ( fd ); g_io_channel_set_encoding ( hFile, NULL, tErrPtr ); Now you can hook up a call-back: RxEventSrc = g_io_add_watch ( hFile, G_IO_IN, HandleAsyncRx, (gpointer)Instance ); Then in the call-back you read the incoming data and pass it to the GUI: gboolean HandleAsyncRx ( GIOChannel *source, GIOCondition condition, gpointer data) { GIOStatus stat; gsize len; GError * err = NULL; unsigned char tmpbuf[32]; stat = g_io_channel_read_chars ( source, (gchar*)tmpbuf, sizeof(tmpbuf), len, err ); // etc ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi, Robert, On Thu, Apr 7, 2011 at 12:59 AM, Robert Pearce r...@bdt-home.demon.co.uk wrote: Hi Igor, On Wed, 6 Apr 2011 22:38:43 -0700 you wrote: Just one question: AFAIU this pair is polling the port for data and when they become available I need to drop them in the GUI. It's going to be something like MT, right? MT? It's not a threaded approach, if that's what you mean. Open the serial port and attach it to a g_io_channel: fd = open ( /dev/ttyS0, O_RDWR|O_NONBLOCK ); hFile = g_io_channel_unix_new ( fd ); g_io_channel_set_encoding ( hFile, NULL, tErrPtr ); Now you can hook up a call-back: RxEventSrc = g_io_add_watch ( hFile, G_IO_IN, HandleAsyncRx, (gpointer)Instance ); But isn't it the same as registering the timer? Then in the call-back you read the incoming data and pass it to the GUI: gboolean HandleAsyncRx ( GIOChannel *source, GIOCondition condition, gpointer data) { GIOStatus stat; gsize len; GError * err = NULL; unsigned char tmpbuf[32]; stat = g_io_channel_read_chars ( source, (gchar*)tmpbuf, sizeof(tmpbuf), len, err ); // etc And this is done the same way as the timer: it creates thread and performs this function in it, right? Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Thu, Apr 7, 2011 at 2:07 PM, Igor Korot ikoro...@gmail.com wrote: Now you can hook up a call-back: RxEventSrc = g_io_add_watch ( hFile, G_IO_IN, HandleAsyncRx, (gpointer)Instance ); But isn't it the same as registering the timer? not at all. And this is done the same way as the timer: it creates thread and performs this function in it, right? not at all. your callback is executed in the thread running the event loop but not based on a timer - based on when actual data arrives from the serial port. --p ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi, On Thu, Apr 7, 2011 at 11:15 AM, Paul Davis p...@linuxaudiosystems.com wrote: On Thu, Apr 7, 2011 at 2:07 PM, Igor Korot ikoro...@gmail.com wrote: Now you can hook up a call-back: RxEventSrc = g_io_add_watch ( hFile, G_IO_IN, HandleAsyncRx, (gpointer)Instance ); But isn't it the same as registering the timer? not at all. And this is done the same way as the timer: it creates thread and performs this function in it, right? not at all. your callback is executed in the thread running the event loop but not based on a timer - based on when actual data arrives from the serial port. So is there one thread or two? ;-) Thank you. --p ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Thu, Apr 7, 2011 at 2:24 PM, Igor Korot ikoro...@gmail.com wrote: So is there one thread or two? ;-) one thread. this has the same problem that anything using a (G)UI event loop for I/O does - the callback may be delayed by other event handling. in the real world, this is rarely a problem, especially with such intermittent bursts of data. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
OK, thanx. On Thu, Apr 7, 2011 at 11:47 AM, Paul Davis p...@linuxaudiosystems.com wrote: On Thu, Apr 7, 2011 at 2:24 PM, Igor Korot ikoro...@gmail.com wrote: So is there one thread or two? ;-) one thread. this has the same problem that anything using a (G)UI event loop for I/O does - the callback may be delayed by other event handling. in the real world, this is rarely a problem, especially with such intermittent bursts of data. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Question about GTK+ and timers
Hi, ALL, I read that the timer event processing is differ between x86 and ARM. On x86 it fires at 1/1000 interval, on ARM it fires at 10/1000 interval. If I use g_timeout_add_seconds( 1, ...) am I guaranteed that the timer events will fire with 1 sec interval independently of the arch? Thank you. ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
On Wed, Apr 6, 2011 at 2:49 PM, Igor Korot ikoro...@gmail.com wrote: Hi, ALL, I read that the timer event processing is differ between x86 and ARM. On x86 it fires at 1/1000 interval, on ARM it fires at 10/1000 interval. If I use g_timeout_add_seconds( 1, ...) am I guaranteed that the timer events will fire with 1 sec interval independently of the arch? you're not guaranteed anything about timeouts. if you are relying on them for precise timing, you've made a mistake already. within the context of a GUI, with its (typically slow) human interaction times, they are entirely accurate enough. for anything else, not at all. the timeout will execute as part of the glib event loop that its a part of. your callback could be delayed by arbitrary amounts of time by other, higher priority callbacks. however, if the interval is 1 second, then you can be assured that your callback is almost certainly going to execute very, very close to once every second. --p ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi, Paul, My task is to read the external device thru the serial port with the 1 sec interval. And then update the GUI with the new data. At least the documentation of this device says that it will write with 1 sec. I am testing on x86, then cross-compiling for ARM and run the program on ARM. Will I be better off with just continuous loop inside thread or the timer will do? Thank you. On Wed, Apr 6, 2011 at 12:05 PM, Paul Davis p...@linuxaudiosystems.com wrote: On Wed, Apr 6, 2011 at 2:49 PM, Igor Korot ikoro...@gmail.com wrote: Hi, ALL, I read that the timer event processing is differ between x86 and ARM. On x86 it fires at 1/1000 interval, on ARM it fires at 10/1000 interval. If I use g_timeout_add_seconds( 1, ...) am I guaranteed that the timer events will fire with 1 sec interval independently of the arch? you're not guaranteed anything about timeouts. if you are relying on them for precise timing, you've made a mistake already. within the context of a GUI, with its (typically slow) human interaction times, they are entirely accurate enough. for anything else, not at all. the timeout will execute as part of the glib event loop that its a part of. your callback could be delayed by arbitrary amounts of time by other, higher priority callbacks. however, if the interval is 1 second, then you can be assured that your callback is almost certainly going to execute very, very close to once every second. --p ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi Igor, On Wed, 6 Apr 2011 12:12:56 -0700 you wrote: My task is to read the external device thru the serial port with the 1 sec interval. And then update the GUI with the new data. At least the documentation of this device says that it will write with 1 sec. I am testing on x86, then cross-compiling for ARM and run the program on ARM. Will I be better off with just continuous loop inside thread or the timer will do? If the device does an autonomous report every second, you're probably better off using a g_io_channel to capture the incoming message and update the GUI using g_io_add_watch. No need for a timeout. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Question about GTK+ and timers
Hi, Robert, On Wed, Apr 6, 2011 at 3:42 PM, Robert Pearce r...@bdt-home.demon.co.uk wrote: Hi Igor, On Wed, 6 Apr 2011 12:12:56 -0700 you wrote: My task is to read the external device thru the serial port with the 1 sec interval. And then update the GUI with the new data. At least the documentation of this device says that it will write with 1 sec. I am testing on x86, then cross-compiling for ARM and run the program on ARM. Will I be better off with just continuous loop inside thread or the timer will do? If the device does an autonomous report every second, you're probably better off using a g_io_channel to capture the incoming message and update the GUI using g_io_add_watch. No need for a timeout. Yes it is autonomous. All I'm doing is connecting it to the serial port. Just one question: AFAIU this pair is polling the port for data and when they become available I need to drop them in the GUI. It's going to be something like MT, right? Thank you. Cheers, Rob ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list