c++codeblocksat-command

Compilation error "error: stray '\302'" in program Code::Blocks


I wrote this code (using the Code::Blocks IDE) in which I want to send a message for a GSM to my mobile. It includes some AT commands.

The problem is that I have this error in the printf with the AT command "at+cmgf=1". I think that my code is correct. Is there a problem with UTF or the ASCII?

#include <stdio.h> // standard input / output functions
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#include <termios.h> // POSIX terminal control definitions


int open_port(void)
{
    int fd; // File description for the serial port

    fd = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);

    if(fd == -1) // If open is unsucessful
    {
        printf("open_port: Unable to open /dev/ttyAMA0. \n");
    }
    else
    {
        fcntl(fd, F_SETFL, 0);
        printf("port is open.\n");
    }

    return(fd);
 } //open_port

int configure_port(int fd) // Configure the port
{
    struct termios port_settings; // Structure to store the port settings in

    cfsetispeed(&port_settings, B9600); // Set baud rates
    cfsetospeed(&port_settings, B9600);

    port_settings.c_cflag &= ~PARENB;   // Set no parity, stop bits, data bits
    port_settings.c_cflag &= ~CSTOPB;
    port_settings.c_cflag &= ~CSIZE;
    port_settings.c_cflag |= CS8;

    tcsetattr(fd, TCSANOW, &port_settings); // Apply the settings to the port
    return(fd);
}

void init_gsm()
{
    printf("at+cmgf=1\r\n");
    printf("at+cmgs=\"60*****\"\r\n");
    printf("Hello\r\n%c", 26);
}

int main(void)
{
    int fd = open_port();
    configure_port(fd);
    //query_modem(fd);
    init_gsm();
    return(0);
} //main

Solution

  • The problem with stray '\302' is that the code contains a non-break-space instead of a normal space somewhere.

    However fixing that, I see two additional problems which I address here.