const char *test_semaphore1(void) { int i, j, k; atomic_count_t consumers; atomic_count_t producers; waitq_initialize(&can_start); semaphore_initialize(&sem, AT_ONCE); for (i = 1; i <= 3; i++) { thread_t *thrd; atomic_set(&items_produced, 0); atomic_set(&items_consumed, 0); consumers = i * CONSUMERS; producers = (4 - i) * PRODUCERS; TPRINTF("Creating %" PRIua " consumers and %" PRIua " producers...", consumers, producers); for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) { for (k = 0; k < i; k++) { thrd = thread_create(consumer, NULL, TASK, THREAD_FLAG_NONE, "consumer"); if (thrd) thread_ready(thrd); else TPRINTF("could not create consumer %d\n", i); } for (k = 0; k < (4 - i); k++) { thrd = thread_create(producer, NULL, TASK, THREAD_FLAG_NONE, "producer"); if (thrd) thread_ready(thrd); else TPRINTF("could not create producer %d\n", i); } } TPRINTF("ok\n"); thread_sleep(1); waitq_wakeup(&can_start, WAKEUP_ALL); while ((items_consumed.count != consumers) || (items_produced.count != producers)) { TPRINTF("%" PRIua " consumers remaining, %" PRIua " producers remaining\n", consumers - items_consumed.count, producers - items_produced.count); thread_sleep(1); } } return NULL; }
static void roStopListeningTimerCb(void *x) { // PRINTF("%lu: (%c) turn radio off\n", getSyncTimeMs(), isRoutingInfoValid() ? '+' : '-'); TPRINTF("--- stop\n"); RADIO_OFF_ENERGSAVE(); isListening = false; if (!seenRoutingInThisFrame) { //PRINTF("%lu: NO ROUTING PACKET THIS TIME!\n", (uint32_t) getJiffies()); TPRINTF("NO ROUTING PACKET THIS TIME!\n"); } seenRoutingInThisFrame = false; }
void onTimer(void *x) { TPRINTF("onTimer\n"); blueLedToggle(); alarmSchedule(&timer, 1000); }
static bool verify_mapping(void *area, int page_count, int expected_rc, const char *expected_rc_str) { TPRINTF("Verifying mapping (expected: %s).\n", expected_rc_str); int i; for (i = 0; i < page_count; i++) { void *page_start = ((char *) area) + PAGE_SIZE * i; int rc = as_get_physical_mapping(page_start, NULL); if (rc != expected_rc) { TPRINTF("as_get_physical_mapping() = %d != %d\n", rc, expected_rc); return false; } } return true; }
const char *test_mips1(void) { TPRINTF("If kconsole is compiled in, you should enter debug mode now.\n"); asm volatile ( "break\n" ); return "Back from debug mode"; }
static void *create_as_area(size_t size) { TPRINTF("Creating AS area...\n"); void *result = as_area_create(AS_AREA_ANY, size, AS_AREA_READ | AS_AREA_WRITE); if (result == AS_MAP_FAILED) return NULL; return result; }
static void touch_area(void *area, size_t size) { TPRINTF("Touching (faulting-in) AS area...\n"); char *ptr = (char *)area; while (size > 0) { *ptr = 0; size--; ptr++; } }
static void roStartListeningTimerCb(void *x) { // PRINTF("%lu: (%c) LISTEN START\n", getSyncTimeMs(), isRoutingInfoValid() ? '+' : '-'); if (!isListening) { TPRINTF("+++ start\n"); } alarmSchedule(&roStartListeningTimer, timeToNextFrame() + 2000); radioOn(); isListening = true; alarmSchedule(&roStopListeningTimer, 2000 + 2 * MOTE_TIME_FULL * MAX_MOTES); }
int TwWaitBusFree( NUTTWIBUS *bus) { int ret = -1; uint32_t tout = 100; NUTTWIICB *icb = bus->bus_icb; I2C_TypeDef* I2Cx = (I2C_TypeDef*)bus->bus_base; /* Wait till last transfer finished */ tout = 100; while (I2C_Is_Busy(I2Cx) && tout) { TPRINTF("B"); NutSleep(1); tout--; } if (tout) { /* Interface released in time */ ret = 0; } else { TPRINTF("R"); I2Cx->CR1 &= ~I2C_CR1_PE; I2Cx->CR1 |= I2C_CR1_SWRST; bus->bus_recover(); I2Cx->CR1 &= ~I2C_CR1_SWRST; I2Cx->CR1 &= ~I2C_CR1_PE; NutSleep(1); if (I2C_Is_Busy(I2Cx)) { /* Bus still blocked */ icb->tw_mm_error = TWERR_BUS; /* Release the interface. */ NutEventPost( &bus->bus_mutex ); } else { /* We made it! */ ret = 0; } } return ret; }
static void forwardRoutingInfo(uint8_t moteNumber) { TPRINTF("forward routing packet to mote %u (%#04x)\n", moteNumber, motes[moteNumber].address); RoutingInfoPacket_t routingInfo; routingInfo.packetType = ROUTING_INFORMATION; routingInfo.senderType = SENDER_COLLECTOR; routingInfo.rootAddress = rootAddress; routingInfo.hopCount = hopCountToRoot + 1; routingInfo.seqnum = lastSeenSeqnum; routingInfo.rootClockMs = getSyncTimeMs64(); routingInfo.moteNumber = moteNumber; // XXX: INC_NETSTAT(NETSTAT_PACKETS_SENT, EMPTY_ADDR); socketSendEx(&roSocket, &routingInfo, sizeof(routingInfo), motes[moteNumber].address); }
static const char *test_it(void) { int second_round = setjmp(jmp_env); counter++; TPRINTF("Just after setjmp(), counter is %d.\n", counter); if (second_round) { if (counter != 2) { return "setjmp() have not returned twice"; } else { return NULL; } } if (counter != 1) { return "Shall not reach here more than once"; } do_the_long_jump(); return "Survived a long jump"; }
static void roRequestTimerCb(void *x) { // check if already found the info static uint8_t cnt; if (isRoutingInfoValid() && cnt > 5) return; cnt++; if (isRoutingInfoValid()) return; // add jitter routingRequestTimeout += randomNumberBounded(100); alarmSchedule(&roRequestTimer, routingRequestTimeout); if (routingRequestTimeout < ROUTING_REQUEST_MAX_EXP_TIMEOUT) { // use exponential increments routingRequestTimeout *= 2; } else if (routingRequestTimeout < ROUTING_REQUEST_MAX_TIMEOUT) { // use linear increments routingRequestTimeout += ROUTING_REQUEST_MAX_EXP_TIMEOUT; } else { // move back to initial (small) timeout routingRequestTimeout = ROUTING_REQUEST_INIT_TIMEOUT; } TPRINTF("SEND ROUTING REQUEST\n"); radioOn(); // wait for response isListening = true; RoutingRequestPacket_t req; req.packetType = ROUTING_REQUEST; req.senderType = SENDER_COLLECTOR; socketSendEx(&roSocket, &req, sizeof(req), MOS_ADDR_BROADCAST); alarmSchedule(&roStopListeningTimer, ROUTING_REPLY_WAIT_TIMEOUT); }
void NvPthreadABIInit(void) { dlopen_handle = 0; dlopen_handle = dlopen(0, RTLD_GLOBAL | RTLD_LAZY); if (!dlopen_handle) { TPRINTF(("%s: Error detecteted \n", __NVFUNCTION__)); goto dlopen_failure; } #define SYMVER_LINUX_X86 "2.0" #define SYMVER_LINUX_X86_64 "2.2.5" GET_PROC(pthread_mutex_init); GET_PROC(pthread_mutexattr_init); GET_PROC(pthread_mutex_lock); GET_PROC(pthread_mutex_unlock); GET_PROC(pthread_mutex_destroy); GET_PROC(pthread_mutexattr_destroy); GET_PROC(pthread_join); GET_PROC(pthread_cond_timedwait); GET_PROC(pthread_mutex_trylock); GET_PROC(pthread_attr_destroy); GET_PROC(pthread_attr_setinheritsched); GET_PROC(pthread_setschedparam); GET_PROC(pthread_getschedparam); GET_PROC(pthread_cond_init); GET_PROC(pthread_cond_destroy); GET_PROC(pthread_cond_signal); GET_PROC(pthread_cond_broadcast); GET_PROC(pthread_cond_wait); GET_PROC(pthread_self); GET_PROC(pthread_equal); #undef SYMVER_LINUX_X86 #undef SYMVER_LINUX_X86_64 #define SYMVER_LINUX_X86 "2.1" #define SYMVER_LINUX_X86_64 "2.2.5" GET_PROC(pthread_mutexattr_settype); GET_PROC(pthread_create); GET_PROC(pthread_attr_init); #undef SYMVER_LINUX_X86 #undef SYMVER_LINUX_X86_64 dlopen_failure: if (!dlopen_handle) { _nv_pthread_mutex_init = _nv_pthread_mutex_init_dummy; _nv_pthread_mutexattr_init = _nv_pthread_mutexattr_init_dummy; _nv_pthread_mutexattr_settype = _nv_pthread_mutexattr_settype_dummy; _nv_pthread_mutex_lock = _nv_pthread_mutex_lock_dummy; _nv_pthread_mutex_unlock = _nv_pthread_mutex_unlock_dummy; _nv_pthread_mutex_destroy = _nv_pthread_mutex_destroy_dummy; _nv_pthread_mutexattr_destroy = _nv_pthread_mutexattr_destroy_dummy; _nv_pthread_create = _nv_pthread_create_dummy; _nv_pthread_join = _nv_pthread_join_dummy; _nv_pthread_cond_timedwait = _nv_pthread_cond_timedwait_dummy; _nv_pthread_mutex_trylock = _nv_pthread_mutex_trylock_dummy; _nv_pthread_attr_init = _nv_pthread_attr_init_dummy; _nv_pthread_attr_destroy = _nv_pthread_attr_destroy_dummy; _nv_pthread_attr_setinheritsched = _nv_pthread_attr_setinheritsched_dummy; _nv_pthread_setschedparam = _nv_pthread_setschedparam_dummy; _nv_pthread_getschedparam = _nv_pthread_getschedparam_dummy; _nv_pthread_cond_init = _nv_pthread_cond_init_dummy; _nv_pthread_cond_destroy = _nv_pthread_cond_destroy_dummy; _nv_pthread_cond_signal = _nv_pthread_cond_signal_dummy; _nv_pthread_cond_broadcast = _nv_pthread_cond_broadcast_dummy; _nv_pthread_cond_wait = _nv_pthread_cond_wait_dummy; _nv_pthread_self = _nv_pthread_self_dummy; _nv_pthread_equal = _nv_pthread_equal_dummy; } }
const char *test_smpcall1(void) { /* Number of received calls that were sent by cpu[i]. */ size_t call_cnt[MAX_CPUS] = {0}; thread_t *thread[MAX_CPUS] = { NULL }; unsigned int cpu_count = min(config.cpu_active, MAX_CPUS); size_t running_thread_cnt = 0; TPRINTF("Spawning threads on %u cpus.\n", cpu_count); /* Create a wired thread on each cpu. */ for (unsigned int id = 0; id < cpu_count; ++id) { thread[id] = thread_create(test_thread, &call_cnt[id], TASK, THREAD_FLAG_NONE, "smp-call-test"); if (thread[id]) { thread_wire(thread[id], &cpus[id]); ++running_thread_cnt; } else { TPRINTF("Failed to create thread on cpu%u.\n", id); } } size_t exp_calls = calc_exp_calls(running_thread_cnt); size_t exp_calls_sum = exp_calls * cpu_count; TPRINTF("Running %zu wired threads. Expecting %zu calls. Be patient.\n", running_thread_cnt, exp_calls_sum); for (unsigned int i = 0; i < cpu_count; ++i) { if (thread[i] != NULL) { thread_ready(thread[i]); } } /* Wait for threads to complete. */ for (unsigned int i = 0; i < cpu_count; ++i) { if (thread[i] != NULL) { thread_join(thread[i]); thread_detach(thread[i]); } } TPRINTF("Threads finished. Checking number of smp_call()s.\n"); bool ok = true; size_t calls_sum = 0; for (size_t i = 0; i < cpu_count; ++i) { if (thread[i] != NULL) { if (call_cnt[i] != exp_calls) { ok = false; TPRINTF("Error: %zu instead of %zu cpu%zu's calls were" " acknowledged.\n", call_cnt[i], exp_calls, i); } } calls_sum += call_cnt[i]; } if (calls_sum != exp_calls_sum) { TPRINTF("Error: total acknowledged sum: %zu instead of %zu.\n", calls_sum, exp_calls_sum); ok = false; } if (ok) { TPRINTF("Success: number of received smp_calls is as expected (%zu).\n", exp_calls_sum); return NULL; } else return "Failed: incorrect acknowledged smp_calls.\n"; }
int NutTwiMasterRegWrite( NUTTWIBUS *bus, uint8_t sla, uint32_t iadr, uint8_t iadrlen, const void *txdata, uint16_t txsiz, uint32_t tmo ) { int rc = -1; NUTTWIICB *icb = bus->bus_icb; // TPRINTF( "TMRW "); /* Quit if nothing to do */ if( txsiz==0) { TPRINTF("! txs=0... OUT\n"); return rc; } /* This routine is marked reentrant, so lock the interface. */ if( NutEventWait( &bus->bus_mutex, tmo ) ) { icb->tw_mm_error = TWERR_IF_LOCKED; TPRINTF("! mtx=LOCKED... OUT\n"); return rc; } #if 0 /* Check if bus is blocked for any reason */ if (TwWaitBusFree( bus)) { return rc; } #endif /* Clear errors. */ icb->tw_mm_err = 0; /* fetch transfer parameters for current transaction */ icb->tw_mm_sla = sla<<1; icb->tw_mm_iadrlen = iadrlen; if( iadrlen) { /* little-endian machine! */ icb->tw_mm_iadr = ((uint8_t*)&iadr)+iadrlen-1; } icb->tw_mm_txbuf = (uint8_t*)txdata; icb->tw_mm_txlen = txsiz; icb->tw_mm_rxbuf = 0; icb->tw_mm_rxlen = 0; icb->tw_mm_dir = MODE_WRITE; icb->tw_mm_err = 0; /* Issue start and wait till transmission completed */ NutTwiStartRolling( bus, tmo); /* Check for errors that may have been detected * by the interrupt routine. */ if( icb->tw_mm_err ) { icb->tw_mm_error = icb->tw_mm_err; rc = -1; TPRINTF( "! Error 0x%d\n", icb->tw_mm_err); /* Soft-Reset this Bus */ // NutTwiSoftReset( bus); } else { rc = (int)(txsiz - icb->tw_mm_txlen); } /* Release the interface. */ NutEventPost( &bus->bus_mutex ); // TPRINTF( "* Bye rc=%d\n", rc); return rc; }
RoutingDecision_e routePacket(MacInfo_t *info) { MosAddr *dst = &info->originalDst; // PRINTF("route: dst address=0x%04x, nexthop=0x%04x\n", dst->shortAddr, info->immedDst.shortAddr); // PRINTF(" localAddress=0x%04x\n", localAddress); if (IS_LOCAL(info)) { // fix root address if we are sending it to the root if (dst->shortAddr == MOS_ADDR_ROOT) { intToAddr(info->originalDst, rootAddress); // info->hoplimit = hopCountToRoot; info->hoplimit = MAX_HOP_COUNT; } } else { // PRINTF("route packet, addr=0x%04x port=%02x\n", dst->shortAddr, info->dstPort); uint8_t index = markAsSeen(info->immedSrc.shortAddr, false); if (index != 0xff) { uint32_t expectedTimeStart = 4000ul + MOTE_TIME_FULL * index + MOTE_TIME + (IS_ODD_COLLECTOR ? MOTE_TIME_FULL * MAX_MOTES : 0); uint32_t expectedTimeEnd = expectedTimeStart + MOTE_TIME; uint32_t now = timeSinceFrameStart(); if (now < expectedTimeStart || now > expectedTimeEnd) { TPRINTF("*** mote %#04x sends out of its time: expected at %lu (+0-512 ms), now %lu!\n", motes[index].address, expectedTimeStart, now); } } else { if (timeSinceFrameStart() > 4000) { TPRINTF("*** unregistered sender!\n"); } } } if (isLocalAddress(dst)) { INC_NETSTAT(NETSTAT_PACKETS_RECV, info->originalSrc.shortAddr); return RD_LOCAL; } if (isBroadcast(dst)) { fillLocalAddress(&info->immedSrc); // XXX if (!IS_LOCAL(info)){ INC_NETSTAT(NETSTAT_PACKETS_RECV, info->originalSrc.shortAddr); } // don't forward broadcast packets return IS_LOCAL(info) ? RD_BROADCAST : RD_LOCAL; } // check if hop limit allows the packet to be forwarded if (!checkHoplimit(info)) { PRINTF("hoplimit reached!\n"); return RD_DROP; } // fill address: may forward it fillLocalAddress(&info->immedSrc); if (dst->shortAddr == rootAddress) { if (isRoutingInfoValid()) { //PRINTF("using 0x%04x as nexthop to root\n", nexthopToRoot); if (!IS_LOCAL(info)) { #if PRECONFIGURED_NH_TO_ROOT if (info->immedDst.shortAddr != localAddress) { TPRINTF("Dropping, I'm not a nexthop for sender %#04x\n", info->originalSrc.shortAddr); INC_NETSTAT(NETSTAT_PACKETS_DROPPED_RX, EMPTY_ADDR); return RD_DROP; } #endif // if (info->hoplimit < hopCountToRoot){ // PRINTF("Dropping, can't reach host with left hopCounts\n"); // return RD_DROP; // } TPRINTF("****** Forwarding a packet to root for %#04x!\n", info->originalSrc.shortAddr); INC_NETSTAT(NETSTAT_PACKETS_FWD, nexthopToRoot); // delay a bit info->timeWhenSend = getSyncTimeMs() + randomNumberBounded(150); } else{ //INC_NETSTAT(NETSTAT_PACKETS_SENT, nexthopToRoot); // Done @ comm.c } info->immedDst.shortAddr = nexthopToRoot; return RD_UNICAST; } else { // PRINTF("root routing info not present or expired!\n"); TPRINTF("DROP\n"); return RD_DROP; } } if (IS_LOCAL(info)) { //INC_NETSTAT(NETSTAT_PACKETS_SENT, dst->shortAddr); // Done @ comm.c // send out even with an unknown nexthop, makes sense? return RD_UNICAST; } return RD_DROP; }
int main() { init_printf(NULL, stdout_putf); printf("Fun with printf and %%!\n"); TPRINTF("d1=%016llx d2=%016lx d3=%02x d4=%02X 42=%03d\n", (long long unsigned)0xd1, (long unsigned)0xd2, 0xd3, 0xd4, 42); TPRINTF("d1=%04x d2=%06x d3=%08x %%100\n", 0xd1, 0xd2, 0xd3); TPRINTF("|%-14s| |%-16s| d2=%2x |%-30s|\n", "str14", "str16", 0xd2, "12345678901234567890123456789012345"); TPRINTF("|%4s|\n", "string4"); TPRINTF("|%-4s|\n", "string4"); TPRINTF("42=%3d d1=%4.4x |%4s| d2=%8.8x\n", 42, 0xd1, "string4", 0xd2); TPRINTF("42=%3d d1=%4.4x |%-4s| d2=%8.8x\n", 42, 0xd1, "string4", 0xd2); TPRINTF("84=%d 21=%ds |%s| |%sOK| d1=%x d2=%#x\n", 84, 21, "hello", "fine", 0xd1, 0xd2); TPRINTF("%lld\n", LLONG_MIN); TPRINTF("%lld\n", LLONG_MAX); TPRINTF("%llu\n", ULLONG_MAX); TPRINTF("%llx\n", LLONG_MIN); TPRINTF("%llx\n", LLONG_MAX); TPRINTF("%llx\n", ULLONG_MAX); TPRINTF("d1=%.1x\n", 0xd1); TPRINTF("d1=%4.1x\n", 0xd1); TPRINTF("d1=%4.x\n", 0xd1); { char blah[256]; TPRINTF("a=%zd\n", sizeof(blah)); TPRINTF("a=%zu\n", sizeof(blah)); TPRINTF("a=%zi\n", sizeof(blah)); TPRINTF("a=0x%zx\n", sizeof(blah)); } { int in_stack; TPRINTF("Adddress of main: %p\n", main); TPRINTF("Adddress of stack variable: %p\n", &in_stack); } return 0; }
static void do_the_long_jump(void) { TPRINTF("Will do a long jump back to test_it().\n"); longjmp(jmp_env, 1); }
static const char *test_virtchar1_internal(const char *path) { TPRINTF("Opening `%s'...\n", path); int fd = open(path, O_RDONLY); if (fd < 0) { TPRINTF(" ...error: %s\n", str_error(fd)); if (fd == ENOENT) { TPRINTF(" (error was ENOENT: " \ "have you compiled test drivers?)\n"); } return "Failed opening devman driver device for reading"; } TPRINTF(" ...file handle %d\n", fd); TPRINTF(" Asking for session...\n"); async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd); if (!sess) { close(fd); TPRINTF(" ...error: %s\n", str_error(errno)); return "Failed to get session to device"; } TPRINTF(" ...session is %p\n", sess); TPRINTF(" Will try to read...\n"); size_t i; char buffer[BUFFER_SIZE]; char_dev_read(sess, buffer, BUFFER_SIZE); TPRINTF(" ...verifying that we read zeroes only...\n"); for (i = 0; i < BUFFER_SIZE; i++) { if (buffer[i] != 0) { return "Not all bytes are zeroes"; } } TPRINTF(" ...data read okay\n"); /* Clean-up. */ TPRINTF(" Closing session and file descriptor\n"); async_hangup(sess); close(fd); return NULL; }
/*! * \brief Transmit and/or receive data as a master. * * The two-wire serial interface must have been initialized by calling * TwInit() before this function can be used. * * \param sla Slave address of the destination. This slave address * must be specified as a 7-bit address. For example, the * PCF8574A may be configured to slave addresses from 0x38 * to 0x3F. * \param txdata Points to the data to transmit. Ignored, if the number * of data bytes to transmit is zero. * \param txlen Number of data bytes to transmit. If zero, then the * interface will not send any data to the slave device * and will directly enter the master receive mode. * \param rxdata Points to a buffer, where the received data will be * stored. Ignored, if the maximum number of bytes to * receive is zero. * \param rxsiz Maximum number of bytes to receive. Set to zero, if * no bytes are expected from the slave device. * \param tmo Timeout in milliseconds. To disable timeout, set this * parameter to NUT_WAIT_INFINITE. * * \return The number of bytes received, -1 in case of an error or timeout. */ int NutTwiMasterTranceive( NUTTWIBUS *bus, uint8_t sla, const void *txdata, uint16_t txlen, void *rxdata, uint16_t rxsiz, uint32_t tmo ) { int rc = -1; NUTTWIICB *icb = bus->bus_icb; // TPRINTF( "TMT "); /* This routine is marked reentrant, so lock the interface. */ if( NutEventWait( &bus->bus_mutex, tmo ) ) { icb->tw_mm_error = TWERR_IF_LOCKED; TPRINTF("! mtx=LOCKED... OUT\n"); return rc; } #if 0 /* Check if bus is blocked for any reason */ if (TwWaitBusFree( bus)) { return rc; } #endif /* Clear errors. */ icb->tw_mm_err = 0; /* fetch transfer parameters for current transaction */ icb->tw_mm_sla = sla<<1; icb->tw_mm_iadr = NULL; icb->tw_mm_iadrlen = 0; icb->tw_mm_txbuf = (uint8_t*)txdata; icb->tw_mm_txlen = txlen; icb->tw_mm_rxbuf = rxdata; icb->tw_mm_rxlen = rxsiz; icb->tw_mm_err = 0; if (icb->tw_mm_rxlen) icb->tw_mm_dir = MODE_READ; else icb->tw_mm_dir = MODE_WRITE; /* Issue start and wait till transmission completed */ NutTwiStartRolling( bus, tmo); /* Check for errors that may have been detected * by the interrupt routine. */ if( icb->tw_mm_err ) { icb->tw_mm_error = icb->tw_mm_err; rc = -1; /* Soft-Reset this Bus */ // NutTwiSoftReset( bus); } else { if( rxsiz) rc = (int)(rxsiz - icb->tw_mm_rxlen); else rc = (int)(txlen - icb->tw_mm_txlen); } /* Release the interface. */ NutEventPost( &bus->bus_mutex ); TPRINTF( "* Bye rc=%d\n", rc); return rc; }
const char *test_print1(void) { TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); TPRINTF("Expected output: \" tex\"\n"); TPRINTF("Real output: \"%*.*s\"\n\n", 5, 3, "text"); TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n"); TPRINTF("Expected output: \" very lon\"\n"); TPRINTF("Real output: \"%10.8s\"\n\n", "very long text"); TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n"); TPRINTF("Expected output: \" text\"\n"); TPRINTF("Real output: \"%8.10s\"\n\n", "text"); TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n"); TPRINTF("Expected output: \"very long \"\n"); TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); TPRINTF("Testing printf(\"%%-*.*s\", 7, 7, \"text\"):\n"); TPRINTF("Expected output: \"text \"\n"); TPRINTF("Real output: \"%-*.*s\"\n\n", 7, 7, "text"); return NULL; }
static void routingReceive(Socket_t *s, uint8_t *data, uint16_t len) { // PRINTF("routingReceive %d bytes from %#04x\n", len, // s->recvMacInfo->originalSrc.shortAddr); // PRINTF("routing rx\n"); if (len == 0) { PRINTF("routingReceive: no data!\n"); return; } #if PRECONFIGURED_NH_TO_ROOT if (s->recvMacInfo->originalSrc.shortAddr != PRECONFIGURED_NH_TO_ROOT) { PRINTF("Dropping routing info: not from the nexthop, but from %#04x\n", s->recvMacInfo->originalSrc.shortAddr); return; } PRINTF("Got routing info from the nexthop\n"); #endif uint8_t type = data[0]; if (type == ROUTING_REQUEST) { uint8_t senderType = data[1]; if (senderType != SENDER_MOTE) return; uint8_t idx = markAsSeen(s->recvMacInfo->originalSrc.shortAddr, true); if (gotRreq == 0xff) { gotRreq = idx; alarmSchedule(&roOutOfOrderForwardTimer, randomNumberBounded(400)); } return; } if (type != ROUTING_INFORMATION) { PRINTF("routingReceive: unknown type!\n"); return; } if (len < sizeof(RoutingInfoPacket_t)) { PRINTF("routingReceive: too short for info packet!\n"); return; } RoutingInfoPacket_t ri; memcpy(&ri, data, sizeof(RoutingInfoPacket_t)); bool update = false; if (!isRoutingInfoValid() || timeAfter16(ri.seqnum, lastSeenSeqnum)) { // XXX: theoretically should add some time to avoid switching to // worse path only because packets from it travel faster update = true; TPRINTF("RI updated: > seqnum\n"); } else if (ri.seqnum == lastSeenSeqnum) { if (ri.hopCount < hopCountToRoot) { update = true; TPRINTF("RI updated: < metric\n"); } else if (ri.hopCount == hopCountToRoot && !seenRoutingInThisFrame) { update = true; TPRINTF("RI updated: == metric\n"); } } if (ri.hopCount > MAX_HOP_COUNT) update = false; if (update) { if (timeSinceFrameStart() < 2000 || timeSinceFrameStart() > 4000) { PRINTF("*** forwarder (?) sends out of time!\n"); } seenRoutingInThisFrame = true; rootAddress = ri.rootAddress; nexthopToRoot = s->recvMacInfo->originalSrc.shortAddr; lastSeenSeqnum = ri.seqnum; hopCountToRoot = ri.hopCount; lastRootMessageTime = (uint32_t) getJiffies(); int64_t oldRootClockDeltaMs = rootClockDeltaMs; rootClockDeltaMs = ri.rootClockMs - getTimeMs64(); if (abs((int32_t)oldRootClockDeltaMs - (int32_t)rootClockDeltaMs) > 500) { PRINTF("large delta change=%ld, time sync off?!\n", (int32_t)rootClockDeltaMs - (int32_t)oldRootClockDeltaMs); PRINTF("delta: old=%ld, new=%ld\n", (int32_t)oldRootClockDeltaMs, (int32_t)rootClockDeltaMs); } // TPRINTF("OK!%s\n", isListening ? "" : " (not listening)"); // reschedule next listen start after this timesync alarmSchedule(&roStartListeningTimer, timeToNextFrame() + 2000); } else { TPRINTF("RI not updated!\n"); } }