We are going to create an application that emulates data exchange with a peripheral device. Follow these steps to do so:
- In your working directory, that is, ~/test, create a subdirectory called fixed_types.
- 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;
}
- 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++)
- 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.
- Switch to the target system's Terminal. Log in using your user credentials, if needed.
- Run the binary to see how it works.