Skip to content

Commit a353daa

Browse files
committed
VC: Change APIs for test routines
1 parent 8fac078 commit a353daa

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

Firmware/Tools/VcServerTest.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#define ADD_VC_STATE_NAMES_TABLE
2+
#include <sys/resource.h>
3+
#include <sys/time.h>
24
#include "settings.h"
35

46
#define BUFFER_SIZE 2048
@@ -76,7 +78,7 @@ int cmdToRadio(uint8_t * buffer, int length)
7678
bytesSent = 0;
7779
while (bytesSent < length)
7880
{
79-
bytesWritten = write(radio, buffer, length);
81+
bytesWritten = write(radio, &buffer[bytesSent], length - bytesSent);
8082
if (bytesWritten < 0)
8183
{
8284
perror("ERROR: Write of data to radio failed!");
@@ -120,7 +122,7 @@ int hostToRadio(uint8_t destVc, uint8_t * buffer, int length)
120122
bytesSent = 0;
121123
while (bytesSent < length)
122124
{
123-
bytesWritten = write(radio, buffer, length);
125+
bytesWritten = write(radio, &buffer[bytesSent], length - bytesSent);
124126
if (bytesWritten < 0)
125127
{
126128
perror("ERROR: Write of data to radio failed!");
@@ -221,7 +223,7 @@ int stdinToRadio()
221223
return status;
222224
}
223225

224-
int hostToStdout(uint8_t * data, uint8_t bytesToSend)
226+
int hostToStdout(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t bytesToSend)
225227
{
226228
uint8_t * buffer;
227229
uint8_t * bufferEnd;
@@ -300,7 +302,7 @@ int hostToStdout(uint8_t * data, uint8_t bytesToSend)
300302
return status;
301303
}
302304

303-
void radioToPcLinkStatus(VC_SERIAL_MESSAGE_HEADER * header, uint8_t length)
305+
void radioToPcLinkStatus(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t length)
304306
{
305307
char cmdBuffer[128];
306308
int newState;
@@ -427,7 +429,7 @@ void radioToPcLinkStatus(VC_SERIAL_MESSAGE_HEADER * header, uint8_t length)
427429
}
428430
}
429431

430-
void radioDataAck(uint8_t * data, uint8_t length)
432+
void radioDataAck(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t length)
431433
{
432434
VC_DATA_ACK_NACK_MESSAGE * vcMsg;
433435

@@ -436,19 +438,26 @@ void radioDataAck(uint8_t * data, uint8_t length)
436438
printf("ACK from VC %d\n", vcMsg->msgDestVc);
437439
}
438440

439-
void radioDataNack(uint8_t * data, uint8_t length)
441+
void radioDataNack(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t length)
440442
{
443+
int vcIndex;
441444
VC_DATA_ACK_NACK_MESSAGE * vcMsg;
442445

443446
vcMsg = (VC_DATA_ACK_NACK_MESSAGE *)data;
447+
vcIndex = vcMsg->msgDestVc & VCAB_NUMBER_MASK;
444448
if (DISPLAY_DATA_NACK)
445-
printf("NACK from VC %d\n", vcMsg->msgDestVc);
449+
printf("NACK from VC %d\n", vcIndex);
450+
451+
//Set the VC state to down
452+
virtualCircuitList[vcIndex].vcState = VC_STATE_LINK_DOWN;
446453
}
447454

448-
void radioCommandComplete(uint8_t srcVc, uint8_t * data, uint8_t length)
455+
void radioCommandComplete(VC_SERIAL_MESSAGE_HEADER * header, uint8_t * data, uint8_t length)
449456
{
450457
VC_COMMAND_COMPLETE_MESSAGE * vcMsg;
458+
uint8_t srcVc;
451459

460+
srcVc = header->radio.srcVc;
452461
vcMsg = (VC_COMMAND_COMPLETE_MESSAGE *)data;
453462
if (DISPLAY_COMMAND_COMPLETE)
454463
printf("Command complete from VC %d: %s\n", srcVc,
@@ -505,7 +514,7 @@ int radioToHost()
505514
length = data - dataStart;
506515
if (length)
507516
//Output the debug data
508-
hostToStdout(dataStart, length);
517+
hostToStdout(NULL, dataStart, length);
509518

510519
//Determine if this is the beginning of a virtual circuit message
511520
length = dataEnd - data;
@@ -545,8 +554,8 @@ int radioToHost()
545554
{
546555
printf("VC Header:\n");
547556
printf(" length: %d\n", header->radio.length);
548-
printf(" destVc: %d\n", header->radio.destVc);
549-
printf(" srcVc: %d\n", header->radio.srcVc);
557+
printf(" destVc: %d (0x%02x)\n", (uint8_t)header->radio.destVc, (uint8_t)header->radio.destVc);
558+
printf(" srcVc: %d (0x%02x)\n", header->radio.srcVc, header->radio.srcVc);
550559
if (length > 0)
551560
dumpBuffer(data, length);
552561
}
@@ -557,29 +566,29 @@ int radioToHost()
557566

558567
//Display link status
559568
if (header->radio.destVc == PC_LINK_STATUS)
560-
radioToPcLinkStatus(header, VC_SERIAL_HEADER_BYTES + length);
569+
radioToPcLinkStatus(header, data, VC_SERIAL_HEADER_BYTES + length);
561570

562571
//Display remote command response
563572
else if (header->radio.destVc == (PC_REMOTE_RESPONSE | myVc))
564-
status = hostToStdout(data, length);
573+
status = hostToStdout(header, data, length);
565574

566575
//Display command completion status
567576
else if (header->radio.destVc == PC_COMMAND_COMPLETE)
568-
radioCommandComplete(header->radio.srcVc, data, length);
577+
radioCommandComplete(header, data, length);
569578

570579
//Display ACKs for transmitted messages
571580
else if (header->radio.destVc == PC_DATA_ACK)
572-
radioDataAck(data, length);
581+
radioDataAck(header, data, length);
573582

574583
//Display NACKs for transmitted messages
575584
else if (header->radio.destVc == PC_DATA_NACK)
576-
radioDataNack(data, length);
585+
radioDataNack(header, data, length);
577586

578587
//Display received messages
579588
else if ((header->radio.destVc == myVc) || (header->radio.destVc == VC_BROADCAST))
580589
{
581590
//Output this message
582-
status = hostToStdout(data, length);
591+
status = hostToStdout(header, data, length);
583592
}
584593

585594
//Unknown messages
@@ -589,8 +598,8 @@ int radioToHost()
589598
{
590599
printf("Unknown message, VC Header:\n");
591600
printf(" length: %d\n", header->radio.length);
592-
printf(" destVc: %d\n", header->radio.destVc);
593-
printf(" srcVc: %d\n", header->radio.srcVc);
601+
printf(" destVc: %d (0x%02x)\n", (uint8_t)header->radio.destVc, (uint8_t)header->radio.destVc);
602+
printf(" srcVc: %d (0x%02x)\n", header->radio.srcVc, header->radio.srcVc);
594603
if (length > 0)
595604
dumpBuffer(data, length);
596605
}

0 commit comments

Comments
 (0)