Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries if the stratum hostname is not found #28

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions components/bm1397/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,22 @@ static void _send_read_address(void)
unsigned char read_address[2] = {0x00, 0x00};
// send serial data
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_READ), read_address, 2, false);

int received = SERIAL_rx(asic_response_buffer, 9, 500);

if (received == 9)
{
//verify the chip ID
if ((asic_response_buffer[2] == 0x13) && (asic_response_buffer[3] == 0x97))
{
ESP_LOGI(TAG, "BM1397 Detected!!!!");
return true;
}
}

ESP_LOGE(TAG, "Fail to receive the chip ID");

return false;
}

void BM1397_init(u_int64_t frequency)
Expand All @@ -275,11 +291,13 @@ void BM1397_init(u_int64_t frequency)
esp_rom_gpio_pad_select_gpio(BM1397_RST_PIN);
gpio_set_direction(BM1397_RST_PIN, GPIO_MODE_OUTPUT);

// reset the bm1397
_reset();
//verify if the BM1397 is prenset
do{
//reset the bm1397
_reset();

// send the init command
_send_read_address();
//send the init command
} while(false==_send_read_address());

_send_init(frequency);
}
Expand Down
32 changes: 26 additions & 6 deletions main/tasks/stratum_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static const char *TAG = "stratum_task";
static ip_addr_t ip_Addr;
static bool bDNSFound = false;
static int8_t bDNSFound = 0;

static StratumApiV1Message stratum_api_v1_message = {};

Expand All @@ -27,8 +27,16 @@ static SystemTaskModule SYSTEM_TASK_MODULE = {

void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg)
{
ip_Addr = *ipaddr;
bDNSFound = true;
if (ipaddr != NULL)
{
ip_Addr = *ipaddr;
bDNSFound = 1;
}
else
{
// it fails to solve the DNS
bDNSFound = -1;
}
}

void stratum_task(void *pvParameters)
Expand All @@ -46,16 +54,28 @@ void stratum_task(void *pvParameters)
// check to see if the STRATUM_URL is an ip address already
if (inet_pton(AF_INET, stratum_url, &ip_Addr) == 1)
{
bDNSFound = true;
bDNSFound = 1;
}
else
{
// it's a hostname. Lookup the ip address.
IP_ADDR4(&ip_Addr, 0, 0, 0, 0);
ESP_LOGI(TAG, "Get IP for URL: %s\n", stratum_url);
dns_gethostbyname(stratum_url, &ip_Addr, dns_found_cb, NULL);
while (!bDNSFound)
;
while (true)
{
vTaskDelay(500 / portTICK_PERIOD_MS);

// try again
if (bDNSFound == -1)
{
bDNSFound = 0;
dns_gethostbyname(stratum_url, &ip_Addr, dns_found_cb, NULL);
}

if (bDNSFound == 1)
break;
}
}

// make IP address string from ip_Addr
Expand Down