kopia lustrzana https://github.com/mobilinkd/tnc3-firmware
Read MAC address from BT module and send it as part of GET_ALL_VALUES. Fixes #2.
rodzic
dc11a1ff29
commit
084566f115
|
@ -43,3 +43,8 @@ ARM_Debug/
|
|||
com.atollic*
|
||||
|
||||
/ARM_Release/
|
||||
*.sav
|
||||
*.save
|
||||
*.bak
|
||||
*.patch
|
||||
*.works
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include <stdint.h>
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
@ -158,6 +158,8 @@
|
|||
extern int reset_requested;
|
||||
extern char serial_number[25];
|
||||
extern char serial_number_64[17];
|
||||
extern uint8_t mac_address[6];
|
||||
|
||||
|
||||
#define CxxErrorHandler() _Error_Handler(const_cast<char*>(__FILE__), __LINE__)
|
||||
|
||||
|
|
|
@ -147,6 +147,8 @@ int lost_power = 0;
|
|||
int reset_requested = 0;
|
||||
char serial_number[25];
|
||||
char serial_number_64[17] = {0};
|
||||
// Make sure it is not overwritten during resets (bss3).
|
||||
uint8_t mac_address[6] __attribute__((section(".bss3"))) = {0};
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
|
|
|
@ -359,6 +359,9 @@ void print_startup_banner()
|
|||
mobilinkd::tnc::kiss::FIRMWARE_VERSION);
|
||||
INFO("CPU core clock: %luHz", SystemCoreClock);
|
||||
INFO(" Serial number: %08lX %08lX %08lX", uid[0], uid[1], uid[2]);
|
||||
INFO("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X",
|
||||
mac_address[0], mac_address[1], mac_address[2],
|
||||
mac_address[3], mac_address[4], mac_address[5])
|
||||
|
||||
uint8_t* version_ptr = (uint8_t*) 0x1FFF6FF2;
|
||||
|
||||
|
|
|
@ -485,10 +485,11 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
|
|||
reply16(hardware::GET_CAPABILITIES,
|
||||
hardware::CAP_EEPROM_SAVE|hardware::CAP_BATTERY_LEVEL|
|
||||
hardware::CAP_ADJUST_INPUT|hardware::CAP_DFU_FIRMWARE);
|
||||
reply16(hardware::GET_MIN_INPUT_GAIN, 0);
|
||||
reply16(hardware::GET_MAX_INPUT_GAIN, 4);
|
||||
reply8(hardware::GET_MIN_INPUT_TWIST, -3);
|
||||
reply8(hardware::GET_MAX_INPUT_TWIST, 9);
|
||||
reply16(hardware::GET_MIN_INPUT_GAIN, 0); // Constants for this FW
|
||||
reply16(hardware::GET_MAX_INPUT_GAIN, 4); // Constants for this FW
|
||||
reply8(hardware::GET_MIN_INPUT_TWIST, -3); // Constants for this FW
|
||||
reply8(hardware::GET_MAX_INPUT_TWIST, 9); // Constants for this FW
|
||||
reply(hardware::GET_MAC_ADDRESS, mac_address, sizeof(mac_address));
|
||||
reply(hardware::GET_DATETIME, get_rtc_datetime(), 7);
|
||||
break;
|
||||
|
||||
|
|
27
TNC/bm78.cpp
27
TNC/bm78.cpp
|
@ -76,6 +76,32 @@ void enter_program_mode()
|
|||
}
|
||||
}
|
||||
|
||||
bool read_mac_address()
|
||||
{
|
||||
// Read (cmd = 0x29) the first 6 bytes at address 0.
|
||||
uint8_t cmd[] = { 0x01, 0x29, 0xfc, 0x03, 0x00, 0x00, 0x06 };
|
||||
constexpr const uint16_t BLOCK_SIZE = 6;
|
||||
if (HAL_UART_Transmit(&huart3, cmd, sizeof(cmd), 100) != HAL_OK)
|
||||
{
|
||||
ERROR("read_mac_address transmit failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t buffer[BLOCK_SIZE + 10];
|
||||
if (HAL_UART_Receive(&huart3, buffer, sizeof(buffer), 1000) != HAL_OK)
|
||||
{
|
||||
ERROR("read_mac_address receive failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i != BLOCK_SIZE; ++i)
|
||||
{
|
||||
mac_address[5 - i] = buffer[i + 10]; // Reverse the bytes
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit BM78 EEPROM programming mode and return to pass-through mode.
|
||||
*
|
||||
|
@ -502,6 +528,7 @@ int bm78_initialize()
|
|||
enter_program_mode();
|
||||
if (!write_eeprom()) result = 1;
|
||||
else if (!write_serial()) result = 2;
|
||||
else if (!read_mac_address()) result = 3;
|
||||
exit_program_mode();
|
||||
|
||||
#if 1
|
||||
|
|
Ładowanie…
Reference in New Issue