#include #include #include "BS_API.h" /* Before using this test program, 'Win32OpenSSL-0_9_8d.exe' must be installed. 'Win32OpenSSL-0_9_8d.exe' exist in installed BioAdminServer directory. 1)Start test program. Then a consol window is created. 2)Wait BS_SERVER_CB_CONN_NOAUTH event. 3)After BS_SERVER_CB_CONN_NOAUTH event, type 'issue [handle] [BioStation ID]' in the consol window and press enter key. 4)Wait BS_SERVER_CB_CONN_SSL event. 5)After BS_SERVER_CB_CONN_SSL event, type 'startlog [handle]' in the consol window and press enter key. 4)Wait BS_SERVER_CB_CONN_LOG event. 6)After BS_SERVER_CB_CONN_LOG event occur, every time a log data occur, the log data is transferred from a biostation to this test program. 7)Type 'getlist' to get the connected biostation's list. 8)Type 'exit' to terminate this test program. */ //--------------------------------------------------------------------------------------------------------- //Declaration //--------------------------------------------------------------------------------------------------------- BS_RET_CODE __stdcall ConnectedProc( int handle, unsigned biostationID, int type, void* data, int dataLen ); BS_RET_CODE __stdcall DisconnectedProc( int handle, unsigned biostationID, int type, void* data, int dataLen ); BS_RET_CODE __stdcall LogProc( int handle, unsigned biostationID, int type, void* data, int dataLen ); enum { ISSUE_CERT = 0, START_LOG, GET_LIST, CLOSE_CONN, EXIT_APP, NO_CMD, }; int readCommand( int* handle, unsigned* bstID ); //---------------------------------------------------------------------------------------------------------- //Main //---------------------------------------------------------------------------------------------------------- int main(int argc, char* argv[]) { BS_RET_CODE result; BS_InitSDK(); //Set event procedure. //BS_SERVER_CB_CONN_NOAUTH event occur when a biostation connect to this application without ssl certificate. //For normal using, BS_IssueCertificate must be called after BS_SERVER_CB_CONN_NOAUTH evnet occur. BS_SetCallback( BS_SERVER_CB_CONN_NOAUTH, ConnectedProc ); //BS_SERVER_CB_CONN_SSL evnet occur when a biostation connect to this application with ssl certificate. //After BS_SERVER_CB_CONN_SSL event occur, other sdk function can be used with handle returned by BS_SERVER_CB_CONN_SSL event. BS_SetCallback( BS_SERVER_CB_CONN_SSL, ConnectedProc ); //BS_SERVER_CB_DISCONN_NOAUTH evnet occur when a biostation having no ssl certificate is disconnected. BS_SetCallback( BS_SERVER_CB_DISCONN_NOAUTH, DisconnectedProc ); //BS_SERVER_CB_DISCONN_SSL evnet occur when a biostation having a ssl certificate is disconnected. BS_SetCallback( BS_SERVER_CB_DISCONN_SSL, DisconnectedProc ); //BS_SERVER_CB_DISCONN_SSL evnet occur when receiving log data start. BS_SetCallback( BS_SERVER_CB_CONN_LOG, ConnectedProc ); //BS_SERVER_CB_DISCONN_SSL evnet occur when log data is received. BS_SetCallback( BS_SERVER_CB_LOG, LogProc ); result = BS_StartServerApp( 1480, 32, "C:\\OpenSSL\\bin\\openssl.exe", "12345678" ); if( result != BS_SUCCESS ) { printf("BS_StartServerApp Fail! \n"); return 0; } printf("BS_StartServerApp... \n"); unsigned id[32]; int idCount, handle, i; unsigned bstID; while(true) { handle = -1; bstID = 0; switch( readCommand( &handle, &bstID ) ) { case ISSUE_CERT : printf("BS_IssueCertificate Handle:%d ID:%d \n", handle, bstID ); result = BS_IssueCertificate( handle, bstID ); if( result != BS_SUCCESS ) printf("BS_IssueCertificate Fail! %d \n", result ); else BS_CloseSocket(handle); //¹Ýµå½Ã È£ÃâÇؾßÇÔ. break; case START_LOG : printf("BS_StartLogMonitoring Handle:%d \n", handle ); result = BS_StartLogMonitoring( handle ); if( result != BS_SUCCESS ) printf("BS_StartLogMonitoring Fail! %d \n", result ); break; case GET_LIST : BS_GetConnectedList( id, &idCount ); for( i = 0 ; i < idCount ; i++ ) { printf("BiostationID:%d \n", id[i] ); } break; case CLOSE_CONN : printf("BS_CloseConnection BiostationID:%d \n", bstID ); result = BS_CloseConnection( bstID ); if( result != BS_SUCCESS ) printf("BS_CloseConnection Fail! %d \n", result ); break; case EXIT_APP : goto exit_program; } } exit_program: BS_StopServerApp(); return 0; } //-------------------------------------------------------------------------------------------------------- //Connect evnet procedure. //-------------------------------------------------------------------------------------------------------- BS_RET_CODE __stdcall ConnectedProc( int handle, unsigned biostationID, int type, void* data, int dataLen ) { if( type == BS_SERVER_CB_CONN_NOAUTH ) { unsigned bstID = 0; printf("\nNo Auth Biostation Handle:%d ID:%d \n", handle, biostationID ); printf("cmd>"); } else if( type == BS_SERVER_CB_CONN_SSL ) { printf("\nSSL Biostation Handle:%d ID:%d \n", handle, biostationID ); printf("cmd>"); } else if( type == BS_SERVER_CB_CONN_LOG ) { printf("\nLog Biostation Handle:%d ID:%d \n", handle, biostationID ); printf("cmd>"); } return BS_SUCCESS; } //-------------------------------------------------------------------------------------------------------- //Disconnect evnet procedure. //-------------------------------------------------------------------------------------------------------- BS_RET_CODE __stdcall DisconnectedProc( int handle, unsigned biostationID, int type, void* data, int dataLen ) { printf("\nDisconnected Handle:%d ID:%d \n", handle, biostationID ); printf("cmd>"); return BS_SUCCESS; } //-------------------------------------------------------------------------------------------------------- //Log receive event procedure. //-------------------------------------------------------------------------------------------------------- BS_RET_CODE __stdcall LogProc( int handle, unsigned biostationID, int type, void* data, int dataLen ) { BSLogRecord* pLogRecord = (BSLogRecord*)data; printf("\nReceive Log Event:%d Handle:%d ID:%d \n", pLogRecord->event, handle, biostationID ); printf("cmd>"); return BS_SUCCESS; } //--------------------------------------------------------------------------------------------------------- // This function operate only to read command from the console created by this program. //--------------------------------------------------------------------------------------------------------- int readCommand( int* handle, unsigned* bstID ) { char readChar; char buffer[1024]; int pos = 0; memset(buffer,0x00,1024); printf("cmd>"); while(true) { if( pos >= 1024 ) pos = 0; readChar = getchar(); if( readChar == 0x0a ) { buffer[pos] = '\0'; if( !strncmp( buffer, "issue", 5 ) ) { *handle = atoi(buffer + 6); int i = 0; while(true) { if( buffer[6 + i] == ' ' ) break; i++; } *bstID = atoi(buffer + 6 + i) ; return ISSUE_CERT; } else if( !strncmp( buffer, "startlog", 8 ) ) { *handle = atoi(buffer + 9); return START_LOG; } else if( !strncmp( buffer, "getlist", 7 ) ) return GET_LIST; else if( !strncmp( buffer, "close", 5 ) ) { *bstID = atoi(buffer + 6); return CLOSE_CONN; } else if( !strncmp( buffer, "exit", 4 ) ) return EXIT_APP; else return NO_CMD; } else buffer[pos] = readChar; pos++; } }