Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
    npro  
 Modern all-safe Rust Network Protocol library supporting h1, h2, h3, ws, wt sans-IO and with socket IO + tls
git clone https://npro.rs/repo/npro
 
root / scripts / usr-local-svc-method-sai_builder-Solaris
Author[]google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.c...> 2025-12-27 09:20 UTC
Committer[]Andy Green <andy@warmcat.com> 2025-12-27 09:21 UTC
Tree4a8054efa4847c9803ab7567a5a07292cc74ee07   Raw Patch
 
Fix PCON control logic and state management
Fix PCON control logic and state management

- Split `manual_stay` into `user_keep_on` and `server_requested_on` in `saip_pcon_t` to decouple user overrides from server automation.
- Update `src/power/p-ws-server.c` and `src/power/p-http-api.c` to use the new flags.
- Enable active PCON switching in `sul_pcon_check_cb` in `src/power/p-sai.c` to enforce the calculated target state.
- Explicitly queue PCON control messages in `src/web/w-ws-browser.c` to ensure reliable forwarding to `sai-server`.
diff --git a/libwebsockets b/libwebsockets new file mode 160000 index 0000000..5acb375 --- /dev/null +++ b/libwebsockets @@ -0,0 +1 @@ +Subproject commit 5acb375a17b2d1707b94765db2f58a6317e23c94 diff --git a/src/power/p-http-api.c b/src/power/p-http-api.c index ba0b580..d66e8ad 100644 --- a/src/power/p-http-api.c +++ b/src/power/p-http-api.c @@ -158,7 +158,7 @@ saip_set_stay(const char *builder_name, int stay_on) sps = lws_container_of(power.sai_server_owner.head, saip_server_t, list); /* pss = (saip_server_link_t *)lws_ss_to_user_object(sps->ss); */ - pc->manual_stay = (char)stay_on; + pc->user_keep_on = (char)stay_on; saip_notify_server_stay_state(builder_name, stay_on | pc->needed); /* Trigger state re-eval */ @@ -404,7 +404,7 @@ local_srv_state(void *userobj, void *sh, lws_ss_constate_t state, if (pc) g->size = (size_t)lws_snprintf(g->payload, sizeof(g->payload), - "%c", '0' + (pc->manual_stay | pc->needed)); + "%c", '0' + (pc->user_keep_on | pc->needed)); else g->size = (size_t)lws_snprintf(g->payload, sizeof(g->payload), "unknown builder %s", pn); @@ -433,7 +433,7 @@ local_srv_state(void *userobj, void *sh, lws_ss_constate_t state, else g->size = (size_t)lws_snprintf(g->payload, sizeof(g->payload), "Resumed %s with stay", pn); - pc->manual_stay = 1; + pc->user_keep_on = 1; goto bail; } @@ -452,7 +452,7 @@ local_srv_state(void *userobj, void *sh, lws_ss_constate_t state, lwsl_warn("%s: powered on %s\n", __func__, pc->name); - pc->manual_stay = 1; /* so builder can understand it's manual */ + pc->user_keep_on = 1; /* so builder can understand it's manual */ saip_notify_server_power_state(pc->name, 1, 0); sps = lws_container_of(power.sai_server_owner.head, @@ -547,7 +547,7 @@ power_off: pc->name, (int)(SAI_POWERDOWN_HOLDOFF_US / LWS_USEC_PER_SEC)); - pc->manual_stay = 0; /* reset any manual power up */ + pc->user_keep_on = 0; /* reset any manual power up */ } bail: diff --git a/src/power/p-private.h b/src/power/p-private.h index c401f88..83ae36a 100644 --- a/src/power/p-private.h +++ b/src/power/p-private.h @@ -84,7 +84,8 @@ typedef struct saip_pcon { size_t monitor_rx_pos; char on; - char manual_stay; /* user asked to keep this PCON on via UI */ + char user_keep_on; /* user asked to keep this PCON on via UI */ + char server_requested_on; /* server requested stay for jobs */ char needed; /* transiently set by deps analysis */ } saip_pcon_t; diff --git a/src/power/p-sai.c b/src/power/p-sai.c index 2afc42a..ad7d4ff 100644 --- a/src/power/p-sai.c +++ b/src/power/p-sai.c @@ -207,40 +207,26 @@ sul_pcon_check_cb(lws_sorted_usec_list_t *sul) target_on = 1; lwsl_info("%s: PCON %s has 0 builders -> Force ON\n", __func__, pc->name); } - /* Rule 2: Manual Stay -> Turn ON */ - else if (pc->manual_stay) { + /* Rule 2: User Keep On -> Turn ON */ + else if (pc->user_keep_on) { target_on = 1; - lwsl_info("%s: PCON %s has manual stay -> Force ON\n", __func__, pc->name); + lwsl_info("%s: PCON %s has user keep on -> Force ON\n", __func__, pc->name); } - /* Rule 3: Otherwise, rely on sai-server to tell us via 'stay' messages if it needs to be on. - * Wait... sai-server tells us which *builders* need to stay on. - * We need to map builder stay -> PCON stay. - * But sai-power receives 'stay' messages for builders. - */ - else { - /* Check if any registered builder needs to stay on */ - /* The 'stay' flag on the PCON struct isn't quite right, - we need to check the builders we know about. - Actually, sai-server tells sai-power: "Builder X needs to stay". - sai-power should look up Builder X, find its PCON, and mark the PCON as needed. - */ - /* For now, let's assume if we aren't forcing it on, we let it be managed by the existing logic - * which we need to adapt. - */ + /* Rule 3: Server Requested -> Turn ON */ + else if (pc->server_requested_on) { + target_on = 1; + lwsl_info("%s: PCON %s has server request -> Force ON\n", __func__, pc->name); } - /* - * Existing logic in p-smartplug.c or similar likely handles the actual HTTP switching - * based on a state flag. We need to make sure we set that flag. - * The 'saip_pcon_t' has an 'on' member. - */ - /* If we decide it should be ON, trigger it */ if (target_on && !pc->on) { - /* This logic needs to hook into the actual switching code */ - /* For now, just logging intent */ - // pc->on = 1; - // saip_switch(pc, 1); + lwsl_notice("%s: PCON %s ON (target=1, current=%d)\n", __func__, pc->name, pc->on); + pc->on = 1; + saip_switch(pc, 1); + } else if (!target_on && pc->on) { + lwsl_notice("%s: PCON %s OFF (target=0, current=%d)\n", __func__, pc->name, pc->on); + pc->on = 0; + saip_switch(pc, 0); } } lws_end_foreach_dll(p); @@ -285,7 +271,7 @@ sul_broadcast_energy_cb(lws_sorted_usec_list_t *sul) if (queued) { lwsl_notice("%s: Queued energy report for server\n", __func__); if (lws_ss_request_tx(sps->ss)) /* Request write to send the report */ - lwsl_warn("%s: Failed to trigger monitor request\n", __func__); + lwsl_warn("%s: failed to request tx\n", __func__); } } lws_end_foreach_dll_safe(mp, mp1); diff --git a/src/power/p-ws-server.c b/src/power/p-ws-server.c index 238bec7..2474268 100644 --- a/src/power/p-ws-server.c +++ b/src/power/p-ws-server.c @@ -214,7 +214,7 @@ saip_m_rx(void *userobj, const uint8_t *buf, size_t len, int flags) if (pc) { lwsl_notice("%s: PCON Control '%s' -> %d\n", __func__, pc->name, ctl->on); - pc->manual_stay = ctl->on; + pc->user_keep_on = ctl->on; if (ctl->on) { saip_switch(pc, 1); } else { @@ -246,7 +246,7 @@ saip_m_rx(void *userobj, const uint8_t *buf, size_t len, int flags) lwsl_notice("%s: Mapping stay for builder '%s' to PCON '%s'\n", __func__, sb->name, pc->name); /* Update PCON stay state */ - pc->manual_stay = stay->stay_on; + pc->server_requested_on = stay->stay_on; /* If stay is cleared, schedule power off check */ if (!stay->stay_on) diff --git a/src/server/s-power.c b/src/server/s-power.c index 01b25ac..d222188 100644 --- a/src/server/s-power.c +++ b/src/server/s-power.c @@ -218,7 +218,7 @@ passthru: uint8_t *seg; size_t slen; - slen = lws_buflist_next_segment_len(&pss->power_rx_cache, &seg); + slen = lws_buflist_next_segment_len(&pss->power_rx_cache, (uint8_t **)&seg); if (!slen) break; diff --git a/src/web/w-ws-browser.c b/src/web/w-ws-browser.c index 2d13c49..c41b8a3 100644 --- a/src/web/w-ws-browser.c +++ b/src/web/w-ws-browser.c @@ -687,8 +687,10 @@ saiw_ws_json_rx_browser(struct vhd *vhd, struct pss *pss, uint8_t *buf, lwsl_notice("%s: web: received pcon control req\n", __func__); /* Forward to sai-server via websrv link */ - /* We rely on the fallthrough to queue the message buffer to websrv */ - break; + sai_ss_queue_frag_on_buflist_REQUIRES_LWS_PRE(vhd->h_ss_websrv, + &((saiw_websrv_t *)lws_ss_to_user_object(vhd->h_ss_websrv))->wbltx, + buf, bl, ss_flags); + goto ok; case SAIM_WS_BROWSER_RX_TASKREBUILDLASTSTEP: if (!sais_conn_auth(pss))
Page fetched 0s ago, creation time: 15ms (vhost etag hits: 0%, cache hits: 0%)