void compressFile(FILE* outFp, FILE* inpFp)
{
    LZ4_stream_t lz4Stream_body;
    LZ4_stream_t* lz4Stream = &lz4Stream_body;

    char inpBuf[2][BLOCK_BYTES];
    int  inpBufIndex = 0;

    LZ4_resetStream(lz4Stream);

    while(1)
    {
        char* const inpPtr = inpBuf[inpBufIndex];
        const int inpBytes = (int) binRead(inpFp, inpPtr, BLOCK_BYTES);
        if (0 == inpBytes)
        {
            break;
        }
        {
            char cmpBuf[LZ4_COMPRESSBOUND(BLOCK_BYTES)];
            const int cmpBytes = LZ4_compress_fast_continue(lz4Stream, inpPtr, cmpBuf, inpBytes, sizeof(cmpBuf), 1);
            if(cmpBytes <= 0)
            {
                break;
            }
            intWrite(outFp, cmpBytes);
            binWrite(outFp, cmpBuf, (size_t) cmpBytes);
        }
        inpBufIndex = (inpBufIndex + 1) % 2;
    }

    intWrite(outFp, 0);
}
Example #2
0
gpio::gpio( int i )
{
	std::cout << "called gpio constructor" << std::endl;
	gpio::id = i;
	gpio::num = (Pin_Bank[i]*32)+Pin_Id[i];
	
	std::stringstream sysfsfile_direction;
	std::stringstream sysfsfile_edge;
	std::stringstream sysfsfile_value;
	std::stringstream sysfsfile_export;

	sysfsfile_direction << SYSFS_GPIO_PREFIX << "gpio" << num << "/" << SYSFS_GPIO_DIRECTION;
	sysfsfile_edge << SYSFS_GPIO_PREFIX << "gpio" << num << "/" << SYSFS_GPIO_EDGE;
	sysfsfile_value << SYSFS_GPIO_PREFIX << "gpio" << num << "/" << SYSFS_GPIO_VALUE;
	sysfsfile_export << SYSFS_GPIO_PREFIX << SYSFS_GPIO_EXPORT;

	std::cout << "new gpio with id: " << i << ", number: " << num << std::endl;
	//std::cout << "export fd: " << sysfsfile_export.str().c_str() << endl;
	
	sysfsfd_export = open(sysfsfile_export.str().c_str(), O_WRONLY);
	if(sysfsfd_export<0){
	 	printf("Cannot open GPIO to export it: %s\n", strerror( errno ));
	}
	intWrite(sysfsfd_export, gpio::num);//export gpio
	close(sysfsfd_export);

	//std::cout << "direction fd: " << sysfsfile_direction.str().c_str() << endl;
	sysfsfd_direction = open(sysfsfile_direction.str().c_str(),  
O_RDWR);
	if(sysfsfd_direction<0){
	 	printf("Cannot open GPIO direction: %s\n", strerror( errno ));
	}

	sysfsfd_edge = open(sysfsfile_edge.str().c_str(),  O_RDWR);
	if(sysfsfd_edge<0){
	 	printf("Cannot open GPIO edge: %s\n", strerror( errno ));
	}

	sysfsfd_value = open(sysfsfile_value.str().c_str(),  O_RDWR | 
O_NONBLOCK);
	if(sysfsfd_value<0){
	 	printf("Cannot open GPIO value: %s\n", strerror( errno ));
	}

}
Example #3
0
/**
 * cPWM Destructor, stops the PWMss
 *
 */
gpio::~gpio()
{
	std::stringstream sysfsfile_unexport;
	sysfsfile_unexport << SYSFS_GPIO_PREFIX << SYSFS_GPIO_UNEXPORT;

	std::cout << "gpio"<< gpio::num << " unexported" << std::endl;
	close(sysfsfd_direction);
	close(sysfsfd_edge);
	close(sysfsfd_value);
	sysfsfd_unexport = open(sysfsfile_unexport.str().c_str(), 
O_RDWR);
	if(sysfsfd_unexport<0){
	 	printf("Cannot open GPIO to unexport it: %s\n", strerror( errno ));
	}
	intWrite(sysfsfd_unexport, gpio::num);//unexport gpio
	close(sysfsfd_unexport);
	std::cout << "called gpio"<<gpio::num<<" destructor"<< std::endl;
}