version 1.1.2.3, 2011/11/21 14:51:23
|
version 1.1.2.5, 2011/11/21 15:27:26
|
Line 11
|
Line 11
|
* @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE |
* @msgID = MessageID >0, if QOS != MQTT_QOS_ONCE |
* @Dup = Duplicate message |
* @Dup = Duplicate message |
* @QOS = QoS |
* @QOS = QoS |
|
* @Retain = Retain message |
|
* @pData = Publish data into topic |
|
* @datlen = Publish data length |
* return: -1 error or >-1 message size for send |
* return: -1 error or >-1 message size for send |
*/ |
*/ |
int |
int |
mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, u_short msgID, |
mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const char *csTopic, u_short msgID, |
u_char Dup, u_char QOS) | u_char Dup, u_char QOS, u_char Retain, const void *pData, u_short datlen) |
{ |
{ |
int siz = 0; |
int siz = 0; |
struct mqtthdr *hdr; |
struct mqtthdr *hdr; |
mqtthdr_var_t *topic; |
mqtthdr_var_t *topic; |
mqtt_v_t *mid; |
mqtt_v_t *mid; |
|
void *data; |
|
|
if (!buf || !csTopic) |
if (!buf || !csTopic) |
return -1; |
return -1; |
Line 51 mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
|
Line 55 mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
|
mid->val = htons(msgID); |
mid->val = htons(msgID); |
siz += sizeof(mqtt_v_t); |
siz += sizeof(mqtt_v_t); |
|
|
|
/* load with data */ |
|
|
|
if (pData && datlen) { |
|
data = buf->msg_base + siz; |
|
memcpy(data, pData, datlen); |
|
siz += datlen; |
|
} |
|
|
/* fixed header */ |
/* fixed header */ |
|
|
hdr->mqtt_msg.type = MQTT_TYPE_PUBLISH; |
hdr->mqtt_msg.type = MQTT_TYPE_PUBLISH; |
hdr->mqtt_msg.qos = QOS; |
hdr->mqtt_msg.qos = QOS; |
hdr->mqtt_msg.dup = Dup ? 1 : 0; |
hdr->mqtt_msg.dup = Dup ? 1 : 0; |
hdr->mqtt_msg.retain = 0; | hdr->mqtt_msg.retain = Retain ? 1 : 0; |
*hdr->mqtt_len = mqtt_encodeLen(siz - sizeof(struct mqtthdr)); |
*hdr->mqtt_len = mqtt_encodeLen(siz - sizeof(struct mqtthdr)); |
|
|
mqtt_msgRealloc(buf, siz); |
mqtt_msgRealloc(buf, siz); |