I'm working on a robot that is controlled by an xbox controller connected to a windows computer and commands are sent to a pcduino through a tcp connection. I have it working by sending a string of 1's and 0's to tell the pcduino which motors to turn on. I'm trying to optimize it by just sending an int and using bit masks to make the decisions on the pcduino but I can't get the pcduino to receive the int correctly. I tested the windows function sending the command with sokit and its sending the correct values but the pcduino is receiving the same number even when the commands are changing.
This is what its doing:
Windows -> PCDuino
command = 1 -> sendBuff = 73932
cmdstring = 1 -> n = 1
command = 1025 -> sendBuff = 73932
cmdstring = 1025 -> n = 4
My windows functions are:
bool Client::Send(char * smsg)
{
int iResult = send(ConnectSocket, smsg, strlen(smsg), 0);
if (iResult == SOCKET_ERROR)
{
std::cout << "Sending Message has failed: " << WSAGetLastError() << "\n";
Stop();
return false;
}
return true;
}
bool sendCommand()
{
cmdbuffer << command;
cmdstring = cmdbuffer.str();
if (!client->Send((char *)cmdstring.c_str()))
{
std::cout << "Disconnected from Server. Press Enter to Exit";
std::cin.ignore();
std::cin.get();
return false;
}
return true;
}
PCDuino Loop Function
void loop()
{
recBuff = 0;
deviceFlag = 0;
//Read Socket
/******************************************************************************/
read(connfd, sendBuff, strlen(sendBuff));
recBuff = atoi(sendBuff);
/******************************************************************************/
//Set Current Device to Receive Instructions From
checkAuto(recBuff, currDevice);
//Find Current Device of Command
deviceFlag = checkDevice(recBuff);
//If Current Device and Set Device are the Same Parse Command
if (deviceFlag == currDevice)
{
parseHex(recBuff);
}
usleep(50000);
}
I have a printf after the read call and that's where I am getting the 73932 number. I think I have everything you guys need but if there's anything else I need to add let me know. I'm stumped...I don't know if its just a casting problem or what.
Update 1
What I have before everything the setup and loop functions on the PCduino run is:
int listenfd = 0, connfd = 0;
int n;
struct sockaddr_in serv_addr;
char sendBuff[1025];
time_t ticks;