Replaced c array buffer with c++ array class buffer
This commit is contained in:
parent
8e249b46b5
commit
8b081b8c9f
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "usart/array"]
|
||||||
|
path = usart/array
|
||||||
|
url = git@blackmark.me:array.git
|
1
usart/array
Submodule
1
usart/array
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 634564a7bb6f34305dbc6f68993a34a4419899a6
|
@ -7,6 +7,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
|
#include "array/array.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -15,75 +16,74 @@ int main()
|
|||||||
|
|
||||||
uint32_t ui32Counter = 0;
|
uint32_t ui32Counter = 0;
|
||||||
|
|
||||||
constexpr size_t sizeBUFFER_SIZE = 64;
|
array<char, 64> arrBuffer;
|
||||||
char szBuffer[sizeBUFFER_SIZE];
|
|
||||||
|
|
||||||
cUSART.transmitString( "\r\nSizes: \r\n" );
|
cUSART.transmitString( "\r\nSizes: \r\n" );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( char ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( char ) );
|
||||||
cUSART.transmitString( "sizeof( char ) = " );
|
cUSART.transmitString( "sizeof( char ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( unsigned char ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned char ) );
|
||||||
cUSART.transmitString( "sizeof( unsigned char ) = " );
|
cUSART.transmitString( "sizeof( unsigned char ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( short int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( short int ) );
|
||||||
cUSART.transmitString( "sizeof( short int ) = " );
|
cUSART.transmitString( "sizeof( short int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( unsigned short int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned short int ) );
|
||||||
cUSART.transmitString( "sizeof( unsigned short int ) = " );
|
cUSART.transmitString( "sizeof( unsigned short int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( int ) );
|
||||||
cUSART.transmitString( "sizeof( int ) = " );
|
cUSART.transmitString( "sizeof( int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( unsigned int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned int ) );
|
||||||
cUSART.transmitString( "sizeof( unsigned int ) = " );
|
cUSART.transmitString( "sizeof( unsigned int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( long int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long int ) );
|
||||||
cUSART.transmitString( "sizeof( long int ) = " );
|
cUSART.transmitString( "sizeof( long int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( unsigned long int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long int ) );
|
||||||
cUSART.transmitString( "sizeof( unsigned long int ) = " );
|
cUSART.transmitString( "sizeof( unsigned long int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( long long int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long long int ) );
|
||||||
cUSART.transmitString( "sizeof( long long int ) = " );
|
cUSART.transmitString( "sizeof( long long int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( unsigned long long int ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long long int ) );
|
||||||
cUSART.transmitString( "sizeof( unsigned long long int ) = " );
|
cUSART.transmitString( "sizeof( unsigned long long int ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( float ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( float ) );
|
||||||
cUSART.transmitString( "sizeof( float ) = " );
|
cUSART.transmitString( "sizeof( float ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( double ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( double ) );
|
||||||
cUSART.transmitString( "sizeof( double ) = " );
|
cUSART.transmitString( "sizeof( double ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n", sizeof( long double ) );
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long double ) );
|
||||||
cUSART.transmitString( "sizeof( long double ) = " );
|
cUSART.transmitString( "sizeof( long double ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
sprintf( szBuffer, "%d\r\n\r\n", sizeof( void* ) );
|
sprintf( arrBuffer.data(), "%d\r\n\r\n", sizeof( void* ) );
|
||||||
cUSART.transmitString( "sizeof( void* ) = " );
|
cUSART.transmitString( "sizeof( void* ) = " );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
sprintf( szBuffer, "%lu", ui32Counter++ );
|
sprintf( arrBuffer.data(), "%lu", ui32Counter++ );
|
||||||
cUSART.transmitString( "This has been running for \"" );
|
cUSART.transmitString( "This has been running for \"" );
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
cUSART.transmitString( "\" seconds!\r\n" );
|
cUSART.transmitString( "\" seconds!\r\n" );
|
||||||
|
|
||||||
if( !cUSART.receiveLine( szBuffer, sizeBUFFER_SIZE, "\r" ) )
|
if( !cUSART.receiveLine( arrBuffer.data(), arrBuffer.size(), "\r" ) )
|
||||||
{
|
{
|
||||||
cUSART.transmitString( "Receive error: " );
|
cUSART.transmitString( "Receive error: " );
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ int main()
|
|||||||
cUSART.transmitString( "Echo: " );
|
cUSART.transmitString( "Echo: " );
|
||||||
}
|
}
|
||||||
|
|
||||||
cUSART.transmitString( szBuffer );
|
cUSART.transmitString( arrBuffer.data() );
|
||||||
cUSART.transmitString( "\r\n" );
|
cUSART.transmitString( "\r\n" );
|
||||||
|
|
||||||
uint8_t ui8Byte;
|
uint8_t ui8Byte;
|
||||||
|
@ -291,11 +291,11 @@ bool USART0::receiveByte( uint8_t &ui8Data, uint16_t ui16DelayMS )
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
bool USART0::receiveLine( char *szBuffer, size_t sizeLength, const char *szLineTerminator /* = "\r\n" */, size_t sizeMaxSize /* = 1024 */ )
|
bool USART0::receiveLine( char *szBuffer, size_t sizeBufferLength, const char *szLineTerminator /* = "\r\n" */, size_t sizeMaxSize /* = 512 */ )
|
||||||
{
|
{
|
||||||
size_t sizeReceived = 0;
|
size_t sizeReceived = 0;
|
||||||
|
|
||||||
while( sizeReceived < sizeMaxSize - 1 && sizeReceived < sizeLength - 1 )
|
while( sizeReceived < sizeMaxSize - 1 && sizeReceived < sizeBufferLength - 1 )
|
||||||
{
|
{
|
||||||
uint8_t ui8ReceiveByte;
|
uint8_t ui8ReceiveByte;
|
||||||
|
|
||||||
|
@ -192,6 +192,9 @@
|
|||||||
<PreBuildEvent>echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat"</PreBuildEvent>
|
<PreBuildEvent>echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat"</PreBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="array\array.h">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="clock.h">
|
<Compile Include="clock.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -205,5 +208,8 @@
|
|||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="array" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
</Project>
|
</Project>
|
@ -137,7 +137,7 @@ public:
|
|||||||
|
|
||||||
bool receiveByte( uint8_t &ui8Data );
|
bool receiveByte( uint8_t &ui8Data );
|
||||||
bool receiveByte( uint8_t &ui8Data, uint16_t ui16DelayMS );
|
bool receiveByte( uint8_t &ui8Data, uint16_t ui16DelayMS );
|
||||||
bool receiveLine( char *szBuffer, size_t sizeLength, const char *szLineTerminator = "\r\n", size_t sizeMaxSize = 512 );
|
bool receiveLine( char *szBuffer, size_t sizeBufferLength, const char *szLineTerminator = "\r\n", size_t sizeMaxSize = 512 );
|
||||||
|
|
||||||
void transmitByte( uint8_t ui8Data );
|
void transmitByte( uint8_t ui8Data );
|
||||||
void transmitString( const char *szString );
|
void transmitString( const char *szString );
|
||||||
|
Loading…
Reference in New Issue
Block a user