Checksum: 0x83f1 [incorrect, should be 0x3791 (maybe caused by "TCP checksum offload"?)]
Thats what I got for 30 in wireshark.
Here's my revised code
#include "config.h"
#include "IKSClient.h"
#define OWN_TASK TASK_IKS_CLIENT
#define INITIALISATION 0
#define ACTIVE 1
// TCP Settings
#define IKS_SERVER_PORT 8000
static USOCKET iks_client_socket;
static unsigned char iks_server_ip[IPV4_LENGTH] = {192, 168, 1, 69};
#define MAX_DATA_LEN 100
typedef struct stTCP_MESSAGE
{
TCP_HEADER tTCP_Header; // reserve header space
unsigned char ucTCP_Message[MAX_DATA_LEN]; // data payload space
} TCP_MESSAGE;
// Serial Port Settings
QUEUE_HANDLE SerialPortID = 0;
static int fnIKSListener(USOCKET Socket, unsigned char ucEvent, unsigned char *ucIp_Data, unsigned short usPortLen)
{
switch (ucEvent) {
case TCP_EVENT_ARP_RESOLUTION_FAILED:
break;
case TCP_EVENT_DATA: // a time server sends the time in seconds from 0:0:0 1900 and terminates
//ulPresentTime = *ucIp_Data++;
//uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(1*SEC), E_SECOND_TICK );
break;
case TCP_EVENT_CLOSE:
case TCP_EVENT_CLOSED:
break;
// If remote server closed before we received the time, try next
case TCP_EVENT_ABORT: // no connection was established
//if (ucTimeServerTry < NUMBER_OF_TIME_SERVERS) {
// fnTCP_Connect(TIME_TCP_socket, (unsigned char *)&ucTimeServers[ucTimeServerTry++], TIME_PORT, 0, 0); // {15} ucTimeServerTry incremented after use and not before
//}
break;
}
return APP_ACCEPT;
}
static int fnReadIrd(unsigned char * buf)
{
static int iRxReceived = 0; // the number of byte received (until now)
static int iExpectedbytes = 0;
unsigned char ucInputMessage; // reserve space for receiving messages
while (fnRead(SerialPortID, &ucInputMessage, 1) != 0) { // read each presently available input byte
if (iRxReceived == 0) { // searching for sync byte
if (ucInputMessage != 0x21) {
continue; // still not found sync byte
}
iRxReceived = 1; // synchronised
buf[0] = ucInputMessage;
}
else {
if (iRxReceived >= RX_BUFFER_SIZE) { // protect buffer overrun on invalid frames
iRxReceived = iExpectedbytes = 0; // go back to sync hunt mode
continue;
}
buf[iRxReceived++] = ucInputMessage; // collect message content
if (iRxReceived == 3) { // the expected length is now known
iExpectedbytes = (ucInputMessage + 4); // note the expected length
}
if (iRxReceived == iExpectedbytes) { // the complete message has now been collected
return iExpectedbytes; // inform of the frame length so that it can be processed
}
}
}
return -1; // frame not yet ready
}
// This task is started once to initialise the interface and then for each received character
//
extern void fnIKSClient(TTASKTABLE *ptrTaskTable)
{
static TCP_MESSAGE IKSData;
static unsigned char ucSerialInput[RX_BUFFER_SIZE]; // static buffer for collecting UART data
QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID; // queue ID for task input
int iSerialRxLenth = 0; // length of collected UART data
if (!SerialPortID) { // configure interfaces on initialisation
SerialPortID = fnSetNewSerialMode(FOR_I_O);
}
while ((iSerialRxLenth = fnReadIrd(ucSerialInput)) != -1) { // collect the data until ready
if ((iks_client_socket = fnGetTCP_Socket(TOS_MINIMISE_DELAY, TCP_DEFAULT_TIMEOUT, fnIKSListener)) >= 0) {
fnTCP_Connect(iks_client_socket, iks_server_ip, IKS_SERVER_PORT, 0, 0);
}
memcpy(IKSData.ucTCP_Message,ucSerialInput,iSerialRxLenth);
if(fnSendTCP(iks_client_socket, (unsigned char *)&IKSData.tTCP_Header, iSerialRxLenth, TCP_FLAG_PUSH) >0) {
//successfull
}
// data ready
// handle it here
}
// else quit - we return on further input
}
// After changes, we set up the new serial configuration
// (moved from application.c to here) - in application.s #undef SERIAL_INTERFACE added to remove its control of the serial interface
extern QUEUE_HANDLE fnSetNewSerialMode(unsigned char ucDriverMode)
{
TTYTABLE tInterfaceParameters; // table for passing information to driver
tInterfaceParameters.Channel = DEMO_UART; // set UART channel for serial use
tInterfaceParameters.ucSpeed = temp_pars->temp_parameters.ucSerialSpeed; // baud rate
tInterfaceParameters.Rx_tx_sizes.RxQueueSize = RX_BUFFER_SIZE; // input buffer size
tInterfaceParameters.Rx_tx_sizes.TxQueueSize = TX_BUFFER_SIZE; // output buffer size
tInterfaceParameters.Task_to_wake = OWN_TASK; // wake self when messages have been received
#ifdef SUPPORT_FLOW_HIGH_LOW
tInterfaceParameters.ucFlowHighWater = temp_pars->temp_parameters.ucFlowHigh;// set the flow control high and low water levels in %
tInterfaceParameters.ucFlowLowWater = temp_pars->temp_parameters.ucFlowLow;
#endif
tInterfaceParameters.usConfig = temp_pars->temp_parameters.usSerialMode;
#ifdef SERIAL_SUPPORT_DMA
tInterfaceParameters.ucDMAConfig = UART_TX_DMA; // activate DMA on transmission
#endif
if ((SerialPortID = fnOpen( TYPE_TTY, ucDriverMode, &tInterfaceParameters )) != 0) { // open or change the channel with defined configurations (initially inactive)
fnDriver( SerialPortID, ( TX_ON | RX_ON ), 0 ); // enable rx and tx
}
return SerialPortID;
}