5. 发送无线数据

2025-04-28

5.1查询发送状态


函数名

char QueryTxMsgStatus( char   iShell, char * pStatus )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

char * pStatus

指向一个已分配好实体内存空间的单字节变量,用于记录发送状态,详细定义见“发送状态”表所示。

返回值

0X01=操作成功,0X00=操作失败





名称

发送状态

数值

说明

0XFF

系统空闲,没有发送任务

0-100

正在发送报文,当前数值为发送的百分进度比,比如35代表发送了总长度35%的报文

0X81

发送成功,且已经附加了前导描述信息,报文总长度,32位的CRC等校验信息

0X82

发送失败

0X83

发送成功,但是没有附加前导描述信息



5.2以TCP发送数据报文


函数名

char SendHiQoSMessage(

char   iShell,

short   iNode,

char * pBuffer,

long   dwSize )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

short   iNode

报文的目标接收节点ID号码

参数三

char * pBuffer

报文数据块的内存地址

参数四

long dwSize

报文数据块的长度

备注

途径的所有的传输节点,都采用TCP方式传输数据

返回值

0X01=操作成功,0X00=操作失败



5.3以UDP发送数据报文


函数名

char SendNoQoSMessage(

char   iShell,

short   iNode,

char * pBuffer,

long   dwSize )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

short   iNode

报文的目标接收节点ID号码

参数三

char * pBuffer

报文数据块的内存地址

参数四

long dwSize

报文数据块的长度

备注

途径的所有的传输节点,都采用UDP方式传输数据

返回值

0X01=操作成功,0X00=操作失败



5.4以TCP/UDP发送数据报文


函数名

char SendMxQoSMessage(

char   iShell,

short   iNode,

char * pBuffer,

long   dwSize )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

short   iNode

报文的目标接收节点ID号码

参数三

char * pBuffer

报文数据块的内存地址

参数四

long dwSize

报文数据块的长度

备注

接收报文的目标节点采用UDP传输方式,其余节点采用TCP传输方式

返回值

0X01=操作成功,0X00=操作失败



5.5设置UDP发送等级


函数名

char SetTxPerformance( char   iShell, unsigned char iSize )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

参数二

unsigned char iSize

UDP发送的等级,取值范围0-255,数值越大,发送的等级越高,可靠性越强。0代表采用设备默认的配置,最低数值0X03

返回值

0X01=操作成功,0X00=操作失败



5.6读取UDP发送等级


函数名

char GetTxPerformance( char iShell )

头文件

API-WiMinet.h

静态库

WiMinet.lib

动态库

WiMinet.dll


形式

说明

参数一

char iShell

通讯端口的编号,填写固定数值0X00

返回值

UDP发送的等级,取值范围0-255,数值越大,发送的等级越高,可靠性越强。0代表采用设备默认的配置,最低数值0X03




5.7 数据发送测试例子程序

数据发送测试例子程序

#include <stdio.h>
#include <stdlib.h>
#include "API-WiMinet.h"
int main( int argc, char* argv[] )
{
   char iRetVal;
   char * pBuffer;
   FILE * pFile;
   char   pFileName[1024];
   unsigned char iStatus;
   unsigned char iProgress;
   unsigned long dwSize;
   unsigned long dwTimerA;
   unsigned long dwTimerB;
   unsigned long dwTimerX;
   
   // COM port interface
   iRetVal = OpenWiMinetShell( "COM3",115200, 0X01 );
   // Ethernet interface
   //iRetVal = OpenWiMinetShell( "192.168.0.240",12580, 0X01 );
   // Validate the shell open interface
   if ( !iRetVal )
   {
      printf( "Open shell failed!\r\n" );
      return 0X00;
   }
   // Query the TxStatus
   while ( 0X01 )
   {
      // Query the Tx status
      QueryTxMsgStatus( 0X00, ( char * )&iStatus );
     
      // Check if end of the Tx procedure
      if ( iStatus == TXD_TASK_STATUS_JOB_WAITING )
      {
         break;
      }
      // Waiting the task is free
      printf( "." );
      // Release the control of the processor
      Sleep( 0X01 );     
   }
   
   // The input file name
   printf( "\r\nPlease input file name:" );
   // Clear the string
   memset( pFileName, 0X00, sizeof( pFileName ) );
   // The input file name
   scanf( "%s", pFileName );
   // Open the file
   pFile = fopen( pFileName, "rb" );
   // Validate the file pointer
   if ( !pFile )
   {
      printf( "Failed To Open File!\r\n" );
   }
   // Seek to the file end
   fseek( pFile, 0X00, SEEK_END );
   // The file size
   dwSize = ftell( pFile );
   // Seek to the file head
   fseek( pFile, 0X00, SEEK_SET );
   // allocate the buffer
   pBuffer = ( char * )malloc( dwSize );
   // Read this file contents
   fread( pBuffer, 0X01, dwSize, pFile );
   // Close this file
   fclose( pFile );
   // Send out this packet
   SendHiQoSMessage( 0X00, ( short )0XA117, pBuffer, dwSize );
   // delete this buffer
   free( pBuffer );
   // The initial time counter
   dwTimerA = GetTickCount();
   // The default Tx progress
   iProgress = 0XFF;
   // Query the TxStatus
   while ( 0X01 )
   {
      // Release the control of the processor
      Sleep( 0X01 );
      // Query the Tx status
      QueryTxMsgStatus( 0X00, ( char * )&iStatus );
      // Check if end of the Tx procedure
      if ( iStatus & TXD_TASK_STATUS_REPORTTABLE )
      {
         break;
      }
      // Compare the progress value
      if ( iStatus == iProgress )
      {
         continue;
      }
      // Current time counter
      dwTimerB = GetTickCount();
      // The offset timer
      dwTimerX = dwTimerB - dwTimerA;
     
      // Update the progress value
      iProgress = iStatus;
      // Current Tx progress
      printf( "%9lu ms --> %d%%\r\n", dwTimerX, iStatus );
   }
   // Query the Tx timer
   GetTxMessageTime( 0X00, &dwTimerX );
   // The task completed status
   switch ( iStatus )
   {
   case TXD_TASK_STATUS_END_SUCCESS:
      {
         printf( "\r\nTx Completed Successfully,Time=%lu(ms)\r\n\r\n", dwTimerX );
      }
      break;
   case TXD_TASK_STATUS_END_FAILURE:
      {
         printf( "\r\nTx Completed With Error,Time=%lu(ms)\r\n\r\n", dwTimerX );
      }
      break;
   case TXD_TASK_STATUS_END_NOCRC32:
      {
         printf( "\r\nTx Completed Without CRC32,Time=%lu(ms)\r\n\r\n", dwTimerX );
      }
      break;
   default:
      {
         printf( "\r\nTx Completed With Unknown Error,Time=%lu(ms)\r\n\r\n", dwTimerX );
      }
      break;
   }
   
   // Stop the shell
   StopWiMinetShell( 0X00 );
   
   // Exit this main program
   return 0X01;
}



5.8 测试程序说明

程序基本的逻辑如下:

  1. 查询发送队列,是否处于空闲状态,如果没有需要等待当前发送任务完成

  2. 提示输入需要传输的文件名称

  3. 读取文件的总长度

  4. 分配相应长度的内存块

  5. 将文件内容加载到内存块

  6. 关闭文件

  7. 将内存块中的内容提交给发送队列

  8. 释放之前分配的内存块

  9. 查询发送状态,打印发送时间和进度信息

  10. 查询发送任务是否已经结束

  11. 打印发送的结果信息


阅读0
分享
写下您的评论吧