//------------------------------------------------------------------------------ int StdioStream::printDec(uint32_t n) { #ifdef NEW_WAY char buf[10]; char *ptr = fmtDec(n, buf + sizeof(buf)); uint8_t len = buf + sizeof(buf) - ptr; return write(ptr, len); #else uint8_t len; if (n < 0X10000) { return printDec((uint16_t)n); } if (n < 10000000) { len = n < 100000 ? 5 : n < 1000000 ? 6 : 7; } else { len = n < 100000000 ? 8 : n < 1000000000 ? 9 : 10; } char* str = fmtSpace(len); if (!str) { return -1; } fmtDec(n, str); return len; #endif }
void throughPutTest(void) { static enum {INIT,LOADING} state = INIT; static whoPacket_t clear = {CLEAR_STATS}, get = {GET_STATS}; switch(state) { case INIT: clear.who.to = testdest; clear.who.from = whoami(); if (sendNormalPacketLink((Byte *)&clear, sizeof(clear), loadLink)) { whoPacket_t *wp = (whoPacket_t *)testPacket; print ("\nstarting throughput test..."); flush(); setPacketHandler(STATS, testResults); state = LOADING; framesOut = packetsInGroup; setTimeout(0, &testLength_to); setTimeout(1 TO_SEC, &sendwait_to); get.who.to = testdest; get.who.from = whoami(); wp->who.to = testdest; wp->who.from = whoami(); } break; case LOADING: if (framesOut) { bool flag; if (loadLink->enableSps) flag = sendSecurePacketLink(testPacket, sizeof(testPacket), loadLink); else flag = sendNormalPacketLink(testPacket, sizeof(testPacket), loadLink); if (flag) { framesOut--; setTimeout(1 TO_SEC, &sendwait_to); } if (checkTimeout(&sendwait_to)) { print ("\n timedout - "); printDec((Long)sinceTimeout(&testLength_to)); print(" ms; giving up throughput test\n"); state = INIT; return; } } else if (sendNormalPacketLink((Byte *)&get, sizeof(get), loadLink)) { state = INIT; print (" done. getting results..."); flush(); return; } break; } activate(throughPutTest); }
bool testResults(Byte *packet, Byte length) { statsPacket *p = (statsPacket *)packet; Long n = bytesToLong(p->good_frame) - 1; Long ms = (Long)sinceTimeout(&testLength_to); (void)length; print("\n"); printDec(n), print("packets sent in "); if (ms > 10000) printDec(ms/1000), print("secs at "); else printDec(ms), print("msecs at "); printDec( ( n * sizeof(testPacket) * 8 ) / ms ), print("Kb/S\n"); return true; }
//------------------------------------------------------------------------------ int StdioStream::printDec(signed char n) { if (n < 0) { if (fputc('-') < 0) { return -1; } n = -n; } return printDec((unsigned char)n); }
//------------------------------------------------------------------------------ int StdioStream::printDec(int32_t n) { uint8_t s = 0; if (n < 0) { if (fputc('-') < 0) { return -1; } n = -n; s = 1; } int rtn = printDec((uint32_t)n); return rtn > 0 ? rtn + s : -1; }
void printEl(Tree *tmp) { printf("\n In ascending or descending order (a/d)? "); char c = 0; scanf("%c", &c); if (c == '\n') scanf("%c", &c); printf("\n "); if (c == 'a') printInc(tmp); else if (c == 'd') printDec(tmp); printf("\n"); }
//------------------------------------------------------------------------------ int StdioStream::printDec(int16_t n) { int s; uint8_t rtn = 0; if (n < 0) { if (fputc('-') < 0) { return -1; } n = -n; rtn++; } if ((s = printDec((uint16_t)n)) < 0) { return s; } return rtn; }
/* **----------------------------------------------------------------------------- ** ** Abstract: ** This function selects according to which type of element to print ** the function to send the data via UART. A new line character is added ** ** Parameters: ** string: data to be sent via UART ** typeString: selects whether it is string, decimal or hex ** ** Returns: ** True: Successful UART transmission ** False: Unsuccessful UART transmission ** **----------------------------------------------------------------------------- */ bool selectPrintln(uint8_t * string, uint8_t typeString) { bool result = false; switch(typeString){ case TYPE_STRING: result = printString(string, WITH_LINE); break; case TYPE_HEX: result = printHex((uint8_t)string, WITH_LINE); break; case TYPE_DEC: result = printDec((uint8_t)string, WITH_LINE); break; default: break; } return result; }
/*********************************************************** * * bttnUp * ***********************************************************/ void TTUI::bttnDown(boolean hold) { int decVal = 0; if(activeMenu == DOWN_MENU || activeMenu == UP_MENU) //only increment when its the second+ time pressed for this bttn { decVal = 1; if(hold == true) { //speed up increment if held down for a long time unsigned long holdTime = millis() - touch.getStartTime(); if(holdTime > 10000) { decVal = 5; } //increase after 10sec } } activeMenu = DOWN_MENU; clear(); printSelect(0); printDec(1,decVal); //don't print just dec }
//------------------------------------------------------------------------------ int StdioStream::printDec(float value, uint8_t prec) { #define FLOAT_NEW_WAY #ifdef FLOAT_NEW_WAY char buf[24]; char *ptr = fmtFloat(value, buf + sizeof(buf), prec); // return fputs(ptr); // uint8_t len = buf + sizeof(buf) - ptr; return write(ptr, buf + sizeof(buf) - ptr); #else char* ptr; uint8_t rtn = 0; uint8_t sign = 0; if (value < 0) { value = -value; sign = '-'; } // check for NaN INF OVF if (isnan(value)) { if (fputs_P(PSTR("nan")) < 0) { return -1; } rtn += 3; } else if (isinf(value)) { if (fputs_P(PSTR("inf")) < 0) { return -1; } rtn += 3; } else if (value > 4294967040.0) { if (fputs_P(PSTR("ovf")) < 0) { return -1; } rtn += 3; } else { if (sign) { if (putc(sign) < 0) { return -1; } rtn++; } if (prec > 9) { prec = 9; } /* uint32_t s = 1; for (uint8_t i = 0; i < prec; i++) { // s *= 10; s = ((s << 2) + s) << 1; } // round value value += 0.5/s; */ value += scale10(0.5, -prec); uint32_t whole = value; int np; if ((np = printDec(whole)) < 0) { return -1; } rtn += np; if (prec) { if (putc('.') < 0) { return -1; } char* str = fmtSpace(prec); if (!str) { return -1; } char* tmp = str - prec; // uint32_t fraction = s*(value - whole); uint32_t fraction = scale10(value - whole, prec); ptr = fmtDec(fraction, str); while (ptr > tmp) { *--ptr = '0'; } rtn += prec + 1; } } return rtn; #endif }