mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Merge branch 'master' into add_v4l
Former-commit-id: b3f1d532c6145ba80c161b18214de6efbc55ff7b
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
# Needed for testing non-public components
|
||||
# Needed for testing non-public components
|
||||
include_directories(../libsrc)
|
||||
|
||||
# Add the simple test executable 'TestSpi'
|
||||
add_executable(test_spi
|
||||
TestSpi.cpp)
|
||||
target_link_libraries(test_spi
|
||||
hyperion)
|
||||
if(ENABLE_SPIDEV)
|
||||
# Add the simple test executable 'TestSpi'
|
||||
add_executable(test_spi TestSpi.cpp)
|
||||
target_link_libraries(test_spi hyperion)
|
||||
|
||||
add_executable(spidev_test spidev_test.c)
|
||||
|
||||
add_executable(gpio2spi switchPinCtrl.c)
|
||||
endif(ENABLE_SPIDEV)
|
||||
|
||||
add_executable(test_configfile
|
||||
TestConfigFile.cpp)
|
||||
@@ -49,9 +53,9 @@ add_executable(test_qregexp TestQRegExp.cpp)
|
||||
target_link_libraries(test_qregexp
|
||||
${QT_LIBRARIES})
|
||||
|
||||
add_executable(spidev_test spidev_test.c)
|
||||
|
||||
add_executable(gpio2spi switchPinCtrl.c)
|
||||
add_executable(test_qtscreenshot TestQtScreenshot.cpp)
|
||||
target_link_libraries(test_qtscreenshot
|
||||
${QT_LIBRARIES})
|
||||
|
||||
add_executable(determineWs2811Timing DetermineWs2811Timing.cpp)
|
||||
|
||||
@@ -62,6 +66,9 @@ add_executable(test_rs232highspeed
|
||||
target_link_libraries(test_rs232highspeed
|
||||
serialport)
|
||||
|
||||
include_directories(/usr/include)
|
||||
add_executable(test_uartHighSpeed TestUartHighSpeed.cpp)
|
||||
target_link_libraries(test_uartHighSpeed ${QT_LIBRARIES})
|
||||
if(NOT APPLE AND UNIX)
|
||||
include_directories(/usr/include)
|
||||
add_executable(test_uartHighSpeed TestUartHighSpeed.cpp)
|
||||
|
||||
add_executable(test_nonInvWs2812b TestNonInvWs2812b.cpp)
|
||||
endif()
|
||||
|
@@ -49,6 +49,8 @@ int main()
|
||||
requiredTiming(400, 850, 150, 5); // Zero
|
||||
requiredTiming(800, 450, 150, 5); // One
|
||||
|
||||
requiredTiming(650, 600, 150, 5); // One
|
||||
|
||||
// 4bits
|
||||
requiredTiming(400, 850, 150, 4); // Zero
|
||||
requiredTiming(800, 450, 150, 4); // One
|
||||
|
138
test/TestNonInvWs2812b.cpp
Normal file
138
test/TestNonInvWs2812b.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
std::vector<uint8_t> encode(const std::vector<uint8_t> & data);
|
||||
void split(const uint8_t byte, uint8_t & out1, uint8_t & out2);
|
||||
uint8_t encode(const bool bit1, const bool bit2, const bool bit3);
|
||||
|
||||
void print(uint8_t byte)
|
||||
{
|
||||
for (int i=0; i<8; ++i)
|
||||
{
|
||||
if (byte & (1 << i))
|
||||
{
|
||||
std::cout << '1';
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<uint8_t> data(3, 0x55);
|
||||
|
||||
std::vector<uint8_t> encData = encode(data);
|
||||
|
||||
for (uint8_t encByte : encData)
|
||||
{
|
||||
std::cout << "0 ";
|
||||
print(encByte);
|
||||
std::cout << " 1";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> encode(const std::vector<uint8_t> & data)
|
||||
{
|
||||
std::vector<uint8_t> result;
|
||||
|
||||
uint8_t previousByte = 0x00;
|
||||
uint8_t nextByte = 0x00;
|
||||
for (unsigned iData=0; iData<data.size(); iData+=3)
|
||||
{
|
||||
const uint8_t byte1 = data[iData];
|
||||
const uint8_t byte2 = data[iData+1];
|
||||
const uint8_t byte3 = data[iData+2];
|
||||
|
||||
uint8_t encByte;
|
||||
encByte = encode(byte1 & 0x80, byte1 & 0x40, byte1 & 0x20);
|
||||
std::cout << "Encoded byte 1: "; print(encByte); std::cout << std::endl;
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
|
||||
encByte = encode(byte1 & 0x10, byte1 & 0x08, byte1 & 0x04);
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
|
||||
encByte = encode(byte1 & 0x02, byte1 & 0x01, byte2 & 0x80);
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
|
||||
encByte = encode(byte2 & 0x40, byte2 & 0x20, byte2 & 0x10);
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
|
||||
encByte = encode(byte2 & 0x08, byte2 & 0x04, byte2 & 0x02);
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
|
||||
encByte = encode(byte2 & 0x01, byte3 & 0x80, byte3 & 0x40);
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
|
||||
encByte = encode(byte3 & 0x20, byte3 & 0x10, byte3 & 0x08);
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
|
||||
encByte = encode(byte3 & 0x04, byte3 & 0x02, byte3 & 0x01);
|
||||
split(encByte, previousByte, nextByte);
|
||||
result.push_back(previousByte);
|
||||
previousByte = nextByte;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void split(const uint8_t byte, uint8_t & out1, uint8_t & out2)
|
||||
{
|
||||
print(byte); std::cout << " => ";
|
||||
print(out2); std::cout << " => ";
|
||||
out1 &= ~0x0F;
|
||||
out1 |= (byte & 0x0F) << 4;
|
||||
// out2 &= ~0xF0;
|
||||
print(out2); std::cout << " => ";
|
||||
out2 = (byte & 0xF0) >> 4;
|
||||
print(out2); std::cout << std::endl;
|
||||
}
|
||||
|
||||
uint8_t encode(const bool bit1, const bool bit2, const bool bit3)
|
||||
{
|
||||
if (bit2)
|
||||
{
|
||||
uint8_t result = 0x19; // 0--1 01 10-1
|
||||
if (bit1) result |= 0x02;
|
||||
// else result &= ~0x02;
|
||||
|
||||
if (bit3) result |= 0x60;
|
||||
// else result &= ~0x60;
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t result = 0x21;// 0x21 (0-10 01 0--1)
|
||||
if (bit1) result |= 0x06;
|
||||
// else result &= ~0x06;
|
||||
|
||||
if (bit3) result |= 0x40;
|
||||
// else result &= ~0x40;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
20
test/TestQtScreenshot.cpp
Normal file
20
test/TestQtScreenshot.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
// STL includes
|
||||
#include <iostream>
|
||||
|
||||
// QT includes
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPixmap>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QPixmap originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
|
||||
|
||||
std::cout << "Grabbed image: [" << originalPixmap.width() << "; " << originalPixmap.height() << "]" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
@@ -62,7 +62,9 @@ int testSerialPortLib()
|
||||
continue;
|
||||
}
|
||||
|
||||
rs232Port.flushOutput();
|
||||
rs232Port.write(data);
|
||||
rs232Port.flush();
|
||||
|
||||
data.clear();
|
||||
for (int i=0; i<9; ++i)
|
||||
@@ -110,7 +112,7 @@ public:
|
||||
open();
|
||||
}
|
||||
|
||||
int write(const std::vector<ColorRgb> &ledValues) \
|
||||
int write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
std::vector<uint8_t> bytes(ledValues.size() * 3 * 4);
|
||||
|
||||
@@ -130,7 +132,7 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int switchOff() { return 0; }
|
||||
int switchOff() { return 0; };
|
||||
|
||||
void writeTestSequence(const std::vector<uint8_t> & data)
|
||||
{
|
||||
|
@@ -12,8 +12,80 @@
|
||||
#include <csignal>
|
||||
#include <cstdint>
|
||||
#include <bitset>
|
||||
#include <vector>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
|
||||
void set_realtime_priority() {
|
||||
int ret;
|
||||
|
||||
// We'll operate on the currently running thread.
|
||||
pthread_t this_thread = pthread_self();
|
||||
// struct sched_param is used to store the scheduling priority
|
||||
struct sched_param params;
|
||||
// We'll set the priority to the maximum.
|
||||
params.sched_priority = sched_get_priority_max(SCHED_FIFO);
|
||||
std::cout << "Trying to set thread realtime prio = " << params.sched_priority << std::endl;
|
||||
|
||||
// Attempt to set thread real-time priority to the SCHED_FIFO policy
|
||||
ret = pthread_setschedparam(this_thread, SCHED_FIFO, ¶ms);
|
||||
if (ret != 0) {
|
||||
// Print the error
|
||||
std::cout << "Unsuccessful in setting thread realtime prio (erno=" << ret << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Now verify the change in thread priority
|
||||
int policy = 0;
|
||||
ret = pthread_getschedparam(this_thread, &policy, ¶ms);
|
||||
if (ret != 0) {
|
||||
std::cout << "Couldn't retrieve real-time scheduling paramers" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the correct policy was applied
|
||||
if(policy != SCHED_FIFO) {
|
||||
std::cout << "Scheduling is NOT SCHED_FIFO!" << std::endl;
|
||||
} else {
|
||||
std::cout << "SCHED_FIFO OK" << std::endl;
|
||||
}
|
||||
|
||||
// Print thread scheduling priority
|
||||
std::cout << "Thread priority is " << params.sched_priority << std::endl;
|
||||
}
|
||||
|
||||
|
||||
struct ColorSignal
|
||||
{
|
||||
uint8_t green_1;
|
||||
uint8_t green_2;
|
||||
uint8_t green_3;
|
||||
uint8_t green_4;
|
||||
|
||||
uint8_t red_1;
|
||||
uint8_t red_2;
|
||||
uint8_t red_3;
|
||||
uint8_t red_4;
|
||||
|
||||
uint8_t blue_1;
|
||||
uint8_t blue_2;
|
||||
uint8_t blue_3;
|
||||
uint8_t blue_4;
|
||||
};
|
||||
|
||||
static ColorSignal RED_Signal = { 0xCE, 0xCE, 0xCE, 0xCE,
|
||||
0xCE, 0x8C, 0x8C, 0x8C,
|
||||
0xCE, 0xCE, 0xCE, 0xCE };
|
||||
static ColorSignal GREEN_Signal = { 0xCE, 0x8C, 0x8C, 0x8C,
|
||||
0xCE, 0xCE, 0xCE, 0xCE,
|
||||
0xCE, 0xCE, 0xCE, 0xCE };
|
||||
static ColorSignal BLUE_Signal = { 0xCE, 0xCE, 0xCE, 0xCE,
|
||||
0xCE, 0xCE, 0xCE, 0xCE,
|
||||
0xCE, 0x8C, 0x8C, 0x8C};
|
||||
static ColorSignal BLACK_Signal = { 0xCE, 0xCE, 0xCE, 0xCE,
|
||||
0xCE, 0xCE, 0xCE, 0xCE,
|
||||
0xCE, 0xCE, 0xCE, 0xCE};
|
||||
|
||||
static volatile bool _running;
|
||||
|
||||
@@ -23,8 +95,16 @@ void signal_handler(int signum)
|
||||
|
||||
}
|
||||
|
||||
void test3bitsEncoding();
|
||||
|
||||
int main()
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
test3bitsEncoding();
|
||||
return 0;
|
||||
}
|
||||
|
||||
_running = true;
|
||||
signal(SIGTERM, &signal_handler);
|
||||
|
||||
@@ -46,7 +126,7 @@ int main()
|
||||
// immediately with a failure status if the output can't be written immediately.
|
||||
//
|
||||
// O_NOCTTY - When set and path identifies a terminal device, open() shall not cause the terminal device to become the controlling terminal for the process.
|
||||
uart0_filestream = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY); //Open in non blocking read/write mode
|
||||
uart0_filestream = open("/dev/ttyAMA0", O_WRONLY | O_NOCTTY | O_NDELAY); //Open in non blocking read/write mode
|
||||
if (uart0_filestream == -1)
|
||||
{
|
||||
//ERROR - CAN'T OPEN SERIAL PORT
|
||||
@@ -67,17 +147,18 @@ int main()
|
||||
// PARODD - Odd parity (else even)
|
||||
struct termios options;
|
||||
tcgetattr(uart0_filestream, &options);
|
||||
options.c_cflag = B4000000 | CS8 | CLOCAL | CREAD; //<Set baud rate
|
||||
options.c_cflag = B4000000 | CS8 | CLOCAL; //<Set baud rate
|
||||
options.c_iflag = IGNPAR;
|
||||
options.c_oflag = 0;
|
||||
options.c_lflag = 0;
|
||||
tcflush(uart0_filestream, TCIFLUSH);
|
||||
cfmakeraw(&options);
|
||||
|
||||
std::cout << "options.c_cflag = " << options.c_cflag << std::endl;
|
||||
std::cout << "options.c_iflag = " << options.c_iflag << std::endl;
|
||||
std::cout << "options.c_oflag = " << options.c_oflag << std::endl;
|
||||
std::cout << "options.c_lflag = " << options.c_lflag << std::endl;
|
||||
|
||||
tcflush(uart0_filestream, TCIFLUSH);
|
||||
tcsetattr(uart0_filestream, TCSANOW, &options);
|
||||
// Let's verify configured options
|
||||
tcgetattr(uart0_filestream, &options);
|
||||
@@ -128,47 +209,9 @@ int main()
|
||||
}
|
||||
|
||||
//----- TX BYTES -----
|
||||
uint8_t tx_buffer[3*3*8*4];
|
||||
uint8_t *p_tx_buffer;
|
||||
|
||||
// for (int i=0; i<3; ++i)
|
||||
// {
|
||||
// Writing 0xFF, 0x00, 0x00
|
||||
// *p_tx_buffer++ = 0x8C;
|
||||
// *p_tx_buffer++ = 0x8C;
|
||||
// *p_tx_buffer++ = 0x8C;
|
||||
// *p_tx_buffer++ = 0x8C;
|
||||
|
||||
std::default_random_engine generator;
|
||||
std::uniform_int_distribution<int> distribution(1,2);
|
||||
|
||||
p_tx_buffer = &tx_buffer[0];
|
||||
for (int i=0; i<9; ++i)
|
||||
{
|
||||
int coinFlip = distribution(generator);
|
||||
if (coinFlip == 1)
|
||||
{
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Binary stream: [";
|
||||
for (unsigned char* txIt=&(tx_buffer[0]); txIt!=p_tx_buffer; ++txIt)
|
||||
{
|
||||
std::cout << " 1 " << (std::bitset<8>) (*txIt) << " 0 ";
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
std::vector<ColorSignal> signalData(10, RED_Signal);
|
||||
|
||||
int loopCnt = 0;
|
||||
std::cout << "Type 'c' to continue, 'q' or 'x' to quit: ";
|
||||
while (_running)
|
||||
{
|
||||
@@ -182,38 +225,28 @@ int main()
|
||||
continue;
|
||||
}
|
||||
|
||||
int count = write(uart0_filestream, &tx_buffer[0], (p_tx_buffer - &tx_buffer[0])); //Filestream, bytes to write, number of bytes to write
|
||||
if (count < 0)
|
||||
set_realtime_priority();
|
||||
for (int iRun=0; iRun<10; ++iRun)
|
||||
{
|
||||
std::cerr << "UART TX error" << std::endl;
|
||||
// tcflush(uart0_filestream, TCOFLUSH);
|
||||
write(uart0_filestream, signalData.data(), signalData.size()*sizeof(ColorSignal));
|
||||
tcdrain(uart0_filestream);
|
||||
|
||||
//----- CLOSE THE UART -----
|
||||
close(uart0_filestream);
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Writing " << count << " bytes to uart" << std::endl;
|
||||
usleep(100000);
|
||||
++loopCnt;
|
||||
|
||||
if (loopCnt%3 == 2)
|
||||
signalData = std::vector<ColorSignal>(10, GREEN_Signal);
|
||||
else if(loopCnt%3 == 1)
|
||||
signalData = std::vector<ColorSignal>(10, BLUE_Signal);
|
||||
else if(loopCnt%3 == 0)
|
||||
signalData = std::vector<ColorSignal>(10, RED_Signal);
|
||||
|
||||
p_tx_buffer = &tx_buffer[0];
|
||||
for (int i=0; i<9; ++i)
|
||||
{
|
||||
int coinFlip = distribution(generator);
|
||||
if (coinFlip == 1)
|
||||
{
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
*p_tx_buffer++ = 0xCE;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
*p_tx_buffer++ = 0x8C;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signalData = std::vector<ColorSignal>(50, BLACK_Signal);
|
||||
write(uart0_filestream, signalData.data(), signalData.size()*sizeof(ColorSignal));
|
||||
//----- CLOSE THE UART -----
|
||||
close(uart0_filestream);
|
||||
|
||||
@@ -221,3 +254,133 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> bit3Encode(const std::vector<uint8_t> & bytes);
|
||||
uint8_t bit3Encode(const bool bit_1, const bool bit_2, const bool bit_3);
|
||||
|
||||
void test3bitsEncoding()
|
||||
{
|
||||
//OPEN THE UART
|
||||
int uart0_filestream = open("/dev/ttyAMA0", O_WRONLY | O_NOCTTY | O_NDELAY);
|
||||
if (uart0_filestream == -1)
|
||||
{
|
||||
//ERROR - CAN'T OPEN SERIAL PORT
|
||||
printf("Error - Unable to open UART. Ensure it is not in use by another application\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Configure the port
|
||||
struct termios options;
|
||||
tcgetattr(uart0_filestream, &options);
|
||||
options.c_cflag = B2500000 | CS7 | CLOCAL;
|
||||
options.c_iflag = IGNPAR;
|
||||
options.c_oflag = 0;
|
||||
options.c_lflag = 0;
|
||||
|
||||
tcflush(uart0_filestream, TCIFLUSH);
|
||||
tcsetattr(uart0_filestream, TCSANOW, &options);
|
||||
|
||||
std::vector<uint8_t> colorRed;
|
||||
for (unsigned i=0; i<10; ++i)
|
||||
{
|
||||
colorRed.push_back(0x00);
|
||||
colorRed.push_back(0xFF);
|
||||
colorRed.push_back(0x00);
|
||||
}
|
||||
std::vector<uint8_t> colorGreen;
|
||||
for (unsigned i=0; i<10; ++i)
|
||||
{
|
||||
colorGreen.push_back(0xFF);
|
||||
colorGreen.push_back(0x00);
|
||||
colorGreen.push_back(0x00);
|
||||
}
|
||||
std::vector<uint8_t> colorBlue;
|
||||
for (unsigned i=0; i<10; ++i)
|
||||
{
|
||||
colorBlue.push_back(0x00);
|
||||
colorBlue.push_back(0x00);
|
||||
colorBlue.push_back(0xFF);
|
||||
}
|
||||
std::vector<uint8_t> colorBlack;
|
||||
for (unsigned i=0; i<10; ++i)
|
||||
{
|
||||
colorBlack.push_back(0x00);
|
||||
colorBlack.push_back(0x00);
|
||||
colorBlack.push_back(0x00);
|
||||
}
|
||||
const std::vector<uint8_t> colorRedSignal = bit3Encode(colorRed);
|
||||
const std::vector<uint8_t> colorGreenSignal = bit3Encode(colorGreen);
|
||||
const std::vector<uint8_t> colorBlueSignal = bit3Encode(colorBlue);
|
||||
const std::vector<uint8_t> colorBlackSignal = bit3Encode(colorBlack);
|
||||
|
||||
for (unsigned i=0; i<100; ++i)
|
||||
{
|
||||
size_t res;
|
||||
res = write(uart0_filestream, colorRedSignal.data(), colorRedSignal.size());
|
||||
(void)res;
|
||||
usleep(100000);
|
||||
res = write(uart0_filestream, colorGreenSignal.data(), colorGreenSignal.size());
|
||||
(void)res;
|
||||
usleep(100000);
|
||||
res = write(uart0_filestream, colorBlueSignal.data(), colorBlueSignal.size());
|
||||
(void)res;
|
||||
usleep(100000);
|
||||
}
|
||||
size_t res = write(uart0_filestream, colorBlackSignal.data(), colorBlackSignal.size());
|
||||
(void)res;
|
||||
//----- CLOSE THE UART -----
|
||||
res = close(uart0_filestream);
|
||||
(void)res;
|
||||
|
||||
std::cout << "Program finished" << std::endl;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> bit3Encode(const std::vector<uint8_t> & bytes)
|
||||
{
|
||||
std::vector<uint8_t> result;
|
||||
|
||||
for (unsigned iByte=0; iByte<bytes.size(); iByte+=3)
|
||||
{
|
||||
const uint8_t & byte1 = bytes[iByte];
|
||||
const uint8_t & byte2 = bytes[iByte + 1];
|
||||
const uint8_t & byte3 = bytes[iByte + 2];
|
||||
|
||||
result.push_back(bit3Encode(byte1 & 0x80, byte1 & 0x40, byte1 & 0x20));
|
||||
result.push_back(bit3Encode(byte1 & 0x10, byte1 & 0x08, byte1 & 0x04));
|
||||
result.push_back(bit3Encode(byte1 & 0x02, byte1 & 0x01, byte2 & 0x80));
|
||||
result.push_back(bit3Encode(byte2 & 0x40, byte2 & 0x20, byte2 & 0x10));
|
||||
result.push_back(bit3Encode(byte2 & 0x08, byte2 & 0x04, byte2 & 0x02));
|
||||
result.push_back(bit3Encode(byte2 & 0x01, byte3 & 0x80, byte3 & 0x40));
|
||||
result.push_back(bit3Encode(byte3 & 0x20, byte3 & 0x10, byte3 & 0x08));
|
||||
result.push_back(bit3Encode(byte3 & 0x04, byte3 & 0x02, byte3 & 0x01));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t bit3Encode(const bool bit_1, const bool bit_2, const bool bit_3)
|
||||
{
|
||||
// Bit index(default):1 2 3
|
||||
// | | |
|
||||
// default value (1) 00 100 10 (0)
|
||||
//
|
||||
// Reversed value (1) 01 001 00 (0)
|
||||
// | | |
|
||||
// Bit index (rev): 3 2 1
|
||||
uint8_t result = 0x24;
|
||||
|
||||
if(bit_1)
|
||||
{
|
||||
result |= 0x01;
|
||||
}
|
||||
if (bit_2)
|
||||
{
|
||||
result |= 0x08;
|
||||
}
|
||||
if (bit_3)
|
||||
{
|
||||
result |= 0x40;
|
||||
}
|
||||
|
||||
return ~result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user