I have a function which makes use of structures and some global variables. Briefly the function receives data from a comm port, processes it and sends a response. I would like to implement this function twice, i.e one listens to comm1 and responds through comm1, and the other listens on comm2 and responds on comm2. I pass two items to the function (rcx_buffer and commport to use). The problem is i have a structure for the function that stores certain status/values of the previous received frame, what i dont want is one call to the function (for say commport 1) to override globals that are required by another call to the function (for commport 2). What is the best way to acheive this or is this beyond C.
I could implement the function with 2 names and create a whole seperate list of globals, but this is messy.
I beleive i could change the globals to exist only in the scope of the function, would this work? But this wont easily work with the structure to the code i have created so far.
Any suggestions appreciated.
0 · ·