void GCodeExport::switchExtruder(int new_extruder)
{
    if (current_extruder == new_extruder)
        return;
    
    if (!isRetracted) // assumes the last retraction already was an extruder switch retraction
    {
        writeRetraction_extruderSwitch();
    }
    
    int old_extruder = current_extruder;
    current_extruder = new_extruder;
    if (flavor == EGCodeFlavor::MACH3)
        resetExtrusionValue();
    isRetracted = true;
    writeCode(extruder_attr[old_extruder].end_code.c_str());
    if (flavor == EGCodeFlavor::MAKERBOT)
        *output_stream << "M135 T" << current_extruder << "\n";
    else
        // TinyG TODO: find out what a T code does
        *output_stream << "T" << current_extruder << "\n";
    writeCode(extruder_attr[new_extruder].start_code.c_str());
    
    //Change the Z position so it gets re-writting again. We do not know if the switch code modified the Z position.
    currentPosition.z += 1;
}
Exemple #2
0
void TclWriter::writeHeaderFile(UMLClassifier * c, QFile & fileh)
{
    // open stream for writing
    QTextStream stream(&fileh);
    mStream = &stream;

    // reset the indent level
    m_indentLevel = 0;

    // write header blurb
    QString str = getHeadingFile(".tcl");
    if (!str.isEmpty()) {
        str.replace(QRegExp("%filename%"), fileName_);
        str.replace(QRegExp("%filepath%"), fileh.fileName());
        writeCode(str);
    }
    // set current namespace
    writeCode("namespace eval " + mNamespace + " {");
    m_indentLevel++;

    // check on already existing
    writeComm("Do not load twice");
    writeCode("if {[namespace exist " + className_ + "]} return");

    // source used superclass files
    UMLClassifierList superclasses = c->getSuperClasses();
    if (superclasses.count() > 0) {
        writeComm
        ("Source found and used class files and import class command if necessary");

        foreach (UMLClassifier * classifier , superclasses ) {
            writeUse(classifier);
        }
void GCodeExport::switchExtruder(int new_extruder)
{
    if (current_extruder == new_extruder)
        return;

    writeRetraction_extruderSwitch();

    resetExtrusionValue(); // should be called on the old extruder

    int old_extruder = current_extruder;
    current_extruder = new_extruder;

    if (flavor == EGCodeFlavor::MACH3)
    {
        resetExtrusionValue(); // also zero the E value on the new extruder
    }
    
    writeCode(extruder_attr[old_extruder].end_code.c_str());
    if (flavor == EGCodeFlavor::MAKERBOT)
    {
        *output_stream << "M135 T" << current_extruder << "\n";
    }
    else
    {
        *output_stream << "T" << current_extruder << "\n";
    }
    writeCode(extruder_attr[new_extruder].start_code.c_str());
    
    //Change the Z position so it gets re-writting again. We do not know if the switch code modified the Z position.
    currentPosition.z += 1;
}
Exemple #4
0
/**
 * Write end code and flush bitstream
 * @param s LZW state
 * @return Number of bytes written or -1 on error
 */
int ff_lzw_encode_flush(LZWEncodeState * s)
{
    if (s->last_code != -1)
        writeCode(s, s->last_code);
    writeCode(s, s->end_code);
    flush_put_bits(&s->pb);
    s->last_code = -1;

    return writtenBytes(s);
}
Exemple #5
0
/**
 * Write end code and flush bitstream
 * @param s LZW state
 * @return Number of bytes written or -1 on error
 */
int ff_lzw_encode_flush(LZWEncodeState *s,
                        void (*lzw_flush_put_bits)(PutBitContext *))
{
    if (s->last_code != -1)
        writeCode(s, s->last_code);
    writeCode(s, s->end_code);
    lzw_flush_put_bits(&s->pb);
    s->last_code = -1;

    return writtenBytes(s);
}
Exemple #6
0
//-----------------------------------------------------------------
// end of data
void mgLZWEncode::compressTerm()
{
  // Flush out the buffered code 
  if (!m_firstByte)
    writeCode(m_waitingCode);

  // Send an EOF code 
  writeCode(m_EOFCode);

  // Flush the bit-packing buffer 
  if (m_curBits > 0)
    writeLZWByte(m_curAccum & 0xFF);
}
void encodeData(istream& input, const map<int, string> &encodingMap, obitstream& output) {
	int byte = input.get();

    // continue until input end of input, byte == -1
	while (byte != -1) {
		string code = encodingMap.at(byte);
		writeCode(code, output);
		byte = input.get();
	}

	string eofCode = encodingMap.at(PSEUDO_EOF);
	writeCode(eofCode, output);
}
Exemple #8
0
void GCodeExport::startExtruder(int new_extruder)
{
    if (new_extruder != current_extruder) // wouldn't be the case on the very first extruder start if it's extruder 0
    {
        if (flavor == EGCodeFlavor::MAKERBOT)
        {
            *output_stream << "M135 T" << new_extruder << new_line;
        }
        else
        {
            *output_stream << "T" << new_extruder << new_line;
        }
    }

    current_extruder = new_extruder;

    assert(getCurrentExtrudedVolume() == 0.0 && "Just after an extruder switch we haven't extruded anything yet!");
    resetExtrusionValue(); // zero the E value on the new extruder, just to be sure

    writeCode(extruder_attr[new_extruder].start_code.c_str());
    CommandSocket::setExtruderForSend(new_extruder);
    CommandSocket::setSendCurrentPosition( getPositionXY() );

    //Change the Z position so it gets re-writting again. We do not know if the switch code modified the Z position.
    currentPosition.z += 1;
}
Exemple #9
0
void emitLOC(REG reg, const int Const)
{
    int opcode = 0x00;
    int SizeOfopcode = 1;
    switch (reg)
    {
    case REG_EAX :
        opcode = 0xB8;
        break;
    case REG_EBX :
        opcode = 0xBB;
        break;
    case REG_ECX :
        break;
    case REG_EDX :
        break;
    case REG_ESI :
        break;
    case REG_EDI :
        break;
    case REG_ESP :
        break;
    case REG_EBP :
        break;
    default :
        return ;
    }
    writeCode(opcode, SizeOfopcode, Const, 4);
}
Exemple #10
0
/**
 * LZW main compress function
 * @param s LZW state
 * @param inbuf Input buffer
 * @param insize Size of input buffer
 * @return Number of bytes written or -1 on error
 */
int ff_lzw_encode(LZWEncodeState *s, const uint8_t *inbuf, int insize)
{
    int i;

    if(insize * 3 > (s->bufsize - s->output_bytes) * 2)
    {
        return -1;
    }

    if (s->last_code == LZW_PREFIX_EMPTY)
        clearTable(s);

    for (i = 0; i < insize; i++)
    {
        uint8_t c = *inbuf++;
        int code = findCode(s, c, s->last_code);
        if (s->tab[code].hash_prefix == LZW_PREFIX_FREE)
        {
            writeCode(s, s->last_code);
            addCode(s, c, s->last_code, code);
            code = hash(0, c);
        }
        s->last_code = s->tab[code].code;
        if (s->tabsize >= s->maxcode - 1)
        {
            clearTable(s);
        }
    }

    return writtenBytes(s);
}
Exemple #11
0
//-----------------------------------------------------------------
// reset compressor and issue a clear code
void mgLZWEncode::clearBlock()
{
  clearHash();			// delete all the symbols 

  m_freeCode = m_clearCode + 2;
  writeCode(m_clearCode);	// inform decoder 
  m_bits = m_initBits;	// reset code size 
  m_maxCode = MAXCODE(m_bits);
}
void GCodeExport::finalize(double moveSpeed, const char* endCode)
{
    writeFanCommand(0);
    writeCode(endCode);
    log("Print time: %d\n", int(getTotalPrintTime()));
    log("Filament: %d\n", int(getTotalFilamentUsed(0)));
    for(int n=1; n<MAX_EXTRUDERS; n++)
        if (getTotalFilamentUsed(n) > 0)
            log("Filament%d: %d\n", n + 1, int(getTotalFilamentUsed(n)));
    output_stream->flush();
}
void GCodeExport::finalize(int maxObjectHeight, double moveSpeed, const char* endCode)
{
    writeFanCommand(0);
    setZ(maxObjectHeight + 5000);
    writeMove(Point3(0,0,maxObjectHeight + 5000) + getPositionXY(), moveSpeed, 0);
    writeCode(endCode);
    log("Print time: %d\n", int(getTotalPrintTime()));
    log("Filament: %d\n", int(getTotalFilamentUsed(0)));
    for(int n=1; n<MAX_EXTRUDERS; n++)
        if (getTotalFilamentUsed(n) > 0)
            log("Filament%d: %d\n", n + 1, int(getTotalFilamentUsed(n)));
    output_stream->flush();
}
Exemple #14
0
void GCodeExport::finalize(const char* endCode)
{
    writeFanCommand(0);
    writeCode(endCode);
    long print_time = getTotalPrintTime();
    int mat_0 = getTotalFilamentUsed(0);
    log("Print time: %d\n", print_time);
    log("Print time (readable): %dh %dm %ds\n", print_time / 60 / 60, (print_time / 60) % 60, print_time % 60);
    log("Filament: %d\n", mat_0);
    for(int n=1; n<MAX_EXTRUDERS; n++)
        if (getTotalFilamentUsed(n) > 0)
            log("Filament%d: %d\n", n + 1, int(getTotalFilamentUsed(n)));
    output_stream->flush();
}
Exemple #15
0
int main(void)
{
	char command[100] = {'\0'};
	help();

	signal(SIGINT, intHandler);
	while (true)
	{
		prompt(command);
		writeCode(command);
	}

	return 0;
}
Exemple #16
0
/*!
*	换一台打印机
*	\param newExtruder 新的打印机的序号
*/
void GCodeExport::switchExtruder(int newExtruder)
{
    if (extruderNr == newExtruder)
        return;
    
    if (flavor == GCODE_FLAVOR_BFB)
    {
        if (!isRetracted)
            *output_stream << "M103\r\n";

        isRetracted = true;
        return;
    }
    
    resetExtrusionValue();
    if (flavor == GCODE_FLAVOR_ULTIGCODE || flavor == GCODE_FLAVOR_REPRAP_VOLUMATRIC)
    {
        *output_stream << "G10 S1\n";
    }else{
        *output_stream << "G1 F" << (extruderSwitchRetractionSpeed * 60) << " " << extruderCharacter[extruderNr] << std::setprecision(5) << (extrusion_amount - extruderSwitchRetraction) << "\n";
        currentSpeed = extruderSwitchRetractionSpeed;
    }

    extruderNr = newExtruder;
    if (flavor == GCODE_FLAVOR_MACH3)
        resetExtrusionValue();
    isRetracted = true;
    writeCode(preSwitchExtruderCode[extruderNr].c_str());
    if (flavor == GCODE_FLAVOR_MAKERBOT)
        *output_stream << "M135 T" << extruderNr << "\n";
    else
        *output_stream << "T" << extruderNr << "\n";
    writeCode(postSwitchExtruderCode[extruderNr].c_str());
    
    //Change the Z position so it gets re-writting again. We do not know if the switch code modified the Z position.
    currentPosition.z += 1;
}
Exemple #17
0
void emitMov(REG reg, int loc, VTYPE vtype)
{
    int opcode = 0x89;
    int SizeOfopcode = 2;

    char oprand = 0x00;
    char opmod = 0x00;
    char oprm  = 0x05;
    char opreg = 0x00;

    switch (reg)
    {
    case REG_EAX :
        opreg = 0x00;
        break;
    case REG_EBX :
        opreg = 0x03;
        break;
    case REG_ECX :
        opreg = 0x01;
        break;
    case REG_EDX :
        opreg = 0x02;
        break;
    case REG_ESI :
        opreg = 0x06;
        break;
    case REG_EDI :
        opreg = 0x07;
        break;
    case REG_ESP :
        opreg = 0x04;
        break;
    case REG_EBP :
        opreg = 0x05;
        break;
    default :
        return ;
    }
    oprand += (opreg << 3);
    oprand += oprm;

    opcode += (oprand << 8);

    writeCode(opcode, SizeOfopcode, loc, 4);
    AddVarRef(loc, offset - 4, vtype);
}
void HuffmanTree::writeCode(Tree* node,Writer& w)
{
	if (node!=root)
	{
		writeCode(node->getParent(),w);
		if (node->isLeftChild())
		{
			//cout << 0;
			w.writeBit(0);
		}
		else
		{
			//cout << 1;
			w.writeBit(1);
		}
	}
}
Exemple #19
0
/**
 * Clear LZW code table
 * @param s LZW state
 */
static void clearTable(LZWEncodeState * s)
{
    int i, h;

    writeCode(s, s->clear_code);
    s->bits = 9;
    for (i = 0; i < LZW_HASH_SIZE; i++) {
        s->tab[i].hash_prefix = LZW_PREFIX_FREE;
    }
    for (i = 0; i < 256; i++) {
        h = hash(0, i);
        s->tab[h].code = i;
        s->tab[h].suffix = i;
        s->tab[h].hash_prefix = LZW_PREFIX_EMPTY;
    }
    s->tabsize = 258;
}
Exemple #20
0
/*******************************************************************************
 * Main
 ******************************************************************************/
int main(int argc, char const* argv[]) {

  int argi = 0;
  tgState *T = tgState_create(&tgMalloc, NULL);
  TOPT_PARSE(argi, argc, argv, options) {
  case TERR_ARGUMENT:
    // Not an option, assume it's a file.
    writeCode(T, argv[argi++], NULL);
    break;
  default:
    printf("tc has encountered a fatal error!\n");
    exit(1);
  }
  tgState_free(T);

  return 0;
}
Exemple #21
0
void GCodeExport::switchExtruder(int new_extruder, const RetractionConfig& retraction_config_old_extruder)
{
    if (current_extruder == new_extruder)
        return;

    bool force = true;
    bool extruder_switch = true;
    writeRetraction(&const_cast<RetractionConfig&>(retraction_config_old_extruder), force, extruder_switch);

    resetExtrusionValue(); // zero the E value on the old extruder, so that the current_e_value is registered on the old extruder

    int old_extruder = current_extruder;

    writeCode(extruder_attr[old_extruder].end_code.c_str());

    startExtruder(new_extruder);
}
void writeSendCodelockPacket(uint8_t* packet_start, int code,
	uint32_t count, uint32_t len, pcap_t* adHandle) {

	// write the current code
	writeCode(packet_start, code);

	// seq numbers
	increment_sequence_number(packet_start, 5, count);
	increment_sequence_number(packet_start, 11, count);
	increment_sequence_number(packet_start, 14, count);

	// checksums
	write_checksum_ip(packet_start);
	InsertUDPChecksum(packet_start, len);

	// fire away
	pcap_sendpacket(adHandle, packet_start, len);
}
Exemple #23
0
void Functionality::addTask(vector<string> eventDetails)
{
	EventStorage tempEvent;
	int tempCode;
	int tempDigit;
	string tempString;
	ifstream eventCodeGenerate("EventCode.txt");
	eventCodeGenerate>>tempCode;
	eventCodeGenerate.close();
	tempCode += 1;
	ofstream writeCode("EventCode.txt");
	writeCode<<tempCode;
	writeCode.close();
	while(tempCode != 0)
	{
		tempDigit = tempCode%10;
		tempString += char(tempDigit+48);
		tempCode /= 10;		
	}
	eventDetails.pop_back();
	eventDetails.push_back(tempString);
	tempEvent.storeUserInput(eventDetails, 0);
	string eventPriority=tempEvent.getPriority();

	if(eventPriority[0] == '1')
	{
		highPriority.push_back(tempEvent);
		undoHighVector.push_back(highPriority);
		undoCount.push_back(0);
	}
	else
		if(eventPriority[0] == '2')
		{
			normalPriority.push_back(tempEvent);
			undoNormalVector.push_back(normalPriority);
			undoCount.push_back(1);
		}
		redoCount.clear();
		redoHighVector.clear();
		redoNormalVector.clear();
		callSort();
		updateFile();
		notificationFile();
}
Exemple #24
0
void emitMul(REG reg1, REG reg2)
{
    int opcode = 0x0FAF;
    int SizeOfopcode = 2;
    char opmod = 0xC0;
    char temp = 0x00;

    switch (reg2)
    {
    case REG_EAX :
        temp = 0x00;
        break;
    case REG_EBX :
        temp = 0x03;
        break;
    case REG_ECX :
        temp = 0x01;
        break;
    case REG_EDX :
        temp = 0x02;
        break;
    }
    opmod += temp;

    switch (reg1)
    {
    case REG_EAX :
        temp = 0x00;
        break;
    case REG_EBX :
        temp = 0x03;
        break;
    case REG_ECX :
        temp = 0x01;
        break;
    case REG_EDX :
        temp = 0x02;
        break;
    }
    opmod += (temp << 3);

    writeCode(opcode, SizeOfopcode, opmod, 1);
}
Exemple #25
0
void GCodeExport::finalize(int maxObjectHeight, int moveSpeed, const char* endCode)
{
    writeFanCommand(0);
    writeRetraction();
    setZ(maxObjectHeight + 5000);
    writeMove(getPositionXY(), moveSpeed, 0);
    writeCode(endCode);
    log("Print time: %d\n", int(getTotalPrintTime()));
    log("Filament: %d\n", int(getTotalFilamentUsed(0)));
    log("Filament2: %d\n", int(getTotalFilamentUsed(1)));
    
    if (getFlavor() == GCODE_FLAVOR_ULTIGCODE)
    {
        char numberString[16];
        sprintf(numberString, "%d", int(getTotalPrintTime()));
        replaceTagInStart("<__TIME__>", numberString);
        sprintf(numberString, "%d", int(getTotalFilamentUsed(0)));
        replaceTagInStart("<FILAMENT>", numberString);
        sprintf(numberString, "%d", int(getTotalFilamentUsed(1)));
        replaceTagInStart("<FILAMEN2>", numberString);
    }
}
Exemple #26
0
int Encoding::length(const unsigned char *output) const
{
    return writeCode((unsigned char*)output, false);
}
Exemple #27
0
/** Opens appropriate files and handles them
    @param argc number of command line arguments 
    @param argv array of command line arguments
    @return the exit status of the program
  */
int main( int argc, char *argv[] )
{
  char *wordFile = "words.txt";
  
  FILE *input;
  FILE *output;
  
  if ( argc < 3 || argc > 4 ) {
    fprintf( stderr, "usage: pack <input.txt> <compressed.raw> [wordfile.txt]\n" );
    exit( 1 );
  }
  input = fopen( argv[ 1 ], "r" );
  if ( !input ) {
    printf( "usage: readFile <input-file>\n" );
    exit( 1 );
  }
  output = fopen( argv[ 2 ], "wb" );
  if ( !output ) {
    printf( "usage: readFile <input-file>\n" );
    exit( 1 );
  }
  if ( argc == 4 ) {
    wordFile = argv[ 3 ];
  }
  
  WordList *wordList = readWordList( wordFile );

#ifdef DEBUG
  // Report the entire contents of the word list, once it's built.
  printf( "---- word list -----\n" );
  for ( int i = 0; i < wordList->len; i++ )
    printf( "%d == %s\n", i, wordList->words[ i ] );
  printf( "--------------------\n" );
#endif

  // ... 

  // Read the contents of the whole file into one big buffer.  This could be more
  // efficient, but it simplifies the rest of the program.
  char *buffer = readFile( input );

  // Write out codes for everything in the buffer.
  int pos = 0;
  PendingBits pending = { 0, 0 };
  while ( buffer[ pos ] ) {
    // Get the next code.
    int code = bestCode( wordList, buffer + pos );
#ifdef DEBUG
    printf( "%d <- %s\n", code, wordList->words[ code ] );
#endif

    // Write it out and move ahead by the number of characters we just encoded.
    writeCode( code, &pending, output );
    pos += strlen( wordList->words[ code ] );
  }

  // Write out any remaining bits in the last, partial byte.
  flushBits( &pending, output );

  // ...
  fclose( input );
  fclose( output );
  freeWordList( wordList );
  return EXIT_SUCCESS;
}
Exemple #28
0
//-----------------------------------------------------------------
// compress a byte
void mgLZWEncode::compressByte(
  BYTE nByte)
{
  if (m_firstByte) 
  {	
    // need to initialize nWaitingCode 
    m_waitingCode = nByte;
    m_firstByte = FALSE;
    return;
  }

  // Probe hash table to see if a symbol exists for 
  // waiting_code followed by nByte.

  HashInt i = ((HashInt) nByte << (MAX_LZW_BITS-8)) + m_waitingCode;
  HashInt nDisp;

  // i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE
  if (i >= HASH_SIZE)
    i -= HASH_SIZE;

  mgLZWHash lProbeValue = HASH_ENTRY(m_waitingCode, nByte);
  // is first probed slot not empty?
  if (m_hashCode[i] != 0) 
  { 
    if (m_hashValue[i] == lProbeValue) 
    {
      m_waitingCode = m_hashCode[i];
      return;
    }
    if (i == 0)			// secondary hash (after G. Knott) 
      nDisp = 1;
    else nDisp = HASH_SIZE - i;

    for (;;) 
    {
      i -= nDisp;
      if (i < 0)
        i += HASH_SIZE;
      if (m_hashCode[i] == 0)
        break;			// hit empty slot
      if (m_hashValue[i] == lProbeValue) 
      {
	      m_waitingCode = m_hashCode[i];
        return;
      }
    }
  }

  // here when hashtable[i] is an empty slot; desired symbol not in table 
  writeCode(m_waitingCode);

  if (m_freeCode < LZW_TABLE_SIZE) 
  {
    m_hashCode[i] = m_freeCode++; // add symbol to hashtable
    m_hashValue[i] = lProbeValue;
  } 
  else clearBlock();

  m_waitingCode = nByte;
}
Exemple #29
0
//-----------------------------------------------------------------
// start of data
void mgLZWEncode::compressInit()
{
  // write an initial Clear code
  writeCode(m_clearCode);
}