|
|
@@ -1,4 +1,5 @@
|
|
|
#include "nbus_app.h"
|
|
|
+#include <string.h>
|
|
|
|
|
|
nBus_TypeDef nBus;
|
|
|
|
|
|
@@ -38,6 +39,11 @@ static uint8_t crc8x_fast(void const *mem, uint16_t len) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+inline static void receivePacket(void){
|
|
|
+ nBus.hw_platform->uart_receive(nBus.rx_buffer, 64);
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
inline static void receiveOneByte(){
|
|
|
nBus.hw_platform->uart_abort_receive();
|
|
|
nBus.hw_platform->uart_receive(nBus.rx_buffer, 1);
|
|
|
@@ -50,6 +56,7 @@ inline static void receiveNBytes(uint8_t n){
|
|
|
nBus.hw_platform->uart_receive(nBus.rx_buffer, nBus.rx_length);
|
|
|
nBus.uart_state = UART_RX_PAYLOAD;
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
inline static void send_response(){
|
|
|
if(nBus.send_response == SEND_RESPONSE) {
|
|
|
@@ -160,7 +167,8 @@ static void process_request(){
|
|
|
/* ----------------------- CALLBACKS----------------------- */
|
|
|
/* -------------------------------------------------------- */
|
|
|
|
|
|
-void nbus_cb_UART_RX(void){
|
|
|
+void nbus_cb_UART_RX(uint8_t *uartData, int size){
|
|
|
+ /*
|
|
|
if(nBus.uart_state == UART_RX_PAYLOAD) {
|
|
|
nBus.uart_state = UART_RECEIVED;
|
|
|
nBus.hw_platform->timer_uart_stop();
|
|
|
@@ -176,10 +184,13 @@ void nbus_cb_UART_RX(void){
|
|
|
receiveOneByte();
|
|
|
}
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
+ memcpy(nBus.rx_buffer, uartData, size);
|
|
|
+ nBus.uart_state = UART_RX_RECEIVED;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+/*
|
|
|
void nbus_cb_TIM_periodElapsed(void) {
|
|
|
if(nBus.uart_state == UART_RX_PAYLOAD) {
|
|
|
nBus.hw_platform->led_off();
|
|
|
@@ -189,6 +200,7 @@ void nbus_cb_TIM_periodElapsed(void) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+*/
|
|
|
void nbus_blink_LED(uint8_t delay) {
|
|
|
nBus.hw_platform->led_on();
|
|
|
nBus.hw_platform->delay_ms(delay);
|
|
|
@@ -212,12 +224,13 @@ void nbus_init(nBusAppInterface_t *interface, nBusPlatformInterface_t *hw){
|
|
|
nBus.measure_active = MEASURE_STOPPED;
|
|
|
|
|
|
// init restart timer
|
|
|
- nBus.uart_state = UART_RX_1B;
|
|
|
- nBus.hw_platform->timer_uart_start(100); // dummy value
|
|
|
- nBus.hw_platform->timer_uart_stop();
|
|
|
+ nBus.uart_state = UART_RX_WAIT;
|
|
|
+// nBus.hw_platform->timer_uart_start(100); // dummy value
|
|
|
+// nBus.hw_platform->timer_uart_stop();
|
|
|
|
|
|
nBus.interface = interface;
|
|
|
- receiveOneByte();
|
|
|
+// receiveOneByte();
|
|
|
+ receivePacket();
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -236,12 +249,13 @@ void nbus_stack(void){
|
|
|
nbus_blink_LED(50);
|
|
|
|
|
|
while(1){
|
|
|
- if(nBus.uart_state == UART_RECEIVED){
|
|
|
+ if(nBus.uart_state == UART_RX_RECEIVED){
|
|
|
|
|
|
process_request();
|
|
|
+ nBus.uart_state = UART_RX_WAIT;
|
|
|
|
|
|
// ready for next receiving
|
|
|
- receiveOneByte();
|
|
|
+ //receiveOneByte();
|
|
|
|
|
|
send_response();
|
|
|
#if MODULE_MASTER == 1
|
|
|
@@ -249,7 +263,7 @@ void nbus_stack(void){
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
- if (nBus.hw_platform->loop_callback != NULL) {
|
|
|
+ if (nBus.uart_state != UART_RX_RECEIVING && nBus.hw_platform->loop_callback != NULL) {
|
|
|
if (nBus.hw_platform->loop_callback() == 1){
|
|
|
nBus.interface->read();
|
|
|
}
|