我试图通过串行线将一些Hayes命令(AT命令)发送到我的调制解调器。
我调用的函数是post_request::open()
。在此方法中,有一个静态命令字符串数组,其中包含用于配置连接配置文件的命令。
我的第一个问题是:我应该使用更多"灵活的"创建命令列表的方法?
我总是需要将这八个命令发送到我的调制解调器。当然,url,content_type和content_length会有所不同。
也许有人可以告诉我更好的方法。
int post_request::open(const char *url, unsigned content_length, const char *content_type)
{
static const char *commands[] =
{
// Connection profile
"AT^SISS=0,conId,0;",
// HTTP
"AT^SISS=0,srvType,Http;",
// User Agent
"AT^SISS=0,hcUsrAgent," USER_AGENT_STRING ";",
// HTTP method
"AT^SISS=0,hcMethod,1;",
// Placeholder for modem type bdx80
"AT;",
// Placeholder for address
"AT;",
// Placeholder for number of bytes sent
"AT;",
// Placeholder for content type
"AT;",
// Open internet session with configured profile
"AT^SISO=0\r",
NULL
};
// Some code...
if (modem->modem_type == bdx80)
commands[4] = "AT^SISS=0,secOpt,-1;";
// Some more code...
commands[6] = "AT^SISS=0,hcContLen,",content_length,";";
// Code for content_type settings...
int error = send_commands(modem, timeout, commands);
if (error)
return error;
}
完成连接配置文件设置后,我致电send_commands()
。
我有一个第三方库,用于uart传输和放大器。接收东西。
我在send_commands()
中调用的函数是uart_tx()
。
问题:我需要做什么才能正确拨打uart_tx()
?我希望立即发送完整的命令列表。
THX
static int
send_commands(modem_t *modem, unsigned timeout, const char *commands[])
{
// determine size of commands pointer array
unsigned len = ???;
// Send commands through serial line
if (uart_tx(modem->port, ???, &len, timeout))
return TIMEOUT;
}
/**
* Sends count bytes.
* @param port The serial port.
* @param buf[in] Pointer to the buffer containing the bytes to be sent.
* @param count[in,out] Pointer to the value containing the number of bytes to send
* (in) and the number of bytes actually sent (out).
* @param time_to_wait The maximum amount of time the task should block waiting
* for count bytes to be sent should the transmit queue be full at some time.
* @return 0 on successful transmission, 1 on timeout
*/
unsigned uart_tx(SerialPort port, const void *buf, unsigned *count, unsigned time_to_wait)
答案 0 :(得分:0)
在将它们发送出去之前,您似乎只想将所有命令(memcpy或strcat或其他)连接到单个缓冲区中。