G'day all
OK, I have placed it on the server. It can be downloaded from
www.modtronix.com/soft/valweb.zip. The code does UDP<-->RS232 conversion. It uses an interrupt driven USART ISR, with a circular buffer.
See the main.c file for details. The project uses the SBC45EC and an older version of the Modtronix TCP/IP stack. Best is if you just copy the couple of relevant functions from main.c and paste them into your project (download new source code from
www.modtronix.com). Just as
long as it uses the Modtronix TCP/IP stack, it should work.
Please
no bitching if the code does not do exactly what you want. This is a working project, and is used on coin machines that are working in field. It is stable. Converting it to be used with the new version of the stack, or for use with the SBC44EC, SBC65EC or SBC68EC should be very simple to do - if you however have to change some defines or whatever, don't complain too much ..... dear sir "imxo"

In the Udp2SerProcess() function the received RS232 data is checked for protocol specific information relevant to this project - this can be removed. The following code checks this protocol specific information (only complete message packets received via RS232 are placed in packets and sent via UDP) relevant to this project:
/////////////////////////////////////////////////
//Was anything received on the USART - store it and schedule for transmission
//once all bytes are received
while( !serRxBufEmpty()) {
//If the contents of the "Ser to UDP" buffer is waiting to be TXed via UDP, break
if (flagsUDP2Ser & UDP2SER_TX_TXBUF) {
break;
}
c = serGetByte();
//This is the first byte of the Validator command, which can be SOH, ACK or NAK
if (bytesRxedSer2UDP == 0) {
//ACK and NAK
if ((c == 0x06) || (c == 0x15)) {
//Can be sent straight away
flagsUDP2Ser |= UDP2SER_TX_TXBUF; //Indicate the "Ser to UDP" buffer must be TXed via UDP
}
//SOH byte was NOT received, continue
else if (c != 0x01) {
continue;
}
}
//This is the command lenght byte (second byte of packet)
else if (bytesRxedSer2UDP == 1) {
currValCmdLen = c;
}
//Add the received byte to the Validator Command buffer
bufSer2UDP[bytesRxedSer2UDP++] = c;
//If
// - Last byte of validator command has been received
// - The buffer full
//set flag for UDP to send it!
if (bytesRxedSer2UDP > 2) {
if ( (bytesRxedSer2UDP >= currValCmdLen)
|| (bytesRxedSer2UDP >= (BUF_SER2UDP_MAXSIZE - 1)) )
{
flagsUDP2Ser |= UDP2SER_TX_TXBUF; //Indicate the "Ser to UDP" buffer must be TXed via UDP
}
}
}
To simply transmit everything that is received via RS232 in UDP packets, replace the above code with:
/////////////////////////////////////////////////
//Was anything received on the USART - store it and schedule for transmission
//once all bytes are received
while( !serRxBufEmpty()) {
//If the contents of the "Ser to UDP" buffer is waiting to be TXed via UDP, break
if (flagsUDP2Ser & UDP2SER_TX_TXBUF) {
break;
}
c = serGetByte();
//Add the received byte to the Validator Command buffer
bufSer2UDP[bytesRxedSer2UDP++] = c;
//If
// - User check is true
// - The buffer full
//set flag for UDP to send it!
if ((use check) || (bytesRxedSer2UDP >= (BUF_SER2UDP_MAXSIZE - 1)) ) {
flagsUDP2Ser |= UDP2SER_TX_TXBUF; //Indicate the "Ser to UDP" buffer must be TXed via UDP
}
}
In the above example, the user check has to be true before the received RS232 data is sent. For example, to only send the received RS232 data once there is 5 or more bytes to send, replace the (use check) if condition code with (bytesRxedSer2UDP >= 5).