FW bidir comms work
This commit is contained in:
parent
424310d957
commit
6ebd1a667d
2 changed files with 20 additions and 14 deletions
|
|
@ -53,7 +53,7 @@ int main(void) {
|
|||
|
||||
USART1->CR1 = USART_CR1_TE | USART_CR1_RE;
|
||||
USART1->BRR = (apb2_clock + baudrate/2) / baudrate;
|
||||
USART1->CR1 |= USART_CR2_RXINV;
|
||||
USART1->CR2 |= USART_CR2_RXINV;
|
||||
USART1->CR1 |= USART_CR1_UE;
|
||||
|
||||
int req_seq = 0;
|
||||
|
|
@ -71,6 +71,7 @@ int main(void) {
|
|||
|
||||
USART1->TDR = 0; /* Kick off transmission */
|
||||
while (23) {
|
||||
/*
|
||||
if (tx_st.remaining_bytes == 0) {
|
||||
res_buf.req_seq = req_seq;
|
||||
res_buf.res_seq = res_seq;
|
||||
|
|
@ -87,6 +88,7 @@ int main(void) {
|
|||
tx_st.tx_char += 1;
|
||||
tx_st.remaining_bytes -= 1;
|
||||
}
|
||||
*/
|
||||
|
||||
if (USART1->ISR & USART_ISR_ORE)
|
||||
USART1->ICR = USART_ICR_ORECF;
|
||||
|
|
@ -100,19 +102,21 @@ int main(void) {
|
|||
if (USART1->ISR & USART_ISR_RXNE) {
|
||||
uint8_t c = USART1->RDR;
|
||||
if (!c) {
|
||||
int rc = cobs_decode(rx_buf, rx_char, (uint8_t *)&req_buf, sizeof(req_buf));
|
||||
if (rc < 0) {
|
||||
rx_cobs_error += 1;
|
||||
} else {
|
||||
if (rc == sizeof(req_buf)) {
|
||||
crc32_t check_crc = pkt_crc(&req_buf, &req_buf.trailer);
|
||||
if (check_crc != req_buf.trailer.crc32) {
|
||||
rx_crc_error += 1;
|
||||
} else {
|
||||
req_seq = req_buf.req_seq;
|
||||
}
|
||||
if (rx_char < sizeof(rx_buf)) {
|
||||
int rc = cobs_decode(rx_buf, rx_char, (uint8_t *)&req_buf, sizeof(req_buf));
|
||||
if (rc < 0) {
|
||||
rx_cobs_error += 1;
|
||||
} else {
|
||||
rx_framing_error += 1;
|
||||
if (rc == sizeof(req_buf)) {
|
||||
crc32_t check_crc = pkt_crc(&req_buf, &req_buf.trailer);
|
||||
if (check_crc != req_buf.trailer.crc32) {
|
||||
rx_crc_error += 1;
|
||||
} else {
|
||||
req_seq = req_buf.req_seq;
|
||||
}
|
||||
} else {
|
||||
rx_framing_error += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
rx_char = 0;
|
||||
|
|
|
|||
|
|
@ -66,8 +66,10 @@ if __name__ == '__main__':
|
|||
|
||||
|
||||
if time.time() - last_tx > 0.01:
|
||||
seq = int((time.time() - start_time) * 10)
|
||||
data = struct.pack('<I', seq)
|
||||
seq += 1
|
||||
#seq += 1
|
||||
#ser.write(bytes(list(range(255, -1, -1))))
|
||||
ser.write(cobs.encode(data + struct.pack('<I', zlib.crc32(data))) + b'\0')
|
||||
last_tx = time.time()
|
||||
#time.sleep(0.01)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue