Skip to content
Open
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
79 changes: 79 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: TopLevelDefinitions
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 79
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IndentCaseLabels: false
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
1,157 changes: 632 additions & 525 deletions main/db_ble.c

Large diffs are not rendered by default.

81 changes: 48 additions & 33 deletions main/db_ble.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/***************************************************************************************************************************
/******************************************************************************
* @file db_ble.h
* @brief DroneBridge ESP32 BLE Header file
*
* This file is part of DroneBridge and CosmicBridge
*
* @authors Witty-Wizard <[email protected]> modified for DroneBridge for ESP32 by Wolfgang Christl
* @authors Witty-Wizard <[email protected]> modified for
*DroneBridge for ESP32 by Wolfgang Christl
* @license Apache License, Version 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,69 +19,83 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**************************************************************************************************************************/
*******************************************************************************/

#ifndef DB_BLE_H
#define DB_BLE_H

/***************************************************************************************************************************
/******************************************************************************
* Standard & System Headers
**************************************************************************************************************************/
*******************************************************************************/
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#include <freertos/queue.h>
#include <stdint.h>

/***************************************************************************************************************************
/******************************************************************************
* MACROS
**************************************************************************************************************************/
#define BLE_SVC_SERIAL_UUID16 0xDB32 ///< 16-bit UUID for the Serial service.
#define BLE_SVC_SERIAL_CHR_WRITE_UUID16 0xDB33 ///< 16-bit UUID for the Serial Receive service characteristic.
#define BLE_SVC_SERIAL_CHR_NOTIFY_UUID16 0xDB34 ///< 16-bit UUID for the Serial Send service characteristic.
// ToDo: Implement Control/Management Plane Interface via BLE - Below char. are not used
#define BLE_SVC_SPP_CMD_WRITE_UUID16 0xABF3 ///< 16-bit UUID for the - Receive command characteristic.
#define BLE_SVC_SPP_CMD_NOTIFY_UUID16 0xABF4 ///< 16-bit UUID for the - Send command characteristic.
#define BLE_GAP_APPEARANCE_GENERIC_TAG 0x0180 ///< Generic tag appearance value for BLE GAP.
#define BLE_GAP_LE_ROLE_PERIPHERAL 0x00 ///< LE role value indicating a peripheral device.
*******************************************************************************/
#define BLE_SVC_SERIAL_UUID16 0xDB32 ///< 16-bit UUID for the Serial service.
#define BLE_SVC_SERIAL_CHR_WRITE_UUID16 \
0xDB33 ///< 16-bit UUID for the Serial Receive service characteristic.
#define BLE_SVC_SERIAL_CHR_NOTIFY_UUID16 \
0xDB34 ///< 16-bit UUID for the Serial Send service characteristic.
// ToDo: Implement Control/Management Plane Interface via BLE - Below char. are
// not used
#define BLE_SVC_SPP_CMD_WRITE_UUID16 \
0xABF3 ///< 16-bit UUID for the - Receive command characteristic.
#define BLE_SVC_SPP_CMD_NOTIFY_UUID16 \
0xABF4 ///< 16-bit UUID for the - Send command characteristic.
#define BLE_GAP_APPEARANCE_GENERIC_TAG \
0x0180 ///< Generic tag appearance value for BLE GAP.
#define BLE_GAP_LE_ROLE_PERIPHERAL \
0x00 ///< LE role value indicating a peripheral device.

