From c4708b81f7eefa0ac7fd8eae9084b644933782e8 Mon Sep 17 00:00:00 2001 From: Niklas Lantau Date: Mon, 23 May 2022 15:20:08 +0200 Subject: [PATCH 1/2] code-style: using 4 space standard Changed from tabs/space-mix till 4 space standard. Signed-off-by: Niklas Lantau --- MQTTSNPacket/samples/linux/rfcomm/qos0pub.c | 78 ++++++++++----------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/MQTTSNPacket/samples/linux/rfcomm/qos0pub.c b/MQTTSNPacket/samples/linux/rfcomm/qos0pub.c index e2fa09b..da8457a 100644 --- a/MQTTSNPacket/samples/linux/rfcomm/qos0pub.c +++ b/MQTTSNPacket/samples/linux/rfcomm/qos0pub.c @@ -28,26 +28,26 @@ int main(int argc, char** argv) { - int rc = 0; - unsigned char buf[200]; - int buflen = sizeof(buf); - MQTTSN_topicid topic; - unsigned char* payload = (unsigned char*)"mypayload"; - int payloadlen = strlen((char*)payload); - int len = 0; - int dup = 0; - int qos = 0; - int retained = 0; - short packetid = 0; -// char *topicname = "a long topic name"; + int rc = 0; + unsigned char buf[200]; + int buflen = sizeof(buf); + MQTTSN_topicid topic; + unsigned char* payload = (unsigned char*)"mypayload"; + int payloadlen = strlen((char*)payload); + int len = 0; + int dup = 0; + int qos = 0; + int retained = 0; + short packetid = 0; +// char *topicname = "a long topic name"; char *host = ""; int channel = 1; - MQTTSNPacket_connectData options = MQTTSNPacket_connectData_initializer; + MQTTSNPacket_connectData options = MQTTSNPacket_connectData_initializer; - if (argc > 1) - host = argv[1]; + if (argc > 1) + host = argv[1]; - if (argc > 2) + if (argc > 2) channel = atoi(argv[2]); printf("Sending to address %s port %d\n", host, channel); @@ -56,38 +56,38 @@ int main(int argc, char** argv) goto exit; } - options.clientID.cstring = "myclientid"; - len = MQTTSNSerialize_connect(buf, buflen, &options); + options.clientID.cstring = "myclientid"; + len = MQTTSNSerialize_connect(buf, buflen, &options); rc = rfcomm_sendPacketBuffer(buf, len); - /* wait for connack */ + /* wait for connack */ if (MQTTSNPacket_read(buf, buflen, rfcomm_getdata) == MQTTSN_CONNACK) - { - int connack_rc = -1; + { + int connack_rc = -1; - if (MQTTSNDeserialize_connack(&connack_rc, buf, buflen) != 1 || connack_rc != 0) - { - printf("Unable to connect, return code %d\n", connack_rc); - goto exit; - } - else - printf("connected rc %d\n", connack_rc); - } - else - goto exit; + if (MQTTSNDeserialize_connack(&connack_rc, buf, buflen) != 1 || connack_rc != 0) + { + printf("Unable to connect, return code %d\n", connack_rc); + goto exit; + } + else + printf("connected rc %d\n", connack_rc); + } + else + goto exit; - - /* publish with short name */ - topic.type = MQTTSN_TOPIC_TYPE_SHORT; - memcpy(topic.data.short_name, "tt", 2); - len = MQTTSNSerialize_publish(buf, buflen, dup, qos, retained, packetid, - topic, payload, payloadlen); + + /* publish with short name */ + topic.type = MQTTSN_TOPIC_TYPE_SHORT; + memcpy(topic.data.short_name, "tt", 2); + len = MQTTSNSerialize_publish(buf, buflen, dup, qos, retained, packetid, + topic, payload, payloadlen); rc = rfcomm_sendPacketBuffer(buf, len); - printf("rc %d from send packet for publish length %d\n", rc, len); + printf("rc %d from send packet for publish length %d\n", rc, len); exit: rfcomm_close(); - return 0; + return 0; } From af6e2e7a0046fca00613f5bdf0e985a8f235045a Mon Sep 17 00:00:00 2001 From: Niklas Lantau Date: Mon, 23 May 2022 15:22:39 +0200 Subject: [PATCH 2/2] code-style: using 4 space standard Changed from tabs/space-mix to 4 space standard. Signed-off-by: Niklas Lantau --- MQTTSNPacket/samples/linux/rfcomm/pub0sub1.c | 210 +++++++++---------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/MQTTSNPacket/samples/linux/rfcomm/pub0sub1.c b/MQTTSNPacket/samples/linux/rfcomm/pub0sub1.c index b0ff3e2..e5fb3ec 100644 --- a/MQTTSNPacket/samples/linux/rfcomm/pub0sub1.c +++ b/MQTTSNPacket/samples/linux/rfcomm/pub0sub1.c @@ -29,27 +29,27 @@ int main(int argc, char** argv) { - int rc = 0; - unsigned char buf[200]; - int buflen = sizeof(buf); - MQTTSN_topicid topic; - unsigned char* payload = (unsigned char*)"mypayload"; - int payloadlen = strlen((char*)payload); - int len = 0; - unsigned char dup = 0; - int qos = 1; - unsigned char retained = 0; - short packetid = 1; - char *topicname = "a long topic name"; + int rc = 0; + unsigned char buf[200]; + int buflen = sizeof(buf); + MQTTSN_topicid topic; + unsigned char* payload = (unsigned char*)"mypayload"; + int payloadlen = strlen((char*)payload); + int len = 0; + unsigned char dup = 0; + int qos = 1; + unsigned char retained = 0; + short packetid = 1; + char *topicname = "a long topic name"; char *host = ""; int channel = 1; - MQTTSNPacket_connectData options = MQTTSNPacket_connectData_initializer; - unsigned short topicid; + MQTTSNPacket_connectData options = MQTTSNPacket_connectData_initializer; + unsigned short topicid; - if (argc > 1) - host = argv[1]; + if (argc > 1) + host = argv[1]; - if (argc > 2) + if (argc > 2) channel = atoi(argv[2]); printf("Sending to address %s channel %d\n", host, channel); @@ -58,107 +58,107 @@ int main(int argc, char** argv) goto exit; } - options.clientID.cstring = "pub0sub1 MQTT-SN"; - len = MQTTSNSerialize_connect(buf, buflen, &options); + options.clientID.cstring = "pub0sub1 MQTT-SN"; + len = MQTTSNSerialize_connect(buf, buflen, &options); rc = rfcomm_sendPacketBuffer(buf, len); - /* wait for connack */ + /* wait for connack */ if (MQTTSNPacket_read(buf, buflen, rfcomm_getdata) == MQTTSN_CONNACK) - { - int connack_rc = -1; - - if (MQTTSNDeserialize_connack(&connack_rc, buf, buflen) != 1 || connack_rc != 0) - { - printf("Unable to connect, return code %d\n", connack_rc); - goto exit; - } - else - printf("connected rc %d\n", connack_rc); - } - else - goto exit; - - - /* subscribe */ - printf("Subscribing\n"); - topic.type = MQTTSN_TOPIC_TYPE_NORMAL; - topic.data.long_.name = topicname; - topic.data.long_.len = strlen(topic.data.long_.name); - len = MQTTSNSerialize_subscribe(buf, buflen, 0, 2, packetid, &topic); + { + int connack_rc = -1; + + if (MQTTSNDeserialize_connack(&connack_rc, buf, buflen) != 1 || connack_rc != 0) + { + printf("Unable to connect, return code %d\n", connack_rc); + goto exit; + } + else + printf("connected rc %d\n", connack_rc); + } + else + goto exit; + + + /* subscribe */ + printf("Subscribing\n"); + topic.type = MQTTSN_TOPIC_TYPE_NORMAL; + topic.data.long_.name = topicname; + topic.data.long_.len = strlen(topic.data.long_.name); + len = MQTTSNSerialize_subscribe(buf, buflen, 0, 2, packetid, &topic); rc = rfcomm_sendPacketBuffer(buf, len); if (MQTTSNPacket_read(buf, buflen, rfcomm_getdata) == MQTTSN_SUBACK) /* wait for suback */ - { - unsigned short submsgid; - int granted_qos; - unsigned char returncode; - - rc = MQTTSNDeserialize_suback(&granted_qos, &topicid, &submsgid, &returncode, buf, buflen); - if (granted_qos != 2 || returncode != 0) - { - printf("granted qos != 2, %d return code %d\n", granted_qos, returncode); - goto exit; - } - else - printf("suback topic id %d\n", topicid); - } - else - goto exit; - - printf("Publishing\n"); - /* publish with short name */ - topic.type = MQTTSN_TOPIC_TYPE_NORMAL; - topic.data.id = topicid; - ++packetid; - len = MQTTSNSerialize_publish(buf, buflen, dup, qos, retained, packetid, - topic, payload, payloadlen); + { + unsigned short submsgid; + int granted_qos; + unsigned char returncode; + + rc = MQTTSNDeserialize_suback(&granted_qos, &topicid, &submsgid, &returncode, buf, buflen); + if (granted_qos != 2 || returncode != 0) + { + printf("granted qos != 2, %d return code %d\n", granted_qos, returncode); + goto exit; + } + else + printf("suback topic id %d\n", topicid); + } + else + goto exit; + + printf("Publishing\n"); + /* publish with short name */ + topic.type = MQTTSN_TOPIC_TYPE_NORMAL; + topic.data.id = topicid; + ++packetid; + len = MQTTSNSerialize_publish(buf, buflen, dup, qos, retained, packetid, + topic, payload, payloadlen); rc = rfcomm_sendPacketBuffer(buf, len); - /* wait for puback */ + /* wait for puback */ if (MQTTSNPacket_read(buf, buflen, rfcomm_getdata) == MQTTSN_PUBACK) - { - unsigned short packet_id, topic_id; - unsigned char returncode; - - if (MQTTSNDeserialize_puback(&topic_id, &packet_id, &returncode, buf, buflen) != 1 || returncode != MQTTSN_RC_ACCEPTED) - printf("Unable to publish, return code %d\n", returncode); - else - printf("puback received, msgid %d topic id %d\n", packet_id, topic_id); - } - else - goto exit; - - printf("Receive publish\n"); + { + unsigned short packet_id, topic_id; + unsigned char returncode; + + if (MQTTSNDeserialize_puback(&topic_id, &packet_id, &returncode, buf, buflen) != 1 || returncode != MQTTSN_RC_ACCEPTED) + printf("Unable to publish, return code %d\n", returncode); + else + printf("puback received, msgid %d topic id %d\n", packet_id, topic_id); + } + else + goto exit; + + printf("Receive publish\n"); if (MQTTSNPacket_read(buf, buflen, rfcomm_getdata) == MQTTSN_PUBLISH) - { - unsigned short packet_id; - int qos, payloadlen; - unsigned char* payload; - unsigned char dup, retained; - MQTTSN_topicid pubtopic; - - if (MQTTSNDeserialize_publish(&dup, &qos, &retained, &packet_id, &pubtopic, - &payload, &payloadlen, buf, buflen) != 1) - printf("Error deserializing publish\n"); - else - printf("publish received, id %d qos %d\n", packet_id, qos); - - if (qos == 1) - { - len = MQTTSNSerialize_puback(buf, buflen, pubtopic.data.id, packet_id, MQTTSN_RC_ACCEPTED); + { + unsigned short packet_id; + int qos, payloadlen; + unsigned char* payload; + unsigned char dup, retained; + MQTTSN_topicid pubtopic; + + if (MQTTSNDeserialize_publish(&dup, &qos, &retained, &packet_id, &pubtopic, + &payload, &payloadlen, buf, buflen) != 1) + printf("Error deserializing publish\n"); + else + printf("publish received, id %d qos %d\n", packet_id, qos); + + if (qos == 1) + { + len = MQTTSNSerialize_puback(buf, buflen, pubtopic.data.id, packet_id, MQTTSN_RC_ACCEPTED); rc = rfcomm_sendPacketBuffer(buf, len); - if (rc == 0) - printf("puback sent\n"); - } - } - else - goto exit; - - len = MQTTSNSerialize_disconnect(buf, buflen, 0); + if (rc == 0) + printf("puback sent\n"); + } + } + else + goto exit; + + len = MQTTSNSerialize_disconnect(buf, buflen, 0); rc = rfcomm_sendPacketBuffer(buf, len); exit: - rfcomm_close(); + rfcomm_close(); - return 0; + return 0; }