mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-06-19 20:34:25 -04:00
Formatted code (#1007)
* Updated style * Updated files * fixed new line * Updated spacing * File fix WIP * Updated to clang 13 * updated comment style * Removed old comment code
This commit is contained in:
parent
7aca7ce74d
commit
033c4e9a5b
599 changed files with 70746 additions and 66896 deletions
|
@ -29,91 +29,91 @@ using namespace portapack;
|
|||
|
||||
namespace modems {
|
||||
|
||||
void generate_data(const std::string& in_message, uint16_t * out_data) {
|
||||
uint8_t parity_init, parity, bits, bit, cur_byte;
|
||||
uint16_t ordered_word;
|
||||
size_t bytes;
|
||||
|
||||
serial_format_t serial_format = persistent_memory::serial_format();
|
||||
size_t message_length = in_message.length();
|
||||
|
||||
if (serial_format.parity == ODD)
|
||||
parity_init = 1;
|
||||
else
|
||||
parity_init = 0;
|
||||
void generate_data(const std::string& in_message, uint16_t* out_data) {
|
||||
uint8_t parity_init, parity, bits, bit, cur_byte;
|
||||
uint16_t ordered_word;
|
||||
size_t bytes;
|
||||
|
||||
uint8_t data_bits = serial_format.data_bits;
|
||||
|
||||
for (bytes = 0; bytes < message_length; bytes++) {
|
||||
parity = parity_init;
|
||||
cur_byte = in_message[bytes];
|
||||
bit = 0;
|
||||
|
||||
if (serial_format.bit_order == MSB_FIRST) {
|
||||
ordered_word = cur_byte;
|
||||
for (bits = 0; bits < data_bits; bits++) {
|
||||
bit = (cur_byte >> bits) & 1; // Get LSB
|
||||
parity += bit;
|
||||
}
|
||||
} else {
|
||||
ordered_word = 0;
|
||||
for (bits = 0; bits < data_bits; bits++) {
|
||||
bit = (cur_byte >> bits) & 1; // Get LSB
|
||||
parity += bit;
|
||||
ordered_word |= (bit << ((data_bits - 1) - bits)); // Set MSB
|
||||
}
|
||||
}
|
||||
|
||||
if (serial_format.parity) {
|
||||
ordered_word <<= 1;
|
||||
ordered_word |= (parity & 1);
|
||||
}
|
||||
|
||||
for (bits = 0; bits < serial_format.stop_bits; bits++) {
|
||||
ordered_word <<= 1;
|
||||
ordered_word |= 1;
|
||||
}
|
||||
|
||||
out_data[bytes] = ordered_word;
|
||||
}
|
||||
|
||||
out_data[bytes] = 0; // End marker
|
||||
serial_format_t serial_format = persistent_memory::serial_format();
|
||||
size_t message_length = in_message.length();
|
||||
|
||||
if (serial_format.parity == ODD)
|
||||
parity_init = 1;
|
||||
else
|
||||
parity_init = 0;
|
||||
|
||||
uint8_t data_bits = serial_format.data_bits;
|
||||
|
||||
for (bytes = 0; bytes < message_length; bytes++) {
|
||||
parity = parity_init;
|
||||
cur_byte = in_message[bytes];
|
||||
bit = 0;
|
||||
|
||||
if (serial_format.bit_order == MSB_FIRST) {
|
||||
ordered_word = cur_byte;
|
||||
for (bits = 0; bits < data_bits; bits++) {
|
||||
bit = (cur_byte >> bits) & 1; // Get LSB
|
||||
parity += bit;
|
||||
}
|
||||
} else {
|
||||
ordered_word = 0;
|
||||
for (bits = 0; bits < data_bits; bits++) {
|
||||
bit = (cur_byte >> bits) & 1; // Get LSB
|
||||
parity += bit;
|
||||
ordered_word |= (bit << ((data_bits - 1) - bits)); // Set MSB
|
||||
}
|
||||
}
|
||||
|
||||
if (serial_format.parity) {
|
||||
ordered_word <<= 1;
|
||||
ordered_word |= (parity & 1);
|
||||
}
|
||||
|
||||
for (bits = 0; bits < serial_format.stop_bits; bits++) {
|
||||
ordered_word <<= 1;
|
||||
ordered_word |= 1;
|
||||
}
|
||||
|
||||
out_data[bytes] = ordered_word;
|
||||
}
|
||||
|
||||
out_data[bytes] = 0; // End marker
|
||||
}
|
||||
|
||||
// This accepts a word with start and stop bits removed !
|
||||
uint32_t deframe_word(uint32_t raw_word) {
|
||||
uint32_t cur_bit, deframed_word { 0 };
|
||||
size_t bit;
|
||||
|
||||
serial_format_t serial_format = persistent_memory::serial_format();
|
||||
|
||||
/*if (serial_format.parity == ODD)
|
||||
parity = 1;
|
||||
else
|
||||
parity = 0;*/
|
||||
uint32_t cur_bit, deframed_word{0};
|
||||
size_t bit;
|
||||
|
||||
size_t data_bits = serial_format.data_bits;
|
||||
|
||||
// Ignore parity for now
|
||||
if (serial_format.parity)
|
||||
raw_word >>= 1;
|
||||
|
||||
if (serial_format.bit_order == LSB_FIRST) {
|
||||
// Reverse data bits
|
||||
for (bit = 0; bit < data_bits; bit++) {
|
||||
cur_bit = raw_word & 1;
|
||||
|
||||
deframed_word <<= 1;
|
||||
deframed_word |= cur_bit;
|
||||
|
||||
//parity += cur_bit;
|
||||
|
||||
raw_word >>= 1;
|
||||
}
|
||||
|
||||
return deframed_word;
|
||||
} else
|
||||
return raw_word;
|
||||
serial_format_t serial_format = persistent_memory::serial_format();
|
||||
|
||||
/*if (serial_format.parity == ODD)
|
||||
parity = 1;
|
||||
else
|
||||
parity = 0;*/
|
||||
|
||||
size_t data_bits = serial_format.data_bits;
|
||||
|
||||
// Ignore parity for now
|
||||
if (serial_format.parity)
|
||||
raw_word >>= 1;
|
||||
|
||||
if (serial_format.bit_order == LSB_FIRST) {
|
||||
// Reverse data bits
|
||||
for (bit = 0; bit < data_bits; bit++) {
|
||||
cur_bit = raw_word & 1;
|
||||
|
||||
deframed_word <<= 1;
|
||||
deframed_word |= cur_bit;
|
||||
|
||||
// parity += cur_bit;
|
||||
|
||||
raw_word >>= 1;
|
||||
}
|
||||
|
||||
return deframed_word;
|
||||
} else
|
||||
return raw_word;
|
||||
}
|
||||
|
||||
} /* namespace modems */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue