version 1.1.2.3, 2011/11/21 14:51:23
|
version 1.1.2.6, 2011/11/22 14:00:09
|
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 41 mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
|
Line 45 mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
|
} |
} |
|
|
/* variable header */ |
/* variable header */ |
|
|
topic = (mqtthdr_var_t*) (buf->msg_base + siz); |
topic = (mqtthdr_var_t*) (buf->msg_base + siz); |
topic->var_sb.val = htons(strlen(csTopic)); |
topic->var_sb.val = htons(strlen(csTopic)); |
memcpy(topic->var_data, csTopic, ntohs(topic->var_sb.val)); |
memcpy(topic->var_data, csTopic, ntohs(topic->var_sb.val)); |
Line 51 mqtt_msgPUBLISH(mqtt_msg_t * __restrict buf, const cha
|
Line 54 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); |
|
|
/* fixed header */ | /* load with data */ |
| if (pData && datlen) { |
| data = buf->msg_base + siz; |
| memcpy(data, pData, datlen); |
| siz += datlen; |
| } |
|
|
|
/* fixed header */ |
|
MQTTHDR_MSGINIT(hdr); |
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); |
Line 83 _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd,
|
Line 93 _mqtt_msgPUB_(mqtt_msg_t * __restrict buf, u_char cmd,
|
} |
} |
|
|
/* fixed header */ |
/* fixed header */ |
|
MQTTHDR_MSGINIT(hdr); |
hdr->mqtt_msg.type = cmd; |
hdr->mqtt_msg.type = cmd; |
*hdr->mqtt_len = sizeof(mqtt_v_t); |
*hdr->mqtt_len = sizeof(mqtt_v_t); |
|
|