MAC protocol engine for sensor networks