Replaced c array buffer with c++ array class buffer

This commit is contained in:
BlackMark 2016-05-21 19:11:04 +02:00
parent 8e249b46b5
commit 8b081b8c9f
6 changed files with 47 additions and 37 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "usart/array"]
path = usart/array
url = git@blackmark.me:array.git

1
usart/array Submodule

@ -0,0 +1 @@
Subproject commit 634564a7bb6f34305dbc6f68993a34a4419899a6

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include "clock.h"
#include "usart.h"
#include "array/array.h"
int main()
{
@ -15,75 +16,74 @@ int main()
uint32_t ui32Counter = 0;
constexpr size_t sizeBUFFER_SIZE = 64;
char szBuffer[sizeBUFFER_SIZE];
array<char, 64> arrBuffer;
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( 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( 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( 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( 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( 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( 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( 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( 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( 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( 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( 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( 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( 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( szBuffer );
cUSART.transmitString( arrBuffer.data() );
while( true )
{
sprintf( szBuffer, "%lu", ui32Counter++ );
sprintf( arrBuffer.data(), "%lu", ui32Counter++ );
cUSART.transmitString( "This has been running for \"" );
cUSART.transmitString( szBuffer );
cUSART.transmitString( arrBuffer.data() );
cUSART.transmitString( "\" seconds!\r\n" );
if( !cUSART.receiveLine( szBuffer, sizeBUFFER_SIZE, "\r" ) )
if( !cUSART.receiveLine( arrBuffer.data(), arrBuffer.size(), "\r" ) )
{
cUSART.transmitString( "Receive error: " );
}
@ -92,7 +92,7 @@ int main()
cUSART.transmitString( "Echo: " );
}
cUSART.transmitString( szBuffer );
cUSART.transmitString( arrBuffer.data() );
cUSART.transmitString( "\r\n" );
uint8_t ui8Byte;

View File

@ -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;
while( sizeReceived < sizeMaxSize - 1 && sizeReceived < sizeLength - 1 )
while( sizeReceived < sizeMaxSize - 1 && sizeReceived < sizeBufferLength - 1 )
{
uint8_t ui8ReceiveByte;

View File

@ -192,6 +192,9 @@
<PreBuildEvent>echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i &gt; "$(MSBuildProjectDirectory)\avrdude.bat"</PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<Compile Include="array\array.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="clock.h">
<SubType>compile</SubType>
</Compile>
@ -205,5 +208,8 @@
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="array" />
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>

View File

@ -137,7 +137,7 @@ public:
bool receiveByte( uint8_t &ui8Data );
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 transmitString( const char *szString );