Changed HTONS to uip_htons and removed some commented code
This commit is contained in:
parent
825cc4f872
commit
1db955f913
2 changed files with 5 additions and 91 deletions
|
@ -52,73 +52,6 @@ void initialize_packet(coap_packet_t* packet)
|
|||
packet->payload = NULL;
|
||||
}
|
||||
|
||||
//void parse_message(coap_packet_t* packet, uint8_t* buf, uint16_t size)
|
||||
//{
|
||||
// int processed=0;
|
||||
// int i=0;
|
||||
// PRINTF("parse_message size %d-->\n",size);
|
||||
//
|
||||
// initialize_packet(packet);
|
||||
//
|
||||
// packet->ver = (buf[0]&COAP_HEADER_VERSION_MASK)>>COAP_HEADER_VERSION_POSITION;
|
||||
// packet->type = (buf[0]&COAP_HEADER_TYPE_MASK)>>COAP_HEADER_TYPE_POSITION;
|
||||
// packet->option_count = buf[0]&COAP_HEADER_OPTION_COUNT_MASK;
|
||||
// packet->code = buf[1];
|
||||
// packet->tid = (buf[2] << 8) + buf[3];
|
||||
//
|
||||
// processed += 4;
|
||||
//
|
||||
// header_option_t options[5];
|
||||
//
|
||||
// if(packet->option_count){
|
||||
// int option_index=0;
|
||||
// uint8_t option_delta;
|
||||
// uint16_t option_len;
|
||||
//// uint8_t option_value[100];
|
||||
// uint8_t* option_buf = buf+processed;
|
||||
//
|
||||
// while(option_index < packet->option_count){
|
||||
// //DY FIX_ME : put boundary controls
|
||||
//// int j=0;
|
||||
// option_delta=(option_buf[i] & COAP_HEADER_OPTION_DELTA_MASK) >> COAP_HEADER_OPTION_DELTA_POSITION;
|
||||
// option_len=(option_buf[i] & COAP_HEADER_OPTION_SHORT_LENGTH_MASK);
|
||||
// i++;
|
||||
// if(option_len==0xf){
|
||||
// option_len+=option_buf[i];
|
||||
// i++;
|
||||
// }
|
||||
//
|
||||
// options[option_index].option=option_delta;
|
||||
// options[option_index].len=option_len;
|
||||
// options[option_index].value=option_buf+i;
|
||||
// if (option_index){
|
||||
// options[option_index-1].next=&options[option_index];
|
||||
// /*This field defines the difference between the option Type of
|
||||
// * this option and the previous option (or zero for the first option)*/
|
||||
// options[option_index].option+=options[option_index-1].option;
|
||||
// }
|
||||
//
|
||||
// if (options[option_index].option==Option_Type_Uri_Path){
|
||||
// packet->url = (char*)options[option_index].value;
|
||||
// packet->url_len = options[option_index].len;
|
||||
// }
|
||||
//
|
||||
// PRINTF("OPTION %d %u %s \n", options[option_index].option, options[option_index].len, options[option_index].value);
|
||||
//
|
||||
// i += option_len;
|
||||
// option_index++;
|
||||
// }
|
||||
// }
|
||||
// processed += i;
|
||||
//
|
||||
// /**/
|
||||
// if (processed < size) {
|
||||
// packet->payload = &buf[processed];
|
||||
// }
|
||||
//
|
||||
// PRINTF("PACKET ver:%d type:%d oc:%d \ncode:%d tid:%u url:%s len:%u payload:%s\n", (int)packet->ver, (int)packet->type, (int)packet->option_count, (int)packet->code, packet->tid, packet->url, packet->url_len, packet->payload);
|
||||
//}
|
||||
|
||||
int serialize_packet(coap_packet_t* packet, uint8_t* buffer)
|
||||
{
|
||||
int index = 0;
|
||||
|
@ -129,7 +62,7 @@ int serialize_packet(coap_packet_t* packet, uint8_t* buffer)
|
|||
buffer[0] |= (packet->type) << COAP_HEADER_TYPE_POSITION;
|
||||
buffer[0] |= packet->option_count;
|
||||
buffer[1] = packet->code;
|
||||
uint16_t temp = htons(packet->tid);
|
||||
uint16_t temp = uip_htons(packet->tid);
|
||||
memcpy(
|
||||
(void*)&buffer[2],
|
||||
(void*)(&temp),
|
||||
|
@ -168,25 +101,6 @@ int serialize_packet(coap_packet_t* packet, uint8_t* buffer)
|
|||
option_delta += option->option;
|
||||
}
|
||||
|
||||
// //QUICK HACK TO SEND URL
|
||||
// if(packet->url){
|
||||
// buffer[index] = (Option_Type_Uri_Path) << COAP_HEADER_OPTION_DELTA_POSITION;
|
||||
// int uri_len = strlen(packet->url);
|
||||
// if(uri_len < 0xF)
|
||||
// {
|
||||
// buffer[index] |= uri_len;
|
||||
// strcpy((char*)&buffer[index + 1], packet->url);
|
||||
// index += 1 + uri_len;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// buffer[index] |= (0xF); //1111
|
||||
// buffer[index + 1] = uri_len - (0xF);
|
||||
// strcpy((char*)&buffer[index + 2],packet->url);
|
||||
// index += 2 + uri_len;
|
||||
// }
|
||||
// }
|
||||
|
||||
if(packet->payload){
|
||||
memcpy(&buffer[index], packet->payload, packet->payload_len);
|
||||
index += packet->payload_len;
|
||||
|
|
|
@ -322,7 +322,7 @@ handle_data(void)
|
|||
|
||||
if(uip_newdata()) {
|
||||
((char *)data)[datalen] = 0;
|
||||
PRINTF("Server received: '%s' (port:%u) from ", (char *)data, HTONS(UIP_UDP_BUF->srcport));
|
||||
PRINTF("Server received: '%s' (port:%u) from ", (char *)data, uip_htons(UIP_UDP_BUF->srcport));
|
||||
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
|
||||
PRINTF("\n");
|
||||
|
||||
|
@ -379,10 +379,10 @@ PROCESS_THREAD(coap_server, ev, data)
|
|||
#endif /*!UIP_CONF_IPV6_RPL*/
|
||||
|
||||
/* new connection with remote host */
|
||||
server_conn = udp_new(NULL, HTONS(0), NULL);
|
||||
udp_bind(server_conn, HTONS(MOTE_PORT));
|
||||
server_conn = udp_new(NULL, uip_htons(0), NULL);
|
||||
udp_bind(server_conn, uip_htons(MOTE_PORT));
|
||||
PRINTF("Local/remote port %u/%u\n",
|
||||
HTONS(server_conn->lport), HTONS(server_conn->rport));
|
||||
uip_htons(server_conn->lport), uip_htons(server_conn->rport));
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
|
|
Loading…
Reference in a new issue