Skip to content

Commit 34a6dec

Browse files
committed
First frame succeeded
1 parent 0371d5e commit 34a6dec

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/receiver.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int msgno = 0;
3636
Byte rxbuf[RXQSIZE];
3737
Byte msg[RXQSIZE][MAXLEN + 10];
3838
char clientName[MAXLEN];
39-
char recvbuf[MAXLEN << 1], sendbuf[MAXLEN << 1];
39+
char recvbuf[MAXLEN + 40], sendbuf[MAXLEN + 40];
4040

4141
QTYPE rcvq = { 0, 0, 0, RXQSIZE, rxbuf };
4242
QTYPE *rxq = &rcvq;
@@ -138,7 +138,7 @@ static int rcvframe(int sockfd, QTYPE *q){
138138
pair<int,string> M = convbuf(recvbuf);
139139
printf("M.first dari convbuf(recvbuf): %d\n", M.first);
140140
if(M.se != ""){ // dia ga error
141-
printf("Menerima frame ke-%d.\n", M.fi);
141+
printf("Menerima frame ke-%d: %s.\n", M.fi, M.se.c_str());
142142
// receive buffer above minimum upperlimit
143143
// sending XOFF
144144

@@ -226,7 +226,9 @@ pair<int, string> convbuf(char* buf){
226226
if(buf[2] != STX) return res;
227227
res.fi = buf[1];
228228
int idx = 0;
229-
res.se += buf[0] + buf[1] + buf[2];
229+
res.se += buf[0];
230+
res.se += buf[1];
231+
res.se += buf[2];
230232
for(idx = 3;buf[idx] != ETX && idx < MAXLEN + 15; ++idx){
231233
res.se += buf[idx];
232234
}
@@ -236,13 +238,19 @@ pair<int, string> convbuf(char* buf){
236238
while(buf[idx] != 0){
237239
check *= 10;
238240
check += buf[idx] - '0';
241+
++idx;
239242
}
240243
unsigned char t[MAXLEN << 1]; //for checksum
241-
strcpy( (char*) t, (res.se).c_str());
244+
memset(t,0,sizeof t);
245+
printf("HAHAHAHA");
246+
for(int i = 0;i < res.se.length(); ++i){
247+
t[i] = (Byte)res.se[i];
248+
printf(" %d", t[i]);
249+
}
250+
puts("");
242251
unsigned int checksum = crc32a(t);
243252
//////////debug checksum. status : belum lewat///////////////////////
244-
printf("%d\n", check);
245-
printf("%d\n", checksum);
253+
printf("%u %u\n", checksum, check);
246254
if(checksum != check) return make_pair(-1, "");
247255
return res;
248256
}
@@ -293,6 +301,7 @@ void sendACK(int framenum){
293301
for(int i = 0;i < s.length(); ++i){
294302
sendbuf[i] = s[i];
295303
}
304+
printf("SEND ACK!\n");
296305
//kayaknya ini masih ngebug
297306
int send_ack = sendto(sockfd, sendbuf, sizeof(sendbuf), 0, (struct sockaddr*)&cli_addr, clilen);
298307
if(send_ack < 0){//error sending ACK character
@@ -306,6 +315,7 @@ void sendNAK(int framenum){
306315
for(int i = 0;i < s.length(); ++i){
307316
sendbuf[i] = s[i];
308317
}
318+
printf("SEND NAK!\n");
309319
int send_ack = sendto(sockfd, sendbuf, sizeof(sendbuf), 0, (struct sockaddr*)&cli_addr, clilen);
310320
if(send_ack < 0){//error sending ACK character
311321
printf("Error send NAK: %d", send_ack);

src/transmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int sockfd;
2525
int NAKnum = -1;
2626

2727
//buffer to sendto and recvfrom
28-
char c_recvfrom[MAXLEN << 1], c_sendto[MAXLEN << 1];
28+
char c_recvfrom[MAXLEN + 40], c_sendto[MAXLEN + 40];
2929

3030
MESGB mesg;
3131

0 commit comments

Comments
 (0)