예제 #1
0
ThreadError
NcpUart::OutboundFrameFeedData(const uint8_t *frame, uint16_t frameLength)
{
    ThreadError errorCode;
    uint16_t outLength(OutboundFrameGetRemaining());

    errorCode = mFrameEncoder.Encode(frame, frameLength, mSendFrameIter, outLength);

    if (errorCode == kThreadError_None)
    {
        mSendFrameIter += outLength;
    }

    return errorCode;
}
예제 #2
0
ThreadError
NcpUart::OutboundFrameSend(void)
{
    ThreadError errorCode;
    uint16_t outLength(OutboundFrameGetRemaining());

    errorCode = mFrameEncoder.Finalize(mSendFrameIter, outLength);

    if (errorCode == kThreadError_None)
    {
        mSendFrameIter += outLength;
        errorCode = otPlatUartSend(mSendFrame, mSendFrameIter - mSendFrame);
    }

    if (errorCode == kThreadError_None)
    {
        mSending = true;
    }

    return errorCode;
}
예제 #3
0
파일: main.cpp 프로젝트: jmtucker6/Project5
int main(int argc, char* argv[]) {
	Heap heap = Heap(10);
	char c;
	Node *chars = NULL;
	Node *ptr = chars;
	/////////////////////////////// Read and Create Linked List (for Frequencies) ////////////////////////////////
	std::ifstream in(argv[1]);
	while (in.get(c)) {
		std::cout << c;
		if (chars == NULL) {
			Node *temp = new Node;
			temp->content = c;
			temp->label = "L:";
			temp->label += static_cast<std::ostringstream*>(&(std::ostringstream() << (int) c)) -> str(); // Get ASCII Value
			temp->priority = 1;
			temp->next = NULL;
			temp->right = NULL;
			temp->left = NULL;
			chars = temp;
			ptr = temp;
		}
		else {
			Node *temp = find(chars, c);
			if (temp != NULL) {
				temp->priority++;
			}
			else {
				temp = new Node;
				temp->content = c;
				temp->label = "L:";
				temp->label += static_cast<std::ostringstream*>(&(std::ostringstream() << (int)c))->str(); // Get ASCII Value
				temp->priority = 1;
				temp->next = NULL;
				temp->right = NULL;
				temp->left = NULL;
				ptr->next = temp;
				ptr = temp;
			}
		}
	}

	in.close();
	/////////////////////////////////////////////////////////////////////////////////////////

	////////////////////////////// Create Initial Heap //////////////////////////////////////
	ptr = chars;
	while (ptr != NULL) {
		heap.insert(ptr);
		ptr = ptr->next;
	}
	int totalChars = heap.count();

	/////////////////////////////////////////////////////////////////////////////////////////

	////////////////////////////// Create Huffman Code Tree /////////////////////////////////
	int counter = 0;
	Node *parent = NULL;
	while (heap.count() > 1) {
		Node *n1 = heap.removeMin();
		Node *n2 = heap.removeMin();
		parent = new Node;
		parent->label = "I:" + static_cast<std::ostringstream*>(&(std::ostringstream() << counter++))->str();
		parent->content = '*';
		parent->left = n1;
		parent->right = n2;
		parent->next = NULL;
		parent->priority = n1->priority + n2->priority;
		heap.insert(parent);
	}
	Node *codeTree = parent;
	/////////////////////////////////////////////////////////////////////////////////////////

	///////////////////////////// Get Traversals ////////////////////////////////////////////

	std::ofstream outTree("tree.txt");
	outTree << removeSpaces(preorder(codeTree)) << std::endl;
	outTree << removeSpaces(inorder(codeTree)) << std::endl;
	outTree.close();

	/////////////////////////////////////////////////////////////////////////////////////////

	////////////////////////////// Create Encoding Table ////////////////////////////////////

	Table *codeTable = new Table[totalChars];
	std::string code = "";
	generateEncodingTable(codeTree, codeTable, code);

	////////////////////////////////////////////////////////////////////////////////////////

	//////////////////////////// Write Code ////////////////////////////////////////////////
	std::ofstream outCode("code.txt");
	in.open(argv[1]);
	c = '\0';
	while (in.get(c)) {
		for (int i = 0; i < totalChars; i++)
		{
			if (c == codeTable[i].content) {
				outCode << codeTable[i].encoding;
				break;
			}
		}
	}
	in.close();
	outCode.close();
	////////////////////////////////////////////////////////////////////////////////////////

	//////////////////////////////// Output Lengths ////////////////////////////////////////
	std::ofstream outLength("length.txt");
	for (int i = 0; i < totalChars; i++)
	{
		outLength  << (int) codeTable[i].content << " "  << codeTable[i].encoding.length() << std::endl;
	}
	outLength.close();
	////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}