Exemple #1
0
// generates no_rows rows based on the given cube_info pointer,
// then sends them in blocks of size smaller than BUFFER_SIZE (4096) over the sockets.
int generateRows(int no_rows, unsigned int * rand_r_seed,  cube_info *cube, std::vector<socket_info*> sockets,
                 bool with_time = true) {

    int time;
    int socket_index = 0;
    int sockets_size = sockets.size();
    int rows_per_send = BUFFER_SIZE / (cube->no_cols + 1) / (sizeof(int) + 1);
    std::string row = "";

    timespec ts;

    int bytes = 0;
    for (int i = 0; i < no_rows; ++i) {
        clock_gettime(CLOCK_REALTIME, &ts);
        time = (int)(ts.tv_sec % 20000 * 1000.0f + ts.tv_nsec * 0.000001f);
        row += generateIntRow(time, rand_r_seed, cube,  with_time);

        if ((i % rows_per_send) == 0) {
            socket_index = (socket_index + 1) % sockets.size();
            bytes += sendRow(sockets[socket_index], row);
            row = "";
        }
    }
    return bytes;
}
void Communication::sendMap(){
	volatile int k = 0; 
	for(unsigned int i = 0; i < 32; i++){
		sendRow(i);
		k = 0;
		while(!mapConfirmation && k < 5000){
			asm("");
            asm("");
            asm("");
            asm("");
			k++;
		}
#if TESTING == 0
		_delay_ms(10);
		mapConfirmation = false;
#endif
	}
}
extern uchar sendRowCount(uchar idx) {
    return sendRow(idx, rowcount[idx]++);
}