static ssize_t dbg_read(int fd, void *buf, size_t count) { if (ps.opened && ps.fd == fd) return debug_read(ps.tid, buf, count); return debug_read(fd, buf, count); }
void GPSSensorUBX::DoSerialAGPS(void) { // Light PwmOut led1(LED1); PwmOut led2(LED2); led1.write(1.0); led2.write(1.0); bool gotSomething = false; while(1) { char c; if(debug_read(&c)) { DBG("got %c",c); gps.putc(c); gotSomething = true; } else if(gotSomething) { break; } } DBG("out"); led1.write(0.0); led2.write(0.0); }
int _read(int file, char* ptr, int len) { int n; int num = 0; if (file == STDIN_FILENO) { for (n = 0; n < len; n++) { *ptr++ = (char)debug_read(); num++; } } #ifdef SDCARD_ENABLE else if (file >= SDCARD_START_FILE_DESCRIPTOR && file < (SDCARD_START_FILE_DESCRIPTOR + SDCARD_MAX_OPEN_FILES)) { return _newlib_sdcard_read(file, ptr, len); } #endif else { errno = EBADF; return -1; } return num; }
int writeMemory(unsigned long addr){ /* TODO: write all data of image from flash to stm32 */ /* return 1 if successful and 0 if not */ int offs = 0; unsigned char * data = (unsigned char *)malloc(sizeof(unsigned char)*data_size); int complete = 0; while(!complete){ mdebug(0, "@"); //informs python server to send data bytes debug_read(data,data_size); //mdebug(0, "Got data"); if(data[0] == 's' && data[1] == 't' && data[2] == 'o' && data[3] == 'p' && data[4] == '!' && data[5] == '!'){ //complete! return 0; } //mdebug(5, "Write bytes"); cmdWriteMemory(addr, data, data_size); addr = addr + data_size; } mdebug(0, "Write Complete"); return 0; }