view ABP/sender.c @ 9:18d2a590bc10 draft

add fibonacci
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 03 Jun 2012 22:06:40 +0900
parents 5dc0fa7caa57
children
line wrap: on
line source

#include <stdio.h>

extern int comm_bit_s;  /* communication bit for sender */
extern int comm_bit_r;  /* communication bit for receiver */
extern char *comm_msg;  /* communication message */


struct packet {
	int        bit;  /* alternating bit */
	char     **msg;  /* messages */
	code (*next)();  /* next code segment */
};

extern code schedule(struct packet pkt, int i);

code s_sendState(struct packet, int);
code s_receiveState(struct packet, int);

code s_receiveState(struct packet pkt, int i)
{
	/* correct bit */
	if (pkt.bit == comm_bit_r) {
		printf("sender: success\n");
		pkt.bit = !pkt.bit;
		i++;  // for message increment
		pkt.next = s_sendState;
		goto schedule(pkt, i);
	/* wrong bit */
	} else {
		printf("sender: failure\n");
		pkt.next = s_sendState;
		goto schedule(pkt, i);
	}
}

code s_sendState(struct packet pkt, int i)
{
	comm_bit_s = pkt.bit;
	comm_msg = pkt.msg[i];
	pkt.next = s_receiveState;
	goto schedule(pkt, i);
}