feat: integriere Systemspannungen und Temperaturen mit Redux Thunk und Slice
- Neues Slice systemVoltTempSlice.ts erstellt für Speicherung von Spannungen und Verlauf - Thunk fetchSystemVoltTempThunk.ts implementiert für asynchrones Laden der Systemwerte - Service fetchSystemVoltTempService.ts verwendet API /api/cpl/systemVoltTempAPIHandler - Mock-Daten in systemVoltTempMockData.js definiert - system.tsx auf Redux umgestellt: useSelector für Werte und Verlauf, fetch per Thunk - store.ts angepasst: systemVoltTempSlice hinzugefügt - Chart.js Darstellung von Spannungen und Temperaturen mit Echtzeit-Update alle 5 Sekunden
This commit is contained in:
38
redux/slices/systemVoltTempSlice.ts
Normal file
38
redux/slices/systemVoltTempSlice.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// /redux/slices/systemVoltTempSlice.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface VoltagesState {
|
||||
voltages: { [key: string]: number };
|
||||
history: { time: number; [key: string]: number }[];
|
||||
}
|
||||
|
||||
const initialState: VoltagesState = {
|
||||
voltages: {
|
||||
"+5V": 0,
|
||||
"+15V": 0,
|
||||
"-15V": 0,
|
||||
"-98V": 0,
|
||||
"ADC Temp": 0,
|
||||
"CPU Temp": 0,
|
||||
},
|
||||
history: [],
|
||||
};
|
||||
|
||||
const systemVoltTempSlice = createSlice({
|
||||
name: "systemVoltTemp",
|
||||
initialState,
|
||||
reducers: {
|
||||
setVoltages(state, action: PayloadAction<{ [key: string]: number }>) {
|
||||
state.voltages = action.payload;
|
||||
},
|
||||
addHistory(
|
||||
state,
|
||||
action: PayloadAction<{ time: number; [key: string]: number }>
|
||||
) {
|
||||
state.history.push(action.payload);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setVoltages, addHistory } = systemVoltTempSlice.actions;
|
||||
export default systemVoltTempSlice.reducer;
|
||||
@@ -22,6 +22,7 @@ import selectedChartDataReducer from "./slices/selectedChartDataSlice";
|
||||
import tdmSingleChartReducer from "./slices/tdmSingleChartSlice";
|
||||
import tdrReferenceChartDataBySlotReducer from "./slices/tdrReferenceChartDataBySlotSlice";
|
||||
import loopChartTypeSlice from "./slices/loopChartTypeSlice";
|
||||
import systemVoltTempReducer from "./slices/systemVoltTempSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
@@ -46,6 +47,7 @@ const store = configureStore({
|
||||
tdmSingleChartSlice: tdmSingleChartReducer,
|
||||
tdrReferenceChartDataBySlotSlice: tdrReferenceChartDataBySlotReducer,
|
||||
loopChartType: loopChartTypeSlice,
|
||||
systemVoltTemp: systemVoltTempReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
15
redux/thunks/fetchSystemVoltTempThunk.ts
Normal file
15
redux/thunks/fetchSystemVoltTempThunk.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
// /redux/thunks/fetchSystemVoltTempThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchSystemVoltTempService } from "../../services/fetchSystemVoltTempService";
|
||||
import { setVoltages, addHistory } from "../slices/systemVoltTempSlice";
|
||||
|
||||
export const fetchSystemVoltTempThunk = createAsyncThunk(
|
||||
"systemVoltTemp/fetch",
|
||||
async (_, { dispatch }) => {
|
||||
const data = await fetchSystemVoltTempService();
|
||||
if (data) {
|
||||
dispatch(setVoltages(data));
|
||||
dispatch(addHistory({ time: Date.now(), ...data }));
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user