-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update UWBAdapter_ApplicationSTD_serialPacket 10/29
- Loading branch information
Showing
26 changed files
with
1,173 additions
and
632 deletions.
There are no files selected for viewing
54 changes: 42 additions & 12 deletions
54
Software/UWBAdapter_ApplicationSTD_serialPacket/Program/algorithms/mathUnit.h
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,52 @@ | ||
/* #include "algorithms\mathUnit.h" */ | ||
/** | ||
* __ ____ | ||
* / /__ _ __ / __/ __ | ||
* / //_/(_)/ /_ / / ___ ____ ___ __ __ / /_ | ||
* / ,< / // __/_\ \ / _ \ / __// _ \/ // // __/ | ||
* /_/|_|/_/ \__//___// .__//_/ \___/\_,_/ \__/ | ||
* /_/ github.com/KitSprout | ||
* | ||
* @file mathUnit.h | ||
* @author KitSprout | ||
* @date 6-Oct-2016 | ||
* @brief | ||
* | ||
*/ | ||
|
||
/* Define to prevent recursive inclusion ---------------------------------------------------*/ | ||
#ifndef __MATHUNIT_H | ||
#define __MATHUNIT_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* Includes --------------------------------------------------------------------------------*/ | ||
#include "stm32f4xx.h" | ||
#include "arm_math.h" | ||
/*====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
#define invSqrtf( iSq ) (1.0f / sqrtf((float)(iSq))) | ||
#define squa( Sq ) (((float)Sq) * ((float)(Sq))) | ||
|
||
/* Exported types --------------------------------------------------------------------------*/ | ||
|
||
/** | ||
* @brief euler angle structure definition | ||
*/ | ||
typedef struct { | ||
float32_t pitch; | ||
float32_t roll; | ||
float32_t yaw; | ||
} __attribute__((aligned(4))) eulerAngle_t; | ||
|
||
/* Exported constants ----------------------------------------------------------------------*/ | ||
/* Exported macro --------------------------------------------------------------------------*/ | ||
#define invSqrtf( iSq ) (1.0f / sqrtf((float32_t)(iSq))) | ||
#define squa( Sq ) (((float32_t)Sq) * ((float32_t)(Sq))) | ||
#define toRad( _mathD ) ((_mathD) * 0.0174532925f) | ||
#define toDeg( _mathR ) ((_mathR) * 57.2957795f) | ||
|
||
typedef struct { | ||
float pitch; | ||
float roll; | ||
float yaw; | ||
} eulerAngle_t; | ||
/*====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
/* Exported functions ----------------------------------------------------------------------*/ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
98 changes: 60 additions & 38 deletions
98
Software/UWBAdapter_ApplicationSTD_serialPacket/Program/algorithms/string.c
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,107 @@ | ||
/*====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
/** | ||
* __ ____ | ||
* / /__ _ __ / __/ __ | ||
* / //_/(_)/ /_ / / ___ ____ ___ __ __ / /_ | ||
* / ,< / // __/_\ \ / _ \ / __// _ \/ // // __/ | ||
* /_/|_|/_/ \__//___// .__//_/ \___/\_,_/ \__/ | ||
* /_/ github.com/KitSprout | ||
* | ||
* @file string.c | ||
* @author KitSprout | ||
* @date 6-Oct-2016 | ||
* @brief | ||
* | ||
*/ | ||
|
||
/* Includes --------------------------------------------------------------------------------*/ | ||
#include "drivers\stm32f4_system.h" | ||
#include "algorithms\string.h" | ||
/*====================================================================================================*/ | ||
/*====================================================================================================* | ||
**函數 : num2Char | ||
**功能 : Number to string | ||
**輸入 : type, lens, *pChar, number | ||
**輸出 : None | ||
**使用 : num2Str(type, lens, pChar, number); | ||
**====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
void num2Str( StringType type, uint8_t lens, char *pStr, int32_t number ) | ||
|
||
/** @addtogroup STM32_Algorithm | ||
* @{ | ||
*/ | ||
|
||
/* Private typedef -------------------------------------------------------------------------*/ | ||
/* Private define --------------------------------------------------------------------------*/ | ||
/* Private macro ---------------------------------------------------------------------------*/ | ||
/* Private variables -----------------------------------------------------------------------*/ | ||
/* Private function prototypes -------------------------------------------------------------*/ | ||
/* Private functions -----------------------------------------------------------------------*/ | ||
|
||
/** | ||
* @brief num2Str | ||
* @param type: | ||
* @param lens: | ||
* @param pStr: | ||
* @param number: | ||
* @retval None | ||
*/ | ||
void num2Str( StringType_t type, uint8_t lens, char *pStr, int32_t number ) | ||
{ | ||
uint8_t i = 0; | ||
uint32_t tmpStr[48] = {0}; | ||
uint32_t tmpNum = 1; | ||
|
||
switch(type) { | ||
switch (type) { | ||
|
||
case Type_B: | ||
case Type_O: | ||
case Type_D: | ||
case Type_H: | ||
for(i = 0; i < lens; i++) { | ||
case S_BIN: | ||
case S_OCT: | ||
case S_DEC: | ||
case S_HEX: | ||
for (i = 0; i < lens; i++) { | ||
tmpStr[i] = ((uint32_t)number) / tmpNum; | ||
tmpNum = tmpNum * type; | ||
} | ||
for(i = 0; i < lens; i++) { | ||
for (i = 0; i < lens; i++) { | ||
pStr[lens-i-1] = tmpStr[i] - tmpStr[i+1] * type; | ||
if(pStr[lens-i-1] > 9) | ||
if (pStr[lens-i-1] > 9) | ||
pStr[lens-i-1] += 55; // 65-10 | ||
else | ||
pStr[lens-i-1] += 48; | ||
} | ||
pStr[lens] = '\0'; | ||
break; | ||
|
||
case Type_I: | ||
if(number < 0) { | ||
case S_INT: | ||
if (number < 0) { | ||
pStr[0] = '-'; | ||
number = (~number) + 1; | ||
} | ||
else { | ||
pStr[0] = '+'; | ||
} | ||
for(i = 1; i < lens + 1; i++) { | ||
for (i = 1; i < lens + 1; i++) { | ||
tmpStr[i-1] = ((uint32_t)number) / tmpNum; | ||
tmpNum = tmpNum * 10; | ||
} | ||
for(i = 1; i < lens + 1; i++) { | ||
for (i = 1; i < lens + 1; i++) { | ||
pStr[lens-i+1] = tmpStr[i-1] - tmpStr[i] * 10; | ||
pStr[lens-i+1] += 48; | ||
} | ||
pStr[lens+1] = '\0'; | ||
break; | ||
|
||
case Type_F: | ||
case S_FLOAT: | ||
break; | ||
} | ||
} | ||
/*====================================================================================================*/ | ||
/*====================================================================================================* | ||
**函數 : lenOfStr | ||
**功能 : String Lens | ||
**輸入 : *pStr | ||
**輸出 : strLens | ||
**使用 : strLens = lenOfStr("Hello World!!"); | ||
**====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
|
||
/** | ||
* @brief lenOfStr | ||
* @param pStr: | ||
* @retval string lengths | ||
*/ | ||
uint16_t lenOfStr( char *pStr ) | ||
{ | ||
uint16_t strLens = 0; | ||
|
||
if(pStr == NULL) | ||
if (pStr == NULL) | ||
return strLens; | ||
|
||
while(*(pStr++)) | ||
while (*(pStr++)) | ||
strLens++; | ||
|
||
return strLens; | ||
} | ||
/*====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
|
||
/*************************************** END OF FILE ****************************************/ |
60 changes: 43 additions & 17 deletions
60
Software/UWBAdapter_ApplicationSTD_serialPacket/Program/algorithms/string.h
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,49 @@ | ||
/* #include "algorithm_string.h" */ | ||
/** | ||
* __ ____ | ||
* / /__ _ __ / __/ __ | ||
* / //_/(_)/ /_ / / ___ ____ ___ __ __ / /_ | ||
* / ,< / // __/_\ \ / _ \ / __// _ \/ // // __/ | ||
* /_/|_|/_/ \__//___// .__//_/ \___/\_,_/ \__/ | ||
* /_/ github.com/KitSprout | ||
* | ||
* @file string.h | ||
* @author KitSprout | ||
* @date 6-Oct-2016 | ||
* @brief | ||
* | ||
*/ | ||
|
||
#ifndef __ALGORITHM_STRING_H | ||
#define __ALGORITHM_STRING_H | ||
/* Define to prevent recursive inclusion ---------------------------------------------------*/ | ||
#ifndef __STRING_H | ||
#define __STRING_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* Includes --------------------------------------------------------------------------------*/ | ||
#include <string.h> | ||
#include "stm32f4xx.h" | ||
/*====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
|
||
/* Exported types --------------------------------------------------------------------------*/ | ||
typedef enum { | ||
Type_B = 2, // 無號數二進制 | ||
Type_O = 8, // 無號數八進制 | ||
Type_D = 10, // 無號數十進制 | ||
Type_H = 16, // 無號數十六進制 | ||
Type_I = 0, // 有號數 | ||
Type_F = 1, // 浮點數 | ||
} StringType; | ||
/*====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
void num2Str( StringType type, uint8_t lens, char *pStr, int32_t number ); | ||
S_BIN = 2, /* unsigned binary */ | ||
S_OCT = 8, /* unsigned octal */ | ||
S_DEC = 10, /* unsigned decimal */ | ||
S_HEX = 16, /* unsigned hexadecimal */ | ||
S_INT = 0, /* signed decimal */ | ||
S_FLOAT = 1, /* float point */ | ||
} StringType_t; | ||
|
||
/* Exported constants ----------------------------------------------------------------------*/ | ||
/* Exported functions ----------------------------------------------------------------------*/ | ||
void num2Str( StringType_t type, uint8_t lens, char *pStr, int32_t number ); | ||
uint16_t lenOfStr( char *pStr ); | ||
/*====================================================================================================*/ | ||
/*====================================================================================================*/ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
|
||
/*************************************** END OF FILE ****************************************/ |
This file contains 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
Oops, something went wrong.