I need to calculate the used bandwidth in a bus. All packets can be read for any client in the bus, then if I'm a only listener I can catch all packets and know how many bytes are moving in the bus. Then my first approach to calculate the used bandwidth is something like this:
1) unsigned long second[60] to store bytes on the second 0, 1, 2, 3
2) second[now] += readBytes;
3) then use last 3 seconds to calculate the bandwidth Ex: (second[now-2] + second[now-1] + second[now])/3 // Check that 0-2=58
4) Show every second the prev calc based on 1Mbps teoric bandwidth limit.
Is this the way ?
Thanks.