diff --git a/src/stores/dataViewerStore.ts b/src/stores/dataViewerStore.ts
index a1345b1..6b577da 100644
--- a/src/stores/dataViewerStore.ts
+++ b/src/stores/dataViewerStore.ts
@@ -753,6 +753,63 @@ export const useDataViewerStore = defineStore('text-viewer', () => {
uartBaud.value = baud;
}
+
+ const enableLoopSend = ref(false);
+ const loopSendFreq = ref(1000);
+ let loopSendIntervalID: number = -1;
+ const uartInputTextBox = ref("");
+ const isSendTextFormat = ref(true);
+ const isHexStringValid = ref(false);
+
+ function loopSend() {
+ if (!acceptIncomingData.value) {
+ enableLoopSend.value = false;
+ }
+
+ if (isSendTextFormat.value) {
+ addString(uartInputTextBox.value, false, true);
+ } else {
+ if (!isHexStringValid.value) {
+ addString("HEX格式错误", false, false, 1);
+ addHexString(uartInputTextBox.value, false, false, 1);
+ } else {
+ addHexString(uartInputTextBox.value, false, true);
+ }
+ }
+ }
+
+ watch(enableLoopSend, (newValue) => {
+ if (newValue) {
+ if (loopSendIntervalID !== -1) {
+ clearInterval(loopSendIntervalID);
+ }
+ loopSendIntervalID = setInterval(loopSend, loopSendFreq.value);
+ } else {
+ clearInterval(loopSendIntervalID);
+ loopSendIntervalID = -1;
+ }
+ });
+
+ watch(loopSendFreq, (value) => {
+ if (enableLoopSend.value && value) {
+ /* update interval with new value */
+ if (loopSendIntervalID !== -1) {
+ clearInterval(loopSendIntervalID);
+ }
+ loopSendIntervalID = setInterval(loopSend, loopSendFreq.value);
+ }
+ })
+
+ const loopSendRet = {
+ enableLoopSend,
+ loopSendFreq,
+ loopSendIntervalID,
+ isSendTextFormat,
+ uartInputTextBox,
+ isHexStringValid,
+ }
+
+
return {
addItem,
addString,
@@ -804,5 +861,6 @@ export const useDataViewerStore = defineStore('text-viewer', () => {
uartConfig,
uartBaudReal,
setUartBaud,
+ ...loopSendRet,
}
});
diff --git a/src/views/text-data-viewer/textDataViewer.vue b/src/views/text-data-viewer/textDataViewer.vue
index 11943f5..eb23a4b 100644
--- a/src/views/text-data-viewer/textDataViewer.vue
+++ b/src/views/text-data-viewer/textDataViewer.vue
@@ -58,39 +58,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ (isSendTextFormat || isHexStringValid) ? "发送" : "格式化" }}
+ {{ (store.isSendTextFormat || store.isHexStringValid) ? "发送" : "格式化" }}
@@ -255,14 +222,6 @@ const count = ref(0);
const vuetifyVirtualScrollBarRef = ref(document.body);
const vuetifyVirtualScrollContainerRef = ref(document.body);
-const enableLoopSend = ref(false);
-const loopSendFreq = ref(1000);
-let loopSendIntervalID: number = -1;
-
-const isSendTextFormat = ref(true)
-const isHexStringValid = ref(false);
-
-const uartInputTextBox = ref("")
const store = useDataViewerStore();
const RxHexDumpRef = ref(document.body);
@@ -303,6 +262,9 @@ onMounted(() => {
onUnmounted(() => {
mutationObserver.disconnect();
+ if (!store.isHexStringValid) {
+ store.uartInputTextBox = formatHexInput(store.uartInputTextBox);
+ }
});
debouncedWatch(() => store.showVirtualScroll, () => {
@@ -381,43 +343,24 @@ function formatHexInput(input: string) {
}
function checkHexTextValid() {
- isHexStringValid.value = uartInputTextBox.value.toUpperCase() === formatHexInput(uartInputTextBox.value);
+ store.isHexStringValid = store.uartInputTextBox.toUpperCase() === formatHexInput(store.uartInputTextBox);
+ if (!store.isHexStringValid) {
+ store.enableLoopSend = false;
+ }
}
-watch(isSendTextFormat, (value) => {
+watch(() => store.isSendTextFormat, (value) => {
if (!value) {
checkHexTextValid()
}
});
-watch(() => uartInputTextBox.value, () => {
- if (!isSendTextFormat.value) {
+watch(() => store.uartInputTextBox, () => {
+ if (!store.isSendTextFormat) {
checkHexTextValid()
}
})
-watch(enableLoopSend, (newValue) => {
- if (newValue) {
- if (loopSendIntervalID !== -1) {
- clearInterval(loopSendIntervalID);
- }
- loopSendIntervalID = setInterval(onSendClick, loopSendFreq.value);
- } else {
- clearInterval(loopSendIntervalID);
- loopSendIntervalID = -1;
- }
-});
-
-watch(loopSendFreq, (value) => {
- if (enableLoopSend.value && value) {
- /* update interval with new value */
- if (loopSendIntervalID !== -1) {
- clearInterval(loopSendIntervalID);
- }
- loopSendIntervalID = setInterval(onSendClick, loopSendFreq.value);
- }
-})
-
/* patch scroll container does not update clear filter */
watch(() => store.filterChanged, (value) => {
if (value && store.forceToBottom) {
@@ -459,7 +402,7 @@ watch(() => store.forceToBottom, value => {
});
function clearSendInput() {
- uartInputTextBox.value = ""
+ store.uartInputTextBox = ""
}
function handleTextboxKeydown(ev: KeyboardEvent) {
@@ -469,26 +412,26 @@ function handleTextboxKeydown(ev: KeyboardEvent) {
}
function onSendClick() {
- if (!uartInputTextBox.value && !store.hasAddedText) {
+ if (!store.uartInputTextBox && !store.hasAddedText) {
globalNotify("无帧头帧尾、发送框无数据发送")
return;
}
if (store.acceptIncomingData) {
- if (isSendTextFormat.value) {
- store.addString(uartInputTextBox.value, false, true);
- } else if (!isHexStringValid.value) {
- uartInputTextBox.value = formatHexInput(uartInputTextBox.value);
+ if (store.isSendTextFormat) {
+ store.addString(store.uartInputTextBox, false, true);
+ } else if (!store.isHexStringValid) {
+ store.uartInputTextBox = formatHexInput(store.uartInputTextBox);
} else {
- store.addHexString(uartInputTextBox.value, false, true);
+ store.addHexString(store.uartInputTextBox, false, true);
}
} else {
- if (isSendTextFormat.value) {
- store.addString(uartInputTextBox.value, false, true, 1);
- } else if (!isHexStringValid.value) {
- uartInputTextBox.value = formatHexInput(uartInputTextBox.value);
+ if (store.isSendTextFormat) {
+ store.addString(store.uartInputTextBox, false, true, 1);
+ } else if (!store.isHexStringValid) {
+ store.uartInputTextBox = formatHexInput(store.uartInputTextBox);
} else {
- store.addHexString(uartInputTextBox.value, false, true, 1);
+ store.addHexString(store.uartInputTextBox, false, true, 1);
}
}
}