Cancel the message in flight, and the small things from the review
rb9704_cancel() and `rb9704 cancel` ask the modem to abandon the MO in flight; the modem's final status reaches mo_done as -ECANCELED. The library's async path has no timeout, so this is how an application frees a modem that has gone quiet mid-send. The status snapshot carries the in-flight message's id and start time for the application to decide with. rb9704_begin zeroes moQueuedMessages: rbBegin empties the queue but not the count, and a count above zero makes every later send queue without transmitting. The fake modem's mo-hold and mo-release stand in for a modem that has taken a message and said nothing more; a test drives cancel through it. Also: the shell's send buffer is a shell line, not a fourth message buffer; the bridge's TX-disable race has a comment; the CLI turns a Cloudloop error (a bad token's 200 reply included), an unopenable port and a one-word jspr line into one line and exit 1; conftest reads request.node; pyproject uses the current license spelling.
This commit is contained in:
1 parent
509b9b5b6d
commit
f97fcab74b
13 files changed
+235
-34
No files matched your search
+23
-11
@@ -34,6 +34,8 @@ static const char *err_name(int rc)
|
||||
case EINPROGRESS: return "EINPROGRESS";
|
||||
case ENOTSUP: return "ENOTSUP";
|
||||
case EDEADLK: return "EDEADLK";
|
||||
case ENOENT: return "ENOENT";
|
||||
case ECANCELED: return "ECANCELED";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
@@ -90,8 +92,11 @@ static int cmd_status(const struct shell *sh, size_t argc, char **argv)
|
||||
} else {
|
||||
shell_print(sh, "topics provisioning not seen yet");
|
||||
}
|
||||
shell_print(sh, "mo %u sent, %u failed%s", s.mo_sent, s.mo_failed,
|
||||
s.mo_in_flight ? ", one in flight" : "");
|
||||
shell_print(sh, "mo %u sent, %u failed", s.mo_sent, s.mo_failed);
|
||||
if (s.mo_in_flight) {
|
||||
shell_print(sh, " one in flight: topic %u id %u, %lld s so far", s.mo_topic,
|
||||
s.mo_id, (k_uptime_get() - s.mo_started_ms) / 1000);
|
||||
}
|
||||
shell_print(sh, "mt %u received, %u failed", s.mt_received, s.mt_failed);
|
||||
shell_print(sh, "serial %u bytes dropped", s.rx_dropped);
|
||||
return 0;
|
||||
@@ -153,24 +158,30 @@ static int unhex(const char *s, uint8_t *out, size_t cap)
|
||||
|
||||
static int cmd_send(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
static uint8_t buf[CONFIG_RB9704_MESSAGE_MAX];
|
||||
/* An argument cannot be longer than the shell's line, and two hex
|
||||
* digits make a byte. rb9704_send copies, so text goes as it is. */
|
||||
static uint8_t hexbuf[CONFIG_SHELL_CMD_BUFF_SIZE / 2];
|
||||
unsigned long topic = strtoul(argv[1], NULL, 10);
|
||||
bool hex = strcmp(argv[0], "sendhex") == 0;
|
||||
int len;
|
||||
const uint8_t *data = (const uint8_t *)argv[2];
|
||||
int len = strlen(argv[2]);
|
||||
|
||||
ARG_UNUSED(argc);
|
||||
if (hex) {
|
||||
len = unhex(argv[2], buf, sizeof(buf));
|
||||
} else {
|
||||
len = MIN(strlen(argv[2]), sizeof(buf));
|
||||
memcpy(buf, argv[2], len);
|
||||
if (strcmp(argv[0], "sendhex") == 0) {
|
||||
len = unhex(argv[2], hexbuf, sizeof(hexbuf));
|
||||
data = hexbuf;
|
||||
}
|
||||
if (len <= 0) {
|
||||
shell_error(sh, "nothing to send (%d)", len);
|
||||
return -EINVAL;
|
||||
}
|
||||
shell_print(sh, "%d bytes on topic %lu: this costs airtime", len, topic);
|
||||
return report(sh, "send", rb9704_send((uint16_t)topic, buf, len, WAIT));
|
||||
return report(sh, "send", rb9704_send((uint16_t)topic, data, len, WAIT));
|
||||
}
|
||||
|
||||
static int cmd_cancel(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
ARG_UNUSED(argc); ARG_UNUSED(argv);
|
||||
return report(sh, "cancel", rb9704_cancel(WAIT));
|
||||
}
|
||||
|
||||
static int cmd_spy(const struct shell *sh, size_t argc, char **argv)
|
||||
@@ -192,6 +203,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(rb9704_cmds,
|
||||
SHELL_CMD(signal, NULL, "signal bars now", cmd_signal),
|
||||
SHELL_CMD_ARG(send, NULL, "send <topic> <text>: one message, costs airtime", cmd_send, 3, 0),
|
||||
SHELL_CMD_ARG(sendhex, NULL, "sendhex <topic> <hex>: one message, costs airtime", cmd_send, 3, 0),
|
||||
SHELL_CMD(cancel, NULL, "ask the modem to abandon the message in flight", cmd_cancel),
|
||||
SHELL_CMD_ARG(spy, NULL, "spy on|off: print every JSPR line", cmd_spy, 2, 0),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
|
||||
+48
-6
@@ -46,7 +46,7 @@
|
||||
|
||||
LOG_MODULE_REGISTER(rb9704, CONFIG_RB9704_LOG_LEVEL);
|
||||
|
||||
enum op { OP_BEGIN, OP_END, OP_SEND, OP_INFO, OP_SIGNAL, OP_POWER };
|
||||
enum op { OP_BEGIN, OP_END, OP_SEND, OP_CANCEL, OP_INFO, OP_SIGNAL, OP_POWER };
|
||||
enum req_state { REQ_PENDING, REQ_DONE, REQ_ABANDONED };
|
||||
|
||||
static struct {
|
||||
@@ -74,6 +74,7 @@ static K_MUTEX_DEFINE(rb9704_st_lock);
|
||||
|
||||
static const struct rb9704_callbacks *app;
|
||||
static bool mt_waiting;
|
||||
static bool mo_cancel_asked; /* so the failure that follows reads -ECANCELED */
|
||||
|
||||
#if !IS_ENABLED(CONFIG_RB9704_POWER)
|
||||
int rb9704_power_init(void)
|
||||
@@ -99,14 +100,19 @@ bool rb9704_power_present(void)
|
||||
|
||||
static void cb_mo_started(const uint16_t id)
|
||||
{
|
||||
k_mutex_lock(&rb9704_st_lock, K_FOREVER);
|
||||
st.mo_id = id;
|
||||
st.mo_started_ms = k_uptime_get();
|
||||
k_mutex_unlock(&rb9704_st_lock);
|
||||
LOG_DBG("MO accepted by the modem: id %u", id);
|
||||
}
|
||||
|
||||
static void cb_mo_complete(const uint16_t id, const rbMsgStatus_t status)
|
||||
{
|
||||
uint16_t topic;
|
||||
int result = status == RB_MSG_STATUS_OK ? 0 : -EIO;
|
||||
int result = status == RB_MSG_STATUS_OK ? 0 : mo_cancel_asked ? -ECANCELED : -EIO;
|
||||
|
||||
mo_cancel_asked = false;
|
||||
k_mutex_lock(&rb9704_st_lock, K_FOREVER);
|
||||
st.mo_in_flight = false;
|
||||
topic = st.mo_topic;
|
||||
@@ -116,7 +122,8 @@ static void cb_mo_complete(const uint16_t id, const rbMsgStatus_t status)
|
||||
st.mo_failed++;
|
||||
}
|
||||
k_mutex_unlock(&rb9704_st_lock);
|
||||
LOG_INF("MO %s: topic %u id %u", result == 0 ? "sent" : "failed", topic, id);
|
||||
LOG_INF("MO %s: topic %u id %u",
|
||||
result == 0 ? "sent" : result == -ECANCELED ? "cancelled" : "failed", topic, id);
|
||||
if (app != NULL && app->mo_done != NULL) {
|
||||
app->mo_done(topic, id, result, app->user);
|
||||
}
|
||||
@@ -180,6 +187,16 @@ static const rbCallbacks_t callbacks = {
|
||||
|
||||
/* --- the requests, on this thread --------------------------------------- */
|
||||
|
||||
/* Two of the library's globals, as of the commit west.yml pins (v1.0.1);
|
||||
* neither is static there, and a bump of the pin should check they still
|
||||
* are not. messageProvisioningInfo is its provisioning cache (op_send).
|
||||
* moQueuedMessages counts the MOs it holds; rbBegin empties the queue but
|
||||
* leaves the count, and a count above zero makes the next send queue
|
||||
* without transmitting, so a begin after a stuck send would never send
|
||||
* again. */
|
||||
extern jsprMessageProvisioning_t messageProvisioningInfo;
|
||||
extern uint16_t moQueuedMessages;
|
||||
|
||||
static int op_begin(void)
|
||||
{
|
||||
if (st.begun) {
|
||||
@@ -199,8 +216,11 @@ static int op_begin(void)
|
||||
if (!rbBegin("zephyr")) { /* the port name is unused: the UART is in devicetree */
|
||||
return -EIO;
|
||||
}
|
||||
moQueuedMessages = 0; /* rbBegin emptied the queue; this is the count of it */
|
||||
mo_cancel_asked = false;
|
||||
k_mutex_lock(&rb9704_st_lock, K_FOREVER);
|
||||
st.begun = true;
|
||||
st.mo_in_flight = false;
|
||||
k_mutex_unlock(&rb9704_st_lock);
|
||||
return 0;
|
||||
}
|
||||
@@ -234,9 +254,7 @@ static bool topic_provisioned(uint16_t topic)
|
||||
* keeps the answer for good, a miss included, so a modem provisioned after
|
||||
* that would refuse every topic until a reboot. When the topic is not in
|
||||
* what it kept, clear the cache and the library asks again: one free JSPR
|
||||
* round trip. messageProvisioningInfo is the library's own global. */
|
||||
extern jsprMessageProvisioning_t messageProvisioningInfo;
|
||||
|
||||
* round trip. */
|
||||
static int op_send(void)
|
||||
{
|
||||
bool known;
|
||||
@@ -271,6 +289,24 @@ static int op_send(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The modem answers a cancel with a 299 messageOriginateStatus, which the
|
||||
* library reads in rbPoll as a failed MO and removes from its queue; the
|
||||
* flag set here turns that failure into -ECANCELED in cb_mo_complete. */
|
||||
static int op_cancel(void)
|
||||
{
|
||||
if (!st.begun) {
|
||||
return -ENOTCONN;
|
||||
}
|
||||
if (!st.mo_in_flight) {
|
||||
return -ENOENT;
|
||||
}
|
||||
if (!rbCancelMessage(st.mo_topic, st.mo_id)) {
|
||||
return -EIO;
|
||||
}
|
||||
mo_cancel_asked = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void copy_str(char *dst, size_t cap, const char *src)
|
||||
{
|
||||
if (src != NULL) {
|
||||
@@ -349,6 +385,7 @@ static int dispatch(void)
|
||||
case OP_BEGIN: return op_begin();
|
||||
case OP_END: return op_end();
|
||||
case OP_SEND: return op_send();
|
||||
case OP_CANCEL: return op_cancel();
|
||||
case OP_INFO: return op_info();
|
||||
case OP_SIGNAL: return op_signal();
|
||||
case OP_POWER: return op_power();
|
||||
@@ -468,6 +505,11 @@ int rb9704_signal(k_timeout_t timeout)
|
||||
return simple(OP_SIGNAL, timeout);
|
||||
}
|
||||
|
||||
int rb9704_cancel(k_timeout_t timeout)
|
||||
{
|
||||
return simple(OP_CANCEL, timeout);
|
||||
}
|
||||
|
||||
int rb9704_info(struct rb9704_info *out, k_timeout_t timeout)
|
||||
{
|
||||
bool abandoned;
|
||||
|
||||
Reference in new issue
Block a user