mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-04-10 04:49:16 +02:00
added the beginning of stratum result parsing.
This commit is contained in:
parent
4a1933e185
commit
b14f21c697
@ -3,6 +3,7 @@
|
||||
|
||||
#include "cJSON.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_MERKLE_BRANCHES 32
|
||||
#define HASH_SIZE 32
|
||||
@ -25,7 +26,8 @@ typedef enum {
|
||||
STRATUM_UNKNOWN,
|
||||
MINING_NOTIFY,
|
||||
MINING_SET_DIFFICULTY,
|
||||
MINING_SET_VERSION_MASK
|
||||
MINING_SET_VERSION_MASK,
|
||||
STRATUM_RESULT
|
||||
} stratum_method;
|
||||
|
||||
void initialize_stratum_buffer();
|
||||
@ -48,6 +50,8 @@ int parse_stratum_subscribe_result_message(const char * result_json_str,
|
||||
char ** extranonce,
|
||||
int * extranonce2_len);
|
||||
|
||||
bool parse_stratum_result_message(const char * stratum_json, int16_t *);
|
||||
|
||||
int auth_to_stratum(int socket, const char * username);
|
||||
|
||||
void configure_version_rolling(int socket);
|
||||
|
@ -108,6 +108,12 @@ stratum_method parse_stratum_method(const char * stratum_json)
|
||||
} else if (strcmp("mining.set_version_mask", method_json->valuestring) == 0) {
|
||||
result = MINING_SET_VERSION_MASK;
|
||||
}
|
||||
} else {
|
||||
//parse results
|
||||
cJSON * result_json = cJSON_GetObjectItem(json, "result");
|
||||
if (result_json != NULL && cJSON_IsBool(result_json)) {
|
||||
result = STRATUM_RESULT;
|
||||
}
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
@ -144,6 +150,27 @@ uint32_t parse_mining_set_version_mask_message(const char * stratum_json)
|
||||
return version_mask;
|
||||
}
|
||||
|
||||
bool parse_stratum_result_message(const char * stratum_json, int16_t * parsed_id)
|
||||
{
|
||||
cJSON * json = cJSON_Parse(stratum_json);
|
||||
cJSON * result_json = cJSON_GetObjectItem(json, "result");
|
||||
cJSON * id_json = cJSON_GetObjectItem(json, "id");
|
||||
|
||||
if (id_json != NULL && cJSON_IsNumber(id_json)) {
|
||||
*parsed_id = id_json->valueint;
|
||||
} else {
|
||||
*parsed_id = -1;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
if (result_json != NULL && cJSON_IsTrue(result_json)) {
|
||||
result = true;
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
return result;
|
||||
}
|
||||
|
||||
mining_notify parse_mining_notify_message(const char * stratum_json)
|
||||
{
|
||||
cJSON * json = cJSON_Parse(stratum_json);
|
||||
@ -268,15 +295,6 @@ int auth_to_stratum(int socket, const char * username)
|
||||
ESP_LOGI(TAG, "-> %s", authorize_msg);
|
||||
|
||||
write(socket, authorize_msg, strlen(authorize_msg));
|
||||
/*
|
||||
// TODO: Parse authorize results
|
||||
char * line;
|
||||
line = receive_jsonrpc_line(socket);
|
||||
|
||||
ESP_LOGI(TAG, "Received result %s", line);
|
||||
|
||||
free(line);
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -289,6 +307,7 @@ void submit_share(int socket, const char * username, const char * jobid,
|
||||
send_uid++, username, jobid, extranonce_2, ntime, nonce);
|
||||
ESP_LOGI(TAG, "-> %s", submit_msg);
|
||||
write(socket, submit_msg, strlen(submit_msg));
|
||||
|
||||
}
|
||||
|
||||
int should_abandon_work(const char * mining_notify_json_str)
|
||||
|
11
main/miner.c
11
main/miner.c
@ -294,9 +294,10 @@ static void stratum_task(void * pvParameters)
|
||||
while (1)
|
||||
{
|
||||
char * line = receive_jsonrpc_line(sock);
|
||||
//ESP_LOGI(TAG, "%s", line); //debug incoming stratum messages
|
||||
ESP_LOGI(TAG, "stratum rx: %s", line); //debug incoming stratum messages
|
||||
|
||||
stratum_method method = parse_stratum_method(line);
|
||||
|
||||
if (method == MINING_NOTIFY) {
|
||||
if (should_abandon_work(line) && stratum_queue.count > 0) {
|
||||
ESP_LOGI(TAG, "Should abandon work, clearing queues");
|
||||
@ -325,6 +326,14 @@ static void stratum_task(void * pvParameters)
|
||||
|
||||
//1fffe000
|
||||
ESP_LOGI(TAG, "Set version mask: %08x", version_mask);
|
||||
|
||||
} else if (method == STRATUM_RESULT) {
|
||||
int16_t parsed_id;
|
||||
if (parse_stratum_result_message(line, &parsed_id)) {
|
||||
ESP_LOGI(TAG, "message id %d result accepted", parsed_id);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "message id %d result rejected", parsed_id);
|
||||
}
|
||||
} else {
|
||||
free(line);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user