This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432E411Y: Use the tcpip send command.

Part Number: MSP432E411Y

Tool/software: Code Composer Studio

Hello I always thank you for your help.

I am currently creating and using tcpip.c and mainthread.c.

This is my tcpip.c code.

#include <string.h>
#include <stdint.h>
#include <stdio.h>

#include <pthread.h>
/* BSD support */
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>

#include <ti/net/slnetutils.h>

#include <ti/display/Display.h>

static int server = -1;
static char ip_address[] = {"xxx.xxx.xxx.xxx"};

#define TCPPACKETSIZE 256
#define NUMTCPWORKERS 3
#define MAXPORTLEN    6

extern Display_Handle display;

extern void fdOpenSession();
extern void fdCloseSession();
extern void *TaskSelf();

void senddata(char* adcname, int time, int adcresult)
{
    if(server > -1)
    {
        char data[100]={0};
        sprintf(data, "%s_%d_%d", adcname, time, adcresult);
        send(server, data, strlen(data), 0);
    }
}


void *tcpHandler(void *arg0)
{
    int status;
    struct sockaddr_in   pc_addr;
    char buffer[256];
    int pc = -1;

    fdOpenSession(TaskSelf());

    memset(&pc_addr, 0, sizeof(pc_addr));
    pc_addr.sin_family = AF_INET;
    pc_addr.sin_port   = htons(15000);
    pc_addr.sin_addr.s_addr = inet_addr(ip_address);

    while(1)
    {
        pc = socket(AF_INET, SOCK_STREAM, 0);
        status = connect(pc, (struct sockaddr *)&pc_addr, sizeof(pc_addr));

        if(status < 0)
        {
            if (pc != -1) close(pc);
        }
        else break;
    }

    server = pc;

    while(1)
    {
        if(recv(pc, buffer, 2, 0) > 0)
        {
            send(pc, buffer, strlen(buffer), 0);
        }
    }

    close(pc);

    fdCloseSession(TaskSelf());

    return (NULL);
}

And this is my mainthread.c.

#include <ti/drivers/Timer.h>
#include <ti/drivers/ADC.h>

#include <pthread.h>

#include "ti_drivers_config.h"


#define ADC_SAMPLE_COUNT  (10)

#define THREADSTACKSIZE   (768)

extern void senddata(char* adcname, int time, int adcresult);

void timerCallback(Timer_Handle myHandle, int_fast16_t status);

int sec = 0;

void *mainThread(void *arg0)
{
    Timer_Handle timer0;
    Timer_Params params;
    Timer_init();

    Timer_Params_init(&params);
    params.period = 1000000;
    params.periodUnits = Timer_PERIOD_US;
    params.timerMode = Timer_CONTINUOUS_CALLBACK;
    params.timerCallback = timerCallback;

    timer0 = Timer_open(CONFIG_TIMER_0, &params);

    if (timer0 == NULL) {
        while (1) {}
    }

    if (Timer_start(timer0) == Timer_STATUS_ERROR) {
        while (1) {}
    }

    return (NULL);
}

void timerCallback(Timer_Handle myHandle, int_fast16_t status)
{
    sec++;
    senddata("a", sec, 1000);

}

Using the senddata function in tcpip.c, data is transferred to pc very well.

However, if the function is called in mainthread.c, data is not transmitted.

I may have coded stupidly.

After thinking for a few days, I couldn't figure it out.

The send function server was declared as an extern and sent was used by mainthread.c, but the result was the same.

What am I doing wrong?

Help me.

**Attention** This is a public forum