Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
*.log
examples/vs2015/bin/
examples/vs2015/build/
.vs/
.vs/
*.gch
build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "examples/cmake/CppSockets"]
path = examples/cmake/CppSockets
url = https://github.com/simondlevy/CppSockets.git
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++-11 - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
// "preLaunchTask": "C/C++: g++-11 build active file"
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"functional": "cpp",
"iostream": "cpp"
}
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++-11 build active file",
"command": "/usr/local/bin/g++-11",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.10)
project(PSN)

add_subdirectory(examples/cmake)

add_library(psnlib INTERFACE)
target_include_directories(psnlib INTERFACE ./include)
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,41 @@ This package contains the documentation and a C++ implementation of the protocol

The implementation only uses ".hpp" files. If you want to use this implementation in your project, you need to include the file "psn_lib.hpp" in one of your ".cpp" file.

The implementation is cross-platform so it should compile under Windows, Linux and Mac OS X. In revenge, the example projects will only work under a Windows operating system as they use a Windows specific implementation of a simple udp_socket class. If you want to run these demo on another platform, you will need to write your own udp_socket class.
The implementation is cross-platform so it should compile under Windows, Linux and Mac OS X.

For any question about the protocol, please write at **info@posistage.net**

## CMake compilation
You can compile the library and the examples using CMake (for Windows, MacOS and Linux)
- `git submodule update --init --recursive` (fetches the CppSockets library from https://github.com/simondlevy/CppSockets - only required for the examples to work; otherwise bring your own socket library)
- `mkdir build`
- `cd build`
- `cmake ..`
- `cmake --build .`

Now you should be example to run examples as follows:
- `./examples/cmake/send_example` : encode and send PSN messages using UDP ("PSN Server")
- `./examples/cmake/receive_example` : receive PSN messages via UDP and decode ("PSN Client")

## Installing this library using CMake
To install this library in your own CMake-based project, you could use a `CMakeList.txt` similar to the following, assuming you copied or cloned psn-cpp to a directory named `./libs/psn-cpp` relative to the project root:
```
cmake_minimum_required(VERSION 3.19)

project(my_project)

# --- Optional: add CppSockets library if you need it
add_library(cppsockets INTERFACE)
set_property(TARGET cppsockets PROPERTY CXX_STANDARD 11)
target_include_directories(cppsockets INTERFACE ./libs/CppSockets)
# ----

add_executable(my_executable src/my_executable.cpp)
set_property(TARGET my_executable PROPERTY CXX_STANDARD 11)

add_subdirectory(./libs/psn-cpp)

target_include_directories(my_executable PUBLIC ./libs/tether/base_agent/cpp/src)

target_link_libraries(my_executable PUBLIC psnlib cppsockets)
```
1 change: 1 addition & 0 deletions examples/cmake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
14 changes: 14 additions & 0 deletions examples/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.19)
project (psn_cpp_examples)

add_executable(send_example psn_server.cpp)
add_executable(receive_example psn_client.cpp)

set_property(TARGET send_example PROPERTY CXX_STANDARD 11)
set_property(TARGET receive_example PROPERTY CXX_STANDARD 11)

target_include_directories(send_example PUBLIC ../../include)
target_include_directories(send_example PUBLIC ./CppSockets)

