This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于BLE CC2540 数据透传问题,

Other Parts Discussed in Thread: CC2540

在用CC2540透传数据时,目的传输24byte,先将2540配置为server和client,设置每次发送15byte,然后将24byte分成12byte+12byte,先从串口获取24byte,然后两次传输完,但从client到server的数据可以实现24byte传输,从server到client,只有前12byte。因为串口获取数据都是下面的函数,感觉在server中第二个osal_msg_send()似乎没有执行,希望大神们看下是什么原因:

//串口回调函数 OnBoard.c中
static void SerialCallback( uint8 port, uint8 event )
{
mtOSALSerialData_t *pMsgSerial;
uint8 flag=0;
uint32 i,j=0; //flag是判断有没有收到数据,j记录数据长度
uint8 buf[24]; //串口buffer最大缓冲默认是12,我们这里用12.
uint8 buf1[12];
uint8 buf2[12];

(void)event; // Intentionally unreferenced parameter
while (Hal_UART_RxBufLen(port)) //检测串口数据是否接收完成 ;
{
HalUARTRead (port,&buf[j], 1); //把数据接收放到buf中
j++; //记录字符数
flag=1; //已经从串口接收到信息
}

for(i=0;i<12;i++)
buf1[i]=buf[i];
for(i=0;i<12;i++)
buf2[i]=buf[i+12];

if(flag==1) //已经从串口接收到信息
{
// Allocate memory for the data /
//分配内存空间,为机构体内容+数据内容+1个记录长度的数据
//分段发送buf1
pMsgSerial = (mtOSALSerialData_t *)osal_msg_allocate( sizeof
( mtOSALSerialData_t )+12+1);
pMsgSerial->hdr.event = SERIAL_MSG; // 事件号用SERIAL_MSG,需要添加
pMsgSerial->msg = (uint8*)(pMsgSerial+1); // 把数据定位到结构体数据部分
pMsgSerial->msg [0]= 12; //给上层的数据第一个是长度
for(i=0;i<12;i++) //从第二个开始记录数据
pMsgSerial->msg [i+1]= buf1[i];
osal_msg_send( registeredSerialTaskID, (uint8 *)pMsgSerial ); //登记任务,发往上层
// deallocate the msg//
osal_msg_deallocate ( (uint8 *)pMsgSerial ); //释放内存

//分段发送buf2
pMsgSerial = (mtOSALSerialData_t *)osal_msg_allocate( sizeof
( mtOSALSerialData_t )+12+1);
pMsgSerial->hdr.event = SERIAL_MSG; // 事件号用SERIAL_MSG,需要添加
pMsgSerial->msg = (uint8*)(pMsgSerial+1); // 把数据定位到结构体数据部分
pMsgSerial->msg [0]= 12; //给上层的数据第一个是长度
for(i=0;i<12;i++) //从第二个开始记录数据
pMsgSerial->msg [i+1]= buf2[i];
osal_msg_send( registeredSerialTaskID, (uint8 *)pMsgSerial ); //登记任务,发往上层
// deallocate the msg//
osal_msg_deallocate ( (uint8 *)pMsgSerial ); //释放内存
}