- 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
|
||||
hooks:
|
||||
- id: clang-format
|
||||
args: [-i, --style=GNU]
|
||||
args: [-i, --style=Google]
|
||||
# args: [-i, --style=Google]
|
||||
# - id: clang-tidy
|
||||
# args: [-checks=clang-diagnostic-return-type]
|
||||
|
||||
@@ -9,36 +9,28 @@
|
||||
|
||||
#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
|
||||
|
||||
typedef struct pcm_chunk_fragment pcm_chunk_fragment_t;
|
||||
struct pcm_chunk_fragment
|
||||
{
|
||||
struct pcm_chunk_fragment {
|
||||
size_t size;
|
||||
char *payload;
|
||||
pcm_chunk_fragment_t *nextFragment;
|
||||
};
|
||||
|
||||
typedef struct pcmData
|
||||
{
|
||||
typedef struct pcmData {
|
||||
tv_t timestamp;
|
||||
uint32_t totalSize;
|
||||
pcm_chunk_fragment_t *fragment;
|
||||
} pcm_chunk_message_t;
|
||||
|
||||
typedef enum codec_type_e
|
||||
{
|
||||
NONE = 0,
|
||||
PCM,
|
||||
FLAC,
|
||||
OGG,
|
||||
OPUS
|
||||
} codec_type_t;
|
||||
typedef enum codec_type_e { NONE = 0, PCM, FLAC, OGG, OPUS } codec_type_t;
|
||||
|
||||
typedef struct snapcastSetting_s
|
||||
{
|
||||
typedef struct snapcastSetting_s {
|
||||
uint32_t buf_ms;
|
||||
uint32_t chkDur_ms;
|
||||
int32_t cDacLat_ms;
|
||||
@@ -55,22 +47,21 @@ typedef struct snapcastSetting_s
|
||||
uint32_t pcmBufSize;
|
||||
} snapcastSetting_t;
|
||||
|
||||
int init_player (void);
|
||||
int deinit_player (void);
|
||||
int init_player(void);
|
||||
int deinit_player(void);
|
||||
|
||||
int8_t allocate_pcm_chunk_memory (pcm_chunk_message_t **pcmChunk,
|
||||
size_t bytes);
|
||||
int8_t insert_pcm_chunk (pcm_chunk_message_t *pcmChunk);
|
||||
int8_t allocate_pcm_chunk_memory(pcm_chunk_message_t **pcmChunk, size_t bytes);
|
||||
int8_t insert_pcm_chunk(pcm_chunk_message_t *pcmChunk);
|
||||
|
||||
// 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_send_snapcast_setting (snapcastSetting_t *setting);
|
||||
int8_t player_latency_insert(int64_t newValue);
|
||||
int8_t player_send_snapcast_setting(snapcastSetting_t *setting);
|
||||
|
||||
int8_t reset_latency_buffer (void);
|
||||
int8_t latency_buffer_full (void);
|
||||
int8_t get_diff_to_server (int64_t *tDiff);
|
||||
int8_t server_now (int64_t *sNow);
|
||||
int8_t reset_latency_buffer(void);
|
||||
int8_t latency_buffer_full(void);
|
||||
int8_t get_diff_to_server(int64_t *tDiff);
|
||||
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*/
|
||||
static int connect_socket = 0;
|
||||
|
||||
void
|
||||
ota_server_task (void *param)
|
||||
{
|
||||
void ota_server_task(void *param) {
|
||||
// xEventGroupWaitBits(ota_event_group, OTA_CONNECTED_BIT, false, true,
|
||||
// portMAX_DELAY);
|
||||
|
||||
// TODO: find a god place to verify app is working properly after OTA
|
||||
esp_ota_mark_app_valid_cancel_rollback ();
|
||||
// TODO: find a good place to verify app is working properly after OTA
|
||||
esp_ota_mark_app_valid_cancel_rollback();
|
||||
|
||||
ota_server_start_my ();
|
||||
vTaskDelete (NULL);
|
||||
ota_server_start_my();
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -87,207 +85,177 @@ void initialise_wifi(void)
|
||||
}
|
||||
*/
|
||||
|
||||
static int
|
||||
get_socket_error_code (int socket)
|
||||
{
|
||||
static int get_socket_error_code(int socket) {
|
||||
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)
|
||||
{
|
||||
ESP_LOGE (TAG, "getsockopt failed:%s", strerror (err));
|
||||
return -1;
|
||||
}
|
||||
if (err == -1) {
|
||||
ESP_LOGE(TAG, "getsockopt failed:%s", strerror(err));
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
show_socket_error_reason (const char *str, int socket)
|
||||
{
|
||||
int err = get_socket_error_code (socket);
|
||||
static int show_socket_error_reason(const char *str, int socket) {
|
||||
int err = get_socket_error_code(socket);
|
||||
|
||||
if (err != 0)
|
||||
{
|
||||
ESP_LOGW (TAG, "%s socket error %d %s", str, err, strerror (err));
|
||||
}
|
||||
if (err != 0) {
|
||||
ESP_LOGW(TAG, "%s socket error %d %s", str, err, strerror(err));
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t
|
||||
create_tcp_server ()
|
||||
{
|
||||
ESP_LOGI (TAG,
|
||||
"idf.py build ; curl snapclient.local:%d --data-binary @- < "
|
||||
"build/snapclient.bin",
|
||||
OTA_LISTEN_PORT);
|
||||
static esp_err_t create_tcp_server() {
|
||||
ESP_LOGI(TAG,
|
||||
"idf.py build ; curl snapclient.local:%d --data-binary @- < "
|
||||
"build/snapclient.bin",
|
||||
OTA_LISTEN_PORT);
|
||||
int server_socket = 0;
|
||||
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)
|
||||
{
|
||||
show_socket_error_reason ("create_server", server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
if (server_socket < 0) {
|
||||
show_socket_error_reason("create_server", server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_port = htons (OTA_LISTEN_PORT);
|
||||
server_addr.sin_addr.s_addr = htonl (INADDR_ANY);
|
||||
if (bind (server_socket, (struct sockaddr *)&server_addr,
|
||||
sizeof (server_addr))
|
||||
< 0)
|
||||
{
|
||||
show_socket_error_reason ("bind_server", server_socket);
|
||||
close (server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
server_addr.sin_port = htons(OTA_LISTEN_PORT);
|
||||
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (bind(server_socket, (struct sockaddr *)&server_addr,
|
||||
sizeof(server_addr)) < 0) {
|
||||
show_socket_error_reason("bind_server", server_socket);
|
||||
close(server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (listen (server_socket, 5) < 0)
|
||||
{
|
||||
show_socket_error_reason ("listen_server", server_socket);
|
||||
close (server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
if (listen(server_socket, 5) < 0) {
|
||||
show_socket_error_reason("listen_server", server_socket);
|
||||
close(server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
struct sockaddr_in client_addr;
|
||||
unsigned int socklen = sizeof (client_addr);
|
||||
connect_socket
|
||||
= accept (server_socket, (struct sockaddr *)&client_addr, &socklen);
|
||||
unsigned int socklen = sizeof(client_addr);
|
||||
connect_socket =
|
||||
accept(server_socket, (struct sockaddr *)&client_addr, &socklen);
|
||||
|
||||
if (connect_socket < 0)
|
||||
{
|
||||
show_socket_error_reason ("accept_server", connect_socket);
|
||||
close (server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
if (connect_socket < 0) {
|
||||
show_socket_error_reason("accept_server", connect_socket);
|
||||
close(server_socket);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
/*connection established,now can send/recv*/
|
||||
ESP_LOGI (TAG, "tcp connection established!");
|
||||
ESP_LOGI(TAG, "tcp connection established!");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ota_server_start_my (void)
|
||||
{
|
||||
void ota_server_start_my(void) {
|
||||
uint8_t 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
|
||||
= esp_ota_get_next_update_partition (NULL);
|
||||
const esp_partition_t *update_partition =
|
||||
esp_ota_get_next_update_partition(NULL);
|
||||
|
||||
ESP_LOGI (TAG, "Writing to partition subtype %d at offset 0x%x",
|
||||
update_partition->subtype, update_partition->address);
|
||||
ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x",
|
||||
update_partition->subtype, update_partition->address);
|
||||
|
||||
// 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
|
||||
esp_log_level_set (
|
||||
esp_log_level_set(
|
||||
"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.
|
||||
// SuspendAllThreads();
|
||||
// KillAllThreads();
|
||||
// dsp_i2s_task_deinit();
|
||||
vTaskDelete (t_http_get_task);
|
||||
deinit_player (); // ensure this is called after http_task was killed
|
||||
vTaskDelete(t_http_get_task);
|
||||
deinit_player(); // ensure this is called after http_task was killed
|
||||
|
||||
int recv_len;
|
||||
char ota_buff[OTA_BUFF_SIZE] = { 0 };
|
||||
char ota_buff[OTA_BUFF_SIZE] = {0};
|
||||
bool is_req_body_started = false;
|
||||
int content_length = -1;
|
||||
int content_received = 0;
|
||||
|
||||
esp_ota_handle_t ota_handle;
|
||||
|
||||
do
|
||||
{
|
||||
// ESP_LOGW (TAG, "stack free: %d",
|
||||
// uxTaskGetStackHighWaterMark(NULL));
|
||||
do {
|
||||
// ESP_LOGW (TAG, "stack free: %d",
|
||||
// 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 (!is_req_body_started)
|
||||
{
|
||||
const char *content_length_start = "Content-Length: ";
|
||||
char *content_length_start_p
|
||||
= strstr (ota_buff, content_length_start)
|
||||
+ strlen (content_length_start);
|
||||
sscanf (content_length_start_p, "%d", &content_length);
|
||||
ESP_LOGI (TAG, "Detected content length: %d", content_length);
|
||||
ESP_ERROR_CHECK (esp_ota_begin (update_partition,
|
||||
OTA_SIZE_UNKNOWN, &ota_handle));
|
||||
const char *header_end = "\r\n\r\n";
|
||||
char *body_start_p
|
||||
= strstr (ota_buff, header_end) + strlen (header_end);
|
||||
int body_part_len = recv_len - (body_start_p - ota_buff);
|
||||
esp_ota_write (ota_handle, body_start_p, body_part_len);
|
||||
content_received += body_part_len;
|
||||
is_req_body_started = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
esp_ota_write (ota_handle, ota_buff, recv_len);
|
||||
content_received += recv_len;
|
||||
if (recv_len > 0) {
|
||||
if (!is_req_body_started) {
|
||||
const char *content_length_start = "Content-Length: ";
|
||||
char *content_length_start_p = strstr(ota_buff, content_length_start) +
|
||||
strlen(content_length_start);
|
||||
sscanf(content_length_start_p, "%d", &content_length);
|
||||
ESP_LOGI(TAG, "Detected content length: %d", content_length);
|
||||
ESP_ERROR_CHECK(
|
||||
esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &ota_handle));
|
||||
const char *header_end = "\r\n\r\n";
|
||||
char *body_start_p = strstr(ota_buff, header_end) + strlen(header_end);
|
||||
int body_part_len = recv_len - (body_start_p - ota_buff);
|
||||
esp_ota_write(ota_handle, body_start_p, body_part_len);
|
||||
content_received += body_part_len;
|
||||
is_req_body_started = true;
|
||||
} else {
|
||||
esp_ota_write(ota_handle, ota_buff, recv_len);
|
||||
content_received += recv_len;
|
||||
|
||||
percent_loaded
|
||||
= (((float)content_received / (float)content_length)
|
||||
* 100.00);
|
||||
if ((percent_loaded % 10 == 0)
|
||||
& (percent_loaded != old_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);
|
||||
percent_loaded =
|
||||
(((float)content_received / (float)content_length) * 100.00);
|
||||
if ((percent_loaded % 10 == 0) &
|
||||
(percent_loaded != old_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);
|
||||
}
|
||||
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];
|
||||
int send_len;
|
||||
send_len = sprintf (res_buff, "200 OK\n\n");
|
||||
send (connect_socket, res_buff, send_len, 0);
|
||||
vTaskDelay (2000 / portTICK_PERIOD_MS);
|
||||
close (connect_socket);
|
||||
send_len = sprintf(res_buff, "200 OK\n\n");
|
||||
send(connect_socket, res_buff, send_len, 0);
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
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)
|
||||
{
|
||||
const esp_partition_t *boot_partition = esp_ota_get_boot_partition ();
|
||||
if (err == ESP_OK) {
|
||||
const esp_partition_t *boot_partition = esp_ota_get_boot_partition();
|
||||
|
||||
ESP_LOGI (TAG,
|
||||
"***********************************************************");
|
||||
ESP_LOGI (TAG, "OTA Successful");
|
||||
ESP_LOGI (TAG, "Next Boot Partition Subtype %d At Offset 0x%x",
|
||||
boot_partition->subtype, boot_partition->address);
|
||||
ESP_LOGI (TAG,
|
||||
"***********************************************************");
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI (TAG, "!!! OTA Failed !!!");
|
||||
}
|
||||
ESP_LOGI(TAG,
|
||||
"***********************************************************");
|
||||
ESP_LOGI(TAG, "OTA Successful");
|
||||
ESP_LOGI(TAG, "Next Boot Partition Subtype %d At Offset 0x%x",
|
||||
boot_partition->subtype, boot_partition->address);
|
||||
ESP_LOGI(TAG,
|
||||
"***********************************************************");
|
||||
} else {
|
||||
ESP_LOGI(TAG, "!!! OTA Failed !!!");
|
||||
}
|
||||
|
||||
// for (int x = 2; x >= 1; x--)
|
||||
//{
|
||||
ESP_LOGI (TAG, "Prepare to restart system..");
|
||||
vTaskDelay (1000 / portTICK_PERIOD_MS);
|
||||
ESP_LOGI(TAG, "Prepare to restart system..");
|
||||
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