Пример #1
0
/**
 * Adjust the frequency according to the current temperature.
 * Returns the number of seconds to wait until the next adjustment.
 */
void Throttle::adjust()
{
	int temp = readTemp();
	std::vector<int>::iterator new_freq = freqs.end();

	DEBUG_PRINT("[Throttle] Temperature: " << (float)temp/1000 << "°C");

	// slowly reset stabilize counter
	if (stabilize > 0) --stabilize;
	if (stabilize < 0) ++stabilize;

	// If the temperature exceeds a threshold, find the next best frequency.
	if (temp > temp_max && stabilize >= 0) {
		new_freq = std::lower_bound(freqs.begin(), freqs.end(), freq);
		if (new_freq == freqs.begin())
			return;     // There is nothing we can do.
		else
			--new_freq;
		stabilize = -wait_after_adjust;
	}
	if (temp < temp_min && stabilize <= 0) {
		new_freq = std::upper_bound(freqs.begin(), freqs.end(), freq);
		stabilize = wait_after_adjust;
	}

	// Have we found one? Then adjust.
	if (new_freq != freqs.end()) {
		freq = *new_freq;
		writeFreq();
	}
}
Пример #2
0
/**
 * Execute one feedback cycle.
 *
 * Reads the current temperature and adapts the maximum frequency, if necessary.
 */
void Throttle::operator()()
{
	// Look if there is new input in the pipe
	queue.update();

	if (override_freq) {
		if (freq != override_freq) {
			freq = override_freq;
			writeFreq();
		}
	}
	else
		adjust();
}
Пример #3
0
void Compression::huffmanEncode(const char* inputFile)
{
    FILE * src = fopen(inputFile, "rb");

    char outputPath[1000];
    const char * fileExtension = ".bin";
    outputFilePath(inputFile, outputPath, fileExtension);
    FILE * dest = fopen(outputPath, "wb");

    if (src == NULL || dest == NULL)
    {
        printf("Не удается найти файл.");
        exit(EXIT_FAILURE);
    }

    unsigned int fileSize;
    fileSize = getFileSize(src);

    unsigned int * freqList;
    freqList = (unsigned int *)calloc(CHARS_LIMIT, sizeof(unsigned int));
    calcCharFreq(src, freqList);

    unsigned int numOfFreq;
    numOfFreq = calcNumOfFreq(freqList);

    HuffNode * nodeList = NULL;
    buildNodeList(&nodeList, freqList);

    buildHuffTree(&nodeList);
    HuffNode * treeRoot = nodeList;

    unsigned int i;
    HuffCode newCode;
    HuffCode * huffCodeTable;
    huffCodeTable = (HuffCode *)calloc(CHARS_LIMIT, sizeof(HuffCode));
    for(i=0; i<CHARS_LIMIT; i++)
    {
        if(freqList[i] > 0)
        {
            newCode.length = 0;
            buildHuffCode(treeRoot, &newCode, i);
            huffCodeTable[i] = newCode;
        }
    }

    HuffHeader hHeader;
    writeHeader(dest, hHeader, numOfFreq, fileSize);

    HuffFreq hFreq;
    writeFreq(dest, freqList, hFreq);

    writeEncodedData(src, dest, huffCodeTable, fileSize);

    freeHuffTree(treeRoot);
    treeRoot = NULL;
    free(huffCodeTable);
    free(freqList);

    fclose(src);
    fclose(dest);
}