?? ag_data.c
字號:
#include "ag_private.h"
#include "ag_parse.h"
#include "ag.h"
#include <message.h>
#include <print.h>
#include <sched.h>
#include <string.h>
/*
agSendATmessage
Send an AT command to the remote device
*/
uint16 agSendATmessage(const char *at_cmd, uint16 length)
{
uint16 sink_slack = SinkSlack(AGState.rfcDataOutgoing);
{
uint16 i=0;
PRINT(("sendATmessage: len 0x%x", length));
for (i=0; i<length; i++)
{
PRINT(("%c", at_cmd[i]));
}
PRINT(("\n"));
}
if (sink_slack >= length)
{
uint16 flush_result = 0;
uint16 sink_offset = SinkClaim(AGState.rfcDataOutgoing, length);
uint8 *data_out = SinkMap(AGState.rfcDataOutgoing);
if (data_out != NULL)
{
#ifdef BE_EVIL
uint16 ix=0;
for(ix=0; ix<length; ix++)
{
memcpy(data_out+sink_offset, at_cmd+ix, 1);
flush_result = SinkFlush(AGState.rfcDataOutgoing, 1);
if (!flush_result)
break;
}
PRINT(("flush result %d\n", flush_result));
return flush_result;
#else
memcpy(data_out+sink_offset, at_cmd, length);
flush_result = SinkFlush(AGState.rfcDataOutgoing, length);
PRINT(("flush result %d\n", flush_result));
return flush_result;
#endif
}
else
{
PRINT(("SinkMap returned invalid data ptr\n"));
return 0;
}
}
else
{
PRINT(("Insufficient bytes available sink slack: 0x%x bytes\n",
sink_slack));
return 0;
}
}
/*
handleSourceEvent
Called by the scheduler when a source event occurs indicating there
is incoming data available
*/
void handleSourceEvent(void)
{
/* Check we think we're connected before handling RFCOMM data */
if (agRfcommConnectedQuery() || agIsCurrentlyHandsFree())
{
uint16 length = SourceSize(AGState.rfcDataIncoming);
{
/* Used for debug only */
uint16 i;
const uint8 *data = SourceMap(AGState.rfcDataIncoming);
data = data; /* keep the compiler happy */
PRINT(("data to parse len 0x%x\n", length));
for(i=0; i<length; i++)
{
PRINT(("%c ", data[i]));
}
PRINT(("\n"));
}
/* Only bother parsing if there's something to parse */
while (length > 0)
{
if (!parseSource(AGState.rfcDataIncoming, &AGState.remote_addr))
break;
length = SourceSize(AGState.rfcDataIncoming);
}
}
}
/*
agDataReqAction
This message (as received from the headset) does not contain any
recognisable AT command so assume it contains application specific
data and pass it as it is to the client.
*/
void agDataReqAction(uint16 length, const uint8 *data)
{
/* Make sure we have a connection up */
if (agRfcommConnectedQuery())
{
(void) agSendATmessage((char *)data, length);
}
else
{
/* otherwise send an error message */
agSendErrorToClient(AgErrorUnexpectedPrimitive, 0);
}
}
/*
agButtonPressInd
Button press message received, send it up to the client.
*/
void agButtonPressInd(BD_ADDR_T addr)
{
/* stop sending ring alerts */
agStopRings();
/* Inform the interface that a button press has been received */
handleButtonPressInd(agGetConnectionHandle(&addr));
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -