/* nowdat, setday */ int func(struct ymd *nowday, struct ymd *setday) { int y = nowday->year; int m = nowday->month; int d = nowday->day; int yy = setday->year; int mm = setday->month; int dd = setday->day; int returnday = 0; if( (y > yy) || (y == yy && m > mm) || (y == yy && m == mm && d > dd) ) { if (y > yy) returnday = hasR(y, yy) + 365 *(y - yy -1) + toEnd(yy, mm, dd) + toStart(y, m, d); else if (y == yy) returnday = toEnd(yy, mm, dd) - toEnd(y, m, d); } else if ( y == yy && m == mm && d == dd ) { return 0; } else { if (yy > y) returnday = hasR(yy, y) + 365 *(yy - y -1) + toEnd(y ,m, d) + toStart(yy, mm, dd); else if (y == yy) returnday = toEnd(y, m, d) - toEnd(yy, mm, dd); } return returnday; }
/* y is now, yy is the set day */ int func(int y, int m, int d, int yy, int mm, int dd) { int returnday = 0; if( (y > yy) || (y == yy && m > mm) || (y == yy && m == mm && d > dd) ) { if (y > yy) returnday = hasR(y, yy) + 365 *(y - yy -1) + toEnd(yy, mm, dd) + toStart(y, m, d); else if (y == yy) returnday = toEnd(yy, mm, dd) - toEnd(y, m, d); } else if ( y == yy && m == mm && d == dd ) { return 0; } else { if (yy > y) returnday = hasR(yy, y) + 365 *(yy - y -1) + toEnd(y ,m, d) + toStart(yy, mm, dd); else if (y == yy) returnday = toEnd(y, m, d) - toEnd(yy, mm, dd); } return returnday; }
/* * Access2String * */ char* adfAccess2String(int32_t acc) { static char ret[8+1]; strcpy(ret,"----rwed"); if (hasD(acc)) ret[7]='-'; if (hasE(acc)) ret[6]='-'; if (hasW(acc)) ret[5]='-'; if (hasR(acc)) ret[4]='-'; if (hasA(acc)) ret[3]='a'; if (hasP(acc)) ret[2]='p'; if (hasS(acc)) ret[1]='s'; if (hasH(acc)) ret[0]='h'; return(ret); }
/** \brief Print command on serial console */ void GCode::printCommand() { if(hasM()) { Com::print('M'); Com::print((int)M); Com::print(' '); } if(hasG()) { Com::print('G'); Com::print((int)G); Com::print(' '); } if(hasT()) { Com::print('T'); Com::print((int)T); Com::print(' '); } if(hasX()) { Com::printF(Com::tX,X); } if(hasY()) { Com::printF(Com::tY,Y); } if(hasZ()) { Com::printF(Com::tZ,Z); } if(hasE()) { Com::printF(Com::tE,E,4); } if(hasF()) { Com::printF(Com::tF,F); } if(hasS()) { Com::printF(Com::tS,S); } if(hasP()) { Com::printF(Com::tP,P); } if(hasI()) { Com::printF(Com::tI,I); } if(hasJ()) { Com::printF(Com::tJ,J); } if(hasR()) { Com::printF(Com::tR,R); } if(hasString()) { Com::print(text); } Com::println(); }
/** Converts a binary uint8_tfield containing one GCode line into a GCode structure. Returns true if checksum was correct. */ bool GCode::parseBinary(uint8_t *buffer,bool fromSerial) { unsigned int sum1=0,sum2=0; // for fletcher-16 checksum // first do fletcher-16 checksum tests see // http://en.wikipedia.org/wiki/Fletcher's_checksum uint8_t *p = buffer; uint8_t len = binaryCommandSize-2; while (len) { uint8_t tlen = len > 21 ? 21 : len; len -= tlen; do { sum1 += *p++; if(sum1>=255) sum1-=255; sum2 += sum1; if(sum2>=255) sum2-=255; } while (--tlen); } sum1 -= *p++; sum2 -= *p; if(sum1 | sum2) { if(Printer::debugErrors()) { Com::printErrorFLN(Com::tWrongChecksum); } return false; } p = buffer; params = *(unsigned int *)p; p+=2; uint8_t textlen=16; if(isV2()) { params2 = *(unsigned int *)p; p+=2; if(hasString()) textlen = *p++; } else params2 = 0; if(params & 1) { actLineNumber=N=*(uint16_t *)p; p+=2; } if(isV2()) // Read G,M as 16 bit value { if(params & 2) { M=*(uint16_t *)p; p+=2; } if(params & 4) { G=*(uint16_t *)p; p+=2; } } else { if(params & 2) { M=*p++; } if(params & 4) { G=*p++; } } //if(code->params & 8) {memcpy(&code->X,p,4);p+=4;} if(params & 8) { X=*(float *)p; p+=4; } if(params & 16) { Y=*(float *)p; p+=4; } if(params & 32) { Z =*(float *)p; p+=4; } if(params & 64) { E=*(float *)p; p+=4; } if(params & 256) { F=*(float *)p; p+=4; } if(params & 512) { T=*p++; } if(params & 1024) { S=*(int32_t*)p; p+=4; } if(params & 2048) { P=*(int32_t*)p; p+=4; } if(hasI()) { I=*(float *)p; p+=4; } if(hasJ()) { J=*(float *)p; p+=4; } if(hasR()) { R=*(float *)p; p+=4; } if(hasString()) // set text pointer to string { text = (char*)p; text[textlen] = 0; // Terminate string overwriting checksum waitUntilAllCommandsAreParsed=true; // Don't destroy string until executed } formatErrors = 0; return true; }
/* * adfFileOpen * */ struct File* adfOpenFile(struct Volume *vol, char* name, char *mode) { struct File *file; SECTNUM nSect; struct bEntryBlock entry, parent; BOOL write; char filename[200]; write=( strcmp("w",mode)==0 || strcmp("a",mode)==0 ); if (write && vol->dev->readOnly) { (*adfEnv.wFct)("adfFileOpen : device is mounted 'read only'"); return NULL; } adfReadEntryBlock(vol, vol->curDirPtr, &parent); nSect = adfNameToEntryBlk(vol, parent.hashTable, name, &entry, NULL); if (!write && nSect==-1) { sprintf(filename,"adfFileOpen : file \"%s\" not found.",name); (*adfEnv.wFct)(filename); /*fprintf(stdout,"filename %s %d, parent =%d\n",name,strlen(name),vol->curDirPtr);*/ return NULL; } if (!write && hasR(entry.access)) { (*adfEnv.wFct)("adfFileOpen : access denied"); return NULL; } /* if (entry.secType!=ST_FILE) { (*adfEnv.wFct)("adfFileOpen : not a file"); return NULL; } if (write && (hasE(entry.access)||hasW(entry.access))) { (*adfEnv.wFct)("adfFileOpen : access denied"); return NULL; } */ if (write && nSect!=-1) { (*adfEnv.wFct)("adfFileOpen : file already exists"); return NULL; } file = (struct File*)calloc(1,sizeof(struct File)); if (!file) { (*adfEnv.wFct)("adfFileOpen : malloc"); return NULL; } file->fileHdr = (struct bFileHeaderBlock*)calloc(1,sizeof(struct bFileHeaderBlock)); if (!file->fileHdr) { (*adfEnv.wFct)("adfFileOpen : malloc"); free(file); return NULL; } file->currentData = calloc(1,512*sizeof(unsigned char)); if (!file->currentData) { (*adfEnv.wFct)("adfFileOpen : malloc"); free(file->fileHdr); free(file); return NULL; } file->volume = vol; file->pos = 0; file->posInExtBlk = 0; file->posInDataBlk = 0; file->writeMode = write; file->currentExt = NULL; file->nDataBlock = 0; if (strcmp("w",mode)==0) { memset(file->fileHdr,0,512); adfCreateFile(vol,vol->curDirPtr,name,file->fileHdr); file->eof = TRUE; } else if (strcmp("a",mode)==0) { memcpy(file->fileHdr,&entry,sizeof(struct bFileHeaderBlock)); file->eof = TRUE; adfFileSeek(file, file->fileHdr->byteSize); } else if (strcmp("r",mode)==0) { memcpy(file->fileHdr,&entry,sizeof(struct bFileHeaderBlock)); file->eof = FALSE; } /*puts("adfOpenFile");*/ return(file); }