Skip to content

Commit

Permalink
Emulator actual embodiment: memory handle-based mem management and pa…
Browse files Browse the repository at this point in the history
…rsing in protocol handlers and around
  • Loading branch information
divanchykhin committed Mar 31, 2015
1 parent 396bb7f commit fc089d4
Show file tree
Hide file tree
Showing 13 changed files with 1,908 additions and 30 deletions.
38 changes: 38 additions & 0 deletions tests/emulator/sa-commlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ void communicationTerminate()
hPipe = INVALID_HANDLE_VALUE;
}

uint8_t sendMessage( MEMORY_HANDLE mem_h )
{
uint8_t buff[512];
uint16_t msgSize;
// init parser object
parser_obj po;
zepto_parser_init( &po, mem_h );
msgSize = zepto_parsing_remaining_bytes( &po );
assert( msgSize <= 512 );
zepto_parse_read_block( &po, buff, msgSize );
printf( "message sent; size = %d\n", msgSize );
return sendMessage(&msgSize, buff);
}

uint8_t sendMessage(uint16_t* msgSize, const uint8_t * buff)
{
BOOL fSuccess = FALSE;
Expand Down Expand Up @@ -161,6 +175,15 @@ uint8_t sendMessage(uint16_t* msgSize, const uint8_t * buff)
return COMMLAYER_RET_OK;
}

uint8_t getMessage( MEMORY_HANDLE mem_h ) // returns when a packet received
{
uint8_t buff[512];
uint16_t msgSize;
uint8_t ret = getMessage( &msgSize, buff, 512 );
zepto_write_block( mem_h, buff, msgSize );
return ret;
}

uint8_t getMessage(uint16_t* msgSize, uint8_t * buff, int maxSize) // returns when a packet received
{
BOOL fSuccess = FALSE;
Expand Down Expand Up @@ -312,6 +335,21 @@ uint8_t finalizeReading(uint16_t* msgSize, uint8_t * buff, int maxSize)

}


uint8_t tryGetMessage( MEMORY_HANDLE mem_h ) // returns immediately, but a packet reception is not guaranteed
{
uint8_t buff[512];
uint16_t msgSize;
uint8_t ret = tryGetMessage( &msgSize, buff, 512 );
if ( ret == COMMLAYER_RET_OK )
{
printf( "message received; size = %d\n", msgSize );
zepto_write_block( mem_h, buff, msgSize );
}
return ret;
}


uint8_t tryGetMessage(uint16_t* msgSize, uint8_t * buff, int maxSize) // returns immediately, but a packet reception is not guaranteed
{
uint8_t ret_code;
Expand Down
6 changes: 6 additions & 0 deletions tests/emulator/sa-commlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Copyright (C) 2015 OLogN Technologies AG
#if !defined __SA_COMMLAYER_H__
#define __SA_COMMLAYER_H__

#include "zepto-mem-mngmt.h"


// RET codes
#define COMMLAYER_RET_FAILED 0 // not authenticated, etc
Expand All @@ -32,4 +34,8 @@ uint8_t sendMessage( uint16_t* msgSize, const uint8_t * buff );
uint8_t getMessage( uint16_t* msgSize, uint8_t * buff, int maxSize ); // returns when a packet received
uint8_t tryGetMessage(uint16_t* msgSize, uint8_t * buff, int maxSize); // returns immediately, but a packet reception is not guaranteed

uint8_t sendMessage( MEMORY_HANDLE mem_h );
uint8_t getMessage( MEMORY_HANDLE mem_h ); // returns when a packet received
uint8_t tryGetMessage( MEMORY_HANDLE mem_h ); // returns immediately, but a packet reception is not guaranteed

#endif // __SA_COMMLAYER_H__
Loading

0 comments on commit fc089d4

Please sign in to comment.