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

question about util/uart.c #7

Open
mocasrhey opened this issue Apr 11, 2019 · 2 comments
Open

question about util/uart.c #7

mocasrhey opened this issue Apr 11, 2019 · 2 comments

Comments

@mocasrhey
Copy link

mocasrhey commented Apr 11, 2019

I'm working on a school project using SIM7000E and i'm exploring the DAM.
I was going through uart.c code and my mind blocked on this piece of code, if someone could explain me(im fairly new around here), i would apreciate it very much.

Here is the code(in file uart.c, uart_init() function, Lines 61 to 64):
uart_context_t mctx = (uart_context_t)cfg->buf;
mctx->sendbuf = (char*)cfg->buf + sizeof(struct uart_context_s);
mctx->send_buf_len = cfg->buf_len - sizeof(struct uart_context_s);
mctx->is_off = false;

@Thalhammer
Copy link
Owner

Yeah sure.
In a DAM module you cant just use malloc to get memory, however, uart_init needs some memory to do buffering.
That's why you pass a buffer in the uart config which is used for housekeeping and buffering.
Line 60 cleans the buffer to a known state and makes sure there is no garbage inside.
Line 61 casts it into a uart_context_t (which is a typedef for uart_context_s*) to make accessing easier
Line 62 sets the sendbuf pointer inside the struct to the remaining space in the supplied buffer and
Line 63 sets the send_buf_len to the remaining length (i.e. the length of sendbuf).
Line 64 sets the internal power state to off (it is used for bookkeeping as some powersave funktions do not work when the uart is on).

If you use it in a school project please beware of a few things:

@mocasrhey
Copy link
Author

thank you so much for the answer.
Yes i've taken a look to those issues already. Im actually trying to make a bridge, that basically consists in receiving mqtt packets and forward them through UART to another board.

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