Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSTP where to begin.. #4

Open
kg9316 opened this issue Sep 26, 2024 · 1 comment
Open

MSTP where to begin.. #4

kg9316 opened this issue Sep 26, 2024 · 1 comment

Comments

@kg9316
Copy link

kg9316 commented Sep 26, 2024

Thanks for this great repo.

Where to begin porting code to make MSTP work ?
no uart or RS485 stuff in orginal repo
https://github.com/bacnet-stack/bacnet-stack/tree/master/ports/esp32

@lukedukeus
Copy link
Owner

In the original bacnet-stack library, datalink.c provides an abstraction for each interface. See here. based on what interfaces you set up, the bacnet stack library will handle encoding and decoding requests/responses to and from packets.

To get bacnet-stack to work on the esp32, I used the source code in the apps folder, because esp-idf's networking api looks very similar to window's networking API, and the apps are all written to work on windows.

For MSTP, the implementation just reads from and writes to buffers (here), so you will just need to:

  1. Initialize your uart driver on startup example here

  2. Write an implementation of dlmstp_rs485_driver here that will provide send and read functions that control the uart driver

  3. Then use the bacnet-stack library the same way it is used for ip. For example start a task to listen for data, something like:

static uint8_t rx_buffer[MAX_MPDU] = { 0 };
   
BACNET_ADDRESS src = {
    0
}; 
    
uint16_t pdu_len = 0;

while(true) {
        pdu_len = datalink_receive(&src, &rx_buffer[0], MAX_MPDU, 5000);

        if (pdu_len) {
            npdu_handler(&src, &rx_buffer[0], pdu_len);

            if (Analog_Value_Present_Value(0) == 1)
            {
                led_on();
            }
            else
            {
                led_off();
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants