У меня есть массив. Байты массива в шестнадцатеричном формате. Теперь я пытаюсь объединить индексы массива от 1 до 4 в unsigned long int и от 5 до 8 в еще один unsigned long int и индексы 9 и 10 в unsigned int. Я пробовал так. Но это не работает. Я не хочу использовать объединение для объединения. Я использую этот код в STM32F4-Discovery.
Это функция обработчика прерывания приема:
void usart1_IRqHandler()
{
unsigned char received_string[20];
unsigned long int Addr1=0,Addr2=0;
unsigned int Addr=0;
/*Code to Receive Entire packet.......
.....................................
.....................................
At this point whole packet is received, now I want to send back the response to the target node using address from received data, So first step is to concatenate address bytes*/
/*From the logic analyzer I can observe the received_string bytes as shown below
received_string[1]=0x00;
received_string[2]=0x13;
received_string[3]=0xA2;
received_string[4]=0x00;
received_string[5]=0x40;
received_string[6]=0xB4;
received_string[7]=0x14;
received_string[8]=0x35;
received_string[9]=0x8E;
received_string[10]=0xC7;*/
Addr1 = (received_string[1]<<24)| (received_string[2]<<16)| (received_string[3] <<8)| received_string[4]);
Addr2 = (received_string[5]<<24)| (received_string[6]<<16)|(received_string[7] <<8)| received_string[8]);
Addr = (received_string[9]<<8)| (received_string[10]);
Send_packet(Addr1,Addr2,Addr);
}
Функция Send Packet будет нацелена на удаленный узел с этим адресом.
Send_packet(unsigned long int Addr1,unsigned long int Addr1,unsigned int Addr)
{
unsigned char tx_buf[20];
tx_buf[5]=(Addr1>>24) & 0xff;
tx_buf[6]=(Addr1>>16) & 0xff;
tx_buf[7]=(Addr1>>8) & 0xff;
tx_buf[8]=(Addr1>>0) & 0xff;
tx_buf[9]=(Addr2>>24) & 0xff;
tx_buf[10]=(Addr2>>16) & 0xff;
tx_buf[11]=(Addr3>>8) & 0xff;
tx_buf[12]=(Addr4>>0) & 0xff;
tx_buf[9]=(Addr2>>8) & 0xff;
tx_buf[10]=(Addr2>>0) & 0xff;
usart_send(tx_buf);
}
Это результат отправки пакета в логическом анализаторе.
Addr1=0xA2401437
Addr2=0x025500A2
Addr=0x4014
Поскольку адрес не совпадает, я не могу настроить таргетинг на удаленный узел.
received_string[0]
? - person Sourav Ghosh   schedule 31.03.2015