/** * Load configuration **/ void load_config(){ config = (Config)malloc(sizeof(struct CONFIG)); config->ip_rpi_cam = read_in_file("ip_rpi_cam"); config->ip_rpi_toy = read_in_file("ip_rpi_toy"); config->ip_cam = read_in_file("ip_cam"); config->port_cam = read_in_file("port_cam"); config->port_toy = read_in_file("port_toy"); config->port_rpi_toy = read_in_file("port_rpi_toy"); config->port_rpi_cam = read_in_file("port_rpi_cam"); config->pwd_rpi_toy = read_in_file("pwd_rpi_toy"); config->pwd_rpi_cam = read_in_file("pwd_rpi_cam"); config->path_record = read_in_file("path_record"); }
// load and set up a 2sf file int setup_playback(char *name) { int res; res = read_in_file(name); if (res < 0) { return res; } m1sdr_Init(44100); m1sdr_SetCallback(do_frame); m1sdr_PlayStart(); if ((c != NULL) && (c->inf_title[0] != '\0')) { BOLD(); //printf("Playing \"%s\" by %s from %s. Copyright %s %s.\nFilename: %s\n", c->inf_title, c->inf_artist, c->inf_game, c->inf_copy, c->inf_year, name); printf("Playing \"%s\" by %s from %s.\n", c->inf_title, c->inf_artist, c->inf_game); printf("Copyright %s %s.\n", c->inf_copy, c->inf_year); printf("Filename: %s.\n", name); NONBOLDYELLOW(); printf("----------------------------------------------------------------\n"); NORMAL(); } else { BOLD(); printf("Playing %s\n", name); NORMAL(); } return 0; }
int main(int argc, char const *argv[]) { // Check args if(argc < 5){ cout << "Please enter (1) a filename query\n \ (2) a csv input file\n \ (3) the number fo results to generate\n\ (4) the number of processes." <<endl; exit(0); } // Check input file FILE *infile = fopen(argv[2], "r"); if(!infile){ cout << "File invalid" << endl; exit(0); } /*************************** Part zero: Get args ****************************/ string queryFilename(argv[1]); // number of results int numResults = 0; if(is_float(argv[3])){ numResults = atoi(argv[3]); } else{ cout << "Invalid number for argument 3" << endl; exit(0); } // number of processes int numProcesses = 0; if(is_float(argv[4])){ numProcesses = atoi(argv[4]); } else{ cout << "Invalid number for argument 4" << endl; exit(0); } /*************************** Part one: Read in file, store in map ****************************/ // Make map of files map< string, uint > fnames; vector< pair< uint, vector<float> > > lines; // Start clock std::chrono::time_point<std::chrono::system_clock> start, end; start = std::chrono::system_clock::now(); int numLines = read_in_file(infile, fnames, lines); end = std::chrono::system_clock::now(); std::chrono::duration<double> timeElapsed1 = end-start; if(numLines <= 0){ cout << "\n\nFile read was unsucessful."<< endl; exit(0); } /*************************** Part two: Perform query ****************************/ start = std::chrono::system_clock::now(); bool success = process_query(fnames, lines, queryFilename, numResults, numProcesses); end = std::chrono::system_clock::now(); std::chrono::duration<double> timeElapsed2 = end-start; if(!success){ cout << "\n\nUnsucessful processing of query" << endl; exit(0); } cout << "\n\nNumber of lines parsed: " << numLines << endl; cout << "Time to process file: " << timeElapsed1.count() << "s" << endl; cout << "Time to process query: " << timeElapsed2.count() << "s" << endl; return 0; }
/** * @brief Update Arbitrary Signal Generator module towards actual settings. * * A function is intended to be called whenever one of the following settings on each channel * is modified * - enable * - signal type * - amplitude * - frequency * - DC offset * - trigger mode * * @param[in] params Pointer to overall configuration parameters * @retval -1 failure, error message is repoted on standard error device * @retval 0 succesful update */ int generate_update(rp_app_params_t *params) { awg_param_t ch1_param, ch2_param; awg_signal_t ch1_type; awg_signal_t ch2_type; int ch1_enable = params[GEN_ENABLE_CH1].value; int ch2_enable = params[GEN_ENABLE_CH2].value; //float time_vect[AWG_SIG_LEN], ch1_amp[AWG_SIG_LEN], ch2_amp[AWG_SIG_LEN]; float ch1_arb[AWG_SIG_LEN]; float ch2_arb[AWG_SIG_LEN]; int wrap; //int invalid_file=0; int in_smpl_len1 = 0; int in_smpl_len2 = 0; ch1_type = (awg_signal_t)params[GEN_SIG_TYPE_CH1].value; ch2_type = (awg_signal_t)params[GEN_SIG_TYPE_CH2].value; if( (ch1_type == eSignalFile) || (params[GEN_AWG_REFRESH].value == 1) ) { if((in_smpl_len1 = read_in_file(1, ch1_arb)) < 0) { // Invalid file params[GEN_ENABLE_CH1].value = 0; params[GEN_SIG_TYPE_CH1].value = eSignalSine; ch1_type = params[GEN_SIG_TYPE_CH1].value; ch1_enable = params[GEN_ENABLE_CH1].value; //invalid_file=1; } } if( (ch2_type == eSignalFile) || (params[GEN_AWG_REFRESH].value == 2) ) { if((in_smpl_len2 = read_in_file(2, ch2_arb)) < 0) { // Invalid file params[GEN_ENABLE_CH2].value = 0; params[GEN_SIG_TYPE_CH2].value = eSignalSine; ch2_type = params[GEN_SIG_TYPE_CH2].value; ch2_enable = params[GEN_ENABLE_CH2].value; // invalid_file=1; } } params[GEN_AWG_REFRESH].value = 0; /* Waveform from signal gets treated differently then others */ if(ch1_enable > 0) { if(ch1_type < eSignalFile) { synthesize_signal(params[GEN_SIG_AMP_CH1].value, params[GEN_SIG_FREQ_CH1].value, gen_calib_params->be_ch1_dc_offs, gen_calib_params->be_ch1_fs, ch1_max_dac_v, params[GEN_SIG_DCOFF_CH1].value, ch1_type, ch1_data, &ch1_param); wrap = 0; // whole buffer used } else { /* Signal file */ calculate_data(ch1_arb, in_smpl_len1, params[GEN_SIG_AMP_CH1].value, params[GEN_SIG_FREQ_CH1].value, gen_calib_params->be_ch1_dc_offs, gen_calib_params->be_ch1_fs, ch1_max_dac_v, params[GEN_SIG_DCOFF_CH1].value, ch1_data, &ch1_param); wrap = 0; if (in_smpl_len1<AWG_SIG_LEN) wrap = 1; // wrapping after (in_smpl_lenx) samples } } else { clear_signal(gen_calib_params->be_ch1_dc_offs, ch1_data, &ch1_param); } write_data_fpga(0, params[GEN_TRIG_MODE_CH1].value, params[GEN_SINGLE_CH1].value, ch1_data, &ch1_param, wrap); /* Waveform from signal gets treated differently then others */ if(ch2_enable > 0) { if(ch2_type < eSignalFile) { synthesize_signal(params[GEN_SIG_AMP_CH2].value, params[GEN_SIG_FREQ_CH2].value, gen_calib_params->be_ch2_dc_offs, gen_calib_params->be_ch2_fs, ch2_max_dac_v, params[GEN_SIG_DCOFF_CH2].value, ch2_type, ch2_data, &ch2_param); wrap = 0; // whole buffer used } else { /* Signal file */ calculate_data(ch2_arb, in_smpl_len2, params[GEN_SIG_AMP_CH2].value, params[GEN_SIG_FREQ_CH2].value, gen_calib_params->be_ch2_dc_offs, gen_calib_params->be_ch2_fs, ch2_max_dac_v, params[GEN_SIG_DCOFF_CH2].value, ch2_data, &ch2_param); wrap = 0; if (in_smpl_len2<AWG_SIG_LEN) wrap = 1; // wrapping after (in_smpl_lenx) samples } } else { clear_signal(gen_calib_params->be_ch2_dc_offs, ch2_data, &ch2_param); } write_data_fpga(1, params[GEN_TRIG_MODE_CH2].value, params[GEN_SINGLE_CH2].value, ch2_data, &ch2_param, wrap); /* Always return singles to 0 */ params[GEN_SINGLE_CH1].value = 0; params[GEN_SINGLE_CH2].value = 0; //if (invalid_file==1) // return -1; // Use this return value to notify the GUI user about invalid file. return 0; }
/* * The editor used by edit_message() when "builtin" or "none" are selected. * Return 0 if successful, -1 on error. */ static int builtin_editor(const char *filename, SEND_HEADER *shdr) { char linebuf[SLEN]; /* line input buffer */ char wrapbuf[SLEN]; /* wrapped line overflow buffer */ char tmpbuf[SLEN]; /* scratch buffer */ FILE *fp; /* output stream to "filename" */ int rc; /* return code from this procedure */ int is_wrapped; /* wrapped line flag */ int err; /* temp holder for errno */ SIGHAND_TYPE (*oldint)(); /* previous value of SIGINT */ SIGHAND_TYPE (*oldquit)(); /* previous value of SIGQUIT */ SIGHAND_TYPE builtin_interrupt_handler(); /* the built-in editor is not re-entrant! */ assert(!builtin_active); /* initialize return code to failure */ rc = -1; if ((fp = fopen(filename, "r+")) == NULL) { err = errno; sprintf(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmCouldntOpenAppend, "Couldn't open %s for update [%s]."), filename, strerror(err)); PutLine(-1, -1, tmpbuf); dprint(1, (debugfile, "Error encountered trying to open file %s;\n", filename)); dprint(1, (debugfile, "** %s **\n", strerror(err))); return rc; } /* skip past any existing text */ fseek(fp, 0, SEEK_END); /* prompt user, depending upon whether file already has text */ if (fsize(fp) > 0L) strcpy(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmContinueEntering, "\n\rContinue entering message.")); else strcpy(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmEnterMessage, "\n\rEnter message.")); strcat(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmTypeElmCommands, " Type Elm commands on lines by themselves.\n\r")); sprintf(tmpbuf+strlen(tmpbuf), catgets(elm_msg_cat, ElmSet, ElmCommandsInclude, "Commands include: ^D or '.' to end, %cp to list, %c? for help.\n\r\n\r"), escape_char, escape_char); CleartoEOS(); PutLine(-1, -1, tmpbuf); builtin_active = TRUE; builtin_interrupt_count = 0; oldint = signal(SIGINT, builtin_interrupt_handler); oldquit = signal(SIGQUIT, builtin_interrupt_handler); /* return location for interrupts */ while (SETJMP(builtin_jmpbuf) != 0) { if (builtin_interrupt_count == 1) { PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmEditmsgOneMoreCancel, "(Interrupt. One more to cancel this letter.)\n\r")); } else { PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmEditmsgCancelled, "(Interrupt. Letter canceled.)\n\r")); goto done; } } for (;;) { /* re-open file if it was closed out on a call to an external editor */ if (fp == NULL) { if ((fp = fopen(filename, "a+")) == NULL) { err = errno; sprintf(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmCouldntOpenAppend, "Couldn't open %s for update [%s]."), filename, strerror(err)); PutLine(-1, -1, tmpbuf); dprint(1, (debugfile, "Error encountered trying to open file %s;\n", filename)); dprint(1, (debugfile, "** %s **\n", strerror(err))); goto done; } PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmPostEdContinue, "(Continue entering message. Type ^D or '.' on a line by itself to end.)\n\r")); } linebuf[0] = '\0'; wrapbuf[0] = '\0'; is_wrapped = 0; more_wrap: if (wrapped_enter(linebuf, wrapbuf, -1, -1, fp, &is_wrapped) != 0) break; if (is_wrapped) { fprintf(fp, "%s\n", linebuf); NewLine(); (void) strcpy(linebuf, wrapbuf); wrapbuf[0] = '\0'; goto more_wrap; } /* reset consecutive interrupt counter */ builtin_interrupt_count = 0; /* a lone "." signals end of text */ if (strcmp(linebuf, ".") == 0) break; /* process line of text */ if (linebuf[0] != escape_char) { fprintf(fp, "%s\n", linebuf); NewLine(); continue; } /* command character was escaped */ if (linebuf[1] == escape_char) { fprintf(fp, "%s\n", linebuf+1); continue; } switch (tolower(linebuf[1])) { case '?': tilde_help(); break; case 't': get_with_expansion("\n\rTo: ", shdr->to, shdr->expanded_to, linebuf); break; case 'b': get_with_expansion("\n\rBcc: ", shdr->bcc, shdr->expanded_bcc, linebuf); break; case 'c': get_with_expansion("\n\rCc: ", shdr->cc, shdr->expanded_cc, linebuf); break; case 's': get_with_expansion("\n\rSubject: ", shdr->subject, (char *)NULL, linebuf); break; case 'h': get_with_expansion("\n\rTo: ", shdr->to, shdr->expanded_to, (char *)NULL); get_with_expansion("Cc: ", shdr->cc, shdr->expanded_cc, (char *)NULL); get_with_expansion("Bcc: ", shdr->bcc, shdr->expanded_bcc, (char *)NULL); get_with_expansion("Subject: ", shdr->subject, (char *)NULL, (char *)NULL); break; case 'r': read_in_file(fp, linebuf+2, 1); break; case 'e': if (e_editor[0] == '\0') { PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmDontKnowEmacs, "\n\r(Don't know where Emacs would be. Continue.)\n\r")); break; } NewLine(); fclose(fp); fp = NULL; (void) edit_message(filename, shdr, e_editor); break; case 'v': NewLine(); fclose(fp); fp = NULL; (void) edit_message(filename, shdr, v_editor); break; case 'o': PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmEnterNameEditor, "\n\rPlease enter the name of the editor: ")); if (enter_string(tmpbuf, sizeof(tmpbuf), -1, -1, ESTR_ENTER) < 0 || tmpbuf[0] == '\0') { PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmSimpleContinue, "(Continue.)\n\r")); break; } NewLine(); fclose(fp); fp = NULL; (void) edit_message(filename, shdr, tmpbuf); break; case '<': NewLine(); if (strlen(linebuf) < 3) { PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmUseSpecificCommand, "(You need to use a specific command here. Continue.)\n\r")); break; } sprintf(tmpbuf, "%s%s.%d", temp_dir, temp_edit, getpid()); sprintf(linebuf+strlen(linebuf), " >%s 2>&1", tmpbuf); (void) system_call(linebuf+2, SY_COOKED|SY_ENAB_SIGINT|SY_DUMPSTATE); read_in_file(fp, tmpbuf, 0); (void) unlink(tmpbuf); break; case '!': NewLine(); (void) system_call( (strlen(linebuf) < 3 ? (char *)NULL : linebuf+2), SY_COOKED|SY_USER_SHELL|SY_ENAB_SIGINT|SY_DUMPSTATE); PutLine(LINES, 0, catgets(elm_msg_cat, ElmSet, ElmSimpleContinue, "(Continue.)\n\r")); break; case 'm': /* same as 'f' but with leading prefix added */ case 'f': /* this can be directly translated into a 'readmsg' call with the same params! */ NewLine(); read_in_messages(fp, linebuf+1); break; case 'p': /* print out message so far */ print_message_so_far(fp, shdr); break; default: sprintf(tmpbuf, catgets(elm_msg_cat, ElmSet, ElmDontKnowChar, "\n\r(Don't know what %c%c is. Try %c? for help.)\n\r"), escape_char, linebuf[1], escape_char); PutLine(-1, -1, tmpbuf); break; } } PutLine(-1, -1, catgets(elm_msg_cat, ElmSet, ElmEndOfMessage, "\n\r<end-of-message>\n\r\n\r\n\r\n\r")); rc = 0; done: (void) signal(SIGINT, oldint); (void) signal(SIGQUIT, oldquit); if (fp != NULL) fclose(fp); builtin_active = FALSE; return rc; }