drivers: modem: sara-r4: adjust send and receive lengths
- limit max. number of bytes when sending to socket The number of bytes sent to a socket in one transaction is limited to 512 in HEX mode (Sara-R4), and to 1024 otherwise. This corresponds to numbers given in the manual for ublox cellular modems. - report number of bytes actually sent, as reported by modem After writing data to a socket, we now return the number of bytes actually written, as reported by the modem. Signed-off-by: Hans Wilmers <hans@wilmers.no>
This commit is contained in:
parent
a18f78894f
commit
97921368d3
|
@ -144,6 +144,9 @@ struct modem_data {
|
|||
/* modem state */
|
||||
int ev_creg;
|
||||
|
||||
/* bytes written to socket in last transaction */
|
||||
int sock_written;
|
||||
|
||||
/* response semaphore */
|
||||
struct k_sem sem_response;
|
||||
};
|
||||
|
@ -250,6 +253,24 @@ static ssize_t send_socket_data(struct modem_socket *sock,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_MODEM_UBLOX_SARA_R4)
|
||||
/* Hex mode allows sending 512 bytes to the socket in one command */
|
||||
if (buf_len > (MDM_MAX_DATA_LENGTH / 2)) {
|
||||
buf_len = (MDM_MAX_DATA_LENGTH / 2);
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* Binary and ASCII mode allows sending MDM_MAX_DATA_LENGTH bytes to
|
||||
* the socket in one command
|
||||
*/
|
||||
if (buf_len > MDM_MAX_DATA_LENGTH) {
|
||||
buf_len = MDM_MAX_DATA_LENGTH;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The number of bytes written will be reported by the modem */
|
||||
mdata.sock_written = 0;
|
||||
|
||||
if (sock->ip_proto == IPPROTO_UDP) {
|
||||
ret = modem_context_get_addr_port(dst_addr, &dst_port);
|
||||
snprintk(send_buf, sizeof(send_buf),
|
||||
|
@ -318,7 +339,7 @@ exit:
|
|||
return ret;
|
||||
}
|
||||
|
||||
return buf_len;
|
||||
return mdata.sock_written;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -464,9 +485,8 @@ MODEM_CMD_DEFINE(on_cmd_sockcreate)
|
|||
/* Handler: +USO[WR|ST]: <socket_id>[0],<length>[1] */
|
||||
MODEM_CMD_DEFINE(on_cmd_sockwrite)
|
||||
{
|
||||
/* TODO: check length against original send length*/
|
||||
|
||||
/* don't give back semaphore -- OK to follow */
|
||||
mdata.sock_written = ATOI(argv[1], 0, "length");
|
||||
LOG_DBG("bytes written: %d", mdata.sock_written);
|
||||
}
|
||||
|
||||
/* Common code for +USOR[D|F]: "<hex_data>" */
|
||||
|
|
Loading…
Reference in a new issue