mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-25 00:14:02 +00:00
Reformat mqtt.c using astylerc
This commit is contained in:
parent
914a20728e
commit
be5bcc172d
@ -125,8 +125,7 @@ enum mqtt_connect_flag {
|
||||
static void mqtt_cyclic_timer(void *arg);
|
||||
|
||||
#if defined(LWIP_DEBUG)
|
||||
static const char * const mqtt_message_type_str[15] =
|
||||
{
|
||||
static const char *const mqtt_message_type_str[15] = {
|
||||
"UNDEFINED",
|
||||
"CONNECT",
|
||||
"CONNACK",
|
||||
@ -147,7 +146,7 @@ static const char * const mqtt_message_type_str[15] =
|
||||
/**
|
||||
* Message type value to string
|
||||
* @param msg_type see enum mqtt_message_type
|
||||
*
|
||||
*
|
||||
* @return Control message type text string
|
||||
*/
|
||||
static const char *
|
||||
@ -192,7 +191,7 @@ mqtt_ringbuf_put(struct mqtt_ringbuf_t *rb, u8_t item)
|
||||
}
|
||||
|
||||
/** Return pointer to ring buffer get position */
|
||||
static u8_t*
|
||||
static u8_t *
|
||||
mqtt_ringbuf_get_ptr(struct mqtt_ringbuf_t *rb)
|
||||
{
|
||||
return &rb->buf[rb->get];
|
||||
@ -244,8 +243,8 @@ mqtt_output_send(struct mqtt_ringbuf_t *rb, struct altcp_pcb *tpcb)
|
||||
return;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_output_send: tcp_sndbuf: %d bytes, ringbuf_linear_available: %d, get %d, put %d\n",
|
||||
send_len, ringbuf_lin_len, rb->get, rb->put));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_output_send: tcp_sndbuf: %d bytes, ringbuf_linear_available: %d, get %d, put %d\n",
|
||||
send_len, ringbuf_lin_len, rb->get, rb->put));
|
||||
|
||||
if (send_len > ringbuf_lin_len) {
|
||||
/* Space in TCP output buffer is larger than available in ring buffer linear portion */
|
||||
@ -369,7 +368,7 @@ mqtt_take_request(struct mqtt_request_t **tail, u16_t pkt_id)
|
||||
if (iter != NULL) {
|
||||
/* unchain */
|
||||
if (prev == NULL) {
|
||||
*tail= iter->next;
|
||||
*tail = iter->next;
|
||||
} else {
|
||||
prev->next = iter->next;
|
||||
}
|
||||
@ -404,7 +403,7 @@ mqtt_request_time_elapsed(struct mqtt_request_t **tail, u8_t t)
|
||||
}
|
||||
mqtt_delete_request(r);
|
||||
/* Tail might be be modified in callback, so re-read it in every iteration */
|
||||
r = *(struct mqtt_request_t * const volatile *)tail;
|
||||
r = *(struct mqtt_request_t *const volatile *)tail;
|
||||
} else {
|
||||
r->timeout_diff -= t;
|
||||
t = 0;
|
||||
@ -491,7 +490,7 @@ mqtt_output_append_string(struct mqtt_ringbuf_t *rb, const char *str, u16_t leng
|
||||
|
||||
static void
|
||||
mqtt_output_append_fixed_header(struct mqtt_ringbuf_t *rb, u8_t msg_type, u8_t fdup,
|
||||
u8_t fqos, u8_t fretain, u16_t r_length)
|
||||
u8_t fqos, u8_t fretain, u16_t r_length)
|
||||
{
|
||||
/* Start with control byte */
|
||||
mqtt_output_append_u8(rb, (((msg_type & 0x0f) << 4) | ((fdup & 1) << 3) | ((fqos & 3) << 1) | (fretain & 1)));
|
||||
@ -517,7 +516,7 @@ mqtt_output_check_space(struct mqtt_ringbuf_t *rb, u16_t r_length)
|
||||
|
||||
LWIP_ASSERT("mqtt_output_check_space: rb != NULL", rb != NULL);
|
||||
|
||||
/* Calculate number of required bytes to contain the remaining bytes field and add to total*/
|
||||
/* Calculate number of required bytes to contain the remaining bytes field and add to total*/
|
||||
do {
|
||||
total_len++;
|
||||
r_length >>= 7;
|
||||
@ -546,7 +545,7 @@ mqtt_close(mqtt_client_t *client, mqtt_connection_status_t reason)
|
||||
res = altcp_close(client->conn);
|
||||
if (res != ERR_OK) {
|
||||
altcp_abort(client->conn);
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_close: Close err=%s\n", lwip_strerr(res)));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_close: Close err=%s\n", lwip_strerr(res)));
|
||||
}
|
||||
client->conn = NULL;
|
||||
}
|
||||
@ -581,7 +580,7 @@ mqtt_cyclic_timer(void *arg)
|
||||
if (client->conn_state == MQTT_CONNECTING) {
|
||||
client->cyclic_tick++;
|
||||
if ((client->cyclic_tick * MQTT_CYCLIC_TIMER_INTERVAL) >= MQTT_CONNECT_TIMOUT) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_cyclic_timer: CONNECT attempt to server timed out\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_cyclic_timer: CONNECT attempt to server timed out\n"));
|
||||
/* Disconnect TCP */
|
||||
mqtt_close(client, MQTT_CONNECT_TIMEOUT);
|
||||
restart_timer = 0;
|
||||
@ -595,15 +594,15 @@ mqtt_cyclic_timer(void *arg)
|
||||
|
||||
client->server_watchdog++;
|
||||
/* If reception from server has been idle for 1.5*keep_alive time, server is considered unresponsive */
|
||||
if ((client->server_watchdog * MQTT_CYCLIC_TIMER_INTERVAL) > (client->keep_alive + client->keep_alive/2)) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_cyclic_timer: Server incoming keep-alive timeout\n"));
|
||||
if ((client->server_watchdog * MQTT_CYCLIC_TIMER_INTERVAL) > (client->keep_alive + client->keep_alive / 2)) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_cyclic_timer: Server incoming keep-alive timeout\n"));
|
||||
mqtt_close(client, MQTT_CONNECT_TIMEOUT);
|
||||
restart_timer = 0;
|
||||
}
|
||||
|
||||
/* If time for a keep alive message to be sent, transmission has been idle for keep_alive time */
|
||||
if ((client->cyclic_tick * MQTT_CYCLIC_TIMER_INTERVAL) >= client->keep_alive) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_cyclic_timer: Sending keep-alive message to server\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_cyclic_timer: Sending keep-alive message to server\n"));
|
||||
if (mqtt_output_check_space(&client->output, 0) != 0) {
|
||||
mqtt_output_append_fixed_header(&client->output, MQTT_MSG_TYPE_PINGREQ, 0, 0, 0, 0);
|
||||
client->cyclic_tick = 0;
|
||||
@ -613,11 +612,11 @@ mqtt_cyclic_timer(void *arg)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_cyclic_timer: Timer should not be running in state %d\n", client->conn_state));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_cyclic_timer: Timer should not be running in state %d\n", client->conn_state));
|
||||
restart_timer = 0;
|
||||
}
|
||||
if (restart_timer) {
|
||||
sys_timeout(MQTT_CYCLIC_TIMER_INTERVAL*1000, mqtt_cyclic_timer, arg);
|
||||
sys_timeout(MQTT_CYCLIC_TIMER_INTERVAL * 1000, mqtt_cyclic_timer, arg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -639,8 +638,8 @@ pub_ack_rec_rel_response(mqtt_client_t *client, u8_t msg, u16_t pkt_id, u8_t qos
|
||||
mqtt_output_append_u16(&client->output, pkt_id);
|
||||
mqtt_output_send(&client->output, client->conn);
|
||||
} else {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("pub_ack_rec_rel_response: OOM creating response: %s with pkt_id: %d\n",
|
||||
mqtt_msg_type_to_str(msg), pkt_id));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("pub_ack_rec_rel_response: OOM creating response: %s with pkt_id: %d\n",
|
||||
mqtt_msg_type_to_str(msg), pkt_id));
|
||||
err = ERR_MEM;
|
||||
}
|
||||
return err;
|
||||
@ -679,13 +678,13 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u
|
||||
u16_t pkt_id = 0;
|
||||
|
||||
LWIP_ERROR("buffer length mismatch", fixed_hdr_idx + length <= MQTT_VAR_HEADER_BUFFER_LEN,
|
||||
return MQTT_CONNECT_DISCONNECTED);
|
||||
return MQTT_CONNECT_DISCONNECTED);
|
||||
|
||||
if (pkt_type == MQTT_MSG_TYPE_CONNACK) {
|
||||
if (client->conn_state == MQTT_CONNECTING) {
|
||||
/* Get result code from CONNACK */
|
||||
res = (mqtt_connection_status_t)var_hdr_payload[1];
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_message_received: Connect response code %d\n", res));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_message_received: Connect response code %d\n", res));
|
||||
if (res == MQTT_CONNECT_ACCEPTED) {
|
||||
/* Reset cyclic_tick when changing to connected state */
|
||||
client->cyclic_tick = 0;
|
||||
@ -696,10 +695,10 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_message_received: Received CONNACK in connected state\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_message_received: Received CONNACK in connected state\n"));
|
||||
}
|
||||
} else if (pkt_type == MQTT_MSG_TYPE_PINGRESP) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,( "mqtt_message_received: Received PINGRESP from server\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ( "mqtt_message_received: Received PINGRESP from server\n"));
|
||||
|
||||
} else if (pkt_type == MQTT_MSG_TYPE_PUBLISH) {
|
||||
u16_t payload_offset = 0;
|
||||
@ -717,8 +716,8 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u
|
||||
topic = var_hdr_payload + 2;
|
||||
after_topic = 2 + topic_len;
|
||||
/* Check length, add one byte even for QoS 0 so that zero termination will fit */
|
||||
if ((after_topic + (qos? 2 : 1)) > length) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_message_received: Receive buffer can not fit topic + pkt_id\n"));
|
||||
if ((after_topic + (qos ? 2 : 1)) > length) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_message_received: Receive buffer can not fit topic + pkt_id\n"));
|
||||
goto out_disconnect;
|
||||
}
|
||||
|
||||
@ -737,8 +736,8 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u
|
||||
payload_length = length - after_topic;
|
||||
payload_offset = after_topic;
|
||||
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_incomming_publish: Received message with QoS %d at topic: %s, payload length %d\n",
|
||||
qos, topic, remaining_length + payload_length));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_incomming_publish: Received message with QoS %d at topic: %s, payload length %d\n",
|
||||
qos, topic, remaining_length + payload_length));
|
||||
if (client->pub_cb != NULL) {
|
||||
client->pub_cb(client->inpub_arg, (const char *)topic, remaining_length + payload_length);
|
||||
}
|
||||
@ -751,8 +750,8 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u
|
||||
if (remaining_length == 0 && qos > 0) {
|
||||
/* Send PUBACK for QoS 1 or PUBREC for QoS 2 */
|
||||
u8_t resp_msg = (qos == 1) ? MQTT_MSG_TYPE_PUBACK : MQTT_MSG_TYPE_PUBREC;
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_incomming_publish: Sending publish response: %s with pkt_id: %d\n",
|
||||
mqtt_msg_type_to_str(resp_msg), client->inpub_pkt_id));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_incomming_publish: Sending publish response: %s with pkt_id: %d\n",
|
||||
mqtt_msg_type_to_str(resp_msg), client->inpub_pkt_id));
|
||||
pub_ack_rec_rel_response(client, resp_msg, client->inpub_pkt_id, 0);
|
||||
}
|
||||
}
|
||||
@ -761,25 +760,25 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u
|
||||
pkt_id = (u16_t)var_hdr_payload[0] << 8;
|
||||
pkt_id |= (u16_t)var_hdr_payload[1];
|
||||
if (pkt_id == 0) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_message_received: Got message with illegal packet identifier: 0\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_message_received: Got message with illegal packet identifier: 0\n"));
|
||||
goto out_disconnect;
|
||||
}
|
||||
if (pkt_type == MQTT_MSG_TYPE_PUBREC) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_message_received: PUBREC, sending PUBREL with pkt_id: %d\n",pkt_id));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_message_received: PUBREC, sending PUBREL with pkt_id: %d\n", pkt_id));
|
||||
pub_ack_rec_rel_response(client, MQTT_MSG_TYPE_PUBREL, pkt_id, 1);
|
||||
|
||||
} else if (pkt_type == MQTT_MSG_TYPE_PUBREL) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_message_received: PUBREL, sending PUBCOMP response with pkt_id: %d\n",pkt_id));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_message_received: PUBREL, sending PUBCOMP response with pkt_id: %d\n", pkt_id));
|
||||
pub_ack_rec_rel_response(client, MQTT_MSG_TYPE_PUBCOMP, pkt_id, 0);
|
||||
|
||||
} else if (pkt_type == MQTT_MSG_TYPE_SUBACK || pkt_type == MQTT_MSG_TYPE_UNSUBACK ||
|
||||
pkt_type == MQTT_MSG_TYPE_PUBCOMP || pkt_type == MQTT_MSG_TYPE_PUBACK) {
|
||||
pkt_type == MQTT_MSG_TYPE_PUBCOMP || pkt_type == MQTT_MSG_TYPE_PUBACK) {
|
||||
struct mqtt_request_t *r = mqtt_take_request(&client->pend_req_queue, pkt_id);
|
||||
if (r != NULL) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_message_received: %s response with id %d\n", mqtt_msg_type_to_str(pkt_type), pkt_id));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_message_received: %s response with id %d\n", mqtt_msg_type_to_str(pkt_type), pkt_id));
|
||||
if (pkt_type == MQTT_MSG_TYPE_SUBACK) {
|
||||
if (length < 3) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_message_received: To small SUBACK packet\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_message_received: To small SUBACK packet\n"));
|
||||
goto out_disconnect;
|
||||
} else {
|
||||
mqtt_incomming_suback(r, var_hdr_payload[2]);
|
||||
@ -789,10 +788,10 @@ mqtt_message_received(mqtt_client_t *client, u8_t fixed_hdr_idx, u16_t length, u
|
||||
}
|
||||
mqtt_delete_request(r);
|
||||
} else {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,( "mqtt_message_received: Received %s reply, with wrong pkt_id: %d\n", mqtt_msg_type_to_str(pkt_type), pkt_id));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ( "mqtt_message_received: Received %s reply, with wrong pkt_id: %d\n", mqtt_msg_type_to_str(pkt_type), pkt_id));
|
||||
}
|
||||
} else {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,( "mqtt_message_received: Received unknown message type: %d\n", pkt_type));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ( "mqtt_message_received: Received unknown message type: %d\n", pkt_type));
|
||||
goto out_disconnect;
|
||||
}
|
||||
}
|
||||
@ -830,7 +829,7 @@ mqtt_parse_incoming(mqtt_client_t *client, struct pbuf *p)
|
||||
if (fixed_hdr_idx >= 2) {
|
||||
msg_rem_len |= (u32_t)(b & 0x7f) << ((fixed_hdr_idx - 2) * 7);
|
||||
if ((b & 0x80) == 0) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_parse_incoming: Remaining length after fixed header: %d\n", msg_rem_len));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_parse_incoming: Remaining length after fixed header: %d\n", msg_rem_len));
|
||||
if (msg_rem_len == 0) {
|
||||
/* Complete message with no extra headers of payload received */
|
||||
mqtt_message_received(client, fixed_hdr_idx, 0, 0);
|
||||
@ -855,14 +854,14 @@ mqtt_parse_incoming(mqtt_client_t *client, struct pbuf *p)
|
||||
if (cpy_len > buffer_space) {
|
||||
cpy_len = buffer_space;
|
||||
}
|
||||
pbuf_copy_partial(p, client->rx_buffer+cpy_start, cpy_len, in_offset);
|
||||
pbuf_copy_partial(p, client->rx_buffer + cpy_start, cpy_len, in_offset);
|
||||
|
||||
/* Advance get and put indexes */
|
||||
client->msg_idx += cpy_len;
|
||||
in_offset += cpy_len;
|
||||
msg_rem_len -= cpy_len;
|
||||
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_parse_incoming: msg_idx: %d, cpy_len: %d, remaining %d\n", client->msg_idx, cpy_len, msg_rem_len));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_parse_incoming: msg_idx: %d, cpy_len: %d, remaining %d\n", client->msg_idx, cpy_len, msg_rem_len));
|
||||
if (msg_rem_len == 0 || cpy_len == buffer_space) {
|
||||
/* Whole message received or buffer is full */
|
||||
mqtt_connection_status_t res = mqtt_message_received(client, fixed_hdr_idx, (cpy_start + cpy_len) - fixed_hdr_idx, msg_rem_len);
|
||||
@ -897,12 +896,12 @@ mqtt_tcp_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||
LWIP_ASSERT("mqtt_tcp_recv_cb: client->conn == pcb", client->conn == pcb);
|
||||
|
||||
if (p == NULL) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_tcp_recv_cb: Recv pbuf=NULL, remote has closed connection\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_tcp_recv_cb: Recv pbuf=NULL, remote has closed connection\n"));
|
||||
mqtt_close(client, MQTT_CONNECT_DISCONNECTED);
|
||||
} else {
|
||||
mqtt_connection_status_t res;
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_tcp_recv_cb: Recv err=%d\n", err));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_tcp_recv_cb: Recv err=%d\n", err));
|
||||
pbuf_free(p);
|
||||
return err;
|
||||
}
|
||||
@ -949,7 +948,7 @@ mqtt_tcp_sent_cb(void *arg, struct altcp_pcb *tpcb, u16_t len)
|
||||
client->server_watchdog = 0;
|
||||
/* QoS 0 publish has no response from server, so call its callbacks here */
|
||||
while ((r = mqtt_take_request(&client->pend_req_queue, 0)) != NULL) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_tcp_sent_cb: Calling QoS 0 publish complete callback\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_tcp_sent_cb: Calling QoS 0 publish complete callback\n"));
|
||||
if (r->cb != NULL) {
|
||||
r->cb(r->arg, ERR_OK);
|
||||
}
|
||||
@ -971,7 +970,7 @@ mqtt_tcp_err_cb(void *arg, err_t err)
|
||||
{
|
||||
mqtt_client_t *client = (mqtt_client_t *)arg;
|
||||
LWIP_UNUSED_ARG(err); /* only used for debug output */
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_tcp_err_cb: TCP error callback: error %d, arg: %p\n", err, arg));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_tcp_err_cb: TCP error callback: error %d, arg: %p\n", err, arg));
|
||||
LWIP_ASSERT("mqtt_tcp_err_cb: client != NULL", client != NULL);
|
||||
/* Set conn to null before calling close as pcb is already deallocated*/
|
||||
client->conn = 0;
|
||||
@ -1004,10 +1003,10 @@ mqtt_tcp_poll_cb(void *arg, struct altcp_pcb *tpcb)
|
||||
static err_t
|
||||
mqtt_tcp_connect_cb(void *arg, struct altcp_pcb *tpcb, err_t err)
|
||||
{
|
||||
mqtt_client_t* client = (mqtt_client_t *)arg;
|
||||
mqtt_client_t *client = (mqtt_client_t *)arg;
|
||||
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_tcp_connect_cb: TCP connect error %d\n", err));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_tcp_connect_cb: TCP connect error %d\n", err));
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -1019,12 +1018,12 @@ mqtt_tcp_connect_cb(void *arg, struct altcp_pcb *tpcb, err_t err)
|
||||
altcp_sent(tpcb, mqtt_tcp_sent_cb);
|
||||
altcp_poll(tpcb, mqtt_tcp_poll_cb, 2);
|
||||
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_tcp_connect_cb: TCP connection established to server\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_tcp_connect_cb: TCP connection established to server\n"));
|
||||
/* Enter MQTT connect state */
|
||||
client->conn_state = MQTT_CONNECTING;
|
||||
|
||||
/* Start cyclic timer */
|
||||
sys_timeout(MQTT_CYCLIC_TIMER_INTERVAL*1000, mqtt_cyclic_timer, client);
|
||||
sys_timeout(MQTT_CYCLIC_TIMER_INTERVAL * 1000, mqtt_cyclic_timer, client);
|
||||
client->cyclic_tick = 0;
|
||||
|
||||
/* Start transmission from output queue, connect message is the first one out*/
|
||||
@ -1076,7 +1075,7 @@ mqtt_publish(mqtt_client_t *client, const char *topic, const void *payload, u16_
|
||||
LWIP_ERROR("mqtt_publish: total length overflow", (total_len <= 0xFFFF), return ERR_ARG);
|
||||
remaining_length = (u16_t)total_len;
|
||||
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_publish: Publish with payload length %d to topic \"%s\"\n", payload_length, topic));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_publish: Publish with payload length %d to topic \"%s\"\n", payload_length, topic));
|
||||
|
||||
if (qos > 0) {
|
||||
remaining_length += 2;
|
||||
@ -1152,7 +1151,7 @@ mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_
|
||||
|
||||
LWIP_ASSERT("mqtt_sub_unsub: qos < 3", qos < 3);
|
||||
if (client->conn_state == TCP_DISCONNECTED) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_sub_unsub: Can not (un)subscribe in disconnected state\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_sub_unsub: Can not (un)subscribe in disconnected state\n"));
|
||||
return ERR_CONN;
|
||||
}
|
||||
|
||||
@ -1167,7 +1166,7 @@ mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_sub_unsub: Client (un)subscribe to topic \"%s\", id: %d\n", topic, pkt_id));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_sub_unsub: Client (un)subscribe to topic \"%s\", id: %d\n", topic, pkt_id));
|
||||
|
||||
mqtt_output_append_fixed_header(&client->output, sub ? MQTT_MSG_TYPE_SUBSCRIBE : MQTT_MSG_TYPE_UNSUBSCRIBE, 0, 1, 0, remaining_length);
|
||||
/* Packet id */
|
||||
@ -1195,7 +1194,7 @@ mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_
|
||||
*/
|
||||
void
|
||||
mqtt_set_inpub_callback(mqtt_client_t *client, mqtt_incoming_publish_cb_t pub_cb,
|
||||
mqtt_incoming_data_cb_t data_cb, void *arg)
|
||||
mqtt_incoming_data_cb_t data_cb, void *arg)
|
||||
{
|
||||
LWIP_ASSERT("mqtt_set_inpub_callback: client != NULL", client != NULL);
|
||||
client->data_cb = data_cb;
|
||||
@ -1220,7 +1219,7 @@ mqtt_client_new(void)
|
||||
* @param client Pointer to instance to be freed
|
||||
*/
|
||||
void
|
||||
mqtt_client_free(mqtt_client_t* client)
|
||||
mqtt_client_free(mqtt_client_t *client)
|
||||
{
|
||||
mem_free(client);
|
||||
}
|
||||
@ -1254,7 +1253,7 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port,
|
||||
LWIP_ASSERT("mqtt_client_connect: client_info->client_id != NULL", client_info->client_id != NULL);
|
||||
|
||||
if (client->conn_state != TCP_DISCONNECTED) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_client_connect: Already connected\n"));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_client_connect: Already connected\n"));
|
||||
return ERR_ISCONN;
|
||||
}
|
||||
|
||||
@ -1338,15 +1337,15 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port,
|
||||
/* Any local address, pick random local port number */
|
||||
err = altcp_bind(client->conn, IP_ADDR_ANY, 0);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN,("mqtt_client_connect: Error binding to local ip/port, %d\n", err));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_WARN, ("mqtt_client_connect: Error binding to local ip/port, %d\n", err));
|
||||
goto tcp_fail;
|
||||
}
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_client_connect: Connecting to host: %s at port:%"U16_F"\n", ipaddr_ntoa(ip_addr), port));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_client_connect: Connecting to host: %s at port:%"U16_F"\n", ipaddr_ntoa(ip_addr), port));
|
||||
|
||||
/* Connect to server */
|
||||
err = altcp_connect(client->conn, ip_addr, port, mqtt_tcp_connect_cb);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE,("mqtt_client_connect: Error connecting to remote ip/port, %d\n", err));
|
||||
LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_client_connect: Error connecting to remote ip/port, %d\n", err));
|
||||
goto tcp_fail;
|
||||
}
|
||||
/* Set error callback */
|
||||
|
Loading…
Reference in New Issue
Block a user