#include <iostream>
#include <stdio.h>
#include "mxnet1_api.h"

//
// APIs in "mxnet1_api.h" are found in the shared library libmxnet1_api.so
// Link the shared library in linking this sample program.
//
// The sample program must be able to find the shared library.
// 1) copy to /usr/lib or /usr/local/lib and ldconfig to update the 
// or
// 2) Use th enviornment variable LD_LIBRARY_PATH
//

_mxINT32 UserCode = 1234;

int main (int argc, char * const argv[])
{
	int status;

//for( int j = 0 ; j < 50 ; j++ )
//{
	if( (status=rInit_MatrixAPI()) < 0 )
	{
		printf("Init_API Error %d\n", status);
		return 0;
	}
	

	_mxINT32 serNr = rDongle_ReadSerNr(UserCode, 1, 85 );
	if( serNr > 0 )
		printf("SerNr %d\n", serNr );
	
	_mxINT32 ver = rDongle_Version( 1, 85 );
	if( ver >= 0 )
		printf("version %d %d\n", (_mxINT16)(ver >> 16), ver & 0xffff );

	_mxINT32 mem = rDongle_MemSize( 1, 85 );
	if( mem > 0 )
		printf("mem %d\n", mem );

	_mxINT32 model= rDongle_Model( 1, 85 );
	if( model > 0 )
		printf("model %d\n", model );

	_mxINT32 data[16];
	
	if( rDongle_ReadData(UserCode, data, 15, 1, 85 ) > 0 )
	{
		for(int i=0 ; i < 15 ; i++ )
			printf("%d -> %ld \n", i, data[i]);
		printf("\n");
	}
	else {
		printf("ReadData Error\n");
	}

	for (int i=0; i<15; i++) {
		data[i] += 2;
	}
	
	if( rDongle_WriteData(UserCode, data, 15, 1, 85 ) > 0 )
	{
		printf("Write Ok\n");
	}
	else {
		printf("WriteData Error\n");
	}

	if( rDongle_ReadData(UserCode, data, 15, 1, 85 ) > 0 )
	{
		for(int i=0 ; i < 15 ; i++ )
			printf("%d -> %ld \n", i, data[i]);
		printf("\n");
	}
	else {
		printf("ReadData Error\n");
	}
	
	data[0] = 12345678;
	data[1] = 98765432;
	if( rDongle_EncryptData(UserCode, data, 1, 85 ) > 0 )
		printf("EncryptedData %ld %ld\n", data[0], data[1]);
	
	if( rDongle_DecryptData(UserCode, data, 1, 85 ) > 0 )
		printf("DecryptedData %ld %ld\n", data[0], data[1] );

	rRelease_MatrixAPI();

//}	

    return 0;
}
