You've already forked TEF6686_ESP32
changes
This commit is contained in:
@@ -311,3 +311,7 @@ This command is only available on versions 2+
|
|||||||
### CRC
|
### CRC
|
||||||
|
|
||||||
First bit of the length from version 3 control whether there is an crc byte at the end of the command, it is not included in the length. If the request was sent with CRC, response also will be too. In case of a CRC mismatch the radio will send back [0x02 0xFF 0x01]. CRC is calculated with the lenght included
|
First bit of the length from version 3 control whether there is an crc byte at the end of the command, it is not included in the length. If the request was sent with CRC, response also will be too. In case of a CRC mismatch the radio will send back [0x02 0xFF 0x01]. CRC is calculated with the lenght included
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
Length is now 16 bits. MSB is now the last bit of the 16 bits.
|
||||||
@@ -999,7 +999,7 @@ uint8_t crc8(const uint8_t *data, size_t len) {
|
|||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool execute_pc_command(uint8_t *data, uint8_t *&p, uint8_t *output, uint8_t len, uint32_t* baud_change, size_t output_size) {
|
bool execute_pc_command(uint8_t *data, uint8_t *&p, uint8_t *output, uint16_t len, uint32_t* baud_change, size_t output_size) {
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 0: { // Set clock
|
case 0: { // Set clock
|
||||||
if(len < 5) {
|
if(len < 5) {
|
||||||
@@ -1054,6 +1054,7 @@ bool execute_pc_command(uint8_t *data, uint8_t *&p, uint8_t *output, uint8_t len
|
|||||||
*p++ = 3;
|
*p++ = 3;
|
||||||
} break;
|
} break;
|
||||||
case 5: { // Reboot
|
case 5: { // Reboot
|
||||||
|
Serial.write(0);
|
||||||
Serial.write(1);
|
Serial.write(1);
|
||||||
Serial.write(5);
|
Serial.write(5);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
@@ -1105,50 +1106,50 @@ bool execute_pc_command(uint8_t *data, uint8_t *&p, uint8_t *output, uint8_t len
|
|||||||
}
|
}
|
||||||
|
|
||||||
void total_pc_control() {
|
void total_pc_control() {
|
||||||
static uint8_t data[127];
|
static uint8_t data[4096];
|
||||||
static uint8_t output[257];
|
static uint8_t output[4096];
|
||||||
uint8_t *p = output + 2;
|
uint8_t *p = output + 3;
|
||||||
uint32_t baud_change = 0;
|
uint32_t baud_change = 0;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
bool send_crc = false;
|
bool send_crc = false;
|
||||||
|
|
||||||
if(i2c_pc_control_init) {
|
if(Serial.available() > 2 && !done) {
|
||||||
error = true;
|
uint16_t userlen = (Serial.read() << 8) | Serial.read();
|
||||||
done = true;
|
|
||||||
i2c_pc_control_init = false;
|
|
||||||
}
|
|
||||||
if(Serial.available() && !done) {
|
|
||||||
uint8_t userlen = Serial.read();
|
|
||||||
if (userlen == 0) {
|
if (userlen == 0) {
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Serial.available() && userlen == '~' && Serial.peek() == '/') {
|
if(userlen == 0x7e2f) { // ~/
|
||||||
Serial.read();
|
|
||||||
error = true;
|
error = true;
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!done) {
|
bool has_crc = (userlen >> 15) & 1;
|
||||||
bool has_crc = (userlen >> 7) == 1;
|
|
||||||
send_crc = has_crc;
|
send_crc = has_crc;
|
||||||
uint8_t orig_userlen = userlen;
|
uint16_t orig_userlen = userlen;
|
||||||
userlen &= 127;
|
userlen &= 0x7fff;
|
||||||
|
|
||||||
auto len = Serial.read(data, userlen);
|
if(userlen > 4096) {
|
||||||
|
*p++ = 0;
|
||||||
|
send_crc = false;
|
||||||
|
error = true;
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
if(!done) {
|
||||||
|
uint16_t len = Serial.read(data, userlen);
|
||||||
if(len != userlen) {
|
if(len != userlen) {
|
||||||
error = true;
|
error = true;
|
||||||
has_crc = false;
|
send_crc = false;
|
||||||
*p++ = 0;
|
*p++ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(has_crc && Serial.available()) {
|
if(!error & has_crc && Serial.available()) {
|
||||||
uint8_t crc = Serial.read();
|
uint8_t crc = Serial.read();
|
||||||
|
|
||||||
uint8_t expected_crc = 0;
|
uint8_t expected_crc = crc8_update(0, orig_userlen >> 8);
|
||||||
expected_crc = crc8_update(expected_crc, orig_userlen);
|
expected_crc = crc8_update(expected_crc, orig_userlen & 0xff);
|
||||||
for (int i = 0; i < len; i++) expected_crc = crc8_update(expected_crc, data[i]);
|
for (int i = 0; i < len; i++) expected_crc = crc8_update(expected_crc, data[i]);
|
||||||
if(crc != expected_crc) {
|
if(crc != expected_crc) {
|
||||||
error = true;
|
error = true;
|
||||||
@@ -1162,9 +1163,11 @@ void total_pc_control() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(done) {
|
if(done) {
|
||||||
output[0] = (p - output) - 1;
|
uint16_t out_len = (p - output) - 2;
|
||||||
if(error) output[1] = 0xff;
|
output[0] = out_len >> 8;
|
||||||
else output[1] = data[0];
|
output[1] = out_len & 0xff;
|
||||||
|
if(error) output[2] = 0xff;
|
||||||
|
else output[2] = data[0];
|
||||||
|
|
||||||
if(send_crc) {
|
if(send_crc) {
|
||||||
output[0] |= 0x80;
|
output[0] |= 0x80;
|
||||||
|
|||||||
Reference in New Issue
Block a user