chore: snapshot before shared RS485 bus integration
This commit is contained in:
0
components/ocpp/CMakeLists.txt
Executable file → Normal file
0
components/ocpp/CMakeLists.txt
Executable file → Normal file
0
components/ocpp/include/ocpp.h
Executable file → Normal file
0
components/ocpp/include/ocpp.h
Executable file → Normal file
63
components/ocpp/src/ocpp.c
Executable file → Normal file
63
components/ocpp/src/ocpp.c
Executable file → Normal file
@@ -55,7 +55,7 @@ static const char *TAG = "ocpp";
|
||||
* - If it publishes in Wh, keep 0
|
||||
*/
|
||||
#ifndef METER_TOTAL_ENERGY_IS_KWH
|
||||
#define METER_TOTAL_ENERGY_IS_KWH 0
|
||||
#define METER_TOTAL_ENERGY_IS_KWH 1
|
||||
#endif
|
||||
|
||||
// Bounded timeout for esp_event_post from loop/callback paths
|
||||
@@ -318,7 +318,7 @@ void ocpp_get_server(char *value /* out, size>=64 */)
|
||||
|
||||
storage_init_once();
|
||||
|
||||
esp_err_t e = storage_get_str_sync(NVS_NAMESPACE, NVS_OCPP_SERVER, value, 64, STORE_TO);
|
||||
esp_err_t e = storage_get_str_sync(NVS_NAMESPACE, NVS_OCPP_SERVER, value, 256, STORE_TO);
|
||||
if (e == ESP_ERR_NOT_FOUND)
|
||||
{
|
||||
value[0] = '\0';
|
||||
@@ -414,15 +414,11 @@ void ocpp_set_charge_id(char *value)
|
||||
static void ocpp_on_auth_verify(void *arg, esp_event_base_t base, int32_t id, void *event_data)
|
||||
{
|
||||
(void)arg;
|
||||
(void)base;
|
||||
(void)id;
|
||||
|
||||
if (s_stopping || !enabled || g_ocpp_conn == NULL)
|
||||
if (base != AUTH_EVENTS || id != AUTH_EVENT_TAG_VERIFY || event_data == NULL)
|
||||
return;
|
||||
|
||||
const auth_tag_verify_event_t *rq = (const auth_tag_verify_event_t *)event_data;
|
||||
if (!rq)
|
||||
return;
|
||||
|
||||
char idtag[AUTH_TAG_MAX_LEN];
|
||||
if (rq->tag[0] == '\0')
|
||||
@@ -438,6 +434,13 @@ static void ocpp_on_auth_verify(void *arg, esp_event_base_t base, int32_t id, vo
|
||||
|
||||
ESP_LOGI(TAG, "AUTH_EVENT_TAG_VERIFY: tag=%s req_id=%u", idtag, (unsigned)rq->req_id);
|
||||
|
||||
if (s_stopping || !enabled || g_ocpp_conn == NULL)
|
||||
{
|
||||
ESP_LOGW(TAG, "OCPP RFID verification unavailable -> rejecting tag=%s", idtag);
|
||||
(void)esp_event_post(OCPP_EVENTS, OCPP_EVENT_AUTH_REJECTED, NULL, 0, OCPP_EVENT_POST_TO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ocpp_isTransactionActive())
|
||||
{
|
||||
ESP_LOGI(TAG, "Transaction active -> ocpp_endTransaction(\"%s\")", idtag);
|
||||
@@ -519,6 +522,8 @@ static void on_meter_event(void *arg, esp_event_base_t base, int32_t id, void *d
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
ESP_LOGI(TAG, "[OCPP METER EVSE] ");
|
||||
|
||||
if (base != METER_EVENT || id != METER_EVENT_DATA_READY || !data)
|
||||
return;
|
||||
|
||||
@@ -530,12 +535,38 @@ static void on_meter_event(void *arg, esp_event_base_t base, int32_t id, void *d
|
||||
if (!evt->source || strcmp(evt->source, "EVSE") != 0)
|
||||
return;
|
||||
|
||||
int32_t sum_w = (int32_t)evt->watt[0] + (int32_t)evt->watt[1] + (int32_t)evt->watt[2];
|
||||
float avg_v = (evt->vrms[0] + evt->vrms[1] + evt->vrms[2]) / 3.0f;
|
||||
const int32_t phase_sum_w = (int32_t)evt->watt[0] + (int32_t)evt->watt[1] + (int32_t)evt->watt[2];
|
||||
int32_t sum_w = (evt->watt_total != 0) ? evt->watt_total : phase_sum_w;
|
||||
|
||||
float v_sum = 0.0f;
|
||||
int v_count = 0;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (isfinite(evt->vrms[i]) && evt->vrms[i] > 1.0f)
|
||||
{
|
||||
v_sum += evt->vrms[i];
|
||||
v_count++;
|
||||
}
|
||||
}
|
||||
float avg_v = (v_count > 0) ? (v_sum / (float)v_count) : 0.0f;
|
||||
|
||||
float sum_i = evt->irms[0] + evt->irms[1] + evt->irms[2];
|
||||
|
||||
float total_wh = sanitize_energy_wh(energy_to_wh(evt->total_energy));
|
||||
|
||||
ESP_LOGI(TAG,
|
||||
"[OCPP METER EVSE] "
|
||||
"V=[%.1f %.1f %.1f] avg=%.1fV | "
|
||||
"I=[%.3f %.3f %.3f] sum=%.3fA | "
|
||||
"W=[%ld %ld %ld] total=%ldW | "
|
||||
"E=%.3fkWh / %.1fWh | "
|
||||
"Hz=%.2f PF=%.3f",
|
||||
evt->vrms[0], evt->vrms[1], evt->vrms[2], avg_v,
|
||||
evt->irms[0], evt->irms[1], evt->irms[2], sum_i,
|
||||
(long)evt->watt[0], (long)evt->watt[1], (long)evt->watt[2], (long)sum_w,
|
||||
evt->total_energy, total_wh,
|
||||
evt->frequency, evt->power_factor);
|
||||
|
||||
portENTER_CRITICAL(&s_meter_mux);
|
||||
memcpy(s_meter.vrms, evt->vrms, sizeof(s_meter.vrms));
|
||||
memcpy(s_meter.irms, evt->irms, sizeof(s_meter.irms));
|
||||
@@ -845,7 +876,7 @@ void ocpp_start(void)
|
||||
return;
|
||||
}
|
||||
|
||||
char serverstr[64] = {0};
|
||||
char serverstr[256] = {0};
|
||||
ocpp_get_server(serverstr);
|
||||
if (serverstr[0] == '\0')
|
||||
{
|
||||
@@ -926,12 +957,24 @@ void ocpp_start(void)
|
||||
|
||||
ocpp_setEnergyMeterInput(&setEnergyInput);
|
||||
|
||||
ocpp_addMeterValueInputFloat(&setPowerMeterInput,
|
||||
"Power.Active.Import", "W", NULL, NULL);
|
||||
|
||||
/* opcional, mas para certificação eu deixaria desligado inicialmente:
|
||||
ocpp_addMeterValueInputFloat(&setCurrentInput, "Current.Import", "A", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&getCurrentOffered, "Current.Offered", "A", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&setVoltageInput, "Voltage", "V", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&setTemperatureInput, "Temperature", "Celsius", NULL, NULL);
|
||||
*/
|
||||
|
||||
/*
|
||||
ocpp_addMeterValueInputFloat(&setCurrentInput, "Current.Import", "A", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&getCurrentOffered, "Current.Offered", "A", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&setVoltageInput, "Voltage", "V", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&setTemperatureInput, "Temperature", "Celsius", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&setPowerMeterInput, "Power.Active.Import", "W", NULL, NULL);
|
||||
ocpp_addMeterValueInputFloat(&setEnergyMeterInput, "Energy.Active.Import.Register", "Wh", NULL, NULL);
|
||||
*/
|
||||
|
||||
ocpp_addErrorCodeInput(&addErrorCodeInput);
|
||||
|
||||
|
||||
0
components/ocpp/src/ocpp_events.c
Executable file → Normal file
0
components/ocpp/src/ocpp_events.c
Executable file → Normal file
Reference in New Issue
Block a user