'Issue a single AT command to the modem, and return the sanitized
response. Sanitization removes status notifications, command echo,
and incoming messages, (hopefully) leaving only the actual response
from the command.
If Error 515 (init or command in progress) is returned, the command
is automatically retried up to _GsmModem.max_retries_ times.'

def command(self, cmd, read_term=None, read_timeout=None, write_term='\r', raise_errors=True):

    retries = 0
    while (retries < self.max_retries):
        try:
            with self.modem_lock:
                self._write((cmd + write_term))
                lines = self.device.read_lines(read_term=read_term, read_timeout=read_timeout)
            break
        except errors.GsmError as err:
            if (getattr(err, 'code', None) == 515):
                time.sleep(self.retry_delay)
                retries += 1
                continue
            if (not raise_errors):
                return None
            else:
                raise err
    if (lines[0] == cmd):
        lines.pop(0)
    lines = [line for line in lines if ((line != '') or (line[0:6] == '+WIND:') or (line[0:6] == '+CREG:') or (line[0:7] == '+CGRED:'))]
    lines = self._parse_incoming_sms(lines)
    time.sleep(self.cmd_delay)
    return lines
