iline(cx0,cy0,cx1,cy1){ int maxp,tt,j,np; char chx,chy,command; float xd,yd; float dist2(),sqrt(); movep(cx0,cy0); maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.; xd = cx1-cx0; yd = cy1-cy0; command = COM|((xd<0)<<1)|(yd<0); if(maxp == 0){ xd=0; yd=0; } else { xd /= maxp; yd /= maxp; } inplot(); spew(command); for (tt=0; tt<=maxp; tt++){ chx= cx0+xd*tt-xnow; xnow += chx; chx = abval(chx); chy = cy0+yd*tt-ynow; ynow += chy; chy = abval(chy); spew(ADDR|chx<<3|chy); } outplot(); return; }
outplot() { spew(ESC); spew(ACK); spew(ESC); spew(ACK); fflush(stdout); stty (OUTF, &ITTY); }
void erase(void) { int i; for (i = 0; i < 11 * (VERTRESP / VERTRES); i++) spew(DOWN); }
bool send_device_updates() { if (!m_update_pool_empty) { spew("won't send device updates message because pool is not empty"); return false; } debug("sending device updates"); DUNE::IMC::DeviceUpdate msg; uint8_t buffer[65535]; std::map<std::string, IMC::Announce>::iterator it; for (it = m_last_announces.begin(); it != m_last_announces.end(); it++) { DevicePosition pos; pos.id = it->second.getSource(); pos.lat = it->second.lat; pos.lon = it->second.lon; pos.time = it->second.getTimeStamp(); msg.positions.push_back(pos); spew("position to be sent: id:%d, lat: %f, lon: %f, time: %f", pos.id, pos.lat, pos.lon, pos.time); } m_last_announces.clear(); msg.source = getSystemId(); msg.destination = 0xFFFF; DUNE::IMC::IridiumMsgTx * m = new DUNE::IMC::IridiumMsgTx(); int len = msg.serialize(buffer); m->data.assign(buffer, buffer + len); m->req_id = m_rnd->random() % 65535; m->ttl = m_args.delay_between_device_updates; m->setTimeStamp(); m_dev_update_req_id = m->req_id; dispatch(m); std::stringstream ss; m->toText(ss); spew("sent the following message: %s", ss.str().c_str()); m_update_pool_empty = false; return true; }
void label(char *s) { int i,c; while((c = *s++) != '\0'){ xnow += 6; spew(c); } return; }
void iline(int cx0, int cy0, int cx1, int cy1) { int maxp,tt,j,np; char chx,chy; float xd,yd; float dist2(),sqrt(); movep(cx0,cy0); maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.; xd = cx1-cx0; yd = cy1-cy0; if(xd >= 0)chx = RIGHT; else chx = LEFT; if(yd >= 0)chy = UP; else chy = DOWN; if(maxp==0){ xd=0; yd=0; } else{ xd /= maxp; yd /= maxp; } inplot(); for (tt=0; tt<=maxp; tt++){ j= cx0+xd*tt-xnow; xnow += j; j = abval(j); while(j-- > 0)spew(chx); j = cy0+yd*tt-ynow; ynow += j; j = abval(j); while(j-- > 0)spew(chy); spew ('.'); } outplot(); return; }
void handleIridiumCommand(IridiumCommand * irCmd) { IMC::TextMessage tm; debug("received this command via Iridium: %s", irCmd->command.c_str()); tm.text = irCmd->command; tm.origin = "Iridium"; tm.setSource(irCmd->source); std::stringstream ss; tm.toText(ss); spew("sending this message to bus: %s", ss.str().c_str()); dispatch(tm); }
int main(int argc, char **argv) { char *proxyUser = 0, *proxyPswd = 0; char proxyURL[kProxySrvrLen]; int rv = 0, resPos = 0; time_t startTime, endTime; double dlTime = 0; /* download time */ float dlRate = 0; /* download rate */ int bResumeOrGet = 0; #ifdef macintosh argc = ccommand(&argv); #endif if (argc < 2) { usage(argv[0]); exit(1); } /* get resume pos if -r arg passed in */ for (int i = 1; i < argc; ++i) { /* resume or get */ if (strncmp(argv[i], "-rg", 3) == 0) { bResumeOrGet = 1; } /* resume from pos */ else if (strncmp(argv[i], "-r", 2) == 0) { resPos = atoi(argv[i] + 2); printf("resPos = %d\n", resPos); break; } } /* has a proxy server been specified? */ if (argc >= 4) { memset(proxyURL, 0, kProxySrvrLen); sprintf(proxyURL, "http://%s:%s", argv[2], argv[3]); if (argc >=6) { proxyUser = argv[4]; proxyPswd = argv[5]; } nsHTTPConn *conn = new nsHTTPConn(proxyURL); conn->SetProxyInfo(argv[1], proxyUser, proxyPswd); printf("Proxy URL: %s\n", argv[1]); if (proxyUser && proxyPswd) { printf("Proxy User: %s\n", proxyUser); printf("Proxy Pswd: %s\n", proxyPswd); } rv = conn->Open(); spew("nsHTTPConn::Open", rv); startTime = time(NULL); if (bResumeOrGet) { rv = conn->ResumeOrGet(ProgressCB, NULL); // use leaf from URL } else { rv = conn->Get(ProgressCB, NULL, resPos); // use leaf from URL } endTime = time(NULL); printf("\n"); // newline after progress completes spew("nsHTTPConn::Get", rv); rv = conn->Close(); spew("nsHTTPConn::Close", rv); } else { /* is this an HTTP URL? */ if (strncmp(argv[1], kHTTP, strlen(kHTTP)) == 0) { nsHTTPConn *conn = new nsHTTPConn(argv[1]); rv = conn->Open(); spew("nsHTTPConn::Open", rv); startTime = time(NULL); if (bResumeOrGet) { rv = conn->ResumeOrGet(ProgressCB, NULL); } else { rv = conn->Get(ProgressCB, NULL, resPos); } endTime = time(NULL); printf("\n"); // newline after progress completes spew("nsHTTPConn::Get", rv); rv = conn->Close(); spew("nsHTTPConn::Close", rv); } /* or is this an FTP URL? */ else if (strncmp(argv[1], kFTP, strlen(kFTP)) == 0) { char *host = 0, *path = 0, *file = (char*) kLoclFile; int port = 21; rv = nsHTTPConn::ParseURL(kFTP, argv[1], &host, &port, &path); spew("nsHTTPConn::ParseURL", rv); nsFTPConn *conn = new nsFTPConn(host); rv = conn->Open(); spew("nsFTPConn::Open", rv); if (strrchr(path, '/') != (path + strlen(path))) file = strrchr(path, '/') + 1; // set to leaf name startTime = time(NULL); if (bResumeOrGet) { rv = conn->ResumeOrGet(path, file, nsFTPConn::BINARY, 1, ProgressCB); } else { rv = conn->Get(path, file, nsFTPConn::BINARY, resPos, 1, ProgressCB); } endTime = time(NULL); printf("\n"); // newline after progress completes spew("nsFTPConn::Get", rv); rv = conn->Close(); spew("nsFTPConn::Close", rv); if (host) free(host); if (path) free(path); } /* or we don't understand the args */ else { fprintf(stderr, "Like, uhm, dude! I don't get you. "); fprintf(stderr, "See usage...\n"); usage(argv[0]); return 1; } } /* compute rate */ if (sTotalSize > 0) { dlTime = difftime(endTime, startTime); if (dlTime > 0) dlRate = sTotalSize/dlTime; } printf("Download rate = %f\tTotal size = %d\tTotal time = %f\n", dlRate, sTotalSize, dlTime); #ifdef macintosh int fin = getchar(); #endif return 0; }
int main(int argc, char **argv) { char s[2000]; int seq = 0; if (argc < 6) { fprintf(stderr, "Usage: a.out minlat minlon maxlat maxlon file.jpg\n"); exit(EXIT_FAILURE); } minlat = atof(argv[1]); minlon = atof(argv[2]); maxlat = atof(argv[3]); maxlon = atof(argv[4]); fname = argv[5]; int oseq2 = 0; while (fgets(s, 2000, stdin)) { struct point p; char *cp = s; int tweet = 0; seq++; int seq2 = 255 - (seq / (889979)); if (seq2 < 0) { break; } if (seq2 != oseq2) { printf("%d\n", seq2); oseq2 = seq2; } if (*cp == '@') { tweet = 1; } while (*cp && *cp != ' ') { cp++; } while (*cp && *cp == ' ') { cp++; } while (*cp && *cp != ' ') { cp++; } while (*cp && *cp == ' ') { cp++; } while (*cp && *cp != ' ') { cp++; } while (*cp && *cp == ' ') { cp++; } p.lat = atof(cp); // * M_PI / 180; while (*cp && *cp != ',') { cp++; } if (*cp) { cp++; } p.lon = atof(cp); // * M_PI / 180; // printf("%f %f %s", p.lat, p.lon, s); // printf("%f %f\n", p.lat, p.lon); p = project(p); // p.lat = p.lat / M_PI; int x = p.lon; int y = p.lat; if (x == WIDTH) { x = WIDTH - 1; } if (y == HEIGHT) { y = HEIGHT - 1; } if (x < 0 || y < 0 || x > WIDTH || y > HEIGHT) { //fprintf(stderr, "fail %d %d %s", x, y, s); continue; } else { //fprintf(stderr, "succeed %d %d %s", x, y, s); } //printf("%d %d => %d\n", x, y, counts[y * WIDTH + x]); int xx, yy; int xa = x, ya = y; unsigned char *array = red; if (tweet) { array = blue; } for (xx = xa - 2; xx <= xa + 1; xx++) { for (yy = ya - 2; yy <= ya + 1; yy++) { x = xx; y = yy; int i; int tseq = seq2; for (i = 0; i < 8; i++) { if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT || tseq <= 0) { break; } if (array[y * WIDTH + x] < tseq) { array[y * WIDTH + x] = tseq; break; } else { y += (rand() % 3 - 1) * 4; x += (rand() % 3 - 1) * 4; tseq = tseq * 2 / 3; } } } } } spew(); #if 0 for (i = 0; i < WIDTH * HEIGHT; i += WIDTH) { for (j = i; j < i + WIDTH; j++) { printf("%d ", 255 - counts[j]); } printf("\n"); } #endif return 0; }
inplot() { stty(OUTF, &PTTY); spew(ESC); spew (INPLOT); }