version 1.1.2.4, 2011/11/21 15:07:12
|
version 1.1.2.6, 2011/11/22 14:00:09
|
Line 12
|
Line 12
|
* @Dup = Duplicate message |
* @Dup = Duplicate message |
* @QOS = QoS |
* @QOS = QoS |
* @Retain = Retain message |
* @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 Retain) | 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 42 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 52 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; |
Line 84 _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); |
|
|