target_include_directories(receive_example PUBLIC ../../include)
target_include_directories(receive_example PUBLIC ./CppSockets)
1 change: 1 addition & 0 deletions examples/cmake/CppSockets
Submodule CppSockets added at 19d7c9
161 changes: 161 additions & 0 deletions examples/cmake/psn_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/**
* The MIT License (MIT)
*
* Copyright (c) 2014 VYV Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#include <psn_lib.hpp>
#include "UdpServerSocket.hpp"

#include <iostream>

#include <string.h>
#include <unistd.h>
#include <chrono>
#include <thread>

const short PORT = 8888;
static const short BUFLEN = 1024;
static const uint32_t TIMEOUT_MSEC = 1000;

int main( void )
{
char buf[BUFLEN];
// wsa_session session ;


//====================================================
// Init client

UdpServerSocket server(PORT, TIMEOUT_MSEC);
// udp_socket socket_client ;
// socket_client.bind( ::psn::DEFAULT_UDP_PORT ) ;
// socket_client.join_multicast_group( ::psn::DEFAULT_UDP_MULTICAST_ADDR ) ;

::psn::psn_decoder psn_decoder ;
uint8_t last_frame_id = 0 ;
int skip_cout = 0 ;

//====================================================
// Main loop
while ( 1 )
{
// Sleep( 1 ) ;
// sleep(1);
std::this_thread::sleep_for(std::chrono::milliseconds(1) );



printf("Waiting for data...");
fflush(stdout);

memset(buf, 0, BUFLEN);

*buf = 0;

server.receiveData(buf, BUFLEN);

if (*buf) {
printf("Data: %s\n", buf);
// server.sendData(buf, strlen(buf));

// std::cout << "As string: " << msg << " with size " << msg.size() << std::endl;

psn_decoder.decode( buf , BUFLEN ) ;

// if ( psn_decoder.get_data().header.frame_id != last_frame_id )
// {
last_frame_id = psn_decoder.get_data().header.frame_id ;

const ::psn::tracker_map & recv_trackers = psn_decoder.get_data().trackers ;

// if ( skip_cout++ % 20 == 0 )
// {
::std::cout << "--------------------PSN CLIENT-----------------" << ::std::endl ;
::std::cout << "System Name: " << psn_decoder.get_info().system_name << ::std::endl ;
::std::cout << "Frame Id: " << (int)last_frame_id << ::std::endl ;
::std::cout << "Frame Timestamp: " << psn_decoder.get_data().header.timestamp_usec << ::std::endl ;
::std::cout << "Tracker count: " << recv_trackers.size() << ::std::endl ;

for ( auto it = recv_trackers.begin() ; it != recv_trackers.end() ; ++it )
{
const ::psn::tracker & tracker = it->second ;

::std::cout << "Tracker - id: " << tracker.get_id() << " | name: " << tracker.get_name() << ::std::endl ;

if ( tracker.is_pos_set() )
::std::cout << " pos: " << tracker.get_pos().x << ", " <<
tracker.get_pos().y << ", " <<
tracker.get_pos().z << std::endl ;

if ( tracker.is_speed_set() )
::std::cout << " speed: " << tracker.get_speed().x << ", " <<
tracker.get_speed().y << ", " <<
tracker.get_speed().z << std::endl ;

if ( tracker.is_ori_set() )
::std::cout << " ori: " << tracker.get_ori().x << ", " <<
tracker.get_ori().y << ", " <<
tracker.get_ori().z << std::endl ;

if ( tracker.is_status_set() )
::std::cout << " status: " << tracker.get_status() << std::endl ;

if ( tracker.is_accel_set() )
::std::cout << " accel: " << tracker.get_accel().x << ", " <<
tracker.get_accel().y << ", " <<
tracker.get_accel().z << std::endl ;

if ( tracker.is_target_pos_set() )
::std::cout << " target pos: " << tracker.get_target_pos().x << ", " <<
tracker.get_target_pos().y << ", " <<
tracker.get_target_pos().z << std::endl ;

if ( tracker.is_timestamp_set() )
::std::cout << " timestamp: " << tracker.get_timestamp() << std::endl ;
}

::std::cout << "-----------------------------------------------" << ::std::endl ;
//} // skip

}

else {
printf("\n");
// sleep(1);
std::this_thread::sleep_for(std::chrono::milliseconds(1) );
}



// if ( socket_client.receive_message( msg , ::psn::MAX_UDP_PACKET_SIZE ) )
// {


// }
}

return 0;
}


Loading