示例#1
0
void ThreePC::mainLoop() {
	if (myid == masterid) {  // this is master
		// push the commitment to sending queue
		doMaster(false);
	} else {
		doSlave();
	}
}
示例#2
0
文件: main.c 项目: vores8/owrf-slave
int main(void) {

#ifdef DEBUGPRINT
	uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(57600, F_CPU));
#endif

	char* node_address = "OWRF1";
	node_address[4] += NODENUM;

	OWInit(5);

	nrf24l01_init();
	nrf24l01_settxaddr((uint8_t*) node_address);
	nrf24l01_setrxaddr(0, (uint8_t*) node_address);
	nrf24l01_setrxaddr(1, (uint8_t*) "OWRF0");

	sei();

	for (;;) {
		uint8_t pipe;
		if (nrf24l01_readready(&pipe)) {
			int len = owrf_read(transfer_buf);
			if (len != -1) {
#ifdef DEBUGPRINT
				debugPrint("channel=%d command=%X datalen=%d\r\n", transfer_buf[0], transfer_buf[1], transfer_buf[2]);
				for (int i = 0; i < transfer_buf[2]; i++) {
					debugPrint(">%02X", transfer_buf[i+3]);
				}
				debugPrint("\r\n");
#endif
				if (transfer_buf[0] == NODENUM) {
					len = doSlave(transfer_buf + 1) + 3;
#ifdef DEBUGPRINT
					debugPrint("retval=%X datalen=%d\r\n", transfer_buf[1], transfer_buf[2]);
					for (int i = 0; i < transfer_buf[2]; i++) {
						debugPrint("<%02X", transfer_buf[i+3]);
					}
					debugPrint("\r\n");
#endif
					_delay_ms(5);
					owrf_write(transfer_buf, len);
				}
			}
		}
	}
}
示例#3
0
文件: staroc.c 项目: intijk/staroc
int main(int argc, char* argv[])
{
	int rank,size;
	printf("Initialize mpi...\n");
	fflush(stdout);
	MPI_Init(&argc,&argv);
	MPI_Comm_size(MPI_COMM_WORLD,&size);
	MPI_Comm_rank(MPI_COMM_WORLD,&rank);
	if(rank==0){
		doMaster(argc,argv);
		printf("Master return.\n");
		fflush(stdout);
	}else{
		doSlave(rank);
		printf("slave %d return.\n", rank);
		fflush(stdout);
	}
	MPI_Finalize();
	return 0;
}