/* Remove top object from the sexp stack. */ static object_t *pop (reader_t * r) { if (!r->done && stack_height (r) <= 1) { read_error (r, "unbalanced parenthesis"); return err_symbol; } if (!r->done && r->state->dotpair_mode == 1) { read_error (r, "missing cdr object for dotted pair"); return err_symbol; } object_t *p = CDR (r->state->head); CDR (r->state->head) = NIL; obj_destroy (r->state->head); if (r->state->vector_mode) { r->state--; object_t *v = list2vector (p); obj_destroy (p); return v; } r->state--; return p; }
/* Add a new element to the uart_buffer */ void enqueue(unsigned char c) { LinkedList *l; //Create temporary pointer to a linked list l = (LinkedList *) malloc(sizeof (LinkedList)); //Try to allocate memory if (l == NULL) { //If pointer is empty there is no remaining memory read_error(); //Remove two entries from error buffer read_error(); log_error(ERR_BUFF_FULL); //Add buffer full entry l = (LinkedList *) malloc(sizeof (LinkedList)); //Allocate memory } // add data l->c = c; //Write data to variable in element // link l->next = NULL; //clear pointer if (uart_buffer.first == NULL) { //If no elements in uart_buffer uart_buffer.first = l; //First and last both point to the only uart_buffer.last = l; // element } else { uart_buffer.last->next = l; //Set next ptr of last element to new element uart_buffer.last = l; //Set last ptr to new element } uart_buffer.len++; //Increment tally }
static int theme_read(THEME_REC *theme, const char *path, const char *data) { CONFIG_REC *config; THEME_READ_REC rec; char *str; config = config_open(data == NULL ? path : NULL, -1) ; if (config == NULL) { /* didn't exist or no access? */ str = g_strdup_printf("Error reading theme file %s: %s", path, g_strerror(errno)); read_error(str); g_free(str); return FALSE; } if (data != NULL) config_parse_data(config, data, "internal"); else config_parse(config); if (config_last_error(config) != NULL) { str = g_strdup_printf("Ignored errors in theme %s:\n%s", theme->name, config_last_error(config)); read_error(str); g_free(str); } theme->default_color = config_get_int(config, NULL, "default_color", -1); theme->info_eol = config_get_bool(config, NULL, "info_eol", FALSE); /* FIXME: remove after 0.7.99 */ if (theme->default_color == 0 && config_get_int(config, NULL, "default_real_color", -1) != -1) theme->default_color = -1; theme_read_replaces(config, theme); if (data == NULL) { /* get the default abstracts from default theme. */ CONFIG_REC *default_config; default_config = config_open(NULL, -1); config_parse_data(default_config, default_theme, "internal"); theme_read_abstracts(default_config, theme); config_close(default_config); } theme_read_abstracts(config, theme); rec.theme = theme; rec.config = config; g_hash_table_foreach(default_formats, (GHFunc) theme_read_modules, &rec); config_close(config); return TRUE; }
int main (int argc, char **argv) /*{{{*/ { FILE *fp; char *file = "mirr-ee.dat"; int num_ee; int num_energies; float value; float *energies; float *ee; int i, n; if (NULL == (fp = fopen (file, "rb"))) return -1; if ((1 != JDMread_int32 (&num_energies, 1, fp)) || (1 != JDMread_int32 (&num_ee, 1, fp))) read_error (); if ((NULL == (ee = JDMfloat_vector (num_ee))) || (NULL == (energies = JDMfloat_vector (num_energies)))) JDMmsg_error (NULL); if ((num_energies != JDMread_float32 (energies, num_energies, fp)) || (num_ee != JDMread_float32 (ee, num_ee, fp))) read_error (); /* Now interpolate all thetas to this grid */ for (n = 0; n < 4; n++) { for (i = 0; i < num_energies; i++) { int j; fprintf (stdout, "#energy: %e\n", energies[i]); for (j = 0; j < num_ee; j++) { if (1 != JDMread_float32 (&value, 1, fp)) read_error (); fprintf (stdout, "%e %e\n", ee[j], value); } fprintf (stdout, "@eod\n"); } fprintf (stdout, "@pause\n@clear\n"); } fclose (fp); return 0; }
int Ax12Class::moveSpeed(unsigned char ID, long Position, long Speed) { char Position_H,Position_L,Speed_H,Speed_L; Position_H = Position >> 8; Position_L = Position; // 16 bits - 2 x 8 bits variables Speed_H = Speed >> 8; Speed_L = Speed; // 16 bits - 2 x 8 bits variables TChecksum = (ID + AX_GOAL_SP_LENGTH + AX_WRITE_DATA + AX_GOAL_POSITION_L); TChecksum += (Position_L + Position_H + Speed_L + Speed_H); while ( TChecksum >= 255){ TChecksum -= 255; } Checksum = 255 - TChecksum; digitalWrite(Direction_Pin,HIGH); // Set Tx Mode usart_write(AX_START); // Send Instructions over Serial usart_write(AX_START); usart_write(ID); usart_write(AX_GOAL_SP_LENGTH); usart_write(AX_WRITE_DATA); usart_write(AX_GOAL_POSITION_L); usart_write(Position_L); usart_write(Position_H); usart_write(Speed_L); usart_write(Speed_H); usart_write(Checksum); delayMicroseconds(TX_DELAY_TIME); digitalWrite(Direction_Pin,LOW); // Set Rx Mode return (read_error()); // Return the read error }
unsigned char DynamixelSerial::move(unsigned char ID, int Position, int Speed) { unsigned char Checksum; char Position_H,Position_L,Speed_H,Speed_L; Position_H = Position >> 8; Position_L = Position; // 16 bits - 2 x 8 bits variables Speed_H = Speed >> 8; Speed_L = Speed; // 16 bits - 2 x 8 bits variables Checksum = (~(ID + AX_GOAL_SP_LENGTH + AX_WRITE_DATA + AX_GOAL_POSITION_L + Position_L + Position_H + Speed_L + Speed_H))&0xFF; digitalWrite(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_SP_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_GOAL_POSITION_L); sendData(Position_L); sendData(Position_H); sendData(Speed_L); sendData(Speed_H); sendData(Checksum); delayMicroseconds(TX_DELAY_TIME); digitalWrite(Direction_Pin,Rx_MODE); return read_error(); // Return the read error }
int DynamixelClass::moveSpeed(unsigned char ID, int Position, int Speed) { char Position_H,Position_L,Speed_H,Speed_L; Position_H = Position >> 8; Position_L = Position; // 16 bits - 2 x 8 bits variables Speed_H = Speed >> 8; Speed_L = Speed; // 16 bits - 2 x 8 bits variables Checksum = (~(ID + AX_GOAL_SP_LENGTH + AX_WRITE_DATA + AX_GOAL_POSITION_L + Position_L + Position_H + Speed_L + Speed_H))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_SP_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_GOAL_POSITION_L); sendData(Position_L); sendData(Position_H); sendData(Speed_L); sendData(Speed_H); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); // Return the read error }
std::string tester_util::read(const boost::filesystem::path &path, const bacs::file::Range &range) { try { return bacs::system::file::read(m_container->filesystem().keepInRoot(path), range); } catch (std::exception &) { BOOST_THROW_EXCEPTION(read_error() << bunsan::enable_nested_current()); } }
static uint32_t read_long(FILE *in) { uint32_t l; errno = 0; if (fread(&l, sizeof(uint32_t), 1, in) <= 0) read_error(); return ntohl(l); }
static int read_char(FILE *in) { int ch; errno = 0; ch = getc_unlocked(in); if (ch == EOF) read_error(); return ch; }
int DynamixelClass::setEndless(unsigned char ID, bool Status) { if ( Status ) { char AX_CCW_AL_LT = 0; // Changing the CCW Angle Limits for Full Rotation. Checksum = (~(ID + AX_GOAL_LENGTH + AX_WRITE_DATA + AX_CCW_ANGLE_LIMIT_L))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_CCW_ANGLE_LIMIT_L ); sendData(AX_CCW_AL_LT); sendData(AX_CCW_AL_LT); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return(read_error()); } else { turn(ID,0,0); Checksum = (~(ID + AX_GOAL_LENGTH + AX_WRITE_DATA + AX_CCW_ANGLE_LIMIT_L + AX_CCW_AL_L + AX_CCW_AL_H))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_CCW_ANGLE_LIMIT_L); sendData(AX_CCW_AL_L); sendData(AX_CCW_AL_H); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); // Return the read error } }
std::istream & t_count_spectra::read (std::istream & in) { std::ios::iostate in_exceptions = in.exceptions(); // assert(in.good()); t_count_spectra spectra; t_count read_components = 0, read_transactions = 0; t_count c_count = 0, tr_count = 0; try { in.exceptions(std::istream::failbit | std::istream::badbit); in >> c_count >> tr_count; spectra.set_count(c_count, tr_count); for (t_transaction_id tr = 1; tr <= tr_count; tr++) { for (t_component_id c = 1; c <= c_count; c++) { t_count value; in >> value; spectra.hit(c, tr, value); read_components++; } spectra.set_error(tr, read_error(in)); read_transactions++; read_components = 0; } *this = spectra; } catch (std::ios_base::failure e) { if (c_count && tr_count) { if (c_count == read_components) std::cerr << "Problem reading error information in transaction " << read_transactions; else std::cerr << "Problem reading spectra after " << read_transactions << " transactions and " << read_components << " components" << std::endl; } else if(!in.eof()){ std::cerr << "Problem reading spectra size " << std::endl; } } std::ios::iostate in_state = in.rdstate(); in.exceptions(in_exceptions); in.setstate(in_state); return in; }
int read_speed_pairs(const char * vspairs_path) { int nRet; FILE *pInFile; int nPairs = 0; // Leer speed pairs pInFile = open_file(vspairs_path, "r", 1); nRet = fscanf(pInFile, "%d", &n_vlevels); nRet = fscanf(pInFile, "%d", &nPairs); if (m < nPairs) vspairs = new_matrix_double(n_vlevels, nPairs<<1); else vspairs = new_matrix_double(n_vlevels, m<<1); int i, j; for (i = 0; i < n_vlevels; i++) { for (j = 0; j < nPairs<<1; j++) { nRet = fscanf(pInFile, "%lf", &vspairs[i][j]); } } close_file(pInFile); // Si la instancia tiene más maquinas que las disponibles en los speed pairs // se hace un round robin para asignar pairs a las máquinas que faltan. if (m > nPairs) { int cur_pair; for (i = 0; i < n_vlevels; i++) { for (j = nPairs<<1; j < m<<1; j++) { cur_pair = j%(nPairs<<1); vspairs[i][j] = vspairs[i][cur_pair]; } } } if (!nRet) read_error(vspairs_path, 1); return (nRet); }
int AX12_ping(unsigned char ID) { Checksum = (~(ID + AX_READ_DATA + AX_PING))&0xFF; switchCom(Tx_MODE); sendData(AX_START); sendData(AX_START); sendData(ID); sendData(AX_READ_DATA); sendData(AX_PING); sendData(Checksum); delay32Us(1,TX_DELAY_TIME); switchCom(Rx_MODE); return (read_error()); }
int DynamixelClass::reset(unsigned char ID) { Checksum = (~(ID + AX_RESET_LENGTH + AX_RESET))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); sendData(AX_START); sendData(ID); sendData(AX_RESET_LENGTH); sendData(AX_RESET); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); }
int AX12_reset(unsigned char ID) { Checksum = (~(ID + AX_RESET_LENGTH + AX_RESET))&0xFF; switchCom(Tx_MODE); sendData(AX_START); sendData(AX_START); sendData(ID); sendData(AX_RESET_LENGTH); sendData(AX_RESET); sendData(Checksum); delay32Us(1,TX_DELAY_TIME); switchCom(Rx_MODE); return (read_error()); }
int DynamixelClass::ping(unsigned char ID) { Checksum = (~(ID + AX_READ_DATA + AX_PING))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); sendData(AX_START); sendData(ID); sendData(AX_READ_DATA); sendData(AX_PING); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); }
int read_instance(const char * instance_path) { int nRet; FILE *pInFile; // Guardar el nombre de la instancia instance_name = (char*)instance_path; pInFile = open_file(instance_path, "r", 1); nRet = get_instance_size(pInFile); // Reservar memoria para arreglos p_matrix = new_matrix_double(n, m); dag_edges = new_matrix_double(n_edges, 3); int i, j; while (fgetc(pInFile) != '#'); while (fgetc(pInFile) != '#'); nRet = fscanf(pInFile, "%*s"); for (i = 0; i < n; i++) { nRet = fscanf(pInFile, "%*s"); for (j = 0; j < m; j++) { nRet = fscanf(pInFile, "%lf%*c", &p_matrix[i][j]); } } nRet = fscanf(pInFile, "%*s"); for (i = 0; i < n_edges; i++) { nRet = fscanf(pInFile, "%*s"); for (j = 0; j < 3; j++) { nRet = fscanf(pInFile, "%lf%*c", &dag_edges[i][j]); } } close_file(pInFile); if (!nRet) read_error(instance_path, 1); return (nRet); }
void Fl_Type::read_property(const Fl_String &c) { if (!strcmp(c,"label")) label(read_word()); else if (!strcmp(c,"tooltip")) tooltip(read_word()); else if (!strcmp(c,"user_data")) user_data(read_word()); else if (!strcmp(c,"user_data_type")) user_data_type(read_word()); else if (!strcmp(c,"callback")) callback(read_word()); else if (!strcmp(c,"open")) open_ = 1; else if (!strcmp(c,"selected")) select(this,1); else read_error("Unknown property \"%s\"", c.c_str()); }
int AX12_setID(unsigned char ID, unsigned char newID) { Checksum = (~(ID + AX_ID_LENGTH + AX_WRITE_DATA + AX_ID + newID))&0xFF; switchCom(Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_ID_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_ID); sendData(newID); sendData(Checksum); delay32Us(1,TX_DELAY_TIME); switchCom(Rx_MODE); return (read_error()); // Return the read error }
int DynamixelClass::setID(unsigned char ID, unsigned char newID) { Checksum = (~(ID + AX_ID_LENGTH + AX_WRITE_DATA + AX_ID + newID))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_ID_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_ID); sendData(newID); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); // Return the read error }
unsigned char DynamixelSerial::instruction_no_params(uint8_t ID, uint8_t cmd) { unsigned char Checksum; Checksum = (~(ID + AX_INSTRUCTION_0_PARAMS_LENGTH + cmd))&0xFF; digitalWrite(Direction_Pin,Tx_MODE); sendData(AX_START); sendData(AX_START); sendData(ID); sendData(AX_INSTRUCTION_0_PARAMS_LENGTH); sendData(cmd); sendData(Checksum); delayMicroseconds(TX_DELAY_TIME); digitalWrite(Direction_Pin,Rx_MODE); return read_error(); }
/* Turn string in buffer into atom object. */ static object_t *parse_atom (reader_t * r) { char *str = r->buf; char *end; /* Detect integer */ int i = strtol (str, &end, 10); (void) i; if (end != str && *end == '\0') { object_t *o = c_ints (str); reset_buf (r); return o; } /* Detect float */ int d = strtod (str, &end); (void) d; if (end != str && *end == '\0') { object_t *o = c_floats (str); reset_buf (r); return o; } /* Might be a symbol then */ char *p = r->buf; while (p <= r->bufp) { if (strchr (atom_chars, *p) == NULL) { char *errstr = xstrdup ("invalid symbol character: X"); errstr[strlen (errstr) - 1] = *p; read_error (r, errstr); xfree (errstr); return NIL; } p++; } object_t *o = c_sym (r->buf); reset_buf (r); return o; }
int DynamixelClass::setBD(unsigned char ID, long baud) { unsigned char Baud_Rate = (2000000/baud) - 1; Checksum = (~(ID + AX_BD_LENGTH + AX_WRITE_DATA + AX_BAUD_RATE + Baud_Rate))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_BD_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_BAUD_RATE); sendData(Baud_Rate); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return (read_error()); // Return the read error }
int Ax12Class::ping(unsigned char ID) { TChecksum = (ID + AX_READ_DATA + AX_PING); while ( TChecksum >= 255){ TChecksum -= 255; } Checksum = 255 - TChecksum; digitalWrite(Direction_Pin,HIGH); usart_write(AX_START); usart_write(AX_START); usart_write(ID); usart_write(AX_READ_DATA); usart_write(AX_PING); usart_write(Checksum); delayMicroseconds(TX_DELAY_TIME); digitalWrite(Direction_Pin,LOW); return (read_error()); }
int AX12_move(unsigned char ID, int Position) { char Position_H,Position_L; Position_H = Position >> 8; // 16 bits - 2 x 8 bits variables Position_L = Position; Checksum = (~(ID + AX_GOAL_LENGTH + AX_WRITE_DATA + AX_GOAL_POSITION_L + Position_L + Position_H))&0xFF; switchCom(Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_GOAL_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_GOAL_POSITION_L); sendData(Position_L); sendData(Position_H); sendData(Checksum); delay32Us(1,TX_DELAY_TIME); switchCom(Rx_MODE); return (read_error()); // Return the read error }
int Ax12Class::setBD(unsigned char ID, unsigned char Baud_Rate) { TChecksum = (ID + AX_BD_LENGTH + AX_WRITE_DATA + AX_BAUD_RATE + Baud_Rate); while ( TChecksum >= 255){ TChecksum -= 255; } Checksum = 255 - TChecksum; digitalWrite(Direction_Pin,HIGH); // Set Tx Mode usart_write(AX_START); // Send Instructions over Serial usart_write(AX_START); usart_write(ID); usart_write(AX_BD_LENGTH); usart_write(AX_WRITE_DATA); usart_write(AX_BAUD_RATE); usart_write(Baud_Rate); usart_write(Checksum); delayMicroseconds(TX_DELAY_TIME); digitalWrite(Direction_Pin,LOW); // Set Rx Mode return (read_error()); // Return the read error }
int Ax12Class::ledStatus(unsigned char ID, bool Status) { TChecksum = (ID + AX_LED_LENGTH + AX_WRITE_DATA + AX_LED + Status); while ( TChecksum >= 255){ TChecksum -= 255; } Checksum = 255 - TChecksum; digitalWrite(Direction_Pin,HIGH); // Set Tx Mode usart_write(AX_START); // Send Instructions over Serial usart_write(AX_START); usart_write(ID); usart_write(AX_LED_LENGTH); usart_write(AX_WRITE_DATA); usart_write(AX_LED); usart_write(Status); usart_write(Checksum); delayMicroseconds(TX_DELAY_TIME); digitalWrite(Direction_Pin,LOW); // Set Rx Mode return (read_error()); // Return the read error }
/* Push a new object into the current list. */ static void add (reader_t * r, object_t * o) { if (r->state->dotpair_mode == 2) { /* CDR already filled. Cannot add more. */ read_error (r, "invalid dotted pair syntax - too many objects"); return; } if (!r->state->dotpair_mode) { CDR (r->state->tail) = c_cons (o, NIL); r->state->tail = CDR (r->state->tail); if (r->state->quote_mode) addpop (r); } else { CDR (r->state->tail) = o; r->state->dotpair_mode = 2; if (r->state->quote_mode) addpop (r); } }
int DynamixelClass::turn(unsigned char ID, bool SIDE, int Speed) { if (SIDE == 0){ // Move Left/////////////////////////// char Speed_H,Speed_L; Speed_H = Speed >> 8; Speed_L = Speed; // 16 bits - 2 x 8 bits variables Checksum = (~(ID + AX_SPEED_LENGTH + AX_WRITE_DATA + AX_GOAL_SPEED_L + Speed_L + Speed_H))&0xFF; switchCom(Direction_Pin,Tx_MODE); sendData(AX_START); // Send Instructions over Serial sendData(AX_START); sendData(ID); sendData(AX_SPEED_LENGTH); sendData(AX_WRITE_DATA); sendData(AX_GOAL_SPEED_L); sendData(Speed_L); sendData(Speed_H); sendData(Checksum); delayus(TX_DELAY_TIME); switchCom(Direction_Pin,Rx_MODE); return(read_error()); // Return the read error }