85 lines
1.7 KiB
C++
85 lines
1.7 KiB
C++
|
|
#include <Ethernet.h>
|
|
#include <base64.h>
|
|
#include <ArduinoJson.h>
|
|
|
|
#include "config/config.h"
|
|
#include "utils/Time.h"
|
|
|
|
#include "infra/Audio.h"
|
|
#include "infra/Http.h"
|
|
#include "infra/Eth.h"
|
|
|
|
#include "domain/Recorder.h"
|
|
|
|
volatile bool loudnessFlag = false;
|
|
|
|
unsigned long beginMicros, endMicros;
|
|
|
|
Eth eth;
|
|
EthernetClient* client = eth.getEthClient();
|
|
Http http(ð);
|
|
|
|
Recorder* recorder;
|
|
|
|
Time timeService = Time::getInstance();
|
|
|
|
void setInitialTime() {
|
|
String response = http.send("GET", "/time", RAT_IP, RAT_PORT, "", "");
|
|
|
|
DynamicJsonDocument jsonDoc(1024);
|
|
DeserializationError error = deserializeJson(jsonDoc, response);
|
|
JsonVariant root = jsonDoc.as<JsonVariant>();
|
|
|
|
unsigned long currentTime = root["current_timestamp"].as<unsigned long>();
|
|
|
|
timeService.setInitialMicros(micros());
|
|
timeService.setInitialTime(currentTime);
|
|
}
|
|
|
|
void writeToPrecedingBufferTask(void* parameter) {
|
|
while (true) {
|
|
recorder->writeToPrecedingBuffer();
|
|
|
|
if (recorder->isNoiseDetected()) {
|
|
recorder->recordAudio();
|
|
}
|
|
|
|
vTaskDelay(500 / portTICK_PERIOD_MS);
|
|
}
|
|
}
|
|
|
|
void createWriteToPrecedingBufferTask() {
|
|
TaskHandle_t xHandle = NULL;
|
|
|
|
xTaskCreatePinnedToCore(writeToPrecedingBufferTask, "writeToPrecedingBufferTask", 4096, NULL, 1, &xHandle, 0);
|
|
|
|
if (xHandle == NULL) {
|
|
ESP_LOGE("TASK1", "Failed to task create");
|
|
};
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(1000);
|
|
|
|
eth.initEthernet();
|
|
|
|
setInitialTime();
|
|
recorder = new Recorder(ADMP441, &http);
|
|
|
|
//createWriteToPrecedingBufferTask();
|
|
|
|
beginMicros = micros();
|
|
}
|
|
|
|
void loop() {
|
|
eth.readAndPrintData(true); // set to false for better speed measurement
|
|
|
|
recorder->writeToPrecedingBuffer();
|
|
|
|
if (recorder->isNoiseDetected()) {
|
|
recorder->recordAudio();
|
|
}
|
|
}
|