int stepper_motor::off(int motnum) { //off command if (motnum<0 || motnum>2) {return(emsg(3));}; if (!is_motor_ready(motnum)) {return(emsg(4));}; ioctl(handle,SM32Post | mcPower |MOT[motnum],0); }
int main(int argc, char *argv[]) { int fh; float wert; int outword; int channel; fh=open(BOARDNAME,O_RDWR); if (fh==-1) return -emsg(1); switch (argc) { case 2: channel = 0; sscanf(argv[1],"%f",&wert); break; case 3: sscanf(argv[1],"%d",&channel); sscanf(argv[2],"%f",&wert); channel=(channel?1:0); break; default: return -emsg(2); }; if (wert>10. || wert < -10.0) return -emsg(3); outword = (wert+10.0)*MAX_OUT_PATTERN/20.; if (outword <0) { outword = 0; } else if (outword>MAX_OUT_PATTERN) outword = MAX_OUT_PATTERN; ioctl(fh,channel?SET_AND_LOAD_DAC_1:SET_AND_LOAD_DAC_0, outword); close(fh); }
/*--------------------------------------------------------------------------------------------------------------------------------------- * PUBLIC FUNCTIONS DEFINITIONS *--------------------------------------------------------------------------------------------------------------------------------------*/ FUNCTION PUBLIC DEFINITION void Init ( session* ss ) { Session = ss; mimetypes["jar"] = "application/zip"; mimetypes["html"] = "text/html"; mimetypes["css"] = "text/css"; mimetypes["js"] = "text/javascript"; mimetypes["jpeg"] = "image/jpeg"; mimetypes["gif"] = "image/gif"; if (utl::ReadFullTxFile(jquery_js_path, jquery_js) == false) throw emsg("[ERROR][deployapp::Init] Loading file : " + Str_t(jquery_js_path)); request_files[JQUERY_JS] = &jquery_js; if (utl::ReadFullTxFile(jquery_css_path, jquery_css) == false) throw emsg("[ERROR][deployapp::Init] Loading file : " + Str_t(jquery_css_path)); request_files[JQUERY_CSS] = &jquery_css; if (utl::ReadFullTxFile(jquery_ui_js_path, jquery_ui_js) == false) throw emsg("[ERROR][deployapp::Init] Loading file : " + Str_t(jquery_ui_js_path)); request_files[JQUERY_UI_JS] = &jquery_ui_js; if (utl::ReadFullTxFile(custom_js_path, custom_js) == false) throw emsg("[ERROR][deployapp::Init] Loading file : " + Str_t(custom_js_path)); request_files[CUSTOM_JS] = &custom_js; if (utl::ReadFullTxFile(custom_css_path, custom_css) == false) throw emsg("[ERROR][deployapp::Init] Loading file : " + Str_t(custom_css_path)); request_files[CUSTOM_CSS] = &custom_css; }
int stepper_motor::pmode(int motnum) { if (motnum<0 || motnum>2) {return(emsg(3));}; if (!is_motor_ready(motnum)) {return(emsg(4));}; movemode[motnum]=0; ioctl(handle,SM32Post | mcPosMode | MOT[motnum],(movemode[motnum]?mmMove:mmPos)); }
RANDOM_HILL_CLIMBING::RANDOM_HILL_CLIMBING(vector<string>& parameter, paradocks::Fitness* fit, RNG& rng, Vec3_t& center, Float_t& radius) : Optimizer(parameter, fit, rng, center, radius) { if (parameter.size()!=2) { string emsg("Optimizer random expects 1 parameter"); throw OptimizerError(emsg); } try { _iter=boost::lexical_cast<unsigned int>(parameter[0]); } catch(boost::bad_lexical_cast e) { string emsg("Error in input conversion! optimizer iteration line\n"+string(e.what())); throw OptimizerError(emsg); } try { _local_iter=boost::lexical_cast<unsigned int>(parameter[1]); } catch(boost::bad_lexical_cast e) { string emsg("Error in input conversion! local optimizer iteration line\n"+string(e.what())); throw OptimizerError(emsg); } }
int stepper_motor::setzero(int motnum) { if (motnum<0 || motnum>2) {return(emsg(3));}; if (!is_motor_ready(motnum)) {return(emsg(4));}; int position; getpos(motnum, position); zeroposition[motnum] = position; }
int stepper_motor::setvolt(int motnum, double involts) { if (involts<0.0 || involts >MAXVOLT) { return (emsg(5));}; if (motnum<0 || motnum>2) {return(emsg(3));}; volts[motnum]=involts; if (!is_motor_ready(motnum)) {return(emsg(4));}; // set voltage // ioctl(handle,SM32Post | mcU | MOT[motnum],(int)(10.0*volts[motnum])); }
int stepper_motor::setspeed(int motnum, int inspeed) { if (!movemode) if (inspeed<0.0 || inspeed >MAXSPEED) { return(emsg(6));}; if (motnum<0 || motnum>2) {return(emsg(3));}; speed[motnum]=inspeed; if (!is_motor_ready(motnum)) {return(emsg(4));}; // set speed // ioctl(handle,SM32Post | mcF | MOT[motnum], (int)speed[motnum]); }
int stepper_motor::init(int motnum, double involts, int inspeed) { // init command // if (motnum<0 || motnum>2) {return(emsg(3));}; if (inspeed<0.0 || inspeed >MAXSPEED) {return(emsg(6));}; speed[motnum]=inspeed; if (involts<0.0 || involts >MAXVOLT) { return(emsg(5));}; volts[motnum]=involts; if (!is_motor_ready(motnum)) {return(emsg(4));}; // set voltage // ioctl(handle,SM32Post | mcU | MOT[motnum], (int)(volts[motnum]*10.)); // set pos / move mode // if (!is_motor_ready(motnum)) {return(emsg(4));}; ioctl(handle,SM32Post | mcPosMode | MOT[motnum], (movemode[motnum]?mmMove:mmPos)); // set speed // if (!is_motor_ready(motnum)) {return(emsg(4));}; ioctl(handle,SM32Post | mcF | MOT[motnum], (int)(movemode[motnum]?0:speed[motnum])); // switch on // if (!is_motor_ready(motnum)) {return(emsg(4));}; ioctl(handle,SM32Post | mcPower | MOT[motnum], 1); return(emsg(2)); }
/* * Load library and get all pointers. * Parameter 'libname' provides name of DLL. * Return OK or FAIL. */ static int python_runtime_link_init(char *libname, int verbose) { int i; PYTHON_PROC *ucs_as_encoded_string = (PYTHON_PROC*)&py_PyUnicode_AsEncodedString; # if !(defined(PY_NO_RTLD_GLOBAL) && defined(PY3_NO_RTLD_GLOBAL)) && defined(UNIX) && defined(FEAT_PYTHON3) /* Can't have Python and Python3 loaded at the same time. * It cause a crash, because RTLD_GLOBAL is needed for * standard C extension libraries of one or both python versions. */ if (python3_loaded()) { if (verbose) emsg(_("E836: This Vim cannot execute :python after using :py3")); return FAIL; } # endif if (hinstPython) return OK; hinstPython = load_dll(libname); if (!hinstPython) { if (verbose) semsg(_(e_loadlib), libname); return FAIL; } for (i = 0; python_funcname_table[i].ptr; ++i) { if ((*python_funcname_table[i].ptr = symbol_from_dll(hinstPython, python_funcname_table[i].name)) == NULL) { close_dll(hinstPython); hinstPython = 0; if (verbose) semsg(_(e_loadfunc), python_funcname_table[i].name); return FAIL; } } /* Load unicode functions separately as only the ucs2 or the ucs4 functions * will be present in the library. */ *ucs_as_encoded_string = symbol_from_dll(hinstPython, "PyUnicodeUCS2_AsEncodedString"); if (*ucs_as_encoded_string == NULL) *ucs_as_encoded_string = symbol_from_dll(hinstPython, "PyUnicodeUCS4_AsEncodedString"); if (*ucs_as_encoded_string == NULL) { close_dll(hinstPython); hinstPython = 0; if (verbose) semsg(_(e_loadfunc), "PyUnicode_UCSX_*"); return FAIL; } return OK; }
int stepper_motor::go(int motnum, int steps) { if (motnum<0 || motnum>2) {return(emsg(3));}; // do it // if (!is_motor_ready(motnum)) {return(emsg(4));}; ioctl(handle,SM32Post | mcGo | MOT[motnum], steps); while (get_mot_pos(motnum)!=steps) { } if (waitmode) if (!is_motor_there(motnum)) {return(emsg(5));}; nanosleep(&twenty_millisec,&time_left); return(0); }
int enlarge(off_t add) { char *newmem; off_t savecur, savepag, savemax, saveundo; savecur = curpos - mem; savepag = pagepos - mem; savemax = maxpos - mem; saveundo = undo_start - mem; if(mem == NULL) { newmem = malloc(memsize + add); } else { newmem = realloc(mem, memsize + add); } if(newmem == NULL) { emsg("Out of memory"); return 1; } mem = newmem; memsize += add; curpos = mem + savecur; pagepos = mem + savepag; maxpos = mem + savemax; undo_start = mem + saveundo; current = curpos + 1L; return 0; }
/* * ":sign unplace" command */ static void sign_unplace_cmd( buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group) { if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) { emsg(_(e_invarg)); return; } if (id == -2) { if (buf != NULL) // :sign unplace * file={fname} // :sign unplace * group={group} file={fname} // :sign unplace * group=* file={fname} // :sign unplace * buffer={nr} // :sign unplace * group={group} buffer={nr} // :sign unplace * group=* buffer={nr} sign_unplace(0, group, buf, 0); else // :sign unplace * // :sign unplace * group={group} // :sign unplace * group=* FOR_ALL_BUFFERS(buf) if (buf->b_signlist != NULL) buf_delete_signs(buf, group); } else { if (buf != NULL)
XmlSettingsEntry XmlSettingsEntry::find( const QStringList &xpath, QStringList::ConstIterator &itXPath, AbstractNode* &node ) { JQ_ASSERT(m_master); if( xpath.size() == 0 ) return XmlSettingsEntry(m_master, m_rootNode); itXPath = xpath.begin(); QStringList::ConstIterator itXPathEnd = xpath.end(); if( *itXPath == m_master->separator() ) { // Absolute path node = m_master->m_rootNode; itXPath++; } else { // Relative path node = m_rootNode; } for( ; itXPath != itXPathEnd; itXPath++ ) { QString elem(*itXPath); if( elem == "." ) continue; // Error if( node->type() == AbstractNode::Scalar ) { return XmlSettingsEntry(m_master); } if( node->type() == AbstractNode::Vector ) { // index if( elem.startsWith("[") ) { JQ_ASSERT( elem.endsWith("]") && elem.size() > 2 ); VectorNode *vectorNode = (VectorNode*)node; bool ok; int index = elem.mid(1, elem.size()-2).toUInt(&ok); JQ_ASSERT(ok == true); if( index < 0 || index >= vectorNode->size() ) { QString emsg(QString(__E_INDEX_OUT_BOUNDS).arg(index).arg(0).arg(vectorNode->size())); m_master->setError(XmlSettings::XPathError, emsg.toLocal8Bit().data()); return XmlSettingsEntry(m_master); } node = (*vectorNode)[index]; } else { return XmlSettingsEntry(m_master); } } else if( node->type() == AbstractNode::Map ) { MapNode::ConstIterator itm = dynamic_cast<MapNode*>(node)->find(elem); if( itm == dynamic_cast<MapNode*>(node)->end() ) { return XmlSettingsEntry(m_master); } node = itm.value(); } else { JQ_ASSERT( node->type() == AbstractNode::Vector || node->type() == AbstractNode::Map ); } } return XmlSettingsEntry(m_master, node); }
METHOD PUBLIC DEFINITION const input& line::ModInput ( uInt_t index ) const { if (index >= vInput.size()) throw emsg("[ERROR][body::Input const] Index out of range."); return *vInput[index]; }
METHOD PUBLIC DEFINITION const label& line::ModLabel ( uInt_t index ) const { if (index >= vLabel.size()) throw emsg("[ERROR][body::Label const] Index out of range."); return *vLabel[index]; }
METHOD PUBLIC DEFINITION const button& line::ModButton ( uInt_t index ) const { if (index >= vButton.size()) throw emsg("[ERROR][body::Button const] Index out of range."); return *vButton[index]; }
bool_t OpenBackward(int can_ai) { LINE *l; LINE *prev; int newindex = 0; /* index of the cursor on the new * line */ prev = Curschar->linep->prev; l = newline(strlen(Curschar->linep->s) + SLOP); if (l == NULL) { emsg("out of memory"); beep(); sleep(2); return (FALSE); } Curschar->linep->prev = l; /* link neighbors to new line */ prev->next = l; l->next = Curschar->linep; /* link new line to neighbors */ l->prev = prev; if (can_ai && P(P_AI)) { char *p; /* * Copy current line, and truncate after white space */ strcpy(l->s, Curschar->linep->s); for (p = l->s; *p == ' ' || *p == TAB; p++); *p = NUL; newindex = p - l->s; AppendToInsbuff(l->s); did_ai = TRUE; } Curschar->linep = Curschar->linep->prev; Curschar->index = newindex; if (prev == Filetop->linep) { /* new start of file */ Filemem->linep = l; renum(); } else if ((l->prev->num) + 1 == l->next->num) { /* no gap, renumber */ renum(); } else { /* stick it in the middle */ long lnum; lnum = (l->prev->num + l->next->num) / 2; l->num = lnum; } S_NOT_VALID; CHANGED; return (TRUE); }
stepper_motor::stepper_motor(QWidget *parent) : QWidget(parent) { volts[0]=DEFAULT_VOLT; volts[1]=DEFAULT_VOLT; volts[2]=DEFAULT_VOLT; speed[0] = DEFAULT_SPEED; speed[1] = DEFAULT_SPEED; speed[2] = DEFAULT_SPEED; movemode[0] =DEFAULT_MOVEMODE; movemode[1] =DEFAULT_MOVEMODE; movemode[2] =DEFAULT_MOVEMODE; //std::vector<std::string> errormessage; errormessage.push_back("No error."); errormessage.push_back("device not found."); errormessage.push_back("Not enough parameters."); errormessage.push_back("Wrong motor number. Must be 0, 1 or 2."); errormessage.push_back("Motor write timeout."); errormessage.push_back("Voltage out of range (0 to 12V)."); errormessage.push_back("Speed out of range (0 to 1000)."); MOT[0] = MOT_0; MOT[1] = MOT_1; MOT[2] = MOT_2; commands.push_back(""); // 0: do nothing commands.push_back("."); // terminate commands.push_back("go");// go to a certain value commands.push_back("init"); commands.push_back("on"); commands.push_back("off"); // 5 commands.push_back("set"); commands.push_back("exit"); commands.push_back("setvolt"); commands.push_back("setspeed"); commands.push_back("reset"); // 10 commands.push_back("break"); commands.push_back("vmode"); commands.push_back("pmode"); commands.push_back("getpos"); handle=open(DEVICE,O_RDWR); if (handle==-1) { -emsg(1);} if ((fp = fopen(FIFO_FILE, "wb")) ==NULL){ printf("Error opening file\n"); exit(1); } for(int i=0;i<3;i++){ init(i,3.1,1000); on(i); } sleep(1); }
void fileinfo(char *fname) { off_t bytepos; char fstatus[MAXCMD]; char *string; if(fname) { string = malloc((size_t)strlen(fname) + MAXCMD); if(string == NULL) { emsg("Out of memory"); return; } sprintf(string, "\"%s\" ", fname); } else { string = malloc(MAXCMD); if(string == NULL) { emsg("Out of memory"); return; } strcpy(string, "No file "); } if(filemode != NEW && filemode != REGULAR) { strcat(string, "[Not edited] "); } if(P(P_RO)) { strcat(string, "[Read only] "); } if(edits) { strcat(string, "[Modified] "); } if(filesize) { bytepos = (pagepos + y * Anzahl + xpos()) - mem + 1L; sprintf(fstatus, "byte %llu of %llu --%llu%%--", (unsigned long long)bytepos, (unsigned long long)filesize, (unsigned long long)(bytepos * 100L / filesize)); strcat(string, fstatus); } else { strcat(string, " 0 bytes"); } msg(string); free(string); }
/* * Unplace the sign at the current cursor line. */ static void sign_unplace_at_cursor(char_u *groupname) { int id = -1; id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum, groupname); if (id > 0) sign_unplace(id, groupname, curwin->w_buffer, curwin->w_cursor.lnum); else emsg(_("E159: Missing sign number")); }
/* * Write "blob" to file "fd". * Return OK or FAIL. */ int write_blob(FILE *fd, blob_T *blob) { if (fwrite(blob->bv_ga.ga_data, 1, blob->bv_ga.ga_len, fd) < (size_t)blob->bv_ga.ga_len) { emsg(_(e_write)); return FAIL; } return OK; }
inline bool XmlSettingsEntry::splitXPath( const QString &xpath, QStringList &xpsl ) { int epos = -1; if( !XmlSettings::splitXPath( xpath, m_master->separator(), xpsl, &epos ) ) { if( epos > 0 ) { QString emsg(QString(__E_BAD_XPATH).arg(xpath).arg(epos)); m_master->setError(XmlSettings::XPathError, emsg.toLocal8Bit().data()); } return false; } return true; }
/* * ":sign place" command */ static void sign_place_cmd( buf_T *buf, linenr_T lnum, char_u *sign_name, int id, char_u *group, int prio) { if (id <= 0) { // List signs placed in a file/buffer // :sign place file={fname} // :sign place group={group} file={fname} // :sign place group=* file={fname} // :sign place buffer={nr} // :sign place group={group} buffer={nr} // :sign place group=* buffer={nr} // :sign place // :sign place group={group} // :sign place group=* if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) emsg(_(e_invarg)); else sign_list_placed(buf, group); } else { // Place a new sign if (sign_name == NULL || buf == NULL || (group != NULL && *group == '\0')) { emsg(_(e_invarg)); return; } sign_place(&id, group, sign_name, buf, lnum, prio); } }
off_t alloc_buf(off_t n, char **buffer) { if(*buffer == NULL) { *buffer = (char *)malloc(n); } else { *buffer = (char *)realloc(*buffer, n); } if(*buffer == NULL) { emsg("No buffer space available"); return 0L; } return n; }
/* * Allocate a new sign */ static sign_T * alloc_new_sign(char_u *name) { sign_T *sp; sign_T *lp; int start = next_sign_typenr; // Allocate a new sign. sp = (sign_T *)alloc_clear_id((unsigned)sizeof(sign_T), aid_sign_define_by_name); if (sp == NULL) return NULL; // Check that next_sign_typenr is not already being used. // This only happens after wrapping around. Hopefully // another one got deleted and we can use its number. for (lp = first_sign; lp != NULL; ) { if (lp->sn_typenr == next_sign_typenr) { ++next_sign_typenr; if (next_sign_typenr == MAX_TYPENR) next_sign_typenr = 1; if (next_sign_typenr == start) { vim_free(sp); emsg(_("E612: Too many signs defined")); return NULL; } lp = first_sign; // start all over continue; } lp = lp->sn_next; } sp->sn_typenr = next_sign_typenr; if (++next_sign_typenr == MAX_TYPENR) next_sign_typenr = 1; // wrap around sp->sn_name = vim_strsave(name); if (sp->sn_name == NULL) // out of memory { vim_free(sp); return NULL; } return sp; }
XmlSettingsEntry XmlSettingsEntry::operator[]( int i ) { if( type() == AbstractNode::Vector ) { VectorNode *vectorNode = (VectorNode*)m_rootNode; if( i < 0 || i >= vectorNode->size() ) { QString emsg(QString(__E_INDEX_OUT_BOUNDS).arg(i).arg(0).arg(vectorNode->size())); m_master->setError(XmlSettings::XPathError, emsg.toLocal8Bit().data()); return XmlSettingsEntry(m_master); } return XmlSettingsEntry(m_master, (*vectorNode)[i]); } return XmlSettingsEntry(m_master); }
METHOD PUBLIC DEFINITION void line::AddButton ( Str_t labeltx, uInt_t width, uInt_t height ) { button* b = NULL; b = new (VAR2STR(button)) button(labeltx, width, height); if (b != NULL) { vButton.push_back( b ); Widgets[b->Uuid] = b; } else throw emsg("[ERROR][line::AddButton] Allocate Memory error."); }
/* * docmdline() - handle a colon command * * Handles a colon command received interactively by getcmdln() or from * the environment variable "BVIINIT" (or eventually .bvirc). */ void docmdline(char *cmdline) { char buff[CMDSZ]; char cmdbuf[CMDSZ]; char cmdname[MAXNAME]; char *cmd; char *p; size_t len; int n, ok, ret; int force = 0; int saveflag; if(*cmdline == '\0') { return; } if(*cmdline == '"') { return; /** comment **/ } if(strlen(cmdline) > CMDSZ - 2) { emsg("Command too long"); return; } strcpy(buff, cmdline); cmd = buff; /* With no address given, we start at the beginning of the file and * go to the end of the file (not line like in vi). */ addr_flag = 0; start_addr = mem; end_addr = maxpos - 1; SKIP_WHITE if(*cmd == '%') { cmd++; addr_flag = 2; } else { if((start_addr = calc_addr(&cmd, mem)) == NULL) { return; } if(*cmd == ',') { cmd++; addr_flag = 1; SKIP_WHITE if((end_addr = calc_addr(&cmd, maxpos - 1)) == NULL) { return; } } else { if(addr_flag) {
XmlSettingsEntry XmlSettingsEntry::find( const QString &xpath ) { QStringList xpsl; JQ_ASSERT(m_master); if( !splitXPath( xpath, xpsl ) ) { return NULL; } QStringList::ConstIterator itXPath; AbstractNode *node; XmlSettingsEntry entry( find(xpsl, itXPath, node) ); if( entry.isInvalid() ) { QString emsg(QString(__E_SETTING_NOT_FOUND).arg(xpath)); m_master->setError(XmlSettings::SettingNotFound, emsg.toLocal8Bit().data()); } return entry; }