Skip to Content
Embedded Programming with Modern C++ Cookbook
book

Embedded Programming with Modern C++ Cookbook

by Igor Viarheichyk
April 2020
Intermediate to advanced
412 pages
9h 58m
English
Packt Publishing
Content preview from Embedded Programming with Modern C++ Cookbook

How to do it...

We will create an application that reads the current time from the Real-Time Clock (RTC) connected to the Raspberry Pi board:

  1. In your ~/test working directory, create a subdirectory called rtc.
  2. Use your favorite text editor to create a rtc.cpp file in the rtc subdirectory.
  3. Let's put the required include functions into the rtc.cpp file:
#include <iostream>#include <system_error>#include <time.h>#include <unistd.h>#include <fcntl.h>#include <sys/ioctl.h>#include <linux/rtc.h>
  1. Now, we define a class called Rtc that encapsulates the communication to the real-clock device:
class Rtc {  int fd;  public:    Rtc() {      fd = open("/dev/rtc", O_RDWR);      if (fd < 0) {        throw std::system_error(errno,            std::system_category(), "Failed to open RTC ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ System Programming Cookbook

C++ System Programming Cookbook

Onorato Vaticone
C++ Cookbook

C++ Cookbook

D. Ryan Stephens, Christopher Diggins, Jonathan Turkanis, Jeff Cogswell

Publisher Resources

ISBN: 9781838821043Supplemental Content