/***************************************************************************************************************************
/******************************************************************************
* @brief Structure to hold BLE data.
**************************************************************************************************************************/
typedef struct {
*******************************************************************************/
typedef struct
{
uint16_t data_len; /**< Length of the data. */
uint8_t *data; /**< Pointer to the data. */
uint8_t *data; /**< Pointer to the data. */
} __attribute__((__packed__)) db_ble_queue_event_t;

/***************************************************************************************************************************
/******************************************************************************
* Queue Handles
**************************************************************************************************************************/
*******************************************************************************/

extern QueueHandle_t db_uart_write_queue_ble; /** Queue for data to be written to UART, filled by wireless
communication interface task */
extern QueueHandle_t
db_uart_read_queue_ble; /** Queue for data to be written to wireless communication interface - used by BLE, filled by UART */
db_uart_write_queue_ble; /** Queue for data to be written to UART, filled by
wireless communication interface task */
extern QueueHandle_t
db_uart_read_queue_ble; /** Queue for data to be written to wireless
communication interface - used by BLE, filled by
UART */

/***************************************************************************************************************************
/******************************************************************************
* Public Function Declaration
**************************************************************************************************************************/
*******************************************************************************/

/***************************************************************************************************************************
/******************************************************************************
* @brief Drone Bridge BLE initialisation function
**************************************************************************************************************************/
*******************************************************************************/
void db_ble_init();

/***************************************************************************************************************************
/******************************************************************************
* @brief Initializes the global UART read and write queues.
*
* This function creates two FreeRTOS queues using xQueueCreate().
* - `db_uart_write_queue_ble`: Used to store data that needs to be written to UART.
* - `db_uart_read_queue_ble`: Used to store data read from UART for further processing.
* - `db_uart_write_queue_ble`: Used to store data that needs to be written to
*UART.
* - `db_uart_read_queue_ble`: Used to store data read from UART for further
*processing.
*
* The queue size is set to 5, with each element being the size of `BleData_t`.
* If queue creation fails, appropriate error messages are logged using `ESP_LOGI()`.
* If queue creation fails, appropriate error messages are logged using
*`ESP_LOGI()`.
*
* @return void
**************************************************************************************************************************/
*******************************************************************************/
void db_ble_queue_init();

/**
Expand Down
8 changes: 3 additions & 5 deletions main/db_comm_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef DB_ESP32_DB_COMM_PROTOCOL_H
#define DB_ESP32_DB_COMM_PROTOCOL_H


#define DB_COMM_ORIGIN_GND "groundstation"
#define DB_COMM_ORIGIN_UAV "drone"
#define DB_COMM_TYPE_SETTINGS_SUCCESS "settingssuccess"
Expand All @@ -45,18 +44,17 @@
#define DB_COMM_DST_GCS 4
#define DB_COMM_DST_UAV 5


#define DB_COMM_KEY_TYPE "type"
#define DB_COMM_KEY_ORIGIN "origin"
#define DB_COMM_KEY_ID "id"
#define DB_COMM_KEY_DEST "destination"
#define DB_COMM_KEY_HARDWID "HID" // Hardware ID
#define DB_COMM_KEY_FIRMWID "FID" // Firmware version
#define DB_COMM_KEY_HARDWID "HID" // Hardware ID
#define DB_COMM_KEY_FIRMWID "FID" // Firmware version
#define DB_COMM_KEY_MSG "message"

#define DB_COMM_CHANGE_DB "db"
#define DB_COMM_CHANGE_DBESP32 "dbesp32"

#define DB_ESP32_FID 101

#endif //DB_ESP32_DB_COMM_PROTOCOL_H
#endif // DB_ESP32_DB_COMM_PROTOCOL_H
28 changes: 16 additions & 12 deletions main/db_crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,30 @@
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
uint8_t crc8_dvb_s2(uint8_t crc, unsigned char a)
uint8_t
crc8_dvb_s2(uint8_t crc, unsigned char a)
{
crc ^= a;
for (int ii = 0; ii < 8; ++ii) {
if (crc & 0x80) {
crc = (crc << 1) ^ 0xD5;
} else {
crc = crc << 1;
}
crc ^= a;
for(int ii = 0; ii < 8; ++ii) {
if(crc & 0x80) {
crc = (crc << 1) ^ 0xD5;
}
return crc;
else {
crc = crc << 1;
}
}
return crc;
}

/**
* Does the same as crc8_dvb_s2 just way more efficient (CPU) but with a little bit more RAM usage
* Does the same as crc8_dvb_s2 just way more efficient (CPU) but with a little
* bit more RAM usage
* @param crc The current crc value
* @param a The next byte
* @return The new crc value
*/
uint8_t crc8_dvb_s2_table(uint8_t crc, unsigned char a)
uint8_t
crc8_dvb_s2_table(uint8_t crc, unsigned char a)
{
return (uint8_t) (crc_dvb_s2_table[(crc ^ a)] & 0xff);
return (uint8_t)(crc_dvb_s2_table[(crc ^ a)] & 0xff);
}
53 changes: 28 additions & 25 deletions main/db_crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ extern "C" {
*/
#define CRC_ALGO_TABLE_DRIVEN 1


/**
* The type of the CRC values.
*
Expand All @@ -92,35 +91,39 @@ typedef uint_fast8_t crc_t;
* - ReflectOut = False
*/
static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, 0x3b, 0x91, 0x44, 0x6b, 0xbe, 0x14, 0xc1, 0x95,
0x40, 0xea, 0x3f, 0x42, 0x97, 0x3d, 0xe8, 0xbc, 0x69, 0xc3, 0x16, 0xef, 0x3a,
0x90, 0x45, 0x11, 0xc4, 0x6e, 0xbb, 0xc6, 0x13, 0xb9, 0x6c, 0x38, 0xed, 0x47,
0x92, 0xbd, 0x68, 0xc2, 0x17, 0x43, 0x96, 0x3c, 0xe9, 0x94, 0x41, 0xeb, 0x3e,
0x6a, 0xbf, 0x15, 0xc0, 0x4b, 0x9e, 0x34, 0xe1, 0xb5, 0x60, 0xca, 0x1f, 0x62,
0xb7, 0x1d, 0xc8, 0x9c, 0x49, 0xe3, 0x36, 0x19, 0xcc, 0x66, 0xb3, 0xe7, 0x32,
0x98, 0x4d, 0x30, 0xe5, 0x4f, 0x9a, 0xce, 0x1b, 0xb1, 0x64, 0x72, 0xa7, 0x0d,
0xd8, 0x8c, 0x59, 0xf3, 0x26, 0x5b, 0x8e, 0x24, 0xf1, 0xa5, 0x70, 0xda, 0x0f,
0x20, 0xf5, 0x5f, 0x8a, 0xde, 0x0b, 0xa1, 0x74, 0x09, 0xdc, 0x76, 0xa3, 0xf7,
0x22, 0x88, 0x5d, 0xd6, 0x03, 0xa9, 0x7c, 0x28, 0xfd, 0x57, 0x82, 0xff, 0x2a,
0x80, 0x55, 0x01, 0xd4, 0x7e, 0xab, 0x84, 0x51, 0xfb, 0x2e, 0x7a, 0xaf, 0x05,
0xd0, 0xad, 0x78, 0xd2, 0x07, 0x53, 0x86, 0x2c, 0xf9
};

/**
* Calculate the initial crc value.
*
* \return The initial crc value.
*/
static inline crc_t crc_init(void)
static inline crc_t
crc_init(void)
{
return 0x00;
return 0x00;
}


/**
* Update the crc value with new data.
*
Expand All @@ -131,23 +134,23 @@ static inline crc_t crc_init(void)
*/
crc_t crc_update(crc_t crc, const void *data, size_t data_len);


/**
* Calculate the final crc value.
*
* \param[in] crc The current crc value.
* \return The final crc value.
*/
static inline crc_t crc_finalize(crc_t crc)
static inline crc_t
crc_finalize(crc_t crc)
{
return crc;
return crc;
}

uint8_t crc8_dvb_s2(uint8_t crc, unsigned char a);
uint8_t crc8_dvb_s2_table(uint8_t crc, unsigned char a);

#ifdef __cplusplus
} /* closing brace for extern "C" */
} /* closing brace for extern "C" */
#endif

#endif /* CRC_H */
#endif /* CRC_H */
Loading