Я разрабатываю код, в котором я получаю доступ к значениям из одной функции (func1) в другую функцию (func2).Обе функции имеют указатели в качестве аргумента.Я вызываю "func2" в другом файле, чтобы передать значения для дальнейшей записи по UART.
Ниже приведен фрагмент кода:
func1: (файл one.c)
int16_t driver485Compare(uint8_t * message, uint16_t len)
{
int j = 0;
uint8_t FWmsg[9] = {0x09,0x30,0x30,0x32,0x32,0x31,0x31,0x30,0x36};
uint8_t adata[9] = {0x09,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30};
printf("compare command..........");
for (j=0; j<9; j++)
{
adata[j] = message[j] ;
printf("%d ",adata[j]);
}
if(compareArray(FWmsg,adata,7)==0)
{
uint8_t add, fwcommand, fwaction;
uint16_t fwvalue;
GetABFWversion(&message, &add, &fwcommand, &fwaction, &fwvalue);
printf("elements matched \n");
// HERE I NEED TO read VALUES OF add, fwcommand, fwaction, fwvalue and pass to "message"
}
else
{
printf("Arrays have different elements.\n");
}
return 0;
}
func2: (файл two.c)
int8_t GetABFWversion(uint8_t* add, uint8_t* fwcommand, uint8_t* fwaction, uint16_t* fwvalue)
{
char MyCopy[10];
strcpy (MyCopy, FIRMWARE_VERSION);
char MyCopy1[10];
for (int k=0; k<9; k++)
{
int l=1;
MyCopy1[k] = MyCopy[k+l];
}
char FWversion_AB[10] = {0};
for(int x=6;x<9;x++)
{
FWversion_AB[z] = MyCopy1[x];
z++;
}
uint16_t val = atoi(FWversion_AB);
*add = RS485_ADDRESS; //values read from enum
*fwcommand = CMD_GET_VERSION_AB; //values read from enum
*fwaction = CMD_ACTION_AB; //values read from enum
*fwvalue = val;
// NEED TO PASS VALUES OF add, fwcommand, fwaction, fwval to "driver485Compare()"
}
func3: (в другом файле (three.c))
void TaskSlave(void *p_arg) //b - communication Task
{
uint8_t res;
rs485_message_t rs485Msg;
(void)p_arg;
while(1)
{
res = driver485Read((uint8_t *)&rs485Msg, RS485_MSG_LENGTH);
res = driver485Compare((uint8_t *)&rs485Msg, RS485_MSG_LENGTH);
//add, fwcommad, fwaction, fwval SHOULD BE REFLECTED HERE WHILE CALLING "driver485Compare()" IN ABOVE STATEMENT.
}
}