Step 4.1: /stream.sdp from the live config and PTP GM
- aes67_sdp_sap: aes67_sdp_build() builds the AES67 SDP (RFC 4566 + RFC 7273) with the same lines and order as the web UI preview; GET /stream.sdp serves it as application/sdp. - aes67_ptp: public aes67_ptp_gm_id(), aes67_ptp_locked(), aes67_ptp_now_ns(). Clock IDs are now uppercase (RFC 7273 style), also in status.ptp, which the UI copies into ts-refclk. - aes67_net: aes67_net_netif() returns the AES67 interface. - Verified on board: /stream.sdp byte-identical to the UI's sdp() for the same config/status; mono, L16, ptime 0.333, ttl 8, clk_offset 4294967295 and session_ver all follow the config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -183,3 +183,8 @@ esp_err_t aes67_net_init(esp_eth_handle_t eth)
|
|||||||
status_register(net_status);
|
status_register(net_status);
|
||||||
return esp_eth_start(eth);
|
return esp_eth_start(eth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_netif_t *aes67_net_netif(void)
|
||||||
|
{
|
||||||
|
return s_netif;
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "esp_eth_driver.h"
|
#include "esp_eth_driver.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
|
||||||
// Attach a netif (DHCP client) to the Ethernet driver and start it. Logs link and IP events.
|
// Attach a netif (DHCP client) to the Ethernet driver and start it. Logs link and IP events.
|
||||||
esp_err_t aes67_net_init(esp_eth_handle_t eth);
|
esp_err_t aes67_net_init(esp_eth_handle_t eth);
|
||||||
|
|
||||||
|
// The AES67 interface (untagged side once the VLAN split exists). NULL before aes67_net_init().
|
||||||
|
esp_netif_t *aes67_net_netif(void);
|
||||||
|
|||||||
@@ -45,3 +45,23 @@ esp_err_t aes67_ptp_start(esp_eth_handle_t eth)
|
|||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool aes67_ptp_gm_id(char out[24])
|
||||||
|
{
|
||||||
|
return ptp_clock_gm_id(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool aes67_ptp_locked(void)
|
||||||
|
{
|
||||||
|
return ptp_clock_locked();
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t aes67_ptp_now_ns(int64_t *ns)
|
||||||
|
{
|
||||||
|
eth_mac_time_t t;
|
||||||
|
esp_err_t err = ptp_hw_get_time(&t);
|
||||||
|
if (err == ESP_OK) {
|
||||||
|
*ns = (int64_t)t.seconds * 1000000000LL + t.nanoseconds;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
// Core component: must not depend on main/ (project code).
|
// Core component: must not depend on main/ (project code).
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "esp_eth_driver.h"
|
#include "esp_eth_driver.h"
|
||||||
|
|
||||||
@@ -9,3 +12,10 @@
|
|||||||
esp_err_t aes67_ptp_init(void);
|
esp_err_t aes67_ptp_init(void);
|
||||||
// Start the EMAC PTP clock and the PTP task on this Ethernet interface.
|
// Start the EMAC PTP clock and the PTP task on this Ethernet interface.
|
||||||
esp_err_t aes67_ptp_start(esp_eth_handle_t eth);
|
esp_err_t aes67_ptp_start(esp_eth_handle_t eth);
|
||||||
|
|
||||||
|
// Current GM clockIdentity as "XX-XX-XX-XX-XX-XX-XX-XX" (RFC 7273 form). false if none selected.
|
||||||
|
bool aes67_ptp_gm_id(char out[24]);
|
||||||
|
// Servo locked to the GM.
|
||||||
|
bool aes67_ptp_locked(void);
|
||||||
|
// PTP time (EMAC hardware clock) in ns.
|
||||||
|
esp_err_t aes67_ptp_now_ns(int64_t *ns);
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ static int64_t mac_ns(const eth_mac_time_t *t)
|
|||||||
|
|
||||||
static void fmt_id(char *out, const uint8_t *id)
|
static void fmt_id(char *out, const uint8_t *id)
|
||||||
{
|
{
|
||||||
sprintf(out, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]);
|
sprintf(out, "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IEEE 1588 dataset comparison (without the topology part): <0 if a is better.
|
// IEEE 1588 dataset comparison (without the topology part): <0 if a is better.
|
||||||
@@ -487,6 +487,22 @@ static void ptp_task(void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ptp_clock_gm_id(char out[24])
|
||||||
|
{
|
||||||
|
xSemaphoreTake(s.lock, portMAX_DELAY);
|
||||||
|
bool valid = s.gm.valid;
|
||||||
|
if (valid) {
|
||||||
|
fmt_id(out, s.gm.gm_id);
|
||||||
|
}
|
||||||
|
xSemaphoreGive(s.lock);
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ptp_clock_locked(void)
|
||||||
|
{
|
||||||
|
return s.locked;
|
||||||
|
}
|
||||||
|
|
||||||
void ptp_clock_status(cJSON *st)
|
void ptp_clock_status(cJSON *st)
|
||||||
{
|
{
|
||||||
cJSON *p = cJSON_AddObjectToObject(st, "ptp");
|
cJSON *p = cJSON_AddObjectToObject(st, "ptp");
|
||||||
|
|||||||
@@ -6,5 +6,7 @@
|
|||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
|
|
||||||
esp_err_t ptp_clock_start(esp_netif_t *netif);
|
esp_err_t ptp_clock_start(esp_netif_t *netif);
|
||||||
|
bool ptp_clock_gm_id(char out[24]);
|
||||||
|
bool ptp_clock_locked(void);
|
||||||
// Adds the "ptp" object to /api/status.
|
// Adds the "ptp" object to /api/status.
|
||||||
void ptp_clock_status(cJSON *st);
|
void ptp_clock_status(cJSON *st);
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
idf_component_register(SRCS "aes67_sdp_sap.c"
|
idf_component_register(SRCS "aes67_sdp_sap.c"
|
||||||
INCLUDE_DIRS "include")
|
INCLUDE_DIRS "include"
|
||||||
|
PRIV_REQUIRES aes67_net aes67_ptp aes67_web esp_netif)
|
||||||
|
|||||||
@@ -1,7 +1,89 @@
|
|||||||
#include "aes67_sdp_sap.h"
|
#include "aes67_sdp_sap.h"
|
||||||
|
|
||||||
// Stub (build step 0).
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "aes67_cfg.h"
|
||||||
|
#include "aes67_net.h"
|
||||||
|
#include "aes67_ptp.h"
|
||||||
|
#include "aes67_web.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
|
||||||
|
#define SDP_MAX 1024
|
||||||
|
|
||||||
|
// Same lines, in the same order, as the SDP preview in web/index.html.
|
||||||
|
size_t aes67_sdp_build(char *buf, size_t size)
|
||||||
|
{
|
||||||
|
cJSON *a = cfg_get("aes67");
|
||||||
|
cJSON *p = cfg_get("ptp");
|
||||||
|
if (!a || !p) {
|
||||||
|
cJSON_Delete(a);
|
||||||
|
cJSON_Delete(p);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#define NUM(o, k) cJSON_GetObjectItemCaseSensitive(o, k)->valuedouble
|
||||||
|
#define STR(o, k) cJSON_GetObjectItemCaseSensitive(o, k)->valuestring
|
||||||
|
char ip[16] = "0.0.0.0";
|
||||||
|
esp_netif_ip_info_t info;
|
||||||
|
esp_netif_t *netif = aes67_net_netif();
|
||||||
|
if (netif && esp_netif_get_ip_info(netif, &info) == ESP_OK && info.ip.addr) {
|
||||||
|
snprintf(ip, sizeof(ip), IPSTR, IP2STR(&info.ip));
|
||||||
|
}
|
||||||
|
char gm[24];
|
||||||
|
if (!aes67_ptp_gm_id(gm)) {
|
||||||
|
strcpy(gm, "00-00-00-00-00-00-00-00");
|
||||||
|
}
|
||||||
|
int ch = (int)NUM(a, "channels");
|
||||||
|
char info_ch[16];
|
||||||
|
snprintf(info_ch, sizeof(info_ch), ch == 1 ? "mono" : ch == 2 ? "stereo" : "%d ch", ch);
|
||||||
|
int dom = (int)NUM(p, "domain");
|
||||||
|
int pt = (int)NUM(a, "pt");
|
||||||
|
|
||||||
|
int n = snprintf(buf, size,
|
||||||
|
"v=0\r\n"
|
||||||
|
"o=- %.0f %.0f IN IP4 %s\r\n"
|
||||||
|
"s=%s\r\n"
|
||||||
|
"c=IN IP4 %s/%d\r\n"
|
||||||
|
"t=0 0\r\n"
|
||||||
|
"a=clock-domain:PTPv2 %d\r\n"
|
||||||
|
"m=audio %d RTP/AVP %d\r\n"
|
||||||
|
"i=%s\r\n"
|
||||||
|
"a=rtpmap:%d %s/%d/%d\r\n"
|
||||||
|
"a=recvonly\r\n"
|
||||||
|
"a=ptime:%g\r\n"
|
||||||
|
"a=ts-refclk:ptp=IEEE1588-2008:%s:%d\r\n"
|
||||||
|
"a=mediaclk:direct=%.0f\r\n",
|
||||||
|
NUM(a, "session_id"), NUM(a, "session_ver"), ip,
|
||||||
|
STR(a, "name"),
|
||||||
|
STR(a, "mcast"), (int)NUM(a, "ttl"),
|
||||||
|
dom,
|
||||||
|
(int)NUM(a, "port"), pt,
|
||||||
|
info_ch,
|
||||||
|
pt, STR(a, "encoding"), (int)NUM(a, "rate"), ch,
|
||||||
|
NUM(a, "ptime"),
|
||||||
|
gm, dom,
|
||||||
|
NUM(a, "clk_offset"));
|
||||||
|
#undef NUM
|
||||||
|
#undef STR
|
||||||
|
cJSON_Delete(a);
|
||||||
|
cJSON_Delete(p);
|
||||||
|
return n > 0 && (size_t)n < size ? (size_t)n : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_err_t sdp_get(httpd_req_t *req)
|
||||||
|
{
|
||||||
|
char buf[SDP_MAX];
|
||||||
|
size_t len = aes67_sdp_build(buf, sizeof(buf));
|
||||||
|
if (!len) {
|
||||||
|
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "SDP build failed");
|
||||||
|
}
|
||||||
|
httpd_resp_set_type(req, "application/sdp");
|
||||||
|
httpd_resp_set_hdr(req, "Cache-Control", "no-store");
|
||||||
|
return httpd_resp_send(req, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
esp_err_t aes67_sdp_sap_init(void)
|
esp_err_t aes67_sdp_sap_init(void)
|
||||||
{
|
{
|
||||||
return ESP_OK;
|
static const httpd_uri_t uri = { .uri = "/stream.sdp", .method = HTTP_GET, .handler = sdp_get };
|
||||||
|
return web_register_uri(&uri);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
// Core component: must not depend on main/ (project code).
|
// Core component: must not depend on main/ (project code).
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
// Registers GET /stream.sdp. (SAP: step 5.)
|
||||||
esp_err_t aes67_sdp_sap_init(void);
|
esp_err_t aes67_sdp_sap_init(void);
|
||||||
|
// Build the current SDP (RFC 4566 + RFC 7273, AES67). Returns the length, or 0 if it didn't fit.
|
||||||
|
size_t aes67_sdp_build(char *buf, size_t size);
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
idf_component_register(SRCS "main.c" "project_cfg.c"
|
idf_component_register(SRCS "main.c" "project_cfg.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES esp_app_format esp_hw_support
|
REQUIRES esp_app_format esp_hw_support
|
||||||
aes67_board aes67_health aes67_net aes67_ota aes67_ptp
|
aes67_board aes67_health aes67_net aes67_ota aes67_ptp aes67_sdp_sap
|
||||||
aes67_syslog aes67_tx aes67_web)
|
aes67_syslog aes67_tx aes67_web)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "aes67_net.h"
|
#include "aes67_net.h"
|
||||||
#include "aes67_ota.h"
|
#include "aes67_ota.h"
|
||||||
#include "aes67_ptp.h"
|
#include "aes67_ptp.h"
|
||||||
|
#include "aes67_sdp_sap.h"
|
||||||
#include "aes67_syslog.h"
|
#include "aes67_syslog.h"
|
||||||
#include "aes67_tx.h"
|
#include "aes67_tx.h"
|
||||||
#include "aes67_web.h"
|
#include "aes67_web.h"
|
||||||
@@ -36,5 +37,6 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(aes67_syslog_init());
|
ESP_ERROR_CHECK(aes67_syslog_init());
|
||||||
project_cfg_register();
|
project_cfg_register();
|
||||||
ESP_ERROR_CHECK(aes67_ota_init());
|
ESP_ERROR_CHECK(aes67_ota_init());
|
||||||
|
ESP_ERROR_CHECK(aes67_sdp_sap_init());
|
||||||
ESP_ERROR_CHECK(aes67_web_start());
|
ESP_ERROR_CHECK(aes67_web_start());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user