Wednesday, January 28, 2015

Digest for comp.lang.c++@googlegroups.com - 25 updates in 5 topics

"Öö Tiib" <ootiib@hot.ee>: Jan 27 07:50PM -0800

> Would you use a cyclic methodology, with functions recurring at regular intervals? (some more frequently than others, while others more seldom) A kind of timeslice method?
> Or would you use an event-based method?
 
> (What about using C++ on top of embedded linux?)
 
There are millions of lines worth of software in a factory.
Lot of it is written in C++.
jononanon@googlemail.com: Jan 28 08:15AM -0800

On Wednesday, January 28, 2015 at 4:51:08 AM UTC+1, Öö Tiib wrote:
 
> There are millions of lines worth of software in a factory.
> Lot of it is written in C++.
 
I'm sorry... but your brief reply is incredible on so many levels, that I don't know what to say.
 
A dose of reality might be in order:
You've probably never heard of PLCs. To present an alternative to your statement from above:
There is a lot of software in a factory.
Lot of it is written in IEC 61131-3. (Often it is interfaced to Scada Systems.)
 
But I'm not interested in that.
 
My question particularly pertains to methods of using C++ in the automation industry with regards to patterns, frameworks, practices, uses, etc.
 
Think of it like this: with the rise of platforms like the Raspberry Pi, Beaglebone Black, Wandboard, Udoo, Odroid, etc. the use of C++ in industrial hardware and embedded projects is more viable than ever before.
 
But the use of C++ for such embedded projects will be quite different from a "normal desktop program".
scott@slp53.sl.home (Scott Lurndal): Jan 28 05:24PM

>hardware and embedded projects is more viable than ever before.
 
>But the use of C++ for such embedded projects will be quite different from =
>a "normal desktop program".
 
C or C++, it doesn't really matter. When programming for embedded
projects, whatever language you use, the constraints are the same.
 
Typically the constraints include a footprint size that precludes
using much of the standard template library. Often the constraints
also include avoiding C++ exceptions. There may or may not be
run-time facilities to support RTTI or C++ exceptions available
on the platform; there may not even be an operating system.
 
C++ works just fine given those constraints, assuming one avoids
the bits that aren't supported on the target platform; and the
application can still benefit from the data-hiding and encapsulation
provided by the C++ classes.
"Öö Tiib" <ootiib@hot.ee>: Jan 28 10:54AM -0800

> that I don't know what to say.
 
> A dose of reality might be in order:
> You've probably never heard of PLCs.
 
There may be only one PLC per production line. PLC is just a cheap
computer sold expensively. I have seen PLCs with embedded Windows
and Linux. In what language you think software for PLC is written?
 
> To present an alternative to your statement from above:
> There is a lot of software in a factory.
> Lot of it is written in IEC 61131-3. (Often it is interfaced to Scada Systems.)
 
That IEC 61131-3 is a configuration script for PLC that looks like
assembler to scare idiots. IOW configuration script for small fraction
of software in factory. You can't write anything really active in it.
For example how you write variable frequency drive in IEC 61131-3?
 
 
> My question particularly pertains to methods of using C++ in the
> automation industry with regards to patterns, frameworks, practices,
> uses, etc.
 
Things that do work in factory are mostly in C or C++ already.
 
> Raspberry Pi, Beaglebone Black, Wandboard, Udoo, Odroid, etc. the
> use of C++ in industrial hardware and embedded projects is more
> viable than ever before.
 
That has been so for more than decade. It is both inertia of the
sector and rarity of good C++ specialists that majority is in C.
However if a device works then there's no need to rewrite it to
other platform or in other language.
 
> But the use of C++ for such embedded projects will be quite
> different from a "normal desktop program".
 
There are no time for C++ teams to write "normal desktop programs".
Too lot of embedded work, too few specialists.
Wouter van Ooijen <wouter@voti.nl>: Jan 28 08:52PM +0100


