gamerf.h
-------------------------
#ifndef __gamerf_h__
#define __gamerf_h__
#define COMM_RF_CONNECT 0x01
//////////////////RF///////////////
void RfModeInit(void);
void RfConnect(int count,int * p_id);
void SendRfData(unsigned char data);
void PutLinkComm(unsigned char data);
void WaitReady(void);
int GetRfData(uchar * p_data, int flag_block);
unsigned char GetLinkComm(unsigned char * data);
void Disconnect(void);
#endif
-------------------------
gamerf.c
-----------------------
#include "gpnetlib.h"
#include "gpcomm.h"
#include "gpsockdef.h"
#include "gamerf.h"
GPN_DESC m_desc;
GPN_COMM rf_comm,net_comm;
void RfModeInit(void) //RF ├╩▒т╚н ╟╤┤┘.
{
int err;
m_desc.port_kind = COMM_APP_RF;
m_desc.tr_buf_size = 1024;
m_desc.tr_rate = 19200;
m_desc.isr_comm_ram = NULL;
gp_str_func.memset(&rf_comm, 0, sizeof(GPN_COMM));
if ( GpCommCreate(&m_desc,&rf_comm) )
{
//error
while ( 1 )
;
}
err = rf_comm.comm_open(&m_desc);
if ( err )
{
//error
while ( 1 )
;
}
}
void RfConnect(int count, int * p_id)
{
unsigned char data1,data2;
PutLinkComm(COMM_RF_CONNECT); //Connection ┐ф├╗
PutLinkComm(count-1);
while(!GetLinkComm(&data1)); //Connected └└┤ф┤ы▒т
while(!GetLinkComm(&data2));
*p_id = (int)data2;
}
/*******************╡е└╠┼═Transfer*************************/
void SendRfData(unsigned char data)
{
PutLinkComm(0x10);
PutLinkComm(data);
WaitReady();
}
void PutLinkComm(unsigned char data)
{
if ( !rf_comm.comm_send_one(data) )
{
//error
while ( 1 )
;
}
}
void WaitReady(void)
{
unsigned char data1,data2;
data1 = 0;
do{
while(!GetLinkComm(&data1));
while(!GetLinkComm(&data2));
}while(data1 != 0x10);
}
/***********************************************************/
/*******************╡е└╠┼═Receive**************************/
int GetRfData(uchar * p_data, int flag_block)
{
unsigned char data1,data2;
do{
if ( GetLinkComm(&data1) )
{
while (!GetLinkComm(&data2));
*p_data = data2;
return 1;
}
}while (flag_block);
return 0;
}
unsigned char GetLinkComm(unsigned char * data) //╡е└╠┼═Receive
{
return rf_comm.comm_recv_one(data);
}
/***********************************************************/
void Disconnect(void) //DisConect┐ф├╗
{
PutLinkComm(0x04);
PutLinkComm(0x00);
rf_comm.comm_close();
GpCommDelete(&m_desc);
}