How to do it...

We are going to create an application that emulates data exchange with a peripheral device. Follow these steps to do so:

  1. In your working directory, that is, ~/testcreate a subdirectory called fixed_types.
  1. Use your favorite text editor to create a file called fixed_types.cpp in the fixed_types subdirectory. Copy the following code snippet into the fixed_types.cpp file:
#include <iostream>

void SendDataToDevice(void* buffer, uint32_t size) {
// This is a stub function to send data pointer by
// buffer.
std::cout << "Sending data chunk of size " << size << std::endl;
}

int main() {
char buffer[] = "Hello, world!";
uint32_t size = sizeof(buffer);
SendDataToDevice(&size, sizeof(size));
SendDataToDevice(buffer, size);
return 0;
}
  1. Create a file called CMakeLists.txt in the loop subdirectory with the following content:
cmake_minimum_required(VERSION 3.5.1)
project(fixed_types)
add_executable(fixed_types fixed_types.cpp)

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

SET(CMAKE_CXX_FLAGS "--std=c++11")
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabi-g++)

  1. Build the application and copy the resulting executable binary to the target system. Use the recipes from Chapter 2, Setting Up the Environment, to do so.
  2. Switch to the target system's Terminal. Log in using your user credentials, if needed.
  3. Run the binary to see how it works.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.156.35