- repair issue #5 (static IP can't connect)
- increase DMA buffer size from 1 chunk to 3 chunks settable through source code Macro CHNK_CTRL_CNT - activate OTA server Signed-off-by: Karl Osterseher <karli_o@gmx.at>
This commit is contained in:
@@ -14,7 +14,7 @@ repos:
|
|||||||
rev: v1.1.1
|
rev: v1.1.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: clang-format
|
- id: clang-format
|
||||||
args: [-i, --style=GNU]
|
args: [-i, --style=Google]
|
||||||
# args: [-i, --style=Google]
|
# args: [-i, --style=Google]
|
||||||
# - id: clang-tidy
|
# - id: clang-tidy
|
||||||
# args: [-checks=clang-diagnostic-return-type]
|
# args: [-checks=clang-diagnostic-return-type]
|
||||||
|
|||||||
@@ -9,36 +9,28 @@
|
|||||||
|
|
||||||
#define I2S_PORT I2S_NUM_0
|
#define I2S_PORT I2S_NUM_0
|
||||||
|
|
||||||
#define LATENCY_MEDIAN_FILTER_LEN 29 // 99
|
#define CHNK_CTRL_CNT 3
|
||||||
|
|
||||||
|
#define LATENCY_MEDIAN_FILTER_LEN 29 // 99
|
||||||
|
|
||||||
#define SHORT_BUFFER_LEN 9
|
#define SHORT_BUFFER_LEN 9
|
||||||
|
|
||||||
typedef struct pcm_chunk_fragment pcm_chunk_fragment_t;
|
typedef struct pcm_chunk_fragment pcm_chunk_fragment_t;
|
||||||
struct pcm_chunk_fragment
|
struct pcm_chunk_fragment {
|
||||||
{
|
|
||||||
size_t size;
|
size_t size;
|
||||||
char *payload;
|
char *payload;
|
||||||
pcm_chunk_fragment_t *nextFragment;
|
pcm_chunk_fragment_t *nextFragment;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct pcmData
|
typedef struct pcmData {
|
||||||
{
|
|
||||||
tv_t timestamp;
|
tv_t timestamp;
|
||||||
uint32_t totalSize;
|
uint32_t totalSize;
|
||||||
pcm_chunk_fragment_t *fragment;
|
pcm_chunk_fragment_t *fragment;
|
||||||
} pcm_chunk_message_t;
|
} pcm_chunk_message_t;
|
||||||
|
|
||||||
typedef enum codec_type_e
|
typedef enum codec_type_e { NONE = 0, PCM, FLAC, OGG, OPUS } codec_type_t;
|
||||||
{
|
|
||||||
NONE = 0,
|
|
||||||
PCM,
|
|
||||||
FLAC,
|
|
||||||
OGG,
|
|
||||||
OPUS
|
|
||||||
} codec_type_t;
|
|
||||||
|
|
||||||
typedef struct snapcastSetting_s
|
typedef struct snapcastSetting_s {
|
||||||
{
|
|
||||||
uint32_t buf_ms;
|
uint32_t buf_ms;
|
||||||
uint32_t chkDur_ms;
|
uint32_t chkDur_ms;
|
||||||
int32_t cDacLat_ms;
|
int32_t cDacLat_ms;
|
||||||
@@ -55,22 +47,21 @@ typedef struct snapcastSetting_s
|
|||||||
uint32_t pcmBufSize;
|
uint32_t pcmBufSize;
|
||||||
} snapcastSetting_t;
|
} snapcastSetting_t;
|
||||||
|
|
||||||
int init_player (void);
|
int init_player(void);
|
||||||
int deinit_player (void);
|
int deinit_player(void);
|
||||||
|
|
||||||
int8_t allocate_pcm_chunk_memory (pcm_chunk_message_t **pcmChunk,
|
int8_t allocate_pcm_chunk_memory(pcm_chunk_message_t **pcmChunk, size_t bytes);
|
||||||
size_t bytes);
|
int8_t insert_pcm_chunk(pcm_chunk_message_t *pcmChunk);
|
||||||
int8_t insert_pcm_chunk (pcm_chunk_message_t *pcmChunk);
|
|
||||||
|
|
||||||
// int8_t insert_pcm_chunk (wire_chunk_message_t *decodedWireChunk);
|
// int8_t insert_pcm_chunk (wire_chunk_message_t *decodedWireChunk);
|
||||||
int8_t free_pcm_chunk (pcm_chunk_message_t *pcmChunk);
|
int8_t free_pcm_chunk(pcm_chunk_message_t *pcmChunk);
|
||||||
|
|
||||||
int8_t player_latency_insert (int64_t newValue);
|
int8_t player_latency_insert(int64_t newValue);
|
||||||
int8_t player_send_snapcast_setting (snapcastSetting_t *setting);
|
int8_t player_send_snapcast_setting(snapcastSetting_t *setting);
|
||||||
|
|
||||||
int8_t reset_latency_buffer (void);
|
int8_t reset_latency_buffer(void);
|
||||||
int8_t latency_buffer_full (void);
|
int8_t latency_buffer_full(void);
|
||||||
int8_t get_diff_to_server (int64_t *tDiff);
|
int8_t get_diff_to_server(int64_t *tDiff);
|
||||||
int8_t server_now (int64_t *sNow);
|
int8_t server_now(int64_t *sNow);
|
||||||
|
|
||||||
#endif // __PLAYER_H__
|
#endif // __PLAYER_H__
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -30,17 +30,15 @@ EventGroupHandle_t ota_event_group;
|
|||||||
/*socket*/
|
/*socket*/
|
||||||
static int connect_socket = 0;
|
static int connect_socket = 0;
|
||||||
|
|
||||||
void
|
void ota_server_task(void *param) {
|
||||||
ota_server_task (void *param)
|
|
||||||
{
|
|
||||||
// xEventGroupWaitBits(ota_event_group, OTA_CONNECTED_BIT, false, true,
|
// xEventGroupWaitBits(ota_event_group, OTA_CONNECTED_BIT, false, true,
|
||||||
// portMAX_DELAY);
|
// portMAX_DELAY);
|
||||||
|
|
||||||
// TODO: find a god place to verify app is working properly after OTA
|
// TODO: find a good place to verify app is working properly after OTA
|
||||||
esp_ota_mark_app_valid_cancel_rollback ();
|
esp_ota_mark_app_valid_cancel_rollback();
|
||||||
|
|
||||||
ota_server_start_my ();
|
ota_server_start_my();
|
||||||
vTaskDelete (NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -87,207 +85,177 @@ void initialise_wifi(void)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int get_socket_error_code(int socket) {
|
||||||
get_socket_error_code (int socket)
|
|
||||||
{
|
|
||||||
int result;
|
int result;
|
||||||
u32_t optlen = sizeof (int);
|
u32_t optlen = sizeof(int);
|
||||||
|
|
||||||
int err = getsockopt (socket, SOL_SOCKET, SO_ERROR, &result, &optlen);
|
int err = getsockopt(socket, SOL_SOCKET, SO_ERROR, &result, &optlen);
|
||||||
|
|
||||||
if (err == -1)
|
if (err == -1) {
|
||||||
{
|
ESP_LOGE(TAG, "getsockopt failed:%s", strerror(err));
|
||||||
ESP_LOGE (TAG, "getsockopt failed:%s", strerror (err));
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int show_socket_error_reason(const char *str, int socket) {
|
||||||
show_socket_error_reason (const char *str, int socket)
|
int err = get_socket_error_code(socket);
|
||||||
{
|
|
||||||
int err = get_socket_error_code (socket);
|
|
||||||
|
|
||||||
if (err != 0)
|
if (err != 0) {
|
||||||
{
|
ESP_LOGW(TAG, "%s socket error %d %s", str, err, strerror(err));
|
||||||
ESP_LOGW (TAG, "%s socket error %d %s", str, err, strerror (err));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t
|
static esp_err_t create_tcp_server() {
|
||||||
create_tcp_server ()
|
ESP_LOGI(TAG,
|
||||||
{
|
"idf.py build ; curl snapclient.local:%d --data-binary @- < "
|
||||||
ESP_LOGI (TAG,
|
"build/snapclient.bin",
|
||||||
"idf.py build ; curl snapclient.local:%d --data-binary @- < "
|
OTA_LISTEN_PORT);
|
||||||
"build/snapclient.bin",
|
|
||||||
OTA_LISTEN_PORT);
|
|
||||||
int server_socket = 0;
|
int server_socket = 0;
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
server_socket = socket (AF_INET, SOCK_STREAM, 0);
|
server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
if (server_socket < 0)
|
if (server_socket < 0) {
|
||||||
{
|
show_socket_error_reason("create_server", server_socket);
|
||||||
show_socket_error_reason ("create_server", server_socket);
|
return ESP_FAIL;
|
||||||
return ESP_FAIL;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
server_addr.sin_family = AF_INET;
|
server_addr.sin_family = AF_INET;
|
||||||
server_addr.sin_port = htons (OTA_LISTEN_PORT);
|
server_addr.sin_port = htons(OTA_LISTEN_PORT);
|
||||||
server_addr.sin_addr.s_addr = htonl (INADDR_ANY);
|
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
if (bind (server_socket, (struct sockaddr *)&server_addr,
|
if (bind(server_socket, (struct sockaddr *)&server_addr,
|
||||||
sizeof (server_addr))
|
sizeof(server_addr)) < 0) {
|
||||||
< 0)
|
show_socket_error_reason("bind_server", server_socket);
|
||||||
{
|
close(server_socket);
|
||||||
show_socket_error_reason ("bind_server", server_socket);
|
return ESP_FAIL;
|
||||||
close (server_socket);
|
}
|
||||||
return ESP_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (listen (server_socket, 5) < 0)
|
if (listen(server_socket, 5) < 0) {
|
||||||
{
|
show_socket_error_reason("listen_server", server_socket);
|
||||||
show_socket_error_reason ("listen_server", server_socket);
|
close(server_socket);
|
||||||
close (server_socket);
|
return ESP_FAIL;
|
||||||
return ESP_FAIL;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_in client_addr;
|
struct sockaddr_in client_addr;
|
||||||
unsigned int socklen = sizeof (client_addr);
|
unsigned int socklen = sizeof(client_addr);
|
||||||
connect_socket
|
connect_socket =
|
||||||
= accept (server_socket, (struct sockaddr *)&client_addr, &socklen);
|
accept(server_socket, (struct sockaddr *)&client_addr, &socklen);
|
||||||
|
|
||||||
if (connect_socket < 0)
|
if (connect_socket < 0) {
|
||||||
{
|
show_socket_error_reason("accept_server", connect_socket);
|
||||||
show_socket_error_reason ("accept_server", connect_socket);
|
close(server_socket);
|
||||||
close (server_socket);
|
return ESP_FAIL;
|
||||||
return ESP_FAIL;
|
}
|
||||||
}
|
|
||||||
/*connection established,now can send/recv*/
|
/*connection established,now can send/recv*/
|
||||||
ESP_LOGI (TAG, "tcp connection established!");
|
ESP_LOGI(TAG, "tcp connection established!");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void ota_server_start_my(void) {
|
||||||
ota_server_start_my (void)
|
|
||||||
{
|
|
||||||
uint8_t percent_loaded;
|
uint8_t percent_loaded;
|
||||||
uint8_t old_percent_loaded;
|
uint8_t old_percent_loaded;
|
||||||
|
|
||||||
ESP_ERROR_CHECK (create_tcp_server ());
|
ESP_ERROR_CHECK(create_tcp_server());
|
||||||
|
|
||||||
const esp_partition_t *update_partition
|
const esp_partition_t *update_partition =
|
||||||
= esp_ota_get_next_update_partition (NULL);
|
esp_ota_get_next_update_partition(NULL);
|
||||||
|
|
||||||
ESP_LOGI (TAG, "Writing to partition subtype %d at offset 0x%x",
|
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x",
|
||||||
update_partition->subtype, update_partition->address);
|
update_partition->subtype, update_partition->address);
|
||||||
|
|
||||||
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/log.html
|
// https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/log.html
|
||||||
// I don't want to see all the Log esp_image stuff while its flashing it
|
// I don't want to see all the Log esp_image stuff while its flashing it
|
||||||
esp_log_level_set (
|
esp_log_level_set(
|
||||||
"esp_image",
|
"esp_image",
|
||||||
ESP_LOG_ERROR); // set all components to ERROR level ESP_LOG_NONE
|
ESP_LOG_ERROR); // set all components to ERROR level ESP_LOG_NONE
|
||||||
|
|
||||||
// We don't want any other thread running during this update.
|
// We don't want any other thread running during this update.
|
||||||
// SuspendAllThreads();
|
// SuspendAllThreads();
|
||||||
// KillAllThreads();
|
// KillAllThreads();
|
||||||
// dsp_i2s_task_deinit();
|
// dsp_i2s_task_deinit();
|
||||||
vTaskDelete (t_http_get_task);
|
vTaskDelete(t_http_get_task);
|
||||||
deinit_player (); // ensure this is called after http_task was killed
|
deinit_player(); // ensure this is called after http_task was killed
|
||||||
|
|
||||||
int recv_len;
|
int recv_len;
|
||||||
char ota_buff[OTA_BUFF_SIZE] = { 0 };
|
char ota_buff[OTA_BUFF_SIZE] = {0};
|
||||||
bool is_req_body_started = false;
|
bool is_req_body_started = false;
|
||||||
int content_length = -1;
|
int content_length = -1;
|
||||||
int content_received = 0;
|
int content_received = 0;
|
||||||
|
|
||||||
esp_ota_handle_t ota_handle;
|
esp_ota_handle_t ota_handle;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
// ESP_LOGW (TAG, "stack free: %d",
|
||||||
// ESP_LOGW (TAG, "stack free: %d",
|
// uxTaskGetStackHighWaterMark(NULL));
|
||||||
// uxTaskGetStackHighWaterMark(NULL));
|
|
||||||
|
|
||||||
recv_len = recv (connect_socket, ota_buff, OTA_BUFF_SIZE, 0);
|
recv_len = recv(connect_socket, ota_buff, OTA_BUFF_SIZE, 0);
|
||||||
|
|
||||||
if (recv_len > 0)
|
if (recv_len > 0) {
|
||||||
{
|
if (!is_req_body_started) {
|
||||||
if (!is_req_body_started)
|
const char *content_length_start = "Content-Length: ";
|
||||||
{
|
char *content_length_start_p = strstr(ota_buff, content_length_start) +
|
||||||
const char *content_length_start = "Content-Length: ";
|
strlen(content_length_start);
|
||||||
char *content_length_start_p
|
sscanf(content_length_start_p, "%d", &content_length);
|
||||||
= strstr (ota_buff, content_length_start)
|
ESP_LOGI(TAG, "Detected content length: %d", content_length);
|
||||||
+ strlen (content_length_start);
|
ESP_ERROR_CHECK(
|
||||||
sscanf (content_length_start_p, "%d", &content_length);
|
esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &ota_handle));
|
||||||
ESP_LOGI (TAG, "Detected content length: %d", content_length);
|
const char *header_end = "\r\n\r\n";
|
||||||
ESP_ERROR_CHECK (esp_ota_begin (update_partition,
|
char *body_start_p = strstr(ota_buff, header_end) + strlen(header_end);
|
||||||
OTA_SIZE_UNKNOWN, &ota_handle));
|
int body_part_len = recv_len - (body_start_p - ota_buff);
|
||||||
const char *header_end = "\r\n\r\n";
|
esp_ota_write(ota_handle, body_start_p, body_part_len);
|
||||||
char *body_start_p
|
content_received += body_part_len;
|
||||||
= strstr (ota_buff, header_end) + strlen (header_end);
|
is_req_body_started = true;
|
||||||
int body_part_len = recv_len - (body_start_p - ota_buff);
|
} else {
|
||||||
esp_ota_write (ota_handle, body_start_p, body_part_len);
|
esp_ota_write(ota_handle, ota_buff, recv_len);
|
||||||
content_received += body_part_len;
|
content_received += recv_len;
|
||||||
is_req_body_started = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
esp_ota_write (ota_handle, ota_buff, recv_len);
|
|
||||||
content_received += recv_len;
|
|
||||||
|
|
||||||
percent_loaded
|
percent_loaded =
|
||||||
= (((float)content_received / (float)content_length)
|
(((float)content_received / (float)content_length) * 100.00);
|
||||||
* 100.00);
|
if ((percent_loaded % 10 == 0) &
|
||||||
if ((percent_loaded % 10 == 0)
|
(percent_loaded != old_percent_loaded)) {
|
||||||
& (percent_loaded != old_percent_loaded))
|
old_percent_loaded = percent_loaded;
|
||||||
{
|
ESP_LOGI(TAG, "Uploaded %03u%%", percent_loaded);
|
||||||
old_percent_loaded = percent_loaded;
|
|
||||||
ESP_LOGI (TAG, "Uploaded %03u%%", percent_loaded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (recv_len < 0)
|
|
||||||
{
|
|
||||||
ESP_LOGI (TAG, "Error: recv data error! errno=%d", errno);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else if (recv_len < 0) {
|
||||||
|
ESP_LOGI(TAG, "Error: recv data error! errno=%d", errno);
|
||||||
}
|
}
|
||||||
while (recv_len > 0 && content_received < content_length);
|
} while (recv_len > 0 && content_received < content_length);
|
||||||
|
|
||||||
ESP_LOGI (TAG, "OTA Transferred Finished: %d bytes", content_received);
|
ESP_LOGI(TAG, "OTA Transferred Finished: %d bytes", content_received);
|
||||||
|
|
||||||
char res_buff[128];
|
char res_buff[128];
|
||||||
int send_len;
|
int send_len;
|
||||||
send_len = sprintf (res_buff, "200 OK\n\n");
|
send_len = sprintf(res_buff, "200 OK\n\n");
|
||||||
send (connect_socket, res_buff, send_len, 0);
|
send(connect_socket, res_buff, send_len, 0);
|
||||||
vTaskDelay (2000 / portTICK_PERIOD_MS);
|
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||||
close (connect_socket);
|
close(connect_socket);
|
||||||
|
|
||||||
ESP_ERROR_CHECK (esp_ota_end (ota_handle));
|
ESP_ERROR_CHECK(esp_ota_end(ota_handle));
|
||||||
|
|
||||||
esp_err_t err = esp_ota_set_boot_partition (update_partition);
|
esp_err_t err = esp_ota_set_boot_partition(update_partition);
|
||||||
|
|
||||||
if (err == ESP_OK)
|
if (err == ESP_OK) {
|
||||||
{
|
const esp_partition_t *boot_partition = esp_ota_get_boot_partition();
|
||||||
const esp_partition_t *boot_partition = esp_ota_get_boot_partition ();
|
|
||||||
|
|
||||||
ESP_LOGI (TAG,
|
ESP_LOGI(TAG,
|
||||||
"***********************************************************");
|
"***********************************************************");
|
||||||
ESP_LOGI (TAG, "OTA Successful");
|
ESP_LOGI(TAG, "OTA Successful");
|
||||||
ESP_LOGI (TAG, "Next Boot Partition Subtype %d At Offset 0x%x",
|
ESP_LOGI(TAG, "Next Boot Partition Subtype %d At Offset 0x%x",
|
||||||
boot_partition->subtype, boot_partition->address);
|
boot_partition->subtype, boot_partition->address);
|
||||||
ESP_LOGI (TAG,
|
ESP_LOGI(TAG,
|
||||||
"***********************************************************");
|
"***********************************************************");
|
||||||
}
|
} else {
|
||||||
else
|
ESP_LOGI(TAG, "!!! OTA Failed !!!");
|
||||||
{
|
}
|
||||||
ESP_LOGI (TAG, "!!! OTA Failed !!!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// for (int x = 2; x >= 1; x--)
|
// for (int x = 2; x >= 1; x--)
|
||||||
//{
|
//{
|
||||||
ESP_LOGI (TAG, "Prepare to restart system..");
|
ESP_LOGI(TAG, "Prepare to restart system..");
|
||||||
vTaskDelay (1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
esp_restart ();
|
esp_restart();
|
||||||
}
|
}
|
||||||
|
|||||||
6386
main/main.c
6386
main/main.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user