I have a GPS module that you can cycle between "active" and "hibernate" mode by giving a 200ms pulse on its "ON/OFF" pin. It transmits data once per second when it is "active" and doesn't transmit any data when it is in "hibernate" mode. The only way for me to know which state it is in is to see if it is transmitting data so for instance, when I am ready to start receiving location data i will need to toggle the "ON/OFF" pin but first I want to check and make sure that it isn't already active or else my pulse is just going to turn it off instead of on. Likewise when I go to put it into "hibernate" mode I want to be sure that it isn't already in "hibernate" mode or else my pulse is going to inadvertently turn it on. I wrote some code to try to check this because in my mind I need to first empty out the Serial buffer, wait a bit more than a second, and then check to see if any Serial data has come in. I would like some guidance on the most reasonable way to do this. My attempt at it is below.
//check to see if GPS is already awake by purging serial data and then
//checking to see if Serial data is still coming in
if(softSerial.available()) return true;