У меня есть задача получить несколько значений из одной функции, определенной в файле one.c, в другую функцию, определенную в файле two.c.
Ниже приведен фрагмент кода из обоих файлов и любезно помогите получить доступ кзначения из файла one.c в файл two.c.
файл one.c:
void GetABFWversion(uint8_t* fwcommand, uint8_t* fwaction, uint16_t* fwvalue)
{
uint16_t FW_slot=SdusAutoDetectSlotForNewFirmware();
char MyCopy[10];
strcpy (MyCopy, BrakeBoardInfo.firmwareVersion);
char MyCopy1[10];
for (int k=0; k<9; k++)
{
int l=1;
MyCopy1[k] = MyCopy[k+l];
}
char FWversion_AB[10] = {0};
int z = 0;
for(int x=6;x<10;x++)
{
FWversion_AB[z] = MyCopy1[x];
z++;
}
char res=0;
uint16_t val = atoi(FWversion_AB);
//res = proto485OnlyWrite(0x09,0x02,0x00,val);
printf("\n");
printf("FW version is sent to Arduino!!! ");
RESULT = 1;
*fwcommand = 0x02;
*fwaction = 0x00;
*fwvalue = val;
}
файл two.c:
int16_t driver485Read (uint8_t *buffer, const uint16_t length)
{
char head[20];
const char *format="KL%02x:";
int16_t wait_loop_cnt=0;
static uint32_t totalBytes = 0;
static uint32_t respNo = 0;
GPIO_ClearValue(PMAP_GPIO_PORT_DIR_RS485, PMAP_GPIO_PIN_DIR_RS485);
UartRxFlush(UARW_UART_INDEX_RS485); /
respNo++;
int counter = 0;
do
{
OSTimeDly(2);
int8_t newBytesRcv = UartReceive(UARW_UART_INDEX_RS485,
(uint8_t*)&(buffer[counter]), length-counter);
totalBytes += newBytesRcv;
counter = totalBytes;
}
while (/*wait_loop_cnt++<= MAX_WAIT_LOOP &&*/ counter < length);
totalBytes = 0;
uint8_t i = 0;
format="OK%02x:";
printf("Byte received........");
int FWmsg[9] = {0x09,0x30,0x30,0x32,0x32,0x31,0x31,0x31,0x31};
int arduinodata[9] = {0x09,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30};
for (i=0; i<9;i++)
{
printf("%d ",buffer[i]);
arduinodata[i] = buffer[i];
}
if(compareArray(FWmsg,arduinodata,7)==0)
{
printf("Arrays have same elements.\n");
printArray(FWmsg,9);
char res = 0;
uint8_t fwc, fwa;
uint16_t fwv;
GetABFWversion(&fwc, &fwa, &fwv);
res = proto485OnlyWrite(0x09,fwc,fwa,fwv);
printf("\n");
printf("FW version is sent to Arduino!!! ");
}
else
{
printf("Arrays have different elements.\n");
}
/* 1st byte is the slave address byte which value should be >= RS485_ADDRESS_SLAVE_FIRST &&
<= RS485_ADDRESS_SLAVE_LAST and is already checked in dePadLeft() */
for(int i = 1; i < length && buffer[i] >= RS485_PAYLOAD_VALID_MIN && buffer[i] <= RS485_PAYLOAD_VALID_MAX; i++);
counter = i; // to be OK, i = length = RS485_MSG_LENGTH if response (after eventual dePad..) is OK
printf("driver485Read %d\n",counter);
#ifdef RS485_DEBUG
static uint32_t i = 0;
i++;
#endif
return counter;
GPIO_SetValue(PMAP_GPIO_PORT_DIR_RS485, PMAP_GPIO_PIN_DIR_RS485);
}
файл three.c:
uint8_t proto485OnlyWrite(uint8_t address, uint8_t command, uint8_t action, uint16_t value)
{
uint8_t res=ERROR_FOUND;
OSSemPend(pbSemaphore, 0, &res);
if (res == OS_ERR_NONE)
{
rs485_message_t rs485Msg;
if (command ==CMD_POWER_PUMP_PB)
{
printf("CMD_POWER_PUMP_PB");
}
proto485ComposeMsg(&rs485Msg, address, command, action, value);
res = (RS485_MSG_LENGTH == driver485Write((uint8_t *)&rs485Msg, sizeof(rs485Msg))) ?
NO_ERROR:
ERROR_FOUND;
OSSemPost(pbSemaphore);
}
return res;
}
Я хочу получить значения "fwcommand", "fwaction" и "fwvalue", определенные в файле one.c, в файл two.c в том месте, куда я передаю то же самое "res = proto485OnlyWrite (0x09, fwc, fwa, fwv); "вместо «fwc», «fwa» и «fwv» соответственно.
Спасибо ....