> My question particularly pertains to methods of using C++ in the automation industry with regards to patterns, frameworks, practices, uses, etc.
 
> Think of it like this: with the rise of platforms like the Raspberry Pi, Beaglebone Black, Wandboard, Udoo, Odroid, etc. the use of C++ in industrial hardware and embedded projects is more viable than ever before.
 
> But the use of C++ for such embedded projects will be quite different from a "normal desktop program".
 
Different in what sense? The platforms you mention are Linux-level
systems, suited to heavy work, but not so much to fast (ms and faster)
real-time work. The methods to program such systems don't differ that
much from desktop systems.
 
For programming hard resource-constrained systems (small memory, not a
lot of CPU pwoer to spare, hard real-time requiremenst) C++ can (and IMO
should) be used, but in somje aspects not as it is used on a desktop.
For instance:
 
- no heap (unpredictable timing)
- no exceptions (see http://www.voti.nl/blog/?p=40 for more explanation)
- no RTTI
- (depending on the hardware) no floating point
 
Most of the standard and third-party C++ libraries don't adhere to these
limitatins, so they are not useable. Unfortunately, this is seldom clear
in advance.
 
Some C++ features can, when used correctly, be a big asset in such a
resource-constrained situation:
 
- templates (but note that the wrong use can spell a disaster)
- constexpr
 
Wouter van Ooijen
jononanon@googlemail.com: Jan 28 12:38PM -0800

Unfortunately no reply here has hit the nail on the head yet.
 
Taking about constraints of some embedded systems is all fine, but it's quite shallow when compared to "real" meat-and-bone topics such as the actual design of the system.
How do you use C++ efficiently to do it?
 
Something that might go in the direction I was asking about, might be:
http://apfw.sourceforge.net/
 
To quote from the site:
"The development of the framework started when we realized that a lot of embedded software projects start with creating fundamental services such as kernel abstraction, startup handling, simulation of missing (because still under development) hardware, implementation of design pattern and other stuff. All these things were similar in most projects but re-implemented. The problem is that this work doesn't actually add value to the product! The final user has no immediate benefit from a kernel abstraction!"
see also http://apfw.sourceforge.net/tutorials/ApFwCookbook.pdf
 
Possibly also the Boost Meta State Machine (MSM) or Boost Statechart might be useful in an embedded industrial context...
Paavo Helde <myfirstname@osa.pri.ee>: Jan 28 03:01PM -0600

jononanon@googlemail.com wrote in
> it's quite shallow when compared to "real" meat-and-bone topics such
> as the actual design of the system. How do you use C++ efficiently to
> do it?
 
An oblig car analogy :-) How do you use welding to design your car? Well,
you don't. You design your car beforehand, and if your design prescribes
welding, then you use welding for actually making the car.
 
Same here. The design is based on actual requirements for the system and
can be done on paper or for smaller projects in your head, or in some more
formal system if required. After that C++ or some other language can be
used for implementing the design in software (though in reality there will
likely be more iterations as there is very little chance to get the design
exactly right at the first time).
 
C++ is very versatile and can be used for implementing different kinds of
designs, but how it is done depends on the design, not the other way
around.
 
HTH
Paavo
scott@slp53.sl.home (Scott Lurndal): Jan 28 09:05PM

>Unfortunately no reply here has hit the nail on the head yet.
 
This isn't a classroom.
 
What is your goal for asking these questions?
jononanon@googlemail.com: Jan 28 01:14PM -0800

On Wednesday, January 28, 2015 at 10:01:45 PM UTC+1, Paavo Helde wrote:
> around.
 
> HTH
> Paavo
 
Yes true. But realize this also: if you don't know good techniques, you can design as much as you want... it'll just come across as a wish-list of requirements; and nothing will come of it.
 
On Wednesday, January 28, 2015 at 10:05:56 PM UTC+1, Scott Lurndal wrote:
> >Unfortunately no reply here has hit the nail on the head yet.
 
> This isn't a classroom.
 
> What is your goal for asking these questions?
 
Teasing you.
 
No, but seriously: I'm simply asking about good techniques. Recommend to me a book, framework, methodology, technique, ...
 
As far as I can see... everyone seems to be "rolling their own" in the embedded domain. (??)
"Öö Tiib" <ootiib@hot.ee>: Jan 28 02:38PM -0800


> Yes true. But realize this also: if you don't know good techniques, you
> can design as much as you want... it'll just come across as a wish-list
> of requirements; and nothing will come of it.
 
Requirements specification is not product of design. Do you want to learn
basics of software development process using industrial automation as
example?
Christopher Pisz <nospam@notanaddress.com>: Jan 27 05:50PM -0600

On 1/27/2015 4:42 PM, ghada glissa wrote:
> res[2]=e1
> res[3]=88
 
> Regards.
 
If you want to convert each byte and save it independently, you'd
probably need to bitmask your int, figure out how many bytes it is, get
one byte from each mask, convert that to hex using stringstream and
std::hex, std::setw, and std::fill.
Ian Collins <ian-news@hotmail.com>: Jan 28 07:19PM +1300

Stefan Ram wrote:
 
> ::std::string to_hex_string( int const i )
> { ::std::stringstream s; s << ::std::hex << i; return s.str(); }
 
> int main(){ ::std::cout << to_hex_string( 16 )<< '\n'; }
 
Which (minus the superfluous scoping) was what I originally posted!
 
--
Ian Collins
ghada glissa <ghadaglissa@gmail.com>: Jan 28 06:40AM -0800

Le mardi 27 janvier 2015 22:55:23 UTC+1, ghada glissa a écrit :
> Dear all,
 
> Is there any predefined function that convert in to hex or octet string in c++.
 
> Regards.
 
Dear,
 
I'm sorry for any inconvenience but i'm unable to convert each byte and save it independently.
 
Regards.
Greg Martin <greg.at.softsprocket@dot.com>: Jan 28 03:03PM


> Dear,
 
> I'm sorry for any inconvenience but i'm unable to convert each byte and save it independently.
 
> Regards.
 
I think the problem, here and in comp.lang.c is how you asked the
question. Is this what you're looking for?
 
 
#include <stdio.h>
#include <stdint.h>
#include <string.h>
 
int main () {
int i = 0x12f5e188;
unsigned char bytes[4];
 
memcpy (bytes, &i, 4);
 
for (int i = 0; i < 4; ++i) {
printf ("%x\n", bytes[i]);
}
 
return 0;
}
 
Note that the order the bytes are printed in will depend on the byte
order of the platform.
 
 
--
http://www.softsprocket.com
ghada glissa <ghadaglissa@gmail.com>: Jan 28 07:26AM -0800

Le mercredi 28 janvier 2015 16:03:38 UTC+1, Greg Martin a écrit :
> order of the platform.
 
> --
> http://www.softsprocket.com
 
Thank you for this solution but %x is used to display in hexadecimal or I want a function that returns the conversion of each byte independently.
 
Regards.
Greg Martin <greg.at.softsprocket@dot.com>: Jan 28 04:14PM

>> http://www.softsprocket.com
 
> Thank you for this solution but %x is used to display in hexadecimal or I want a function that returns the conversion of each byte independently.
 
> Regards.
 
Wellthen, you have an array of bytes that you can now convert into an array of
strings using one of suggestions that have been made, or is
this about you avoiding any effort on your part?
 
--
http://www.softsprocket.com
ghada glissa <ghadaglissa@gmail.com>: Jan 28 08:23AM -0800

Le mardi 27 janvier 2015 22:55:23 UTC+1, ghada glissa a écrit :
> Dear all,
 
> Is there any predefined function that convert in to hex or octet string in c++.
 
> Regards.
 
No, i really need help,I'm new in C ++ and I can not easily handle its concepts.
Ian Collins <ian-news@hotmail.com>: Jan 29 07:31AM +1300

ghada glissa wrote:
 
> I'm sorry for any inconvenience but i'm unable to convert each byte and save it independently.
 
What was wrong with the solution I posted? It passed the test case you
posted.
 
--
Ian Collins
Geoff <geoff@invalid.invalid>: Jan 28 11:30AM -0800

On Wed, 28 Jan 2015 08:23:17 -0800 (PST), ghada glissa
 
>> Is there any predefined function that convert in to hex or octet string in c++.
 
>> Regards.
 
>No, i really need help,I'm new in C ++ and I can not easily handle its concepts.
 
You also seem to have trouble with the concept of how to reply to
other people on Usenet. DO NOT REPLY TO YOUR OWN POSTS.
ghada glissa <ghadaglissa@gmail.com>: Jan 28 12:47PM -0800

> You also seem to have trouble with the concept of how to reply to
> other people on Usenet. DO NOT REPLY TO YOUR OWN POSTS.
 
I do not speak to you Mr Geoff, remains calm and polite please.
jak <please@nospam.tnx>: Jan 28 06:46PM +0100

Il 27/01/2015 18:04, Christopher Pisz ha scritto:
>> sending error. sorry.
 
> Oh , I thought some fellow named Alessio was the OP. You are using 2
> different accounts then I suppose.
 
 
 
More or less. The question is common and I am the most obstinate among
us. :)
ram@zedat.fu-berlin.de (Stefan Ram): Jan 28 03:06AM

>You asked for a function that converted to a string....
>You can't return an array from a function, so how about:
 
When I hear »string« in a C++ newsgroup, I first think of
»::std::string«, not of an array - even though I cannot
know whether the OP had this in mind.
 
Of course, »convert« is not the best verb between »int«
and »hex«, I'd use »render«: »render an int as a hex numeral«.
Then, I'd think along the lines of »::std::hex« and stringstreams.
ram@zedat.fu-berlin.de (Stefan Ram): Jan 28 05:03AM

>Then, I'd think along the lines of »::std::hex« and stringstreams.
 
#include <iostream>
#include <ostream>
#include <ios> // ::std::hex
#include <sstream>
 
::std::string to_hex_string( int const i )
{ ::std::stringstream s; s << ::std::hex << i; return s.str(); }
 
int main(){ ::std::cout << to_hex_string( 16 )<< '\n'; }
ram@zedat.fu-berlin.de (Stefan Ram): Jan 28 05:29PM

>Which (minus the superfluous scoping) was what I originally posted!
 
Sorry, I had not read all of the thread!
Martijn Lievaart <m@rtij.nl.invlalid>: Jan 28 09:05AM +0100

On Tue, 27 Jan 2015 12:54:38 -0600, Christopher Pisz wrote:
 
 
> Should I expect the process to terminate?
> or Should the thread terminate on its own?
 
> What is expected to happen if this occurs?
 
As others pointed out anything is allowed to happen, but on any modern
sane OS your app is terminated (unless it chooses to catch the violation,
but that is unlikely and very rare).
 
I want to chime in that your next course of action should be to determine
if:
 
1) The library is crap and (from the library users POV) randomly crashes.
Unlikely, but would certainly not be the first => Scrap the library and
get another.
 
2a) The parameter validation of the library leaves to be desired and you
pass it invalid parameters. Very well possible and probably hard to debug
=> Either pass it correct parameters or get a better library
 
2a) You pass the library invalid parameters which it cannot validate.
Very well possible and probably hard to debug => Pass it correct
parameters or get a library with a simpler API that can validate it's
parameters.
 
3) Something other. Still quite likely. => Rule it out or solve it.
 
My money is on 2a, possibly 2b.
 
If the offender is gsoap, you're lucky. It's FOSS, so create a debug
build and run it under a debugger. That should answer this question (note
that I did not say this would be easy)
 
Goed luck!
 
M4
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: