void cam_nplusone_decoder(struct decoder *d) { timeval_t t0, t1; int sync, trigger; decoder_state oldstate = d->state; disable_interrupts(); t0 = d->last_t0; t1 = d->last_t1; trigger = d->needs_decoding_t0; d->needs_decoding_t0 = 0; sync = d->needs_decoding_t1; d->needs_decoding_t1 = 0; enable_interrupts(); if (d->state == DECODER_NOSYNC && trigger) { if (d->current_triggers_rpm >= d->required_triggers_rpm) { d->state = DECODER_RPM; } else { d->current_triggers_rpm++; } } if (trigger && sync) { /* Which came first? */ if (time_in_range(t1, t0, current_time())) { trigger_update(d, t0); sync_update(d); } else { sync_update(d); trigger_update(d, t0); } } else if (trigger) { trigger_update(d, t0); } else { sync_update(d); } if (d->state == DECODER_SYNC) { d->valid = 1; d->last_trigger_time = t0; } else { if (oldstate == DECODER_SYNC) { /* We lost sync */ invalidate_decoder(); } } }
void tfi_pip_decoder(struct decoder *d) { timeval_t t0; decoder_state oldstate = d->state; disable_interrupts(); t0 = d->last_t0; d->needs_decoding_t0 = 0; enable_interrupts(); if (d->state == DECODER_NOSYNC) { if (d->current_triggers_rpm >= d->required_triggers_rpm) { d->state = DECODER_RPM; } else { d->current_triggers_rpm++; } } trigger_update(d, t0); if (d->state == DECODER_RPM || d->state == DECODER_SYNC) { d->state = DECODER_SYNC; d->valid = 1; d->last_trigger_time = t0; d->triggers_since_last_sync = 0; /* There is no sync */; } else { if (oldstate == DECODER_SYNC) { /* We lost sync */ invalidate_decoder(); } } }
RZLWidget::RZLWidget(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_TranslucentBackground); icon_unklar = new QIcon("/usr/share/raumzeitlabor-status-widget/unklar.png"); icon_auf = new QIcon("/usr/share/raumzeitlabor-status-widget/auf.png"); icon_zu = new QIcon("/usr/share/raumzeitlabor-status-widget/zu.png"); icon = icon_unklar; lastUpdated = "?"; hdl = curl_easy_init(); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Pragma: no-cache"); headers = curl_slist_append(headers, "Cache-Control: no-cache"); curl_easy_setopt(hdl, CURLOPT_URL, "http://status.raumzeitlabor.de/api/simple"); curl_easy_setopt(hdl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(hdl, CURLOPT_WRITEFUNCTION, recv_status); curl_easy_setopt(hdl, CURLOPT_WRITEDATA, this); curl_easy_setopt(hdl, CURLOPT_ERRORBUFFER, errbuf); /* set a timeout of 30 seconds */ curl_easy_setopt(hdl, CURLOPT_TIMEOUT, 30); /* Timer will be triggered in setConnection() as soon as the connection * status is known */ timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(trigger_update())); periodic_bearer = new QTimer(this); periodic_bearer->start(60 * 1000); connect(periodic_bearer, SIGNAL(timeout()), this, SLOT(trigger_periodic())); /* Setup stuff for the conic library */ DBusConnection *conn; DBusError err; dbus_error_init(&err); conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); if (!conn) return; dbus_connection_setup_with_g_main(conn, NULL); /* We want to get called on connection events */ connection = con_ic_connection_new(); g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(connection_change), this); g_object_set(G_OBJECT(connection), "automatic-connection-events", TRUE, NULL); /* ConIcConnection object named "connection" has already been created */ g_signal_connect(G_OBJECT(connection), "statistics", G_CALLBACK(connection_statistics), this); con_ic_connection_statistics(connection, NULL); }
void *update_thread(void *arg) { interface_t **interfaces = (interface_t **)arg; int updateCounter; rip_packet_t *packet = (rip_packet_t *)malloc(4 + 8 * MAX_RT_ENTRIES); struct ip *ip_pack; routeentry_t *entry; int update, htsize; int triggerUpdate; //first, send out requests: dbg(DBG_ROUTE, "route: sending out requests to all our interfaces\n"); interface_t **curintp; packet->command = COMMAND_REQUEST; packet->num_entries = 0; rip_packet_hton(packet); int packetlen = 4; for (curintp = &interfaces[0]; *curintp; ++curintp) { interface_t *curint = *curintp; ip_pack = ip_packet_construct(curint->local_virt_ip, curint->remote_virt_ip, 0, 1, RIP_PROTOCOL_NUM, (void *)packet, packetlen); if (net_send_noroute(ip_pack, curint) < 0) { dbg(DBG_ROUTE, "update_thread: Failed to send request packet on interface %s\n", inet_ntoa_host(curint->local_virt_ip)); } ip_packet_destruct(ip_pack); } rip_packet_ntoh(packet); updateCounter = 0; while (1) { // Check for triggered updates pthread_mutex_lock(&g_updateMutex); update = g_update; pthread_mutex_unlock(&g_updateMutex); //printf("done checking.\n"); if (update == 1) // Send your data to everyone { dbg(DBG_ROUTE, "route: Triggered update.\n"); if (announce_all(interfaces) != 0) { dbg(DBG_ROUTE, "update_thread: announce_all has encountered an error\n"); } } if (updateCounter == 0 || update==1) // Do updates every UPDATE_TIME seconds { // Send updates to everyone pthread_mutex_lock(&g_routeMutex); htsize = g_routeTable->ht_size; pthread_mutex_unlock(&g_routeMutex); if (htsize != 0) // Do not send it if it is empty { dbg(DBG_ROUTE, "route: %s update.\n", (updateCounter==0?"Regular":"Triggered")); if (announce_all(interfaces) != 0) { dbg(DBG_ROUTE, "route: %dsec update: announce_all has encountered an error\n", UPDATE_TIME); } } else dbg(DBG_ROUTE, "route: no entries in table, not updating.\n"); //schedule next update updateCounter = -UPDATE_TIME; if (update == 1) { pthread_mutex_lock(&g_updateMutex); g_update = 0; pthread_mutex_unlock(&g_updateMutex); } update_own_interfaces(interfaces); } //check the table for expired entries and such. pthread_mutex_lock(&g_routeMutex); triggerUpdate = 0; int key; htable_iterate_begin(g_routeTable, key, entry, routeentry_t) { if (time(NULL) - entry->lastRefreshTime >= ENTRYEXPIRE_TIME) { if (entry->cost != ROUTE_INFINITY) { dbg(DBG_ROUTE, "route: Route to %d expired.\n", __hnode->hn_id); entry->cost = ROUTE_INFINITY; triggerUpdate = 1; } } } htable_iterate_end(); pthread_mutex_unlock(&g_routeMutex); //check interfaces //if any interfaces are now down, update entries through them to INFINITY for (int i=0;interfaces[i];i++) { int upstate, hashkey; upstate = (interfaces[i]->sock != -1); if (upstate == 0) { pthread_mutex_lock(&g_routeMutex); htable_iterate_begin(g_routeTable, hashkey, entry, routeentry_t) { if (entry->interface == interfaces[i] && entry->cost != ROUTE_INFINITY) { dbg(DBG_ROUTE, "route: Interface %s has gone down - route to %d lost.\n", inet_ntoa_host(interfaces[i]->local_virt_ip), hashkey); entry->cost = ROUTE_INFINITY; triggerUpdate = 1; } } htable_iterate_end(); pthread_mutex_unlock(&g_routeMutex); } } if (triggerUpdate) trigger_update(); updateCounter++; sleep(1); }
void rip_handler(interface_t *interface, struct ip *packet) { int i; rip_packet_t *rip_pack; int triggerUpdate; if (packet == NULL) { dbg(DBG_ROUTE, "rip_handler: received NULL packet"); return; } dbg(DBG_ROUTE, "rip_handler: Received packet from %s", inet_ntoa_host(interface->remote_virt_ip)); dbg(DBG_ROUTE, ", says it's from %s\n", inet_ntoa_host(packet->ip_src)); //ip_packet_print(packet, 1); //now deal with the packet. triggerUpdate = 0; //update the routing table with information directly connecting us to //this node. //the packet's source might be wrong, but the interface is always right pthread_mutex_lock(&g_routeMutex); if (update_routing_table(interface->remote_virt_ip, 1, interface, 0)) triggerUpdate = 1; pthread_mutex_unlock(&g_routeMutex); rip_pack = (rip_packet_t *)(packet + 1); //data starts after the header rip_packet_ntoh(rip_pack); if (rip_pack->command == COMMAND_REQUEST) { // This is a request, so send back a response dbg(DBG_ROUTE, "route: Request received from %s.\n", inet_ntoa_host(packet->ip_src)); announce_routes(interface); } else if (rip_pack->command == COMMAND_RESPONSE) { uint32_t cost; struct in_addr address; // This is a response, parse it and update dbg(DBG_ROUTE, "route: Response received from %s:\n", inet_ntoa_host(packet->ip_src)); pthread_mutex_lock(&g_routeMutex); for (i=0; i < rip_pack->num_entries; i++) { cost = rip_pack->entries[i].cost; address = rip_pack->entries[i].address; int i; int ignore=0; for (i=0; g_interfaces[i]; ++i) { if (address.s_addr == g_interfaces[i]->local_virt_ip.s_addr) { dbg(DBG_ROUTE, " Ignoring an entry about ourselves.\n"); ignore=1; break; } } if (ignore) continue; dbg(DBG_ROUTE, " Cost: %d. Address: %s, ", cost, inet_ntoa_host(address)); //update the routing table //dbg(DBG_ROUTE, " "); if (update_routing_table(address, cost+1, interface, 1)) triggerUpdate = 1; } pthread_mutex_unlock(&g_routeMutex); } else { dbg(DBG_ROUTE, "handleRequests: unknown RIP packet command from %s: %d\n", inet_ntoa_host(packet->ip_src), rip_pack->command); } if (triggerUpdate) trigger_update(); }
int main(int argc, char **argv) { char buf[32]; char *bin_path, *ptr; struct pru_data pru; int fd; #ifndef DEBUG if (fork() != 0) { return 0; } #endif tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA; prussdrv_init(); if (prussdrv_open(PRU_EVTOUT_0)) { fprintf(stderr, "Cannot setup PRU_EVTOUT_0.\n"); return -EINVAL; } prussdrv_pruintc_init(&pruss_intc_initdata); prussdrv_map_prumem(PRUSS0_PRU0_DATARAM, (void *) &pru.prumem); if (pru.prumem == NULL) { fprintf(stderr, "Cannot map PRU0 memory buffer.\n"); return -ENOMEM; } /* Create the FIFO if it does not exist */ umask(0); mknod(FIFO_FILE, S_IFIFO|0666, 0); fd = open(FIFO_FILE, O_RDONLY); if (fd < 0) { fprintf(stderr, "Cannot open FIFO.\n"); return -EINVAL; } pru.prumem[RUN_FLAG_IDX] = 1; /* startup */ bin_path = strdup(argv[0]); ptr = strrchr(bin_path, '/'); *ptr = '\0'; chdir(bin_path); prussdrv_exec_program(0, "pru0_nixie.bin"); blank_vfd(&pru); signal(SIGINT, shutdown_clock); signal(SIGTERM, shutdown_clock); while (running) { if (read(fd, buf, sizeof(buf) - 1) > 0) { update_buffer((const char *) &buf, &pru); trigger_update(&pru); } usleep(msecs(10)); } close(fd); pru.prumem[RUN_FLAG_IDX] = 0; trigger_update(&pru); #ifdef DEBUG fprintf(stdout, "Waiting for PRU core to shutdown..\n"); #endif prussdrv_pru_wait_event(PRU_EVTOUT_0); prussdrv_pru_clear_event(PRU0_ARM_INTERRUPT); prussdrv_pru_disable(0); prussdrv_exit(); if (bin_path) { free(bin_path); } return 0; }
static void blank_vfd(struct pru_data *pru) { /* blank VFD */ memset(pru->prumem, 0, NUM_DIGITS * sizeof(uint32_t)); trigger_update(pru); }