This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void *memcpy(void *dst, void *src, unsigned n) { | |
| if (!dst || !src) { | |
| return nullptr; | |
| } | |
| auto dst_c = (char *) dst; | |
| auto src_c = (char *) src; | |
| if (dst_c < src || dst_c > (src_c + n)) { | |
| while (n--) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <ulog/ulog.h> | |
| namespace ulog { | |
| namespace token { | |
| // void * | |
| inline void print(const char *name, const void *value) { | |
| logger_raw(false, "%s => %p", name ? name : "unnamed", value); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <stdio.h> | |
| #include <string.h> | |
| // Precompiler define to get only filename; | |
| #if !defined(__FILENAME__) | |
| #define __FILENAME__ \ | |
| (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 \ | |
| : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Reference from kfifo of linux | |
| class FifoPowerOfTwo { | |
| #define _is_power_of_2(x) ((x) != 0 && (((x) & ((x)-1)) == 0)) | |
| public: | |
| FifoPowerOfTwo(void *buffer, size_t buf_size, size_t element_size = 1) | |
| : data_((unsigned char *)buffer), | |
| element_size_(element_size != 0 ? element_size : 1), | |
| is_allocated_memory_(false) { | |
| size_t num_elements = buf_size / element_size_; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| target_language=$(trans -id ${!#} | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" | awk '$1=="Code" && $2!="zh-CN" {printf ":zh-CN"}') | |
| trans $target_language "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <ctype.h> | |
| #include <inttypes.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| uintptr_t HexDumpData(const uint8_t *data, size_t length, size_t width = 16, | |
| uintptr_t base_address = 0, bool tail_addr_out = true) { | |
| const uint8_t *data_cur = data; | |
| if (!data || width == 0) return 0; | |
| while (length) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char *Hex2Str(uint8_t *addr, size_t len, char *out_str, size_t out_str_len, | |
| bool from_end) { | |
| if (addr == NULL || len == 0 || out_str == NULL || out_str_len < 3) | |
| return out_str; | |
| len = len < (out_str_len-1) / 2 ? len : (out_str_len-1) / 2; | |
| char hex[] = "0123456789ABCDEF"; | |
| char *str = out_str; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| #include <stdlib.h> | |
| enum BatteryLevel { | |
| BATTERY_LEVEL_VERY_LOW = 0, | |
| BATTERY_LEVEL_LOW = 1, | |
| BATTERY_LEVEL_MEDIUM = 2, | |
| BATTERY_LEVEL_HIGH = 3, | |
| BATTERY_LEVEL_VERY_HIGH = 4, | |
| BATTERY_LEVEL_END = 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Modify some bits within a number | |
| * | |
| * @note The lowest index is 0, increasing sequentially | |
| * | |
| * @param origin Original data | |
| * @param offset Offset that needs to be modified | |
| * @param len Bit length | |
| * @param value The value to which the specified bit needs to be replaced | |
| * @return Modified value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cmake_minimum_required(VERSION 2.8.4) | |
| project(Ardupilot) | |
| # Function: EXCLUDE_FILES_FROM_DIR_IN_LIST | |
| # Description: Exclude all files from a list under a specific directory. | |
| # Param _InFileList: Input and returned List | |
| # Param _excludeDirName: Name of the directory, which shall be ignored. | |
| # Param _verbose: Print the names of the files handled | |
| FUNCTION (EXCLUDE_FILES_FROM_DIR_IN_LIST _InFileList _excludeDirName _verbose) |