int main(void) { // board setup stuff led_init(); uart_init(); floppy_low_init(); sdpin_init(); spi_low_cs_init(); spi_low_mst_init(); //timer_init(); // say hello uart_send_string((u08 *)"--- dfx-sampler sam7x/SPI ---"); uart_send_crlf(); // do initial setup rtc_init(); memory_init(); floppy_select_on(); track_init(); floppy_select_off(); net_init(); // print current RTC uart_send_string((u08 *)"rtc: "); uart_send_string((u08 *)rtc_get_time_str()); uart_send_crlf(); // show network info net_info(); while(1) { uart_send_string((u08 *)"> "); led_green(1); // get next command via SPI u08 *cmd; u08 len = cmd_uart_get_next(&cmd); led_green(0); if(len>0) { u08 result[CMD_MAX_SIZE]; u08 res_size = CMD_MAX_SIZE; // parse and execute command cmd_parse(len, cmd, &res_size, result); // report result if(res_size > 0) { uart_send_data(result, res_size); uart_send_crlf(); } } } }
PyMODINIT_FUNC init_spotify(void) { PyObject *m; if (PyType_Ready(&SessionType) < 0) return; if (PyType_Ready(&ArtistType) < 0) return; if (PyType_Ready(&ArtistBrowserType) < 0) return; if (PyType_Ready(&LinkType) < 0) return; if (PyType_Ready(&PlaylistType) < 0) return; if (PyType_Ready(&PlaylistContainerType) < 0) return; if (PyType_Ready(&ResultsType) < 0) return; if (PyType_Ready(&ToplistBrowserType) < 0) return; if (PyType_Ready(&TrackType) < 0) return; if (PyType_Ready(&ImageType) < 0) return; if (PyType_Ready(&UserType) < 0) return; m = Py_InitModule("_spotify", module_methods); if (m == NULL) return; PyObject *spotify = PyImport_ImportModule("spotify"); PyObject *d = PyModule_GetDict(spotify); PyObject *s = PyUnicode_FromString("SpotifyError"); SpotifyError = PyDict_GetItem(d, s); Py_INCREF(SpotifyError); SpotifyApiVersion = Py_BuildValue("i", SPOTIFY_API_VERSION); Py_INCREF(SpotifyApiVersion); PyModule_AddObject(m, "api_version", SpotifyApiVersion); album_init(m); albumbrowser_init(m); artist_init(m); artistbrowser_init(m); link_init(m); playlist_init(m); playlistcontainer_init(m); session_init(m); search_init(m); toplistbrowser_init(m); track_init(m); image_init(m); user_init(m); }
static void new_track_button_clicked(GtkWidget *widget, gpointer data) { if (! track_init(TRUE)) return; g_context.track_enabled = TRUE; gtk_widget_set_sensitive(new_track_button, FALSE); gtk_widget_set_sensitive(stop_track_button, TRUE); ctx_gpsfix_on_track_state_changed(); }
/** * OS time is not reliable, so we use GPS time to determine relative span. * GPS tow can be smaller than previous when cross GPS week. * Anyway, restart a new log file when time reverse detected */ void track_add(/*double lat, double lon, U4 gps_tow*/) { static const float threshold = TRACK_MAX_DELTA * (180.0 / (WGS84_SEMI_MAJOR_AXIS * M_PI)); /* NOTE: make max frequency is 1 HZ, since we record time offset with unit of seconds */ //if (g_gpsdata.llh_itow - previous_gps_tow < 1000) // return; trackpoint_t *tp; if (tracks->count > 0) { tp = &(tracks->tps[tracks->count-1]); float lat_delta = (float)fabs(g_gpsdata.lat - tp->wgs84.lat); float lon_delta = (float)fabs(g_gpsdata.lon - tp->wgs84.lon); if (sqrt(lat_delta * lat_delta + lon_delta * lon_delta) < threshold) return; /* new GPS week: split track file */ if (g_context.track_enabled && (g_gpsdata.llh_itow < previous_gps_tow)) { track_save(TRUE, FALSE); track_init(TRUE); return; } } else { tracks->starttime = time(NULL); first_gps_tow = g_gpsdata.llh_itow; } tp = &(tracks->tps[tracks->count]); /* Copy values */ tp->wgs84.lat = g_gpsdata.lat; tp->wgs84.lon = g_gpsdata.lon; tp->id = tracks->total_count; tp->time_offset = (g_gpsdata.llh_itow - first_gps_tow) / (U4)1000; previous_gps_tow = g_gpsdata.llh_itow; ++tracks->count; ++tracks->total_count; if (tracks->count >= TRACK_MAX_IN_MEM_RECORDS) { int saved_count = 0; if (g_context.track_enabled) saved_count = track_save(FALSE, FALSE); if (saved_count == 0) { /* lose data but we need space */ saved_count = tracks->count / 2; } /* move the remaining elements to array head */ tracks->count -= saved_count; memcpy(&tracks->tps[0], &(tracks->tps[saved_count]), tracks->count * sizeof(trackpoint_t)); } }
Track *cd_add_track (Cd *cd) { if (MAXTRACK - 1 > cd->ntrack) cd->ntrack++; else fprintf(stderr, "too many tracks\n"); /* this will reinit last track if there were too many */ cd->track[cd->ntrack - 1] = track_init(); return cd->track[cd->ntrack - 1]; }
static void track_free(void* p, size_t size) { track_init(); assert(!track.internal); track.internal = true; track.stack = pool_track_push(track.stack, POOL_TRACK_FREE); track.stack = pool_track_push(track.stack, p); track.stack = pool_track_push(track.stack, (void*)size); track.stack = pool_track_push(track.stack, (void*)cpu_tick()); track.internal = false; }
static void track_alloc(void* p, size_t size) { track_init(); if(track.internal) return; track.internal = true; track.stack = pool_track_push(track.stack, POOL_TRACK_ALLOC); track.stack = pool_track_push(track.stack, p); track.stack = pool_track_push(track.stack, (void*)size); track.stack = pool_track_push(track.stack, (void*)cpu_tick()); track.internal = false; }
/* catch any incoming messages and display them. returning 1 means that the * message has not been fully handled and the server should try other methods */ int track_load_handler(const char *path, const char *types, lo_arg ** argv, int argc, void *data, void *user_data) { int i, d; printf("track_load_handler: path: <%s>\n", path); #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "osc.c", "path: <%s>\n", path); #endif for (i = 0; i < argc; i++) { #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "osc.c", "arg %d '%c' ", i, types[i]); #endif //lo_arg_pp((lo_type)types[i], argv[i]); //printf("\n"); } /* Shut closeup updater thread before swapping track */ interface_closeup_free(osc->twinterface); d = argv[0]->i; osc->ndeck = max(osc->ndeck, d+1); fprintf(stderr, "updated ndeck: %i\n", osc->ndeck); track_init(d); tracks[d].id = argv[1]->i; tracks[d].artist = (char *) argv[2]; tracks[d].title = (char *) argv[3]; tracks[d].rate = argv[4]->i; //interface_update_overview(osc->twinterface); interface_update_closeup(osc->twinterface); #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "osc.c", "artist:%s\ntitle:%s", tracks[0].artist, tracks[0].title); #endif //printf("\n"); //fflush(stdout); return 1; }
GtkWidget * track_tab_create() { track_init(g_context.track_enabled); GtkWidget *vbox = gtk_vbox_new(FALSE, 5); /* Track record */ GtkWidget *button_hbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox), button_hbox, FALSE, FALSE, 5); new_track_button = gtk_button_new_with_label("New track"); g_signal_connect (G_OBJECT(new_track_button), "clicked", G_CALLBACK (new_track_button_clicked), NULL); gtk_container_add (GTK_CONTAINER(button_hbox), new_track_button); stop_track_button = gtk_button_new_with_label("Stop track"); g_signal_connect (G_OBJECT(stop_track_button), "clicked", G_CALLBACK (stop_track_button_clicked), NULL); gtk_container_add (GTK_CONTAINER(button_hbox), stop_track_button); /* color */ GtkWidget *color_hbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox), color_hbox, FALSE, FALSE, 0); GtkWidget *color_label = gtk_label_new("Set line color: "); gtk_misc_set_alignment(GTK_MISC(color_label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX(color_hbox), color_label, FALSE, FALSE, 5); create_colorlist(); gtk_box_pack_start (GTK_BOX(color_hbox), colorlist, TRUE, TRUE, 5); change_color_button = gtk_button_new_with_label("Change"); g_signal_connect (G_OBJECT (change_color_button), "clicked", G_CALLBACK (change_color_button_clicked), NULL); gtk_box_pack_start (GTK_BOX(color_hbox), change_color_button, TRUE, TRUE, 0); track_colorlist_set_initial_color(); gtk_box_pack_start(GTK_BOX(vbox), create_replay_pane(), TRUE, TRUE, 5); return vbox; }
static void track_pull(pool_item_t* p, size_t length, size_t size) { track_init(); assert(!track.internal); track.internal = true; uint64_t tsc = cpu_tick(); track.stack = pool_track_push(track.stack, POOL_TRACK_PULL_LIST); track.stack = pool_track_push(track.stack, (void*)length); track.stack = pool_track_push(track.stack, (void*)size); track.stack = pool_track_push(track.stack, (void*)tsc); while(p != NULL) { track.stack = pool_track_push(track.stack, POOL_TRACK_PULL); track.stack = pool_track_push(track.stack, p); track.stack = pool_track_push(track.stack, (void*)size); track.stack = pool_track_push(track.stack, (void*)tsc); p = p->next; } track.internal = false; }
int track_capture_time() { track_init(); return tracklib_results_snapshot.frame_time; }
// Entry point of track-server void track_server_entry() { RegisterAs(TRACK_SERVER); // Initialize the track track_init(); // Initialize the reservation list reservation_init(train_reservations); // So we can update our own cached copy of the switch table int switch_courier_tid = CreateSwitchCourier(PRIORITY_HIGHEST - 1); int sender_tid; // Message buffer large enough to hold the largest message request char message_buffer[32]; while (1) { Receive(&sender_tid, message_buffer, sizeof(message_buffer)); if (sender_tid == switch_courier_tid) { // This is an update from the switch server, record the switch that changed // so that our cached table of switches is in sync int reply = 0; Reply(sender_tid, (char*)&reply, sizeof(reply)); struct switch_report* report = (struct switch_report*)message_buffer; switch_table[(int)report->sw] = report->direction; } else { // API requests to the track_server struct track_reply_message reply = {-1, -1}; int op = *(int*)message_buffer; switch(op) { // Handle track reservation requests case TRACK_OP_RESERVATION: { int reply = -1; struct reservation_request_message* reservation_msg = (struct reservation_request_message*)message_buffer; // Make the location be a sensor and positive offset that fits in the edge if (normalize_location(track, switch_table, &reservation_msg->position) != -1) { // Check if we can reserve this space for the train int status = reservation_verify(reservation_msg->train, &(reservation_msg->position), reservation_msg->length, reservation_msg->branch_safety); reply = status; if (status == 0) { // We succeeded. Reserve the track // Find the train's reservation_node struct reservation_node* train_r = get_reservation(train_reservations, reservation_msg->train); if (train_r != 0) { clear_train_reservations(train_r); // Add new reservation reservation_insert(train_r, &(reservation_msg->position), reservation_msg->length, reservation_msg->branch_safety); } } else if (status == -2) { // Reached max reservation } } else { Printf("Could not normalize\r"); } Reply(sender_tid, (char*)&reply, sizeof(reply)); } break; case TRACK_OP_RESERVATION_STRING: { struct reservation_request_message* reservation_msg = (struct reservation_request_message*)message_buffer; struct reservation_node* train_r = get_reservation(train_reservations, reservation_msg->train); char buf[300]; *buf = 0; // null termination character int len = 0; if (train_r != 0) { len = reservation_print(train_r, buf); } Reply(sender_tid, (char*)buf, len); // +1 for null termination char } break; case TRACK_OP_NODE_IS_RESERVED: { struct reservation_request_message* reservation_msg = (struct reservation_request_message*)message_buffer; int reserved = node_is_reserved(reservation_msg->train, reservation_msg->position.node); Reply(sender_tid, (char*)&reserved, sizeof(reserved)); } break; // Handle requests for calculating the distance between 2 nodes case TRACK_OP_TRACK_DISTANCE: { struct track_request_message* track_msg = (struct track_request_message*)message_buffer; if (track_msg->node1 < TRACK_MAX && track_msg->node2 < TRACK_MAX) { reply.distance = dist_between_nodes(track_msg->node1, track_msg->node2); } Reply(sender_tid, (char*)&reply, sizeof(reply)); } break; case TRACK_OP_TRACK_DISTANCE_UNTIL_GOAL: { struct track_request_message* track_msg = (struct track_request_message*)message_buffer; int distance = 0; if (track_msg->node1 < TRACK_MAX && track_msg->node2 < TRACK_MAX) { distance = dist_until_goal(track_msg->node1, track_msg->offset1, track_msg->node2, track_msg->offset2, track_msg->distance); } Reply(sender_tid, (char*)&distance, sizeof(distance)); } break; // Handle requests for getting the next sensor on the track case TRACK_OP_TRACK_NEXT_SENSOR: { struct track_request_message* track_msg = (struct track_request_message*)message_buffer; if (track_msg->node1 >= A1 && track_msg->node1 <= E16) { int distance; int next_sensor = next_sensor_node(track_msg->node1, track_msg->node2, &distance); reply.node = next_sensor; reply.distance = distance; } Reply(sender_tid, (char*)&reply, sizeof(reply)); } break; case TRACK_OP_NORMALIZE: { struct track_request_message *msg = (struct track_request_message*)message_buffer; struct location loc; loc.node = msg->node1; loc.offset = msg->offset1; if (normalize_location(track, switch_table, &loc) == -1) { Reply(sender_tid, (char*)&loc, 0); // reply size 0 means error! } Reply(sender_tid, (char*)&loc, sizeof(loc)); } break; // Handle requests for getting the reverse node of a given node case TRACK_OP_TRACK_REVERSE_NODE: { struct track_request_message* track_msg = (struct track_request_message*)message_buffer; if (track_msg->node1 < TRACK_MAX) { reply.node = track[track_msg->node1].reverse->num; } Reply(sender_tid, (char*)&reply, sizeof(reply)); } break; case TRACK_OP_ROUTE: { struct track_request_message* track_msg = (struct track_request_message*)message_buffer; int train = track_msg->train; int start_node_num = track_msg->node1; int end_node_num = track_msg->node2; short path[TRACK_MAX]; int num_nodes = 0; if (IS_SENSOR(start_node_num) && IS_SENSOR(end_node_num)) { struct track_node *start_node = &track[start_node_num]; struct track_node *end_node = &track[end_node_num]; mark_path(train, track, start_node, end_node); if (end_node->routing_info.visited == 1) { // we have a path! // store all nodes, from bottom up struct track_node *cur_node = end_node; struct location loc; while (cur_node->routing_info.previous != 0 && cur_node != start_node) { node_to_location(cur_node, &loc); path[num_nodes] = loc.node; num_nodes++; if (cur_node->routing_info.previous == cur_node->reverse) { // the next node is the reverse of this node, so we squeeze in a "REVERSE" in the path path[num_nodes] = -99; // magic number for REVERSE commands num_nodes++; } cur_node = cur_node->routing_info.previous; } // we didn't store the beginning node in our path, so we should do that now if (cur_node == start_node) { node_to_location(start_node, &loc); path[num_nodes] = loc.node; num_nodes++; } } else { Printf("Could not find route! num_nodes = %d\r", num_nodes); } } Reply(sender_tid, (char*)path, sizeof(short) * num_nodes); } break; case TRACK_OP_SWITCH_DIRECTION: { struct track_request_message* track_msg = (struct track_request_message*)message_buffer; int switch_node = track_msg->node1; int next_node = track_msg->node2; AssertF(track[switch_node].type == NODE_BRANCH, "TrackSwitchDirection not given a switch node! Given node num %d, type %d", track[switch_node].num, track[switch_node].type); int reserved = node_is_reserved(track_msg->train, switch_node); if (reserved) { // Printf("Attempting to switch %s if reserved .. \r", track[switch_node].name); int direction = -1; if (track[switch_node].edge[DIR_CURVED].dest == &(track[next_node])) { direction = SWITCH_CURVED; } else { direction = SWITCH_STRAIGHT; } SwitchSetDirection(track[switch_node].num, direction, WhoIs(SWITCH_SERVER)); switch_table[track[switch_node].num] = direction; } Reply(sender_tid, (char*)&reserved, sizeof(reserved)); } break; default: AssertF(0, "Invalid message %d to the track server from %d", op, sender_tid); Reply(sender_tid, (char*)&reply, sizeof(reply)); break; } } } Assert("Track server is quitting"); Exit(); }
// sampler commands static void cmd_sampler(void) { u08 cmd, res; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { case 'm': // read track to spi ram { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_to_spiram(parse_hex_byte(1)); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; case 'f': // fake read track (only to spi ram) res = trk_read_sim(parse_hex_byte(1)); set_result(res); break; case 'v': // verify track with spi ram res = trk_check_spiram(parse_hex_byte(1)); set_result(res); break; // ----- checks ----- case 'i': // index check { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_count_index(); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; case 'd': // read data check { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_count_data(); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; case 's': // read data spectrum { u08 sel = floppy_select_on(); u08 mot = floppy_motor_on(); track_init(); res = trk_read_data_spectrum(parse_hex_byte(0)); if(mot) floppy_motor_off(); if(sel) floppy_select_off(); set_result(res); } break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } }
int main(int argc, char *argv[]) { const char *peak_file1 = "peak1.dat"; const char *prof_file1 = "prof1.dat"; const char *peak_file2 = "peak2.dat"; const char *prof_file2 = "prof2.dat"; satdata_mag *data = NULL; current_data sat1, sat2; peak_workspace *peak_workspace_p; struct timeval tv0, tv1; sat1.n = 0; sat2.n = 0; while (1) { int c; int option_index = 0; static struct option long_options[] = { { "curr_file", required_argument, NULL, 'j' }, { "curr_file2", required_argument, NULL, 'k' }, { "swarm_file", required_argument, NULL, 's' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "j:k:s:", long_options, &option_index); if (c == -1) break; switch (c) { case 'j': fprintf(stderr, "main: reading %s...", optarg); read_lc(optarg, &sat1); fprintf(stderr, "done (%zu profiles read)\n", sat1.n); break; case 'k': fprintf(stderr, "main: reading %s...", optarg); read_lc(optarg, &sat2); fprintf(stderr, "done (%zu profiles read)\n", sat2.n); break; case 's': fprintf(stderr, "main: reading %s...", optarg); gettimeofday(&tv0, NULL); data = satdata_swarm_read_idx(optarg, 0); gettimeofday(&tv1, NULL); if (!data) exit(1); fprintf(stderr, "done (%zu points read, %g seconds)\n", data->n, time_diff(tv0, tv1)); break; default: print_help(argv); exit(1); break; } } if (sat1.n == 0) { print_help(argv); exit(1); } peak_workspace_p = peak_alloc(NCURR); if (data) { track_workspace *track_p = track_alloc(); fprintf(stderr, "main: separating into tracks..."); track_init(data, NULL, track_p); fprintf(stderr, "done\n"); /* north hemisphere peak finding */ analyze_hemisphere(-3.0, 23.0, peak_file1, prof_file1, data, track_p, &sat1); /* south hemisphere peak finding */ analyze_hemisphere(-23.0, 0.0, peak_file2, prof_file2, data, track_p, &sat1); satdata_mag_free(data); track_free(track_p); } else if (sat2.n > 0) { const char *data_file1 = "data.dat.north"; const char *corr_file1 = "corr.dat.north"; const char *data_file2 = "data.dat.south"; const char *corr_file2 = "corr.dat.south"; fprintf(stderr, "main: searching for northern J peaks in satellite 1..."); find_J_peaks(5.0, 23.0, -100.0, peak_file1, prof_file1, NULL, NULL, &sat1); fprintf(stderr, "done\n"); fprintf(stderr, "main: searching for northern J peaks in satellite 2..."); find_J_peaks(5.0, 23.0, -100.0, peak_file2, prof_file2, NULL, NULL, &sat2); fprintf(stderr, "done\n"); correlateJ(data_file1, corr_file1, &sat1, &sat2); fprintf(stderr, "main: data printed to %s\n", data_file1); fprintf(stderr, "main: correlation data printed to %s\n", corr_file1); fprintf(stderr, "main: searching for northern J peaks in satellite 2..."); find_J_peaks(-23.0, -5.0, -100.0, peak_file1, prof_file1, NULL, NULL, &sat1); fprintf(stderr, "done\n"); fprintf(stderr, "main: searching for northern J peaks in satellite 2..."); find_J_peaks(-23.0, -5.0, -100.0, peak_file2, prof_file2, NULL, NULL, &sat2); fprintf(stderr, "done\n"); correlateJ(data_file2, corr_file2, &sat1, &sat2); fprintf(stderr, "main: data printed to %s\n", data_file2); fprintf(stderr, "main: correlation data printed to %s\n", corr_file2); } peak_free(peak_workspace_p); return 0; } /* main() */
// track commands static void cmd_track(void) { // ensure floppy is selected u08 did_sel = floppy_select_on(); u08 cmd,res; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { case 'i': track_init(); set_result(STATUS_OK); break; case 'c': res = track_check_max(); set_result(res); break; case 'z': track_zero(); set_result(STATUS_OK); break; case '?': set_result(track_num()); break; case '+': track_step_next(parse_hex_byte(1)); set_result(track_num()); break; case '-': track_step_prev(parse_hex_byte(1)); set_result(track_num()); break; case 'n': track_next(parse_hex_byte(1)); set_result(track_num()); break; case 'p': track_prev(parse_hex_byte(1)); set_result(track_num()); break; case 's': track_side_toggle(); set_result(track_num()); break; case 't': track_side_top(); set_result(track_num()); break; case 'b': track_side_bot(); set_result(track_num()); break; case 'm': track_set_max(parse_hex_byte(79)); set_result(track_get_max()); break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } if(did_sel) { floppy_select_off(); } }
int track_is_new_data_available() { track_init(); return ((TrackingResults*)shared_mem_ptr(tracklib_sm_results))->frame_number != tracklib_results_snapshot.frame_number; }
int track_previous_capture_time() { track_init(); return tracklib_results_snapshot.previous_frame_time; }
void track_update() { track_init(); shared_mem_read(tracklib_sm_results, &tracklib_results_snapshot, sizeof(tracklib_results_snapshot)); }
int track_get_frame() { track_init(); return tracklib_results_snapshot.frame_number; }