mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-06-27 21:01:16 +02:00
* Code clean resulting from looking into #218 * Fixed asic count Set canary value for invalid device's asic_count --------- Co-authored-by: tommy <tommy@tommywatson.com>
This commit is contained in:
parent
344c5d8d22
commit
00a3a0ba3d
@ -150,8 +150,10 @@ esp_netif_t * wifi_init_sta(const char * wifi_ssid, const char * wifi_pass)
|
||||
// .sae_h2e_identifier = EXAMPLE_H2E_IDENTIFIER,
|
||||
},
|
||||
};
|
||||
strncpy((char *) wifi_sta_config.sta.ssid, wifi_ssid, 31);
|
||||
wifi_sta_config.sta.ssid[31] = '\0';
|
||||
strncpy((char *) wifi_sta_config.sta.ssid,
|
||||
wifi_ssid,
|
||||
sizeof(wifi_sta_config.sta.ssid));
|
||||
wifi_sta_config.sta.ssid[sizeof(wifi_sta_config.sta.ssid) - 1] = '\0';
|
||||
strncpy((char *) wifi_sta_config.sta.password, wifi_pass, 63);
|
||||
wifi_sta_config.sta.password[63] = '\0';
|
||||
|
||||
@ -214,4 +216,4 @@ EventBits_t wifi_connect(void)
|
||||
* happened. */
|
||||
|
||||
return bits;
|
||||
}
|
||||
}
|
||||
|
@ -20,14 +20,16 @@
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DEVICE_MAX = 0,
|
||||
DEVICE_UNKNOWN = -1,
|
||||
DEVICE_MAX,
|
||||
DEVICE_ULTRA,
|
||||
DEVICE_SUPRA,
|
||||
} DeviceModel;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ASIC_BM1397 = 0,
|
||||
ASIC_UNKNOWN = -1,
|
||||
ASIC_BM1397,
|
||||
ASIC_BM1366,
|
||||
ASIC_BM1368,
|
||||
} AsicModel;
|
||||
@ -60,7 +62,7 @@ typedef struct
|
||||
char best_session_diff_string[DIFF_STRING_SIZE];
|
||||
bool FOUND_BLOCK;
|
||||
bool startup_done;
|
||||
char ssid[20];
|
||||
char ssid[32];
|
||||
char wifi_status[20];
|
||||
char * pool_url;
|
||||
uint16_t pool_port;
|
||||
@ -103,4 +105,4 @@ typedef struct
|
||||
|
||||
} GlobalState;
|
||||
|
||||
#endif /* GLOBAL_STATE_H_ */
|
||||
#endif /* GLOBAL_STATE_H_ */
|
||||
|
@ -354,7 +354,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
|
||||
char * hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, CONFIG_LWIP_LOCAL_HOSTNAME);
|
||||
char * stratumURL = nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL);
|
||||
char * stratumUser = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER);
|
||||
char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, 'unknown');
|
||||
char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "unknown");
|
||||
|
||||
cJSON * root = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(root, "power", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power);
|
||||
@ -389,6 +389,10 @@ static esp_err_t GET_system_info(httpd_req_t * req)
|
||||
case ASIC_BM1368:
|
||||
core_count = BM1368_CORE_COUNT;
|
||||
break;
|
||||
case ASIC_UNKNOWN:
|
||||
default:
|
||||
core_count = -1;
|
||||
break;
|
||||
}
|
||||
cJSON_AddNumberToObject(root, "coreCount", core_count);
|
||||
cJSON_AddStringToObject(root, "ASICModel", GLOBAL_STATE->asic_model_str);
|
||||
|
@ -47,6 +47,10 @@ void app_main(void)
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Invalid DEVICE model");
|
||||
// maybe should return here to now execute anything with a faulty device parameter !
|
||||
// this stops crashes/reboots and allows dev testing without an asic
|
||||
GLOBAL_STATE.device_model = DEVICE_UNKNOWN;
|
||||
GLOBAL_STATE.asic_count = -1;
|
||||
GLOBAL_STATE.voltage_domain = 1;
|
||||
}
|
||||
GLOBAL_STATE.board_version = atoi(nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "000"));
|
||||
ESP_LOGI(TAG, "Found Device Model: %s", GLOBAL_STATE.device_model_str);
|
||||
@ -122,7 +126,10 @@ void app_main(void)
|
||||
char * hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, HOSTNAME);
|
||||
|
||||
// copy the wifi ssid to the global state
|
||||
strncpy(GLOBAL_STATE.SYSTEM_MODULE.ssid, wifi_ssid, 20);
|
||||
strncpy(GLOBAL_STATE.SYSTEM_MODULE.ssid,
|
||||
wifi_ssid,
|
||||
sizeof(GLOBAL_STATE.SYSTEM_MODULE.ssid));
|
||||
GLOBAL_STATE.SYSTEM_MODULE.ssid[sizeof(GLOBAL_STATE.SYSTEM_MODULE.ssid)-1] = 0;
|
||||
|
||||
// init and connect to wifi
|
||||
wifi_init(wifi_ssid, wifi_pass, hostname);
|
||||
|
@ -213,7 +213,7 @@ int OLED_setPixel(int x, int y, uint8_t ucColor)
|
||||
// The X position is in character widths (8 or 16)
|
||||
// The Y position is in memory pages (8 lines each)
|
||||
//
|
||||
int OLED_writeString(int x, int y, char * szMsg)
|
||||
int OLED_writeString(int x, int y, const char * szMsg)
|
||||
{
|
||||
int i, iLen;
|
||||
uint8_t * s;
|
||||
@ -286,4 +286,4 @@ static esp_err_t write(uint8_t * data, uint8_t len)
|
||||
ret = i2c_master_write_to_device(I2C_MASTER_NUM, 0x3C, data, len, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ int OLED_fill(uint8_t ucPattern);
|
||||
|
||||
// Write a text string to the display at x (column 0-127) and y (row 0-7)
|
||||
// bLarge = 0 - 8x8 font, bLarge = 1 - 16x24 font
|
||||
int OLED_writeString(int x, int y, char *szText);
|
||||
int OLED_writeString(int x, int y, const char *szText);
|
||||
|
||||
// Sets a pixel to On (1) or Off (0)
|
||||
// Coordinate system is pixels, not text rows (0-127, 0-63)
|
||||
|
@ -70,7 +70,7 @@ static void _init_system(GlobalState * GLOBAL_STATE)
|
||||
_suffix_string(module->best_session_nonce_diff, module->best_session_diff_string, DIFF_STRING_SIZE, 0);
|
||||
|
||||
// set the ssid string to blank
|
||||
memset(module->ssid, 0, 20);
|
||||
memset(module->ssid, 0, sizeof(module->ssid));
|
||||
|
||||
// set the wifi_status to blank
|
||||
memset(module->wifi_status, 0, 20);
|
||||
@ -293,8 +293,8 @@ static void _update_connection(GlobalState * GLOBAL_STATE)
|
||||
case DEVICE_SUPRA:
|
||||
if (OLED_status()) {
|
||||
OLED_clearLine(2);
|
||||
memset(module->oled_buf, 0, 20);
|
||||
snprintf(module->oled_buf, 20, "%s", module->ssid);
|
||||
strncpy(module->oled_buf, module->ssid, sizeof(module->oled_buf));
|
||||
module->oled_buf[sizeof(module->oled_buf) - 1] = 0;
|
||||
OLED_writeString(0, 1, module->oled_buf);
|
||||
|
||||
memset(module->oled_buf, 0, 20);
|
||||
@ -470,9 +470,6 @@ void SYSTEM_task(void * pvParameters)
|
||||
_clear_display(GLOBAL_STATE);
|
||||
_init_connection(GLOBAL_STATE);
|
||||
|
||||
wifi_mode_t wifi_mode;
|
||||
esp_err_t result;
|
||||
|
||||
char input_event[10];
|
||||
ESP_LOGI(TAG, "SYSTEM_task started");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user