// 获取一次数据以供发送 void GetData() { Uint8 *data; while(TRUE) { /* Wait 10 sets of data from ADS1298_ISR(). */ Semaphore_pend(semDRDY, BIOS_WAIT_FOREVER); // 获取缓冲区地址 data = dataPool; // 切换数据池 if(dataPool == *DataPool1) { dataPool = *DataPool2; } else { dataPool = *DataPool2; } retrieve_data(data); Data2Send = AllData[8-Channel_No]; signal_process(); //发送单通道数据,触发发送事件 Event_post(eventServer, Event_Id_01); } }
int execute_query( /**/ sqlite3 *db, /**/ char *query, /**/ int (*apply_bindings)(sqlite3_stmt *, const void *), const void *data, /**/ int (*retrieve_data)(sqlite3_stmt *, const void *), /**/ void *output ) { sqlite3_stmt *statement; int rc; if ( (rc = sqlite3_prepare_v2( db, query, strlen(query), &statement, NULL )) != SQLITE_OK ) return rc; if ( apply_bindings != NULL && (rc = apply_bindings( statement, data )) != SQLITE_OK ) return rc; if ( (rc = sqlite3_step( statement )) == SQLITE_DONE ) { if ( (rc = sqlite3_finalize( statement )) != SQLITE_OK ) return rc; return SQLITE_NOTFOUND; } while ( rc == SQLITE_ROW ) { if ( retrieve_data != NULL && (rc = retrieve_data( statement, output )) != SQLITE_OK ) return rc; rc = sqlite3_step( statement ); } if ( rc != SQLITE_DONE ) return rc; return sqlite3_finalize( statement ); }
void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[]){ // check number of arguments if( nrhs!=2 ) mexErrMsgTxt("This function requires 2 arguments\n"); if( !mxIsNumeric(prhs[0]) ) mexErrMsgTxt("varargin{0} must be a valid kdtree pointer\n"); if( !mxIsNumeric(prhs[1]) ) mexErrMsgTxt("varargin{1} must be a query set of points\n"); // retrieve the tree pointer KDTree* tree; retrieve_tree( prhs[0], tree ); // retrieve the query data double* query_data; int npoints, ndims; retrieve_data( prhs[1], query_data, npoints, ndims ); // printf("query size: %dx%d\n", npoints, ndims); // check dimensions if( ndims != tree->ndims() ) mexErrMsgTxt("vararg{1} must be a [Nxk] matrix of N points in k dimensions\n"); // npoints x 1 indexes in output plhs[0] = mxCreateDoubleMatrix(npoints, 1, mxREAL); double* indexes = mxGetPr(plhs[0]); // cout << "nindexes: " << mxGetM(plhs[0]) << "x" << mxGetN(plhs[0]) << endl; // execute the query FOR EVERY point storing the index vector< double > query(ndims,0); for(int i=0; i<npoints; i++) for( int j=0; j<ndims; j++ ){ query[j] = query_data[ i+j*npoints ]; indexes[i] = tree->closest_point(query)+1; } }
int main(int argc, char** argv) { // Initialize the BSP system if (!bsp_init("e_primitives.elf", argc, argv)) { fprintf(stderr, "ERROR: bsp_init() failed\n"); return -1; } // Get the number of processors available int nprocs_available = bsp_nprocs(); printf("Amount of cores available: %i\n", nprocs_available); for (;;) { printf("Enter the amount of cores to use: "); nprocs = 0; if (scanf("%d", &nprocs) < 0) return 1; if (nprocs <= 0 || nprocs > nprocs_available) printf("Invalid. Enter a number between 1 and %d\n", nprocs_available); else break; } // Initialize the epiphany system, and load the e-program if (!bsp_begin(nprocs)) { fprintf(stderr, "ERROR: bsp_begin() failed\n"); return -1; } // Send some initial data to the processors (i.e. matrices) generate_data(); send_data(); // Run the SPMD on the e-cores ebsp_spmd(); printf("Retrieving results\n"); // Retrieve results retrieve_data(); // Finalize bsp_end(); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ // read the parameters // check input uint64 *pointer_to_tree; if( nrhs != 1 || !mxIsNumeric(prhs[0]) ) mexErrMsgTxt("A unique scalar number with the expected size of the queue is necessary.\n"); // retrieve the data int nelems = 100; retrieve_data( prhs[0], nelems ); // instantiate the priority queue MaxHeap<double>* pq = new MaxHeap<double>(nelems); // convert the pointer to generic plhs[0] = mxCreateNumericMatrix(1,1,mxUINT64_CLASS,mxREAL); pointer_to_tree = (uint64 *)mxGetData(plhs[0]); pointer_to_tree[0] = (uint64)pq; }
/* Name: tail() * * Description: * * This function displays the last lines at the end of a file in an ext2 * file system. * * Algorithm: * * Get the directory and basename of the file * Determine the inode number for the file * Open the file for reading * Skip to the last block in the file * While we have not found the last num_lines of newline characters * Skip backwards in the file one block and read it * Display the contents of the block from that point on. * Display the rest of the file if not contained in the block * Save the current location of the file. * If we are following the file as it grows * While forever * Sleep * Re-read the inode for the file * If the size has changed * Display the file from the saved point on * Save the current location of the file. * * * Global Variables: * * None * * Arguments: * * ext2_filsys *fs; Our filesystem * ext2_ino_t root; The root directory inode number * char *input; The name of the input file to tail * int num_lines; The number of lines to display * int follow; Flag indicating if the we should follow any * new contents to the file. * int sleep_int; The number of seconds to sleep between checking * for new lines * char *cur_filesys * * Return Values: * * 0 - the last number of lines was displayed correctly. * an error occurred. * * Author: Keith W. Sheffield * Date: 08/07/2002 * * Modification History: * * MM/DD/YY Name Description */ static long tail(ext2_filsys *fs_ptr, ext2_ino_t root, char *input, int num_lines, int follow, int sleep_int, char *cur_filesys) { ext2_filsys fs = *fs_ptr; ext2_ino_t cwd; ext2_ino_t tail_ino; ext2_ino_t t_tail_ino; char *tail_dir; char *tail_name; long retval; char buf[BLK_SIZE]; unsigned int bytes_to_read; unsigned int bytes_read; char *ptr; struct ext2_inode inode; ext2_file_t tail_fd; ext2_off_t offset; ext2_off_t cur_pos; if (get_file_parts(fs, root, input, &cwd, &tail_dir, &tail_name)) { ext2fs_close(fs); return(-1); } /* get the inode number for the source file */ if ((retval = ext2fs_namei(fs, cwd, cwd, tail_name, &tail_ino))) { fprintf(stderr, "%s: file %s\n",error_message(retval), tail_name); return(retval); } /* open the file */ if ((retval = ext2fs_file_open(fs, tail_ino, 0, &tail_fd))) { fputs(error_message(retval), stderr); return retval; } /* get the length of the file and determine where to start reading */ inode.i_size = offset = ext2fs_file_get_size(tail_fd); bytes_to_read = offset % BLK_SIZE; if (bytes_to_read == 0) bytes_to_read = BLK_SIZE; offset -= bytes_to_read; if (((int32_t)offset) < 0) offset = 0; do { /* seek to the start of the last block in the file */ if ((retval = ext2fs_file_lseek(tail_fd, offset, EXT2_SEEK_SET, NULL))) { fputs(error_message(retval), stderr); return retval; } /* read the last block in the file */ if ((retval = ext2fs_file_read(tail_fd, buf, bytes_to_read, &bytes_read))) { fputs(error_message(retval), stderr); return retval; } if (bytes_to_read != bytes_read) { fputs("error reading file\n", stderr); return(-1); } ptr = buf + bytes_read - 1; while (bytes_to_read--) { if (*ptr == '\n' && num_lines-- == 0) { /* if the newline wasn't the last character in the buffer, then * print what's remaining. */ if (bytes_to_read != bytes_read - 1) { ptr++; if (0 > write(1, ptr, bytes_read - bytes_to_read - 1)) { perror("writing bytes to stdout"); return -1; } } offset = 0; /* make sure we break out of the main loop */ break; } ptr--; } offset -= (offset < BLK_SIZE) ? offset : BLK_SIZE; bytes_to_read = BLK_SIZE; } while (offset > 0); /* if we are here and have any lines left, we hit the beginning, so * dump the rest of what's in memory out. */ if (num_lines > 0) { if (0 > write(1, buf, bytes_read)) { perror("writing bytes to stdout"); return -1; } } /* retreive the current position in the file */ if ((retval = ext2fs_file_lseek(tail_fd, 0, EXT2_SEEK_CUR, &cur_pos))) { fputs(error_message(retval), stderr); return retval; } /* ok, if we are before the end of the file, then dump the rest of it */ if (cur_pos < inode.i_size) { if ((retval = read_to_eof(tail_fd, 1, cur_pos, &cur_pos))) { return retval; } } if ((retval = ext2fs_file_close(tail_fd))) { fputs(error_message(retval), stderr); return retval; } if (follow) { while(1) { sleep(sleep_int); /* I don't know how to force a re-read of the file system info yet, * so, just close the file system and reopen it. */ ext2fs_close(fs); if ((retval = open_filesystem(cur_filesys, &fs, &root, 0))) { *fs_ptr = NULL; fprintf(stderr, "%s: %s\n", error_message(retval), cur_filesys); return retval; } *fs_ptr = fs; /* if we are following the name, find the directory and file name * again. */ if (follow == FOLLOW_NAME) { cwd = root; if (tail_dir != NULL && *tail_dir != '\0' && strcmp(tail_dir, ",") != 0 && (retval = change_cwd(fs, root, &cwd, tail_dir))) { fprintf(stderr, "Error changing to directory %s\n", tail_dir); return(retval); } /* get the inode number for the source file */ if ((retval = ext2fs_namei(fs, cwd, cwd, tail_name, &t_tail_ino))) { fprintf(stderr, "%s: file %s\n",error_message(retval), tail_name); return(retval); } /* if we are dealing with a new file, then start from the * beginning. */ if (t_tail_ino != tail_ino) { tail_ino = t_tail_ino; cur_pos = 0; } } if ((retval = ext2fs_read_inode(fs, tail_ino, &inode))) { fputs(error_message(retval), stderr); return retval; } if (inode.i_size > cur_pos) { if ((retval = retrieve_data(fs, tail_ino, 1, NULL, 0, cur_pos, &cur_pos))) { fputs(error_message(retval), stderr); return retval; } } else if (inode.i_size < cur_pos) { /* the file was truncated, so bail */ return(0); } } } return(0); }