📄 ftp.cpp
字号:
//Copyright May 2000 Cambridge Silicon Radio
//a simple application which shows how packets can be sent from
//one bcsp stack to another
//This code is unsupported and is intended only as an example.
#include "stdafx.h"
#include "envdefs.h"
#include "BCProtocols.h"
#include "win32bcsp.h"
//continueRead
//called every time that a callback is received
void continueRead(BCTransferRequest * req, BCTransferStatus status,void * vcount)
{
uint32 *count = (uint32 *) vcount ;
static uint8 rcvBuf [100] ;
switch (status)
{
case transferComplete:
{
if (*count)
{
printf("getting data count %d\n",*count) ;
BCreloadTransferRequest(req,rcvBuf,sizeof(rcvBuf)) ;
BCreadPacket(BC_HCI_ACL,req) ;
*count = *count -1 ;
}
else
{
free(req) ;
}
}
break ;
case transferCancelled:
printf("Error - transfer cancelled\n") ;
break ;
default :
break ;
}
}
void doRead(uint32*count)
{
BCTransferRequest * req = (BCTransferRequest*) calloc(1,sizeof(BCTransferRequest)) ;
BCinitTransferRequest(req,0,0,continueRead,(void*) count) ;
continueRead(req,transferComplete,count) ;
}
//continue write
//called every time a write callback is received
void continueWrite(BCTransferRequest * req, BCTransferStatus status,void * vcount)
{
uint32 * count = (uint32*) vcount ;
static uint8 xmitBuf [100] ;
switch (status)
{
case transferComplete:
{
if (*count)
{
printf("sending data count %d\n",*count) ;
BCreloadTransferRequest(req,xmitBuf,sizeof(xmitBuf)) ;
BCwritePacket(BC_HCI_ACL,req) ;
*count = *count -1 ;
}
else
{
free(req) ;
}
}
break ;
case transferCancelled:
printf("Error - transfer cancelled\n") ;
break ;
default :
break ;
}
}
void doWrite(uint32 * count)
{
BCTransferRequest * req = (BCTransferRequest*) calloc(1,sizeof(BCTransferRequest)) ;
BCinitTransferRequest(req,0,0,continueWrite,(void*) count) ;
continueWrite(req,transferComplete,count) ;
}
int main(int argc, char* argv[])
{
if (argc ==1)
{
printf("usage is ftp com [write]\n") ;
printf("Eg ftp com2 write\n") ;
return 0 ;
}
Win32BCSP winStack ;
char * cfgStr = "baud=115200 parity=e stop=1 data=8 rts=on dtr=on" ;
if (!winStack.open(argv[1],cfgStr))
{
printf("Error - couldn't open port '%s'\n",argv[1]) ;
return 0 ;
}
BTRACEDISABLE(0xffffffff) ;
winStack.start() ;
if (!winStack.connect(5000))
{
printf("Couldn't establish link with peer\n") ;
return 0;
}
initialiseBCProtocols(winStack.getBCSPStack()) ;
if (!BCopenChannel(BC_HCI_ACL))
{
printf("Couldn't open HCI_ACL channel\n") ;
return 0 ;
}
uint32 count =100 ;;
if (argv[2]) doWrite(&count);
else doRead(&count) ;
while (1) Sleep(100) ;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -