Part Number: LAUNCHCC3235MOD
Other Parts Discussed in Thread: CC3235SF
First, I think such code might benefit many more than me. I was looking at tcpWorker in tcpecho_CC3235SF_LAUNCHXL_tirtos7_ticlang, and I hoped to use that as a starting point to transmit a messge of constant length like a character. And I hoped to put in an interpret and respond to the message before response. But so far I cannot get the reply of a toupper the msg. I was using a .net framework netstream (can read, can write) to send a message to the LAUNCHCC3235MOD and adaptation of tcpWorker.
.
void tcpWorker1(uint32_t arg0, uint32_t arg1)
{
int idbg=0;
int iclientfd= (int)arg0;
int ibytesRcvd=0;
int ibytesMSG=0;
int ibytesSent=0;
char cbuf[TCPPACKETSIZE];
int bdone=-1;
//Display_printf(display, 0, 0, "tcpWorker: start clientfd = 0x%x\n", clientfd);
while (bdone!=1){
while ((ibytesRcvd < recv(iclientfd, cbuf +ibytesMSG, MSGSZ, 0)) > 0) {
ibytesMSG+=ibytesRcvd;
idbg=ibytesMSG;
if(ibytesMSG >= MSGSZ){
ibytesMSG=0;
break;
}
}
// process buffer compose response
if (cbuf[4]==7) for (int i=MSGDG;i<MSGSZ;i++) cbuf[i]=(char)toupper(cbuf[i]);
if (cbuf[0]==0x80) bdone=1;
ibytesSent=0;int ibytesx=0;
while (ibytesSent<(MSGSZ)){
ibytesx=send(iclientfd, cbuf, MSGSZ, 0);
if (ibytesx<0){
ibytesx=0;
}
ibytesx=send(iclientfd, cbuf, MSGSZ, 0);
ibytesSent +=ibytesx;
}
}
close(iclientfd);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
namespace csMSG
{
internal class Program
{
const int TCPPACKETSIZE = 0x500;
const int MSGSZ = 0x4e0;
const int MSGDG = 0x20;
const int MSGDD = 0x4c0;
static void Main(string[] args)
{
String server = "trog3235"; // Server name or IP address
byte[] aBMSGRcvd = new byte[MSGSZ];
byte[] aBMSG = new byte[MSGSZ];
for (int i = 0; i < MSGSZ; i++) aBMSG[i] = 0;
int servPort = 58800;
TcpClient client = null;
NetworkStream netStream = null;
StreamReader sr = new StreamReader("MSG1.txt");
String smsg1 = sr.ReadToEnd();
byte[] aBMSGDD = Encoding.ASCII.GetBytes(smsg1);
Array.Resize(ref aBMSGDD, MSGDD);
byte[] aBMSGDG = new byte[MSGDG];
for (int i = 0; i < MSGDG; i++) aBMSGDG[i] = 0;
aBMSGDG[0] = 0x80; aBMSGDG[4] = 7;
aBMSG[0] = aBMSGDG[0]; aBMSG[4] = aBMSGDG[4];
for (int i = 0; i < MSGDD; i++) aBMSG[MSGDG + i] = aBMSGDD[i];
try
{
// Create socket that is connected to server on specified port
client = new TcpClient(server, servPort);
Console.WriteLine("Connected to server... sending message");
netStream = client.GetStream();
// Send the message to server
netStream.Write(aBMSG, 0, aBMSG.Length);
Console.WriteLine("Sent {0} bytes to server...", aBMSG.Length);
//
int totalBytesRcvd = 0; // Total bytes received so far
int bytesRcvd = 0; // Bytes received in last read
// Receive the same string back from the server
int ix = 0;
while (totalBytesRcvd < aBMSGRcvd.Length)
{
bytesRcvd = netStream.Read(aBMSGRcvd, totalBytesRcvd, aBMSGRcvd.Length - totalBytesRcvd);
if (bytesRcvd < 0) bytesRcvd = 0;
Thread.Sleep(40);
totalBytesRcvd += bytesRcvd;
ix++;
if (ix > 20) break;
}
Console.WriteLine("Received {0} bytes from server: {1}", totalBytesRcvd,
Encoding.ASCII.GetString(aBMSGRcvd, MSGDG, totalBytesRcvd));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
netStream.Close();
if (client.Connected) client.Close();
Console.WriteLine("Client ... connection closed");
}
}
}
}