int main(void) { // Enable pin change interrupt for pulse input PCMSK3 |= _BV(PCINT28); PCICR |= _BV(PCIE3); // Enable pullup resistor on unused pins PORTA = 0xFF; // Set millisecond-timer period to 1ms OCR1A = 9999; STOP_MILLISECOND_TIMER; TIMSK1 |= _BV(OCIE1A); // Set other init usb_initialize(); camera_initialize(); display_initialize(); // Enable relay mode until reboot if (eeprom_read_byte(RELAY_EEPROM_OFFSET) == RELAY_ENABLED) { set_timer_status(TIMER_RELAY); eeprom_update_byte(RELAY_EEPROM_OFFSET, RELAY_DISABLED); } // Enable interrupts sei(); gps_initialize(); // Main program loop for (;;) { // Handle message flags set via interrupt if (message_flags && timer_status != TIMER_RELAY) { uint8_t temp_int_flags = 0; ATOMIC_BLOCK(ATOMIC_FORCEON) { temp_int_flags = message_flags; message_flags = 0; } if (temp_int_flags & FLAG_SEND_TRIGGER) usb_send_trigger(); if (temp_int_flags & FLAG_SEND_TIMESTAMP) usb_send_timestamp(); if (temp_int_flags & FLAG_SEND_STATUS) usb_send_status(timer_status, gps_status); if (temp_int_flags & FLAG_STOP_EXPOSURE) usb_stop_exposure(); if (temp_int_flags & FLAG_DUPLICATE_PULSE) usb_send_message_P(msg_duplicate_pulse); if (temp_int_flags & FLAG_MISSING_PULSE) usb_send_message_P(msg_missing_pulse); if (temp_int_flags & FLAG_TIME_DRIFT) usb_send_message_fmt_P(fmt_time_drift, millisecond_drift); } camera_tick(); usb_tick(); gps_tick(); display_update(); }
int main(int argc, char **argv) { char *dev; int oldMonitor, newMonitor; u_char packet[4096]; int pktlen; wiviz_cfg cfg; int i; int defaultHopSeq[] = { 1, 3, 6, 8, 11 }; int s, one; memset(&cfg, 0, sizeof(cfg)); #ifdef HAVE_RT2880 wl_dev = "ra0"; #elif HAVE_MADWIFI wl_dev = nvram_safe_get("wifi_display"); #else char tmp[32]; sprintf(tmp, "%s_ifname", nvram_safe_get("wifi_display")); wl_dev = nvram_safe_get(tmp); #endif if (argc > 1) if (!strcmp(argv[1], "terminate")) { #ifdef HAVE_MADWIFI // return to original channel #ifdef HAVE_ATH9K if (!is_ath9k(wl_dev)) #endif { sysprintf("iwconfig %s channel %sM", get_monitor(), nvram_nget("%s_channel", nvram_safe_get("wifi_display"))); sleep(1); sysprintf("ifconfig %s down", get_monitor()); if (is_ar5008(nvram_safe_get("wifi_display"))) { sysprintf("80211n_wlanconfig %s destroy", get_monitor()); } else { sysprintf("wlanconfig %s destroy", get_monitor()); } } #elif HAVE_RT2880 nvram_set("wl0_mode", nvram_safe_get("wl0_oldmode")); sysprintf("startservice configurewifi"); if (nvram_match("wl0_mode", "sta") || nvram_match("wl0_mode", "apsta")) { sysprintf("startstop wan"); } #else oldMonitor = 0; wl_ioctl(wl_dev, WLC_SET_MONITOR, &oldMonitor, 4); #endif return 0; } global_cfg = &cfg; signal(SIGUSR1, &signal_handler); signal(SIGUSR2, &signal_handler); printf("Wi-Viz 2 infogathering daemon by Nathan True\n"); printf("http://wiviz.natetrue.com\n"); memset(&cfg, 0, sizeof(wiviz_cfg)); cfg.numHosts = 0; cfg.lastKeepAlive = time(NULL); cfg.channelHopping = 0; cfg.channelDwellTime = 1000; cfg.channelHopSeqLen = 5; memcpy(cfg.channelHopSeq, defaultHopSeq, sizeof(defaultHopSeq)); #if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) wl_ioctl(wl_dev, WLC_GET_MAGIC, &i, 4); if (i != WLC_IOCTL_MAGIC) { printf("Wireless magic not correct, not querying wl for info %X!=%X\n", i, WLC_IOCTL_MAGIC); cfg.readFromWl = 0; } else { cfg.readFromWl = 1; wl_ioctl(wl_dev, WLC_GET_MONITOR, &oldMonitor, 4); newMonitor = 1; wl_ioctl(wl_dev, WLC_SET_MONITOR, &newMonitor, 4); } #elif HAVE_RT2880 nvram_set("wl0_oldmode", nvram_safe_get("wl0_mode")); nvram_set("wl0_mode", "sta"); if (!nvram_match("wl0_oldmode", "sta")) sysprintf("startservice configurewifi"); sysprintf("iwconfig ra0 mode monitor"); cfg.readFromWl = 1; #else #ifdef HAVE_ATH9K if (!is_ath9k(nvram_safe_get("wifi_display"))) #endif { if (is_ar5008(nvram_safe_get("wifi_display"))) { sysprintf("80211n_wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display"))); } else { sysprintf("wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display"))); } sysprintf("ifconfig %s up", get_monitor()); } cfg.readFromWl = 1; #endif reloadConfig(); #if defined(HAVE_MADWIFI) || defined(HAVE_RT2880) s = openMonitorSocket(get_monitor()); // for testing we use ath0 #else if (nvram_match("wifi_display", "wl1")) s = openMonitorSocket("prism1"); else s = openMonitorSocket("prism0"); #endif if (s == -1) return; one = 1; ioctl(s, FIONBIO, (char *)&one); if (cfg.readFromWl) { readWL(&cfg); } #ifdef WIVIZ_GPS gps_init(&cfg); #endif while (!stop) { #ifdef WIVIZ_GPS gps_tick(); #else if (time(NULL) - cfg.lastKeepAlive > 30) stop = 1; #endif pktlen = recv(s, packet, 4096, 0); if (pktlen <= 0) continue; dealWithPacket(&cfg, pktlen, packet); } signal_handler(SIGUSR1); if (cfg.channelHopperPID) kill(cfg.channelHopperPID, SIGKILL); #ifndef WIVIZ_GPS for (i = 0; i < MAX_HOSTS; i++) { print_host(stderr, cfg.hosts + i); if (cfg.hosts[i].occupied) printf("\n"); if (cfg.hosts[i].apInfo) free(cfg.hosts[i].apInfo); if (cfg.hosts[i].staInfo) free(cfg.hosts[i].staInfo); } #endif close(s); return 0; }