/* * 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); }
/** 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) { internalCommand = !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 = *(uint16_t *)p; p += 2; uint8_t textlen = 16; if(isV2()) { params2 = *(uint16_t *)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(hasM()) { M = *(uint16_t *)p; p += 2; } if(hasG()) { G = *(uint16_t *)p; p += 2; } } else { if(hasM()) { M = *p++; } if(hasG()) { G = *p++; } } //if(code->params & 8) {memcpy(&code->X,p,4);p+=4;} if(hasX()) { X = *(float *)p; p += 4; } if(hasY()) { Y = *(float *)p; p += 4; } if(hasZ()) { Z = *(float *)p; p += 4; } if(hasE()) { E = *(float *)p; p += 4; } if(hasF()) { F = *(float *)p; p += 4; } if(hasT()) { T = *p++; } if(hasS()) { S = *(int32_t*)p; p += 4; } if(hasP()) { 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(hasD()) { D = *(float *)p; p += 4; } if(hasC()) { C = *(float *)p; p += 4; } if(hasH()) { H = *(float *)p; p += 4; } if(hasA()) { A = *(float *)p; p += 4; } if(hasB()) { B = *(float *)p; p += 4; } if(hasK()) { K = *(float *)p; p += 4; } if(hasL()) { L = *(float *)p; p += 4; } if(hasO()) { O = *(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; }