feat: add binary AT support
This commit is contained in:
parent
3ec8b74f47
commit
3c7e07c88d
@ -142,6 +142,8 @@ int run_op(PROFILE_T *profile,FDS_T *fds)
|
||||
{
|
||||
case AT_OP:
|
||||
return at(profile,fds);
|
||||
case BINARY_AT_OP:
|
||||
return binary_at(profile,fds);
|
||||
case SMS_READ_OP:
|
||||
return sms_read(profile,fds);
|
||||
case SMS_SEND_OP:
|
||||
|
@ -22,6 +22,8 @@ extern PROFILE_T s_profile; // global profile
|
||||
|
||||
extern int at(PROFILE_T *profile,FDS_T *fds);
|
||||
|
||||
extern int binary_at(PROFILE_T *profile,FDS_T *fds);
|
||||
|
||||
extern int sms_read(PROFILE_T *profile,FDS_T *fds);
|
||||
|
||||
extern int sms_send(PROFILE_T *profile,FDS_T *fds);
|
||||
|
@ -34,6 +34,8 @@
|
||||
//operations
|
||||
#define AT_OP_S 'a'
|
||||
#define AT_OP_L "at"
|
||||
#define BINARY_AT_OP_S 'b'
|
||||
#define BINARY_AT_OP_L "binary_at"
|
||||
#define SMS_READ_OP_S 'r'
|
||||
#define SMS_READ_OP_L "sms_read"
|
||||
#define SMS_SEND_OP_S 's'
|
||||
@ -109,6 +111,7 @@ enum ERROR_CODES {
|
||||
KEYWORD_NOT_MATCH,
|
||||
TIMEOUT_WAITING_NEWLINE,
|
||||
INVALID_PARAM,
|
||||
INVALID_HEX,
|
||||
UNKNOWN_ERROR,
|
||||
};
|
||||
|
||||
@ -135,6 +138,7 @@ enum OPTIONS {
|
||||
enum OPERATIONS {
|
||||
NULL_OP,
|
||||
AT_OP,
|
||||
BINARY_AT_OP,
|
||||
SMS_READ_OP,
|
||||
SMS_SEND_OP,
|
||||
SMS_DELETE_OP
|
||||
|
@ -25,6 +25,48 @@ int at(PROFILE_T *profile,FDS_T *fds)
|
||||
user_msg("%s", output);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int binary_at(PROFILE_T *profile,FDS_T *fds)
|
||||
{
|
||||
int w_ret,r_ret,hex_convert_ret;
|
||||
int binary_at_cmd_len;
|
||||
char *binary_at_cmd;
|
||||
char output[COMMON_BUF_SIZE] = {0};
|
||||
if (profile->at_cmd == NULL)
|
||||
{
|
||||
err_msg("AT command is empty");
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (strlen(profile->at_cmd) % 2 != 0)
|
||||
{
|
||||
err_msg("Invalid AT command length");
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
binary_at_cmd = (char *)malloc(strlen(profile->at_cmd) / 2 + 1);
|
||||
hex_convert_ret = str_to_hex(profile->at_cmd, binary_at_cmd);
|
||||
if (binary_at_cmd == NULL || hex_convert_ret)
|
||||
{
|
||||
err_msg("Binary AT command is empty");
|
||||
return INVALID_PARAM;
|
||||
}
|
||||
|
||||
w_ret = tty_write_raw(fds->fdo, binary_at_cmd);
|
||||
if (w_ret)
|
||||
{
|
||||
return w_ret;
|
||||
}
|
||||
r_ret = tty_read_keyword(fds->fdi, output, COMMON_BUF_SIZE, "OK",profile->timeout);
|
||||
if (r_ret)
|
||||
{
|
||||
dbg_msg("Error sending AT command, error code: %d", r_ret);
|
||||
if (r_ret == COMM_ERROR)
|
||||
return r_ret;
|
||||
}
|
||||
user_msg("%s", output);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int sms_delete(PROFILE_T *profile,FDS_T *fds)
|
||||
{
|
||||
int w_ret,r_ret;
|
||||
|
@ -3,8 +3,10 @@
|
||||
#include "modem_types.h"
|
||||
#include "ttydevice.h"
|
||||
#include "utils.h"
|
||||
int str_to_hex(char *str, char *hex);
|
||||
int tty_open_device(PROFILE_T *profile, FDS_T *fds);
|
||||
int tty_read(FILE *fdi, char *output, int len, int soft_timeout);
|
||||
int tty_read_keyword(FILE *fdi, char *output, int len, char *key_word, int soft_timeout);
|
||||
int tty_write_raw(FILE *fdo, char *input);
|
||||
int tty_write(FILE *fdo, char *input);
|
||||
#endif
|
||||
|
@ -186,6 +186,20 @@ int tty_read_keyword(FILE *fdi, char *output, int len, char *key_word, int soft_
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
int tty_write_raw(FILE *fdo, char *input)
|
||||
{
|
||||
int ret;
|
||||
ret = fputs(input, fdo);
|
||||
fflush(fdo);
|
||||
usleep(100);
|
||||
if (ret < 0)
|
||||
{
|
||||
err_msg("Error writing to tty %d" , ret);
|
||||
return COMM_ERROR;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int tty_write(FILE *fdo, char *input)
|
||||
{
|
||||
int cmd_len, ret;
|
||||
@ -198,14 +212,7 @@ int tty_write(FILE *fdo, char *input)
|
||||
return COMM_ERROR;
|
||||
}
|
||||
snprintf(cmd_line, cmd_len, "%s\r\n", input);
|
||||
ret = fputs(cmd_line, fdo);
|
||||
ret = tty_write_raw(fdo, cmd_line);
|
||||
free(cmd_line);
|
||||
fflush(fdo);
|
||||
usleep(100);
|
||||
if (ret < 0)
|
||||
{
|
||||
err_msg("Error writing to tty %d" , ret);
|
||||
return COMM_ERROR;
|
||||
}
|
||||
return SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
@ -238,6 +238,8 @@ int match_operation(char *operation_name)
|
||||
{
|
||||
case AT_OP_S:
|
||||
return AT_OP;
|
||||
case BINARY_AT_OP_S:
|
||||
return BINARY_AT_OP;
|
||||
case SMS_READ_OP_S:
|
||||
return SMS_READ_OP;
|
||||
case SMS_SEND_OP_S:
|
||||
@ -255,6 +257,10 @@ int match_operation(char *operation_name)
|
||||
{
|
||||
return AT_OP;
|
||||
}
|
||||
else if (strcmp(operation_name, BINARY_AT_OP_L) == 0)
|
||||
{
|
||||
return BINARY_AT_OP;
|
||||
}
|
||||
else if (strcmp(operation_name, SMS_READ_OP_L) == 0)
|
||||
{
|
||||
return SMS_READ_OP;
|
||||
@ -337,16 +343,36 @@ int usage(char* name)
|
||||
err_msg(" -b, --baud_rate <baud rate> Baud rate Default: 115200 Supported: 4800,9600,19200,38400,57600,115200");
|
||||
err_msg(" -B, --data_bits <data bits> Data bits Default: 8 Supported: 5,6,7,8");
|
||||
err_msg(" -t, --timeout <timeout> Timeout Default: 3");
|
||||
err_msg(" -o, --operation <operation> Operation(at[a:defualt], sms_read[r], sms_send[s], sms_delete[d])");
|
||||
err_msg(" -o, --operation <operation> Operation(at[a:defualt],binary_at[b], sms_read[r], sms_send[s], sms_delete[d])");
|
||||
err_msg(" -D, --debug Debug mode Default: off");
|
||||
err_msg(" -p, --sms_pdu <sms pdu> SMS PDU");
|
||||
err_msg(" -i, --sms_index <sms index> SMS index");
|
||||
err_msg("Example:");
|
||||
err_msg(" %s -c ATI -d /dev/ttyUSB2 -b 115200 -B 8 -o at #advance at mode set bautrate and data bit", name);
|
||||
err_msg(" %s -c ATI -d /dev/ttyUSB2 # normal at mode", name);
|
||||
err_msg(" %s -c ATI -d /dev/ttyUSB2 -o binary_at -c 4154490D0A # means sending ATI to ttyUSB2", name);
|
||||
err_msg(" %s -d /dev/mhi_DUN -o r # read sms", name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int str_to_hex(char *str, char *hex)
|
||||
{
|
||||
int len = strlen(str)/2;
|
||||
int high,low;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
high = char_to_hex(str[i*2]);
|
||||
low = char_to_hex(str[i*2+1]);
|
||||
if (high == -1 || low == -1)
|
||||
{
|
||||
return INVALID_HEX;
|
||||
}
|
||||
hex[i] = (high << 4) | low;
|
||||
dbg_msg("hex[%d]: %x", i, hex[i]);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void dump_profile()
|
||||
{
|
||||
dbg_msg("AT command: %s", s_profile.at_cmd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user