// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
#include <conio.h>
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
#include <stdio.h>
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
#include "API-WiMinet.h"
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
#define MAX_SHELL_SIZE 0X02
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
unsigned long dwStatic_Serial[MAX_SHELL_SIZE] = { 0X00, 0X00 };
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
unsigned char iStatic_XShell[MAX_SHELL_SIZE] = { 0X00, 0X00 };
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
unsigned short pStatic_Object[MAX_SHELL_SIZE] = { 0XC3DF, 0X8E45 };
/*
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
char * pOutputFileName[] = {
"G:BMP1.bwrg.mLZO",
"G:BMP2.bwrg.mLZO",
"G:BMP3.bwrg.mLZO",
"G:BMP4.bwrg.mLZO",
"G:BMP5.bwrg.mLZO",
"G:BMP6.bwrg.mLZO",
"G:BMP7.bwrg.mLZO",
"G:BMP8.bwrg.mLZO",
"G:BMP9.bwrg.mLZO",
"G:BMP10.bwrg.mLZO",
"G:BMP11.bwrg.mLZO",
"G:BMP12.bwrg.mLZO",
"G:BMP13.bwrg.mLZO",
"G:BMP14.bwrg.mLZO",
"G:BMP16.bwrg.mLZO",
"G:BMP19.bwrg.mLZO" };
*/
// -----------------------------------------------------------------------------
// DESCRIPTION:
// -----------------------------------------------------------------------------
char * pOutputFileName[] = {
"1.bwrg.mLZO",
"2.bwrg.mLZO",
"3.bwrg.mLZO",
"4.bwrg.mLZO",
"5.bwrg.mLZO",
"6.bwrg.mLZO",
"7.bwrg.mLZO",
"8.bwrg.mLZO",
"9.bwrg.mLZO",
"10.bwrg.mLZO",
"11.bwrg.mLZO",
"12.bwrg.mLZO",
"13.bwrg.mLZO",
"14.bwrg.mLZO",
"16.bwrg.mLZO",
"19.bwrg.mLZO" };
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
unsigned long Translate_Output_File_Number( unsigned long dwChar )
{
unsigned long dwSize;
// Select the file ID
if ( ( dwChar >= '0' ) && ( dwChar <= '9' ) )
{
// Skip off the base value
dwChar -= '0';
}
else if ( ( dwChar >= 'a' ) && ( dwChar <= 'f' ) )
{
// Skip off the base value
dwChar -= 'a';
// Add the basic value
dwChar += 0X0A;
}
else if ( ( dwChar >= 'A' ) && ( dwChar <= 'F' ) )
{
// Skip off the base value
dwChar -= 'A';
// Add the basic value
dwChar += 0X0A;
}
else
{
dwChar = 0XFFFFFFFF;
}
// The max file counter
dwSize = sizeof( pOutputFileName ) / sizeof( pOutputFileName[0X00] );
// Validate the input character
if ( dwChar >= dwSize )
{
dwChar = 0XFFFFFFFF;
}
// The new output file number
return dwChar;
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
char * Translate_Output_File_Name( unsigned long dwIndex )
{
return pOutputFileName[dwIndex];
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
WORD NEW_Console_Color( WORD dwColor )
{
HANDLE hConsole;
CONSOLE_SCREEN_BUFFER_INFO info;
// Get the console handle
hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
// Get the current console information
GetConsoleScreenBufferInfo( hConsole, &info );
// Intensity the color
dwColor |= ( FOREGROUND_INTENSITY | BACKGROUND_INTENSITY );
// Active items
SetConsoleTextAttribute( hConsole, dwColor );
// The default console color
return info.wAttributes;
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void END_Console_Color( void )
{
HANDLE hConsole;
WORD dwColor;
// Get the console handle
hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
// The white color
dwColor = ( FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED );
// Active items
SetConsoleTextAttribute( hConsole, dwColor );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void UserInputKey_Handler( unsigned long dwChar )
{
char * pFile;
unsigned char index;
unsigned long dwFile;
// Translate the input character
dwFile = Translate_Output_File_Number( dwChar );
// Validate the file index
if ( dwFile == 0XFFFFFFFFUL )
{
printf( "Invalid File Number!rn" );
return;
}
// Translate the file names
pFile = Translate_Output_File_Name( dwFile );
// Mode-1: X2.Server + X2.Client
for ( index = 0X00; index < MAX_SHELL_SIZE; index++ )
{
WiMinet_ZipTask_SendFile( iStatic_XShell[index], pStatic_Object[index], pFile );
}
// Mode-2: X1.Server = X2.Client
//WiMinet_ZipTask_SendFile( iStatic_XShell[0X01], pStatic_Object[0X00], pFile );
//WiMinet_ZipTask_SendFile( iStatic_XShell[0X01], pStatic_Object[0X01], pFile );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void PrintTaskInfomation_Time( WiMinet_IOT_Time64 * pTime )
{
FILETIME nFileTime;
SYSTEMTIME nTimerA;
SYSTEMTIME nTimerB;
unsigned char iStatus;
// Check if time out
iStatus = ( pTime->m_iStatus & WIMINET_X64TIMER_STOP );
// Validate the timer status
if ( !iStatus )
{
printf( " Warning: Event Time Out! The Information Is Invalid!rn" );
return;
}
// Convert to local file time
FileTimeToLocalFileTime( ( FILETIME * )&pTime->m_qwTimeA, &nFileTime );
// Convert file time to system time
FileTimeToSystemTime( &nFileTime, &nTimerA );
// Convert to local file time
FileTimeToLocalFileTime( ( FILETIME * )&pTime->m_qwTimeB, &nFileTime );
// Convert file time to system time
FileTimeToSystemTime( &nFileTime, &nTimerB );
// The date time header
printf( " SN=%lu,Active=0X%02X,Time=", pTime->m_dwX32SN, pTime->m_iStatus );
// The open timer
printf( "%04lu-%02lu-%02lu %02lu-%02lu-%02lu.%03lu",
nTimerA.wYear,
nTimerA.wMonth,
nTimerA.wDay,
nTimerA.wHour,
nTimerA.wMinute,
nTimerA.wSecond,
nTimerA.wMilliseconds );
// The date time header
printf( " -> " );
// The open timer
printf( "%04lu-%02lu-%02lu %02lu-%02lu-%02lu.%03lu",
nTimerB.wYear,
nTimerB.wMonth,
nTimerB.wDay,
nTimerB.wHour,
nTimerB.wMinute,
nTimerB.wSecond,
nTimerB.wMilliseconds );
// The offset timer
printf( ",Offset=%lu(ms)rn", pTime->m_dwTimeX );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void PrintTaskInfomation_Node( WiMinet_IOT_Packet * pNode )
{
// The node information
printf( " <1> Node=0X%04Xrn", pNode->m_iX16NET );
// The packet attribute
printf( " <2> Attr=0X%02Xrn", pNode->m_iAttrib );
// The packet size
printf( " <3> Size=%lu Bytesrn", pNode->m_dwCount );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Sub_Sample_CallBack_Notice_Wakeup( unsigned char iShell )
{
WiMinet_IOT_Record nWakeup;
WiMinet_TxReport * pTxReport;
// The event information
printf( "Notice.Wakuprn" );
// Get the event contents
WiMinet_GetNotice_Wakeup( iShell, &nWakeup );
// The task time information
PrintTaskInfomation_Time( &nWakeup.m_nIOTime );
// The task node information
PrintTaskInfomation_Node( &nWakeup.m_nPacket );
// Check the code value
if ( nWakeup.m_nPacket.m_iAttrib != WIMINET_EVENT_WOR_COMMUTE )
{
printf( " Invalid Event Codern" );
return;
}
// The report status
printf( " [4] Events=WOR Commute ENDrn" );
// The TxReport status
pTxReport = ( WiMinet_TxReport * )nWakeup.m_nPacket.m_pBuffer;
// The TaskID number
printf( " [5] TaskID=%urn", pTxReport->m_iTaskID );
// The Tx data size
printf( " [6] TxSize=%lu Bytesrn", pTxReport->m_dwCount );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Sub_Sample_CallBack_Status_TxFile( unsigned char iShell )
{
unsigned long dwTimerX;
WiMinet_IOT_Record nTxFile;
// The event information
printf( "Status.TxFilern" );
// Get the event contents
WiMinet_GetStatus_TxFile( iShell, &nTxFile );
// The task time information
PrintTaskInfomation_Time( &nTxFile.m_nIOTime );
// The task node information
PrintTaskInfomation_Node( &nTxFile.m_nPacket );
// Get the task timer
memcpy( &dwTimerX, nTxFile.m_nPacket.m_pBuffer, sizeof( dwTimerX ) );
// The task completed status
switch ( nTxFile.m_nPacket.m_iAttrib )
{
case TXD_TASK_STATUS_END_SUCCESS:
{
// The task status
printf(
" [4] +%lu Tx Completed Successfully,Time=%lu(ms)rn",
nTxFile.m_nIOTime.m_dwX32SN,
dwTimerX );
}
break;
case TXD_TASK_STATUS_END_FAILURE:
{
// NEW the color
NEW_Console_Color( FOREGROUND_GREEN | BACKGROUND_BLUE );
// The task status
printf(
" [4] +%lu Tx Completed With Error,Time=%lu(ms)rn",
nTxFile.m_nIOTime.m_dwX32SN,
dwTimerX );
// END the color
END_Console_Color();
}
break;
case TXD_TASK_STATUS_END_NOCRC32:
{
// NEW the color
NEW_Console_Color( FOREGROUND_GREEN | BACKGROUND_BLUE );
// The task status
printf(
" [4] +%lu Tx Completed Without CRC32,Time=%lu(ms)rn",
nTxFile.m_nIOTime.m_dwX32SN,
dwTimerX );
// END the color
END_Console_Color();
}
break;
case TXD_TASK_STATUS_ERR_CONNECT:
{
// NEW the color
NEW_Console_Color( FOREGROUND_GREEN | BACKGROUND_BLUE );
// The task status
printf(
" [4] +%lu Tx Device Connection Error,Time=%lu(ms)rn",
nTxFile.m_nIOTime.m_dwX32SN,
dwTimerX );
// END the color
END_Console_Color();
}
break;
case TXD_TASK_STATUS_ERR_ABANDON:
{
// NEW the color
NEW_Console_Color( FOREGROUND_GREEN | BACKGROUND_BLUE );
// The task status
printf(
" [4] +%lu Tx Device Transmit Give Up,Time=%lu(ms)rn",
nTxFile.m_nIOTime.m_dwX32SN,
dwTimerX );
// END the color
END_Console_Color();
}
break;
default:
{
// NEW the color
NEW_Console_Color( FOREGROUND_GREEN | BACKGROUND_BLUE );
// The task status
printf(
" [4] +%lu Tx Completed With Unknown Error,Time=%lu(ms)rn",
nTxFile.m_nIOTime.m_dwX32SN,
dwTimerX );
// END the color
END_Console_Color();
}
break;
}
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Sub_Sample_CallBack_Notice_AirTCP( unsigned char iShell )
{
unsigned char iTaskID;
WiMinet_IOT_Record nAirTCP;
WiMinet_TxReport * pTxReport;
// The event information
printf( "Notice.AirTCPrn" );
// Get the event contents
WiMinet_GetNotice_AirTCP( iShell, &nAirTCP );
// The task time information
PrintTaskInfomation_Time( &nAirTCP.m_nIOTime );
// The task node information
PrintTaskInfomation_Node( &nAirTCP.m_nPacket );
// The event of the object
switch ( nAirTCP.m_nPacket.m_iAttrib )
{
case WIMINET_EVENT_COMMUTE_END:
{
// The TxReport status
pTxReport = ( WiMinet_TxReport * )nAirTCP.m_nPacket.m_pBuffer;
// The report status
printf( " [4] Events=TCP Commute Endrn" );
// The TaskID number
printf( " [5] TaskID=%urn", pTxReport->m_iTaskID );
// The Tx data size
printf( " [6] RxSize=%u Bytesrn", pTxReport->m_iNotUse );
// The Tx data size
printf( " [7] TxSize=%lu Bytesrn", pTxReport->m_dwCount );
// The report status
printf( " [8] Errors=0X%02X", pTxReport->m_iQError );
// The detailed error code: No Header
if ( pTxReport->m_iQError & WIMINET_IO_REPORT_NO_HEADER )
{
printf( "[No Header]" );
}
// The detailed error code: Invalid Size
if ( pTxReport->m_iQError & WIMINET_IO_REPORT_ER_AMOUNT )
{
printf( "[Invalid Size]" );
}
// The detailed error code: Invalid CRC32
if ( pTxReport->m_iQError & WIMINET_IO_REPORT_ER_CRCODE )
{
printf( "[Invalid CRC32]" );
}
// The end of this line
printf( "rn" );
}
break;
case WIMINET_EVENT_COMMUTE_ERR:
{
// The report status
printf( " [4] Events=TCP Commute Errorrn" );
// Get the taskid
iTaskID = nAirTCP.m_nPacket.m_pBuffer[0X00];
// The TaskID number
printf( " [5] TaskID=%urn", iTaskID );
}
break;
case WIMINET_EVENT_CONNECT_ERR:
{
// The report status
printf( " [4] Events=TCP Connect Errorrn" );
// Get the taskid
iTaskID = nAirTCP.m_nPacket.m_pBuffer[0X00];
// The TaskID number
printf( " [5] TaskID=%urn", iTaskID );
}
break;
default:
{
// The report status
printf( " [4] Events=Unknown Eventsrn" );
}
break;
}
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Sub_Sample_CallBack_Report_Client( unsigned char iShell )
{
unsigned long dwSize;
WiMinet_IOT_Record nReport;
WiMinet_RxReport * pRxReport;
// The event information
printf( "Report.Clientrn" );
// Get the event contents
WiMinet_GetReport_Client( iShell, &nReport );
// The task time information
PrintTaskInfomation_Time( &nReport.m_nIOTime );
// The task node information
PrintTaskInfomation_Node( &nReport.m_nPacket );
// The TxReport status
pRxReport = ( WiMinet_RxReport * )nReport.m_nPacket.m_pBuffer;
// Get the device information
printf(
" [4] Device=0X%02X(%d)rn",
pRxReport->m_iDevice,
pRxReport->m_iDevice );
// Get the firmware version
printf( " [5] Version=0X%08lX", pRxReport->m_dwBuild );
// The build version for firmware update
printf(
" --> [20%u.%u.%u+R%u]rn",
( unsigned char )( pRxReport->m_dwBuild >> 0X18 ),
( unsigned char )( pRxReport->m_dwBuild >> 0X10 ),
( unsigned char )( pRxReport->m_dwBuild >> 0X08 ),
( unsigned char )( pRxReport->m_dwBuild >> 0X00 ) );
// The received byte size by the remote endpoint
dwSize = ( ( unsigned long )pRxReport->m_iMBSize << 0X10 );
// The LSB value
dwSize += pRxReport->m_iLBSize;
// The client received byte size
printf( " [6] Counter=%lu Bytesrn", dwSize );
// The battery voltage
printf( " [7] Battery=%.3f(V)rn", pRxReport->m_iBATVol * 0.001f );
// The RxRSSI voltage
printf( " [8] RxRSSI=%d(dBm)rn", pRxReport->m_iRxRSSI );
// The RxRSSI voltage
printf( " [9] TxRSSI=%d(dBm)rn", pRxReport->m_iTxRSSI );
// The client receive error code
printf( " [A] Errors=0X%02X", pRxReport->m_iQError );
// The detailed error code: Rx Time Out
if ( pRxReport->m_iQError & WIMIET_IO_REPORT_RX_TIMEOUT )
{
printf( " [Rx Time Out]" );
}
// The detailed error code: No Header
if ( pRxReport->m_iQError & WIMINET_IO_REPORT_NO_HEADER )
{
printf( "[No Header]" );
}
// The detailed error code: Invalid Size
if ( pRxReport->m_iQError & WIMINET_IO_REPORT_ER_AMOUNT )
{
printf( "[Invalid Size]" );
}
// The detailed error code: Invalid CRC32
if ( pRxReport->m_iQError & WIMINET_IO_REPORT_ER_CRCODE )
{
printf( "[Invalid CRC32]" );
}
// The end of this line
printf( "rn" );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Sub_Sample_CallBack_Task_Complete( unsigned char iShell )
{
unsigned char iSize;
unsigned char iStatus;
unsigned char iRetVal;
unsigned long dwSerial;
// The event information
printf( "Task.Completern" );
// Get the task complete status
iRetVal = WiMinet_GetTask_Complete( iShell, &iStatus, &dwSerial );
// The task serial number
printf( " [1] Serial=%lurn", dwSerial );
// The task over status
printf( " [2] TxOver=%drn", iRetVal );
// The error bit mask
printf( " [3] ERMask=0X%02X", iStatus );
// Check the error status:Wakeup
if ( iStatus & WIMINET_MASK_NOTICE_WAKEUP )
{
printf( " + Wakeup" );
}
// Check the error status:AirTCP
if ( iStatus & WIMINET_MASK_NOTICE_AIRTCP )
{
printf( " + AirTCP" );
}
// Check the error status:TxFile
if ( iStatus & WIMINET_MASK_STATUS_TXFILE )
{
printf( " + TxFile" );
}
// Check the error status:Report
if ( iStatus & WIMINET_MASK_REPORT_CLIENT )
{
printf( " + Report" );
}
// Check the error status:Submit
if ( iStatus & WIMINET_MASK_SUBMIT_PACKET )
{
printf( " + Submit" );
}
// Get the writable status
iStatus = WiMinet_GetTask_Writable( iShell, &iSize );
// The new writable status
printf( "rn [4] Submit=%d/%drn", iStatus, iSize );
// The end of line status
printf( "rnrn" );
printf( "==========================================" );
printf( "==========================================" );
printf( "rn" );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Sample_CallBack( unsigned char iShell, unsigned char iStatus )
{
printf( "rnShell[%d]:Status=0X%02X,Event=", iShell, iStatus );
// Process all the events
switch ( iStatus )
{
case WIMINET_NOTICE_WAKEUP:
{
Sub_Sample_CallBack_Notice_Wakeup( iShell );
}
break;
case WIMINET_STATUS_TXFILE:
{
Sub_Sample_CallBack_Status_TxFile( iShell );
}
break;
case WIMINET_NOTICE_AIRTCP:
{
Sub_Sample_CallBack_Notice_AirTCP( iShell );
}
break;
case WIMINET_REPORT_CLIENT:
{
Sub_Sample_CallBack_Report_Client( iShell );
}
break;
case WIMINET_TASK_COMPLETE:
{
Sub_Sample_CallBack_Task_Complete( iShell );
}
break;
default:
{
}
break;
}
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Active_Poll_Task_Status_X1( unsigned char iShell )
{
unsigned char index;
unsigned char iStatus;
unsigned char iTxOver;
unsigned long dwSerial;
// Get the complete status
iTxOver = WiMinet_GetTask_Complete( iShell, &iStatus, &dwSerial );
// Check if task completed
if ( !iTxOver )
{
return;
}
// Get the shell index
index = ( iShell - 0X01 );
// Compare the task serial
if ( dwSerial == dwStatic_Serial[index] )
{
return;
}
// Update current task serial
dwStatic_Serial[index] = dwSerial;
// Print the notice.wakeup
Sample_CallBack( iShell, WIMINET_NOTICE_WAKEUP );
// Print the status.txfile
Sample_CallBack( iShell, WIMINET_STATUS_TXFILE );
// Print the notice.airtcp
Sample_CallBack( iShell, WIMINET_NOTICE_AIRTCP );
// Print the report.client
Sample_CallBack( iShell, WIMINET_REPORT_CLIENT );
// Print the task.complete
Sample_CallBack( iShell, WIMINET_TASK_COMPLETE );
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
void Active_Poll_Task_Status( void )
{
unsigned char index;
unsigned char iShell;
// Poll every task status
for ( index = 0X00; index < MAX_SHELL_SIZE; index++ )
{
// Get the shell number
iShell = iStatic_XShell[index];
// Get the shell status
Active_Poll_Task_Status_X1( iShell );
}
}
// *****************************************************************************
// Design Notes:
// -----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
unsigned long dwChar;
// Open the shell
iStatic_XShell[0X00] = OpenWiMinetShell( "192.168.0.248",12580, 0X01 );
// Open the shell
iStatic_XShell[0X01] = OpenWiMinetShell( "192.168.0.108",12580, 0X01 );
// Validate the shell open interface
if ( !iStatic_XShell[0X00] || !iStatic_XShell[0X01] )
{
printf( "Open shell failed!rn" );
return 0X00;
}
// Set the task callback function for
//WiMinet_SetTask_CallBack( 0XFF, Sample_CallBack );
// Set the common file path
WiMinet_SetTask_WorkPath( 0XFF, "G:BMP" );
// The notice for user input
printf( "Please select '0'-'9' for file, 'q' or 'Q' to exit!rnrn" );
// The main thread service
while( 0X01 )
{
// Release the processor control
Sleep( 0X01 );
// Poll the task status
Active_Poll_Task_Status();
// Check the keyboard input
if ( _kbhit() )
{
// Get the input character
dwChar = _getche();
// Check if time to exit this process
if ( ( dwChar == 'q' ) || ( dwChar == 'Q' ) )
{
break;
}
// The user input key handler
UserInputKey_Handler( dwChar );
}
}
// Close all the shell
StopWiMinetShell( 0XFF );
// The function exit code
return 0X00;
}