Project

General

Profile

Revision 1772

wireless: added debug info to send functions

View differences:

branches/wireless/code/projects/libwireless/wireless_send.c
90 90
 **/
91 91
int16_t wl_send(uint8_t *data, uint8_t length, uint8_t group, uint8_t scope, uint16_t dest, uint8_t mode) {
92 92
  uint8_t packet[6];
93
  int16_t ret = WL_SUCCESS;
93 94
  
94 95
  // build packet header
95 96
  packet[0] = nextframe;
......
147 148
  if (mode == FAST) {
148 149
    setack(nextframe,ACK_OK); // assume the send was successful
149 150
    nextframe = (nextframe == 0xFF)?1:nextframe+1; // increment frame number
150
    return WL_SUCCESS; // no frame number
151
    return ret; // no frame number
151 152
  } else if (mode == RELIABLE) {
152 153
    setack(nextframe,SENDING); // set status to SENDING
153 154
    // save packet on sending buffer
154 155
    scope = send_buf_last; // use as ptr to send buffer    
155 156
    if (send_buf_add(&scope,length+6) != WL_SUCCESS) { // add length
156
      WL_DEBUG_PRINT_P("Error: sending buffer full\r\n");
157
      return WL_ERROR_SENDING_BUFFER_FULL;
157
      WL_DEBUG_PRINT_P("Error adding length to sending buffer\r\n");
158
      ret = WL_ERROR_SENDING_BUFFER_FULL;
158 159
    }    
159 160
    for(mode=0;mode<6;mode++) { // add header
160 161
      if (send_buf_add(&scope,packet[mode]) != WL_SUCCESS) {
161
        WL_DEBUG_PRINT_P("Error: sending buffer full\r\n");
162
        return WL_ERROR_SENDING_BUFFER_FULL;
162
        WL_DEBUG_PRINT_P("Error adding header to sending buffer\r\n");
163
        ret = WL_ERROR_SENDING_BUFFER_FULL;
163 164
      }
164 165
    }
165 166
    for(mode=0;mode<length;mode++) { // add data
166 167
      if (send_buf_add(&scope,data[mode]) != WL_SUCCESS) {
167
        WL_DEBUG_PRINT_P("Error: sending buffer full\r\n");
168
        return WL_ERROR_SENDING_BUFFER_FULL;
168
        WL_DEBUG_PRINT_P("Error adding data to sendig buffer\r\n");
169
        ret = WL_ERROR_SENDING_BUFFER_FULL;
169 170
      }
170 171
    }
171 172
    if (send_buf_add(&scope,0) != WL_SUCCESS) { // add num retries=0
172
      WL_DEBUG_PRINT_P("Error: sending buffer full\r\n");
173
      return WL_ERROR_SENDING_BUFFER_FULL;
173
      WL_DEBUG_PRINT_P("Error adding num_retries to sending buffer\r\n");
174
      ret = WL_ERROR_SENDING_BUFFER_FULL;
174 175
    }
175 176
    send_buf_last = scope;
176 177
    send_buf_num_packets++;
......
181 182
    WL_DEBUG_PRINT_P("send_buf_num_packets:");
182 183
    WL_DEBUG_PRINT_INT(send_buf_num_packets);
183 184
    
184
    
185 185
    nextframe = (nextframe == 0xFF)?1:nextframe+1; // increment frame number
186
    return packet[0]; // return frame number for ack tracking
186
    return (ret == WL_SUCCESS)?packet[0]:ret; // return frame number for ack tracking
187 187
  }
188
  return WL_ERROR_SEND;
188
  return WL_ERROR_SEND; // shouldn't get here, but if it does there's a problem
189 189
}
190 190

  
191 191
/**
......
253 253
 * @return the # of packets lost (up to 255)
254 254
 **/
255 255
uint8_t wl_ack_error(void) {
256
  WL_DEBUG_PRINT_P("entering wl_ack_error function\r\n");
256
  WL_DEBUG_PRINT_P("entering wl_ack_error function");
257 257
  uint8_t val=0,i=1;
258 258
  
259 259
  while(1) {
......
262 262
    if (i==255)
263 263
      break;
264 264
    i++;
265
  }
266

  
265
  }  
266
  WL_DEBUG_PRINT_P("|num_errors:");
267
  WL_DEBUG_PRINT_INT(val);
268
  WL_DEBUG_PRINT_P("\r\n");
269
  
267 270
  return val;
268 271
}
269 272

  
......
277 280
 * @return {SENDING,ACK_OK,ACK_FAILURE,CCA_FAILURE}
278 281
 **/
279 282
int8_t wl_ack_check(uint8_t packet) {
280
  WL_DEBUG_PRINT_P("entering wl_ack_check function\r\n");
283
  WL_DEBUG_PRINT_P("entering wl_ack_check function|ack=");
281 284
  if (packet == 0) {
282 285
    // no ack information here
283 286
    WL_DEBUG_PRINT_P("packet number cannot be 0\r\n");
284 287
    return WL_ERROR_ARGUMENT;
285 288
  }
286 289
  
290
  WL_DEBUG_PRINT_HEX(ack_buf[packet/4]&(0x3<<(packet%4)));
291
  WL_DEBUG_PRINT_P("\r\n");
292
  
287 293
  // check ack
288 294
  return ack_buf[packet/4]&(0x3<<(packet%4));
289 295
}
......
310 316
 * @param val {SENDING,ACK_OK,ACK_FAILURE,CCA_FAILURE}
311 317
 */
312 318
void setack(uint8_t num,uint8_t val) {
313
  WL_DEBUG_PRINT_P("entering setack function\r\n");
319
  WL_DEBUG_PRINT_P("entering setack function|num=");
320
  WL_DEBUG_PRINT_INT(num);
321
  WL_DEBUG_PRINT_P("|val=");
322
  WL_DEBUG_PRINT_HEX(val);
323
  WL_DEBUG_PRINT_P("\r\n");
314 324
  switch(num%4) {
315 325
  case 0:
316 326
    ack_buf[num/4] &= (0xFC|val);
......
354 364
      WL_DEBUG_PRINT_INT(send_buf_first);
355 365
      WL_DEBUG_PRINT_P("|send_packet_last:");
356 366
      WL_DEBUG_PRINT_INT(send_buf_last);
367
      WL_DEBUG_PRINT_P("|send_buf:");
368
      for(int i=send_buf_first;i<send_buf_last;i++)
369
        WL_DEBUG_PRINT_HEX(send_buf[i]);
357 370
      if (send_buf_get(&val) != num) {
358 371
        // not the correct packet, so continue
359 372
        WL_DEBUG_PRINT_P("|not correct packet");
360 373
        val += len;
374
        WL_DEBUG_PRINT_P("|send_packet_buf_pos:");
375
        WL_DEBUG_PRINT_INT(val);
361 376
        if (val >= PACKET_BUFFER_SIZE)
362 377
          val -= PACKET_BUFFER_SIZE;
363 378
        if (val == send_buf_last || ++packets >= send_buf_num_packets) {
......
376 391
            return; // error
377 392
        }
378 393
        send_buf_last = val; // set new end of buffer
394
        
395
        WL_DEBUG_PRINT_P("|send_packet_first:");
396
        WL_DEBUG_PRINT_INT(send_buf_first);
397
        WL_DEBUG_PRINT_P("|send_packet_last:");
398
        WL_DEBUG_PRINT_INT(send_buf_last);
379 399
        return;
380 400
      }
381 401
    }

Also available in: Unified diff