Skip to content

Commit 3ec1810

Browse files
committed
updating global state provider for thermal and power specification
1 parent ea5bbd3 commit 3ec1810

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

src/GlobalStateProvider.js

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ export function GlobalStateProvider({ children, fetch }) { // TODO temp fix for
3838
const [bcpuNames, setBcpuNames] = useState([]);
3939
const [connectivityNames, setConnectivityNames] = useState([]);
4040
const [dmaNames, setDmaNames] = useState([]);
41+
const [thermalData, setThermalData] = useState({
42+
ambientTypical: 25,
43+
ambientWorseCase: 50,
44+
thetaJa: 10,
45+
});
46+
const [powerData, setPowerData] = useState({
47+
powerBudget: 1.0,
48+
fpgaScaling: 25,
49+
pcScaling: 25,
50+
});
4151

4252
let peripheralsMessages = {};
4353

@@ -128,6 +138,22 @@ export function GlobalStateProvider({ children, fetch }) { // TODO temp fix for
128138
updatePeripherals(device, item.href, item.type);
129139
});
130140
});
141+
142+
server.GET(server.deviceInfo(device), (result) => {
143+
if (result && result.specification) {
144+
const { specification } = result;
145+
setThermalData({
146+
ambientTypical: specification.thermal?.ambient?.typical || 25,
147+
ambientWorseCase: specification.thermal?.ambient?.worsecase || 50,
148+
thetaJa: specification.thermal?.theta_ja || 10,
149+
});
150+
setPowerData({
151+
powerBudget: specification.power?.budget || 1.0,
152+
fpgaScaling: (specification.power?.typical_dynamic_scaling?.fpga_complex || 0) * 100,
153+
pcScaling: (specification.power?.typical_dynamic_scaling?.processing_complex || 0) * 100,
154+
});
155+
}
156+
});
131157
} else {
132158
setClockingState([]);
133159
setFleState([]);
@@ -136,9 +162,49 @@ export function GlobalStateProvider({ children, fetch }) { // TODO temp fix for
136162
setIoState([]);
137163
setSocState({});
138164
setPeripherals([]);
165+
setThermalData({
166+
ambientTypical: 25,
167+
ambientWorseCase: 50,
168+
thetaJa: 10,
169+
});
170+
setPowerData({
171+
powerBudget: 1.0,
172+
fpgaScaling: 25,
173+
pcScaling: 25,
174+
});
139175
}
140176
}
141177

178+
function updateThermalAndPowerData(device, newThermalData, newPowerData) {
179+
const updatedData = {
180+
specification: {
181+
thermal: {
182+
ambient: {
183+
typical: newThermalData.ambientTypical,
184+
worsecase: newThermalData.ambientWorseCase,
185+
},
186+
theta_ja: newThermalData.thetaJa,
187+
},
188+
power: {
189+
budget: newPowerData.powerBudget,
190+
typical_dynamic_scaling: {
191+
fpga_complex: newPowerData.fpgaScaling / 100,
192+
processing_complex: newPowerData.pcScaling / 100,
193+
},
194+
},
195+
},
196+
};
197+
198+
server.PATCH(server.deviceInfo(device), updatedData, (response) => {
199+
if (response.ok) {
200+
setThermalData(newThermalData);
201+
setPowerData(newPowerData);
202+
} else {
203+
console.error('Error updating thermal and power data:', response.statusText);
204+
}
205+
});
206+
}
207+
142208
function GetOptions(id) {
143209
const found = attributes.find((elem) => id === elem.id);
144210
return (found === undefined) ? [] : found.options;
@@ -150,6 +216,7 @@ export function GlobalStateProvider({ children, fetch }) { // TODO temp fix for
150216

151217
const values = useMemo(() => ({
152218
updateGlobalState,
219+
updateThermalAndPowerData,
153220
clockingState,
154221
fleState,
155222
bramState,
@@ -163,8 +230,10 @@ export function GlobalStateProvider({ children, fetch }) { // TODO temp fix for
163230
connectivityNames,
164231
dmaNames,
165232
fetchAttributes,
233+
thermalData,
234+
powerData,
166235
// eslint-disable-next-line react-hooks/exhaustive-deps
167-
}), [bramState, clockingState, dspState, fleState, ioState, socState]);
236+
}), [bramState, clockingState, dspState, fleState, ioState, socState, thermalData, powerData]);
168237

169238
return (
170239
<GlobalStateContext.Provider value={values}>

0 commit comments

Comments
 (0)