Skip to content

Switch to MAVLink for Ground Station communication #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.12)

project(RocketCode2020 C CXX)
set(CMAKE_CXX_STANDARD 17)

cmake_host_system_information(RESULT _memfree QUERY AVAILABLE_PHYSICAL_MEMORY)
set_property(GLOBAL PROPERTY JOB_POOLS four_jobs=4)
Expand Down Expand Up @@ -128,6 +129,8 @@ target_link_libraries(MainLoopLib cobs-c)

target_link_libraries(MainLoopLib ${CMAKE_THREAD_LIBS_INIT})

target_link_libraries(MainLoopLib mavlink)

target_link_libraries(MainLoopLib i2c)
add_executable(MainLoop ./src/init/MainLoop.cpp)
target_link_libraries(MainLoop MainLoopLib)
Expand Down
4 changes: 4 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ target_include_directories(cobs-c PUBLIC ./cobs-c)
# ---------------
add_subdirectory(./protobuf-definitions)

# ---------------
# MAVLink Definitions
# ---------------
add_subdirectory(./mavlink)
8 changes: 8 additions & 0 deletions libraries/mavlink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_library(mavlink INTERFACE)

target_include_directories(mavlink INTERFACE generated/)
target_include_directories(mavlink INTERFACE generated/common)
target_include_directories(mavlink INTERFACE generated/minimal)
target_include_directories(mavlink INTERFACE generated/uorocketry)

target_compile_options(mavlink INTERFACE -Wno-address-of-packed-member -Wno-cast-align)
4 changes: 4 additions & 0 deletions libraries/mavlink/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file needs to be ran anytime the MAVLink message definitions are changed.
# First, install the needed utility: pip install pymavlink

mavgen.py --lang=C++11 --wire-protocol=2.0 --output=./generated ../protobuf-definitions/mavlink/uorocketry.xml
95 changes: 95 additions & 0 deletions libraries/mavlink/generated/checksum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#pragma once

#if defined(MAVLINK_USE_CXX_NAMESPACE)
namespace mavlink {
#elif defined(__cplusplus)
extern "C" {
#endif

// Visual Studio versions before 2010 don't have stdint.h, so we just error out.
#if (defined _MSC_VER) && (_MSC_VER < 1600)
#error "The C-MAVLink implementation requires Visual Studio 2010 or greater"
#endif

#include <stdint.h>

/**
*
* CALCULATE THE CHECKSUM
*
*/

#define X25_INIT_CRC 0xffff
#define X25_VALIDATE_CRC 0xf0b8

#ifndef HAVE_CRC_ACCUMULATE
/**
* @brief Accumulate the CRC16_MCRF4XX checksum by adding one char at a time.
*
* The checksum function adds the hash of one char at a time to the
* 16 bit checksum (uint16_t).
*
* @param data new char to hash
* @param crcAccum the already accumulated checksum
**/
static inline void crc_accumulate(uint8_t data, uint16_t *crcAccum)
{
/*Accumulate one byte of data into the CRC*/
uint8_t tmp;

tmp = data ^ (uint8_t)(*crcAccum &0xff);
tmp ^= (tmp<<4);
*crcAccum = (*crcAccum>>8) ^ (tmp<<8) ^ (tmp <<3) ^ (tmp>>4);
}
#endif


/**
* @brief Initialize the buffer for the MCRF4XX CRC16
*
* @param crcAccum the 16 bit MCRF4XX CRC16
*/
static inline void crc_init(uint16_t* crcAccum)
{
*crcAccum = X25_INIT_CRC;
}


/**
* @brief Calculates the CRC16_MCRF4XX checksum on a byte buffer
*
* @param pBuffer buffer containing the byte array to hash
* @param length length of the byte array
* @return the checksum over the buffer bytes
**/
static inline uint16_t crc_calculate(const uint8_t* pBuffer, uint16_t length)
{
uint16_t crcTmp;
crc_init(&crcTmp);
while (length--) {
crc_accumulate(*pBuffer++, &crcTmp);
}
return crcTmp;
}


/**
* @brief Accumulate the MCRF4XX CRC16 by adding an array of bytes
*
* The checksum function adds the hash of one char at a time to the
* 16 bit checksum (uint16_t).
*
* @param data new bytes to hash
* @param crcAccum the already accumulated checksum
**/
static inline void crc_accumulate_buffer(uint16_t *crcAccum, const char *pBuffer, uint16_t length)
{
const uint8_t *p = (const uint8_t *)pBuffer;
while (length--) {
crc_accumulate(*p++, crcAccum);
}
}

#if defined(MAVLINK_USE_CXX_NAMESPACE) || defined(__cplusplus)
}
#endif
2,747 changes: 2,747 additions & 0 deletions libraries/mavlink/generated/common/common.h

Large diffs are not rendered by default.

2,591 changes: 2,591 additions & 0 deletions libraries/mavlink/generated/common/common.hpp

Large diffs are not rendered by default.

Loading