homecloud computingcloud data Processingclound of networks
cloud of things

Introduction to C++ for the RaspberryPi

Duration: 5 Days

Course Background

This intensive, fast paced course enables experienced C programmers to begin writing embedded C++ software. It covers all the commonly used features of the C++ language and provides insights into the strengths and limitations of these features in the context of implementing embedded applications. Additionally, the course discusses the implemention of C++ class wrappers around C-based operating system APIs and TCP/IP socket APIs.

Practical work uses the GNU C++ compiler running under Linux. Projects are built using the traditional command-line-and-Makefile approach, and also using an Eclipse based C++ Integrated Development Environment. Applications are run on a PC running one of the standard Linux distributions, and also on an RaspberryPi board running embedded Linux.

Course Benefits

Migrating from C to C++ is challenging task if the true benefits of using C++ are to be realised. Unless careful thought is given to Analysis and Design, the resulting code may be little more than C code with C++ wrappers, with little or no gain in productivity through using an object-oriented language. C++ is essential when developing more advanced RaspberryPi applications such as more complex robotics applications, image processing, and audio.

The real benefits of C++ come from:

  • Expertise in object oriented analysis and design
  • An understanding of object oriented programming patterns and idioms
  • The ability to identify and use existing C++ frameworks, or to design and implement new frameworks from scratch
  • Experience with the C++ STL (Standard Template Library) and the Boost C++ libraries
  • Experience with C++ oriented user interface widget frameworks such as Qt.

On completing this course you will

  • Have a sound understanding of UML Notation to specify C++ applications and an ability to think and work with objects as the underlying abstraction
  • Understand polymorphism and be able to identify situations where the use of polymorphism in an embedded system environment is appropriate
  • Be able to make the best use of constructors and destructors, delete and new operators and understand key idioms and patterns such as reference counting, copy on modify, and the Singleton.
  • Be able to write C++ code that can access embedded system hardware and can be used, for example, in writing device control applications
  • Understand the advantages and disadvantages of wrapping C operating system API calls in C++ classes
  • Understand C++ exception handling and the C++ RTTI (Run Time Type Identification) mechanism, and identify situations where their use is appropriate .
  • Be aware of object oriented patterns and their uses
  • Be aware of framework oriented approaches and their uses
  • Appreciate how to realise dynamic data structures and their associated algorithms in C++
  • Understand the principles underlying templates and the STL, and decide where the use of templates and the STL is appropriate
  • Be aware of C++ techniques for implementing small memory systems
  • Be able to build applications that combine C++, C and assembler and that reuse existing C code and libraries
  • Understand basic principles and strategies for wrapping operating system API functions in C++ clases - e.g. for multi-threading and inter-process communication
  • Understand the design underlying the C++ IOSTREAM classes, where to use them in embedded applications, and where to use low level I/O in the C standard library instead.

Course Prerequisites and Target Audience

This course is designed for experienced C programmers with some experience of either embedded system or Win32 API or POSIX API programming and a basic knowledge of Linux.

Course Outline

  • Brief History of C++
    • Early C++ (translation of C++ code to C code)
    • C++ as an extension of C
    • Non object-oriented C++ enhancements to basic C
    • C++ as an evolving language and the development of the ANSI C++ standard - up to and includint C+11
    • Possible memory and performance costs of using C++ in embedded applications
  • The C in C++
    • Base data types (numeric char, integer and floating point types)
    • Pointers and arrays
    • Function prototypes and function pointers
    • structs , pointers to structs and dynamic data structures
    • typedefs, enums and macros
    • I/O in C
    • Replacing C based I/O (printf, scanf etc) with C++ based I/O
  • Functions in C++
    • Function overloading
    • Name mangling / decorating
    • Mixing C and C++ code modules (use of extern C)
    • Operators and operator overloading in C++
  • Key Object Orientated Concept - Classes and Instances
    • Member variables and member functions (private, public, protected)
    • Constructors and destructors
    • Default constructors and default destructors
    • Initialiser lists
    • Derived classes
    • Arrays of classes
    • UML class diagram notation
  • More advanced aspects of working with classes and instances
    • Copy constructors
    • Deep vs. shallow copying
    • Virtual functions and virtual classes (compile time vs. run time binding)
    • Implementing dynamic data structures using classes (linked lists, binary trees, etc)
    • Friend classes and friend functions
    • Static member variables and static member functions
    • Templates and the Standard Template Library
  • A more detailed look at input and output in C++
    • The C++ iostream classes
    • Overloading the insertion and extraction operators for use with user defined classes
    • Reading and writing files
    • Basics of object and data persistence
  • Dynamic memory management
    • The new and delete operators
    • Overloading the new and delete operators
    • Application specific memory management
  • Exception Handling
    • The concept and structure of exceptions and exception handling
    • Throwing an exception
    • The try block
    • Catching an exception
    • Re-throwing exceptions
    • Catch-all handlers
    • Exception specifications
    • Exception handling implemention mechanisms
    • Appropriateness of exception handling in embedded applications
    • Alternatives to the C++ exception handling mechanism
  • Templates and their uses
    • Data parameterised collections of classes and functions
    • How C++ compilers handle templates
    • The C++ Standard Template Library - a brief overview
    • The Boost C++ libraries - a brief overview
  • Namespaces - an extra level of scoping
    • Usefulness of namespaces in large projects and when re-using code
  • Mixed C and C++ applications and extern C
  • C++ programming and the Linux Posix API
    • Idioms and patterns for wrapping C operating system APIs in C++ (Inter Process Communication and Task Management)
    • C+11 multithreading
    • Interprocess communication and synchronisation classes
    • Implementing a simple timer-driven user space scheduler in C++
  • Example C++ Frameworks
    • Multithreaded application development
    • Implementing Graphical User Interfaces with Qt and QtWayland
    • Image processing and Image Capture
      • The RaspberryPi camera and the RaspberryPi NoIR IR camera
      • Implementing image capture applications
      • OpenCV Image Processing Framework
      • Image processing and basic face recognition example
      • C++ Sockets programming
      • An overview of the ROS Robotics operating system