Recieve & Send Functions

Hi all,

I have a function below "readIn" that reads the data it recieves from an external source and puts the data in the given bytes of array. I need to send some of this data back
(slave, code, start and values) as well as the contents of pInfo->values. In the second function below "createResponse" I have implicitly defined the values to send back and it seems to work.Obviously this isn't useful as I will not always know what these values are. How can I read from one function and send it back with the extra info? Any help would be much appreciated.

1
2
3
4
5
6
7
8
9
10
void readIn(MB_Info *pInfo, 
                       U8 *pRawData)
{
  if((pMsgInfo == 0) || (pRawData == 0) ) return;

  pInfo->slave = pRawData[0];
  pInfo->code = pRawData[1];
  pInfo->start = readModbusWord(pRawData[2], pRawData[3]);
  pInfo->values = readModbusWord(pRawData[4], pRawData[5]);
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
U16 createResponse()
{
	MB_Info respInfo;
	respInfo.code = 0x04;
	respInfo.value = 2;
	respInfo.slave = 1;
	respInfo.start = 4001;
	U8 values[2];
	values[0] = 5;
	values[1] = 6;
	U16 numBytes = 0;
	U8 writeBuffer[512];
	numBytes = MB_createPacket(&writeBuffer, sizeof(writeBuffer), respInfo, values);
	U16 i=0;
	for(i=0; i<numBytes; i++)
	{
	  USART0_Interrupt_Transmit(writeBuffer[i]);      		
	}
	return numBytes;
}
Putting them in a string and returning it? Extra work right?
Topic archived. No new replies allowed.