mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-03-23 10:06:34 +03:00
@@ -8,9 +8,19 @@ For more details go to [docs.emsesp.org](https://docs.emsesp.org/).
|
||||
|
||||
- change enum_heatingtype for remote control [#2268](https://github.com/emsesp/EMS-ESP32/issues/2268)
|
||||
- system service commands [#2182](https://github.com/emsesp/EMS-ESP32/issues/2282)
|
||||
- read 0x02A5 for thermostat CT200 [#2277](https://github.com/emsesp/EMS-ESP32/issues/2277)
|
||||
- Add "duplicate" option to Custom Entities [#2266](https://github.com/emsesp/EMS-ESP32/discussion/2266)
|
||||
- Mask bits for bool custom entities
|
||||
|
||||
## Fixed
|
||||
|
||||
- long numbers of custom entities [#2267](https://github.com/emsesp/EMS-ESP32/issues/2267)
|
||||
- modbus command path to `api/` [#2276](https://github.com/emsesp/EMS-ESP32/issues/2276)
|
||||
- info command for devices without entity-commands [#2274](https://github.com/emsesp/EMS-ESP32/issues/2274)
|
||||
|
||||
## Changed
|
||||
|
||||
- show operation in pretty telegram between src and dst [#2263](https://github.com/emsesp/EMS-ESP32/discussions/2263)
|
||||
- update eModbus to 1.7.2 [#2254](https://github.com/emsesp/EMS-ESP32/issues/2254)
|
||||
- modbus timeout default to 300 sec, change setting from ms to sec [#2254](https://github.com/emsesp/EMS-ESP32/issues/2254)
|
||||
- update AsyncTCP to v3.2.14
|
||||
|
||||
@@ -24,18 +24,18 @@
|
||||
"@alova/adapter-xhr": "2.0.11",
|
||||
"@emotion/react": "^11.13.5",
|
||||
"@emotion/styled": "^11.13.5",
|
||||
"@mui/icons-material": "^6.1.9",
|
||||
"@mui/material": "^6.1.9",
|
||||
"@mui/icons-material": "^6.1.10",
|
||||
"@mui/material": "^6.1.10",
|
||||
"@table-library/react-table-library": "4.1.7",
|
||||
"alova": "3.2.6",
|
||||
"async-validator": "^4.2.5",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"mime-types": "^2.1.35",
|
||||
"preact": "^10.25.1",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-icons": "^5.3.0",
|
||||
"react-router": "^7.0.1",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-icons": "^5.4.0",
|
||||
"react-router": "^7.0.2",
|
||||
"react-toastify": "^10.0.6",
|
||||
"typesafe-i18n": "^5.26.2",
|
||||
"typescript": "^5.7.2"
|
||||
@@ -45,20 +45,20 @@
|
||||
"@eslint/js": "^9.16.0",
|
||||
"@preact/compat": "^18.3.1",
|
||||
"@preact/preset-vite": "^2.9.2",
|
||||
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
||||
"@trivago/prettier-plugin-sort-imports": "^5.0.1",
|
||||
"@types/formidable": "^3",
|
||||
"@types/node": "^22.10.1",
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react": "^18.3.13",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"concurrently": "^9.1.0",
|
||||
"eslint": "^9.16.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"formidable": "^3.5.2",
|
||||
"prettier": "^3.4.1",
|
||||
"prettier": "^3.4.2",
|
||||
"rollup-plugin-visualizer": "^5.12.0",
|
||||
"terser": "^5.36.0",
|
||||
"terser": "^5.37.0",
|
||||
"typescript-eslint": "8.17.0",
|
||||
"vite": "^6.0.2",
|
||||
"vite": "^6.0.3",
|
||||
"vite-plugin-imagemin": "^0.6.1",
|
||||
"vite-tsconfig-paths": "^5.1.3"
|
||||
},
|
||||
|
||||
@@ -83,7 +83,7 @@ const CustomEntities = () => {
|
||||
|
||||
const entity_theme = useTheme({
|
||||
Table: `
|
||||
--data-table-library_grid-template-columns: repeat(1, minmax(60px, 1fr)) minmax(80px, auto) 80px 80px 80px 90px;
|
||||
--data-table-library_grid-template-columns: repeat(1, minmax(60px, 1fr)) minmax(80px, auto) 80px 80px 80px 120px;
|
||||
`,
|
||||
BaseRow: `
|
||||
font-size: 14px;
|
||||
@@ -195,6 +195,25 @@ const CustomEntities = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const onDialogDup = (item: EntityItem) => {
|
||||
setCreating(true);
|
||||
setSelectedEntityItem({
|
||||
id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100),
|
||||
name: item.name + '_',
|
||||
ram: item.ram,
|
||||
device_id: item.device_id,
|
||||
type_id: item.type_id,
|
||||
offset: item.offset,
|
||||
factor: item.factor,
|
||||
uom: item.uom,
|
||||
value_type: item.value_type,
|
||||
writeable: item.writeable,
|
||||
deleted: false,
|
||||
value: item.value
|
||||
});
|
||||
setDialogOpen(true);
|
||||
};
|
||||
|
||||
const addEntityItem = () => {
|
||||
setCreating(true);
|
||||
setSelectedEntityItem({
|
||||
@@ -220,7 +239,7 @@ const CustomEntities = () => {
|
||||
: typeof value === 'number'
|
||||
? new Intl.NumberFormat().format(value) +
|
||||
(uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom])
|
||||
: (value as string);
|
||||
: (value as string) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
|
||||
}
|
||||
|
||||
function showHex(value: number, digit: number) {
|
||||
@@ -296,6 +315,7 @@ const CustomEntities = () => {
|
||||
creating={creating}
|
||||
onClose={onDialogClose}
|
||||
onSave={onDialogSave}
|
||||
onDup={onDialogDup}
|
||||
selectedItem={selectedEntityItem}
|
||||
validator={entityItemValidation(entities, selectedEntityItem)}
|
||||
/>
|
||||
|
||||
@@ -34,6 +34,7 @@ interface CustomEntitiesDialogProps {
|
||||
creating: boolean;
|
||||
onClose: () => void;
|
||||
onSave: (ei: EntityItem) => void;
|
||||
onDup: (ei: EntityItem) => void;
|
||||
selectedItem: EntityItem;
|
||||
validator: Schema;
|
||||
}
|
||||
@@ -43,6 +44,7 @@ const CustomEntitiesDialog = ({
|
||||
creating,
|
||||
onClose,
|
||||
onSave,
|
||||
onDup,
|
||||
selectedItem,
|
||||
validator
|
||||
}: CustomEntitiesDialogProps) => {
|
||||
@@ -91,6 +93,10 @@ const CustomEntitiesDialog = ({
|
||||
onSave(editItem);
|
||||
};
|
||||
|
||||
const dup = () => {
|
||||
onDup(editItem);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog sx={dialogStyle} open={open} onClose={handleClose}>
|
||||
<DialogTitle>
|
||||
@@ -128,18 +134,36 @@ const CustomEntitiesDialog = ({
|
||||
</TextField>
|
||||
</Grid>
|
||||
{editItem.ram === 1 && (
|
||||
<Grid>
|
||||
<TextField
|
||||
name="value"
|
||||
label={LL.DEFAULT(0) + ' ' + LL.VALUE(0)}
|
||||
type="string"
|
||||
value={editItem.value as string}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
/>
|
||||
</Grid>
|
||||
<>
|
||||
<Grid>
|
||||
<TextField
|
||||
name="value"
|
||||
label={LL.DEFAULT(0) + ' ' + LL.VALUE(0)}
|
||||
type="string"
|
||||
value={editItem.value as string}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
fullWidth
|
||||
margin="normal"
|
||||
/>
|
||||
</Grid>
|
||||
<Grid>
|
||||
<TextField
|
||||
name="uom"
|
||||
label={LL.UNIT()}
|
||||
value={editItem.uom}
|
||||
margin="normal"
|
||||
onChange={updateFormValue}
|
||||
select
|
||||
>
|
||||
{DeviceValueUOM_s.map((val, i) => (
|
||||
<MenuItem key={val} value={i}>
|
||||
{val}
|
||||
</MenuItem>
|
||||
))}
|
||||
</TextField>
|
||||
</Grid>
|
||||
</>
|
||||
)}
|
||||
{editItem.ram === 0 && (
|
||||
<>
|
||||
@@ -255,7 +279,7 @@ const CustomEntitiesDialog = ({
|
||||
<TextField
|
||||
name="factor"
|
||||
label={LL.FACTOR()}
|
||||
value={numberValue(editItem.factor)}
|
||||
value={numberValue(editItem.factor as number)}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
sx={{ width: '11ch' }}
|
||||
@@ -292,15 +316,41 @@ const CustomEntitiesDialog = ({
|
||||
fieldErrors={fieldErrors}
|
||||
name="factor"
|
||||
label="Bytes"
|
||||
value={numberValue(editItem.factor)}
|
||||
value={numberValue(editItem.factor as number)}
|
||||
sx={{ width: '11ch' }}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
margin="normal"
|
||||
type="number"
|
||||
slotProps={{
|
||||
htmlInput: { step: '1', min: '1', max: '255' }
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
{editItem.value_type === DeviceValueType.BOOL && (
|
||||
<Grid>
|
||||
<ValidatedTextField
|
||||
fieldErrors={fieldErrors}
|
||||
name="factor"
|
||||
label="Mask"
|
||||
value={editItem.factor as string}
|
||||
sx={{ width: '11ch' }}
|
||||
variant="outlined"
|
||||
onChange={updateFormValue}
|
||||
margin="normal"
|
||||
type="string"
|
||||
slotProps={{
|
||||
input: {
|
||||
startAdornment: (
|
||||
<InputAdornment position="start">0x</InputAdornment>
|
||||
)
|
||||
},
|
||||
htmlInput: { style: { textTransform: 'uppercase' } }
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Grid>
|
||||
@@ -316,6 +366,15 @@ const CustomEntitiesDialog = ({
|
||||
>
|
||||
{LL.REMOVE()}
|
||||
</Button>
|
||||
<Button
|
||||
sx={{ ml: 1 }}
|
||||
startIcon={<AddIcon />}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={dup}
|
||||
>
|
||||
{LL.DUPLICATE()}
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
<Button
|
||||
|
||||
@@ -34,7 +34,7 @@ export function formatValue(
|
||||
if (value === undefined || typeof value === 'boolean') {
|
||||
return '';
|
||||
}
|
||||
return value as string;
|
||||
return (value as string) + (uom === undefined || uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]);
|
||||
}
|
||||
|
||||
switch (uom) {
|
||||
|
||||
@@ -368,7 +368,7 @@ export interface EntityItem {
|
||||
device_id: number | string;
|
||||
type_id: number | string;
|
||||
offset: number;
|
||||
factor: number;
|
||||
factor: number | string;
|
||||
uom: number;
|
||||
value_type: number;
|
||||
value?: unknown;
|
||||
@@ -380,7 +380,7 @@ export interface EntityItem {
|
||||
o_device_id?: number | string;
|
||||
o_type_id?: number | string;
|
||||
o_offset?: number;
|
||||
o_factor?: number;
|
||||
o_factor?: number | string;
|
||||
o_uom?: number;
|
||||
o_value_type?: number;
|
||||
o_deleted?: boolean;
|
||||
|
||||
@@ -383,8 +383,7 @@ export const entityItemValidation = (entity: EntityItem[], entityItem: EntityIte
|
||||
{ type: 'number', min: 0, max: 255, message: 'Must be between 0 and 255' }
|
||||
],
|
||||
factor: [
|
||||
{ required: true, message: 'is required' },
|
||||
{ type: 'number', message: 'Must be a number' }
|
||||
{ required: true, message: 'is required' }
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ const ApplicationSettings = () => {
|
||||
name="modbus_timeout"
|
||||
label="Timeout"
|
||||
slotProps={{
|
||||
input: MilliSecondsInputProps
|
||||
input: SecondsInputProps
|
||||
}}
|
||||
variant="outlined"
|
||||
value={numberValue(data.modbus_timeout)}
|
||||
|
||||
@@ -343,6 +343,7 @@ const cz: Translation = {
|
||||
NO_DATA: 'Žádná data nejsou k dispozici',
|
||||
DASHBOARD_1: 'Přizpůsobte si dashboard označením EMS entit jako Oblíbené pomocí modulu Přizpůsobení',
|
||||
DEVELOPER_MODE: 'Režim vývojáře',
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,7 +343,8 @@ const de: Translation = {
|
||||
NO_DATA: 'Keine Daten verfügbar',
|
||||
DASHBOARD_1: 'Passen Sie Ihr Dashboard an, indem Sie EMS-Entitäten mithilfe des Moduls „Anpassungen“ als Favorit markieren',
|
||||
DEVELOPER_MODE: 'Entwicklermodus',
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
DUPLICATE: 'Kopieren',
|
||||
UPGRADE: 'Aktualisieren'
|
||||
};
|
||||
|
||||
export default de;
|
||||
|
||||
@@ -343,6 +343,7 @@ const en: Translation = {
|
||||
NO_DATA: 'No data available',
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module',
|
||||
DEVELOPER_MODE: 'Developer Mode',
|
||||
DUPLICATE: 'Duplicate',
|
||||
UPGRADE: 'Upgrade'
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const fr: Translation = {
|
||||
NO_DATA: 'No data available', // TODO translate
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const it: Translation = {
|
||||
NO_DATA: 'No data available', // TODO translate
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const nl: Translation = {
|
||||
NO_DATA: 'No data available', // TODO translate
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const no: Translation = {
|
||||
NO_DATA: 'No data available', // TODO translate
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const pl: BaseTranslation = {
|
||||
NO_DATA: 'No data available', // TODO translate
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const sk: Translation = {
|
||||
NO_DATA: 'Nie sú k dispozícii žiadne údaje',
|
||||
DASHBOARD_1: 'Prispôsobte si svoj informačný panel tak, že označíte entity EMS ako Obľúbené pomocou modulu Prispôsobenia',
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const sv: Translation = {
|
||||
NO_DATA: 'No data available', // TODO translate
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -343,6 +343,7 @@ const tr: Translation = {
|
||||
NO_DATA: 'No data available', // TODO translate
|
||||
DASHBOARD_1: 'Customize your dashboard by marking EMS entities as Favorite using the Customizations module', // TODO translate
|
||||
DEVELOPER_MODE: 'Developer Mode', // TODO translate
|
||||
DUPLICATE: 'Duplicate', // TODO translate
|
||||
UPGRADE: 'Upgrade' // TODO translate
|
||||
};
|
||||
|
||||
|
||||
@@ -74,18 +74,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/generator@npm:7.17.7":
|
||||
version: 7.17.7
|
||||
resolution: "@babel/generator@npm:7.17.7"
|
||||
dependencies:
|
||||
"@babel/types": "npm:^7.17.0"
|
||||
jsesc: "npm:^2.5.1"
|
||||
source-map: "npm:^0.5.0"
|
||||
checksum: 10c0/8088453c4418e0ee6528506fbd5847bbdfd56327a0025ca9496a259261e162c594ffd08be0d63e74c32feced795616772f38acc5f5e493a86a45fd439fd9feb0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/generator@npm:^7.23.0, @babel/generator@npm:^7.25.9, @babel/generator@npm:^7.26.0":
|
||||
"@babel/generator@npm:^7.25.9, @babel/generator@npm:^7.26.0":
|
||||
version: 7.26.2
|
||||
resolution: "@babel/generator@npm:7.26.2"
|
||||
dependencies:
|
||||
@@ -98,6 +87,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/generator@npm:^7.26.2":
|
||||
version: 7.26.3
|
||||
resolution: "@babel/generator@npm:7.26.3"
|
||||
dependencies:
|
||||
"@babel/parser": "npm:^7.26.3"
|
||||
"@babel/types": "npm:^7.26.3"
|
||||
"@jridgewell/gen-mapping": "npm:^0.3.5"
|
||||
"@jridgewell/trace-mapping": "npm:^0.3.25"
|
||||
jsesc: "npm:^3.0.2"
|
||||
checksum: 10c0/54f260558e3e4ec8942da3cde607c35349bb983c3a7c5121243f96893fba3e8cd62e1f1773b2051f936f8c8a10987b758d5c7d76dbf2784e95bb63ab4843fa00
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-annotate-as-pure@npm:^7.25.9":
|
||||
version: 7.25.9
|
||||
resolution: "@babel/helper-annotate-as-pure@npm:7.25.9"
|
||||
@@ -120,34 +122,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-environment-visitor@npm:^7.22.20":
|
||||
version: 7.24.7
|
||||
resolution: "@babel/helper-environment-visitor@npm:7.24.7"
|
||||
dependencies:
|
||||
"@babel/types": "npm:^7.24.7"
|
||||
checksum: 10c0/36ece78882b5960e2d26abf13cf15ff5689bf7c325b10a2895a74a499e712de0d305f8d78bb382dd3c05cfba7e47ec98fe28aab5674243e0625cd38438dd0b2d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-function-name@npm:^7.23.0":
|
||||
version: 7.24.7
|
||||
resolution: "@babel/helper-function-name@npm:7.24.7"
|
||||
dependencies:
|
||||
"@babel/template": "npm:^7.24.7"
|
||||
"@babel/types": "npm:^7.24.7"
|
||||
checksum: 10c0/e5e41e6cf86bd0f8bf272cbb6e7c5ee0f3e9660414174435a46653efba4f2479ce03ce04abff2aa2ef9359cf057c79c06cb7b134a565ad9c0e8a50dcdc3b43c4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-hoist-variables@npm:^7.22.5":
|
||||
version: 7.24.7
|
||||
resolution: "@babel/helper-hoist-variables@npm:7.24.7"
|
||||
dependencies:
|
||||
"@babel/types": "npm:^7.24.7"
|
||||
checksum: 10c0/19ee37563bbd1219f9d98991ad0e9abef77803ee5945fd85aa7aa62a67c69efca9a801696a1b58dda27f211e878b3327789e6fd2a6f6c725ccefe36774b5ce95
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-module-imports@npm:^7.16.7, @babel/helper-module-imports@npm:^7.25.9":
|
||||
version: 7.25.9
|
||||
resolution: "@babel/helper-module-imports@npm:7.25.9"
|
||||
@@ -178,15 +152,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-split-export-declaration@npm:^7.22.6":
|
||||
version: 7.24.7
|
||||
resolution: "@babel/helper-split-export-declaration@npm:7.24.7"
|
||||
dependencies:
|
||||
"@babel/types": "npm:^7.24.7"
|
||||
checksum: 10c0/0254577d7086bf09b01bbde98f731d4fcf4b7c3fa9634fdb87929801307c1f6202a1352e3faa5492450fa8da4420542d44de604daf540704ff349594a78184f6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-string-parser@npm:^7.25.9":
|
||||
version: 7.25.9
|
||||
resolution: "@babel/helper-string-parser@npm:7.25.9"
|
||||
@@ -194,7 +159,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-validator-identifier@npm:^7.16.7, @babel/helper-validator-identifier@npm:^7.25.9":
|
||||
"@babel/helper-validator-identifier@npm:^7.25.9":
|
||||
version: 7.25.9
|
||||
resolution: "@babel/helper-validator-identifier@npm:7.25.9"
|
||||
checksum: 10c0/4fc6f830177b7b7e887ad3277ddb3b91d81e6c4a24151540d9d1023e8dc6b1c0505f0f0628ae653601eb4388a8db45c1c14b2c07a9173837aef7e4116456259d
|
||||
@@ -218,7 +183,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/parser@npm:^7.20.5, @babel/parser@npm:^7.23.0, @babel/parser@npm:^7.25.9, @babel/parser@npm:^7.26.0, @babel/parser@npm:^7.26.2":
|
||||
"@babel/parser@npm:^7.25.9, @babel/parser@npm:^7.26.0, @babel/parser@npm:^7.26.2":
|
||||
version: 7.26.2
|
||||
resolution: "@babel/parser@npm:7.26.2"
|
||||
dependencies:
|
||||
@@ -229,6 +194,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/parser@npm:^7.26.3":
|
||||
version: 7.26.3
|
||||
resolution: "@babel/parser@npm:7.26.3"
|
||||
dependencies:
|
||||
"@babel/types": "npm:^7.26.3"
|
||||
bin:
|
||||
parser: ./bin/babel-parser.js
|
||||
checksum: 10c0/48f736374e61cfd10ddbf7b80678514ae1f16d0e88bc793d2b505d73d9b987ea786fc8c2f7ee8f8b8c467df062030eb07fd0eb2168f0f541ca1f542775852cad
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-syntax-jsx@npm:^7.25.9":
|
||||
version: 7.25.9
|
||||
resolution: "@babel/plugin-syntax-jsx@npm:7.25.9"
|
||||
@@ -275,7 +251,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/template@npm:^7.24.7, @babel/template@npm:^7.25.9":
|
||||
"@babel/template@npm:^7.25.9":
|
||||
version: 7.25.9
|
||||
resolution: "@babel/template@npm:7.25.9"
|
||||
dependencies:
|
||||
@@ -286,24 +262,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/traverse@npm:7.23.2":
|
||||
version: 7.23.2
|
||||
resolution: "@babel/traverse@npm:7.23.2"
|
||||
dependencies:
|
||||
"@babel/code-frame": "npm:^7.22.13"
|
||||
"@babel/generator": "npm:^7.23.0"
|
||||
"@babel/helper-environment-visitor": "npm:^7.22.20"
|
||||
"@babel/helper-function-name": "npm:^7.23.0"
|
||||
"@babel/helper-hoist-variables": "npm:^7.22.5"
|
||||
"@babel/helper-split-export-declaration": "npm:^7.22.6"
|
||||
"@babel/parser": "npm:^7.23.0"
|
||||
"@babel/types": "npm:^7.23.0"
|
||||
debug: "npm:^4.1.0"
|
||||
globals: "npm:^11.1.0"
|
||||
checksum: 10c0/d096c7c4bab9262a2f658298a3c630ae4a15a10755bb257ae91d5ab3e3b2877438934859c8d34018b7727379fe6b26c4fa2efc81cf4c462a7fe00caf79fa02ff
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/traverse@npm:^7.25.9":
|
||||
version: 7.25.9
|
||||
resolution: "@babel/traverse@npm:7.25.9"
|
||||
@@ -319,17 +277,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/types@npm:7.17.0":
|
||||
version: 7.17.0
|
||||
resolution: "@babel/types@npm:7.17.0"
|
||||
dependencies:
|
||||
"@babel/helper-validator-identifier": "npm:^7.16.7"
|
||||
to-fast-properties: "npm:^2.0.0"
|
||||
checksum: 10c0/ad09224272b40fedb00b262677d12b6838f5b5df5c47d67059ba1181bd4805439993393a8de32459dae137b536d60ebfcaf39ae84d8b3873f1e81cc75f5aeae8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/types@npm:^7.17.0, @babel/types@npm:^7.23.0, @babel/types@npm:^7.24.7, @babel/types@npm:^7.25.9, @babel/types@npm:^7.26.0":
|
||||
"@babel/types@npm:^7.25.9, @babel/types@npm:^7.26.0":
|
||||
version: 7.26.0
|
||||
resolution: "@babel/types@npm:7.26.0"
|
||||
dependencies:
|
||||
@@ -339,6 +287,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/types@npm:^7.26.3":
|
||||
version: 7.26.3
|
||||
resolution: "@babel/types@npm:7.26.3"
|
||||
dependencies:
|
||||
"@babel/helper-string-parser": "npm:^7.25.9"
|
||||
"@babel/helper-validator-identifier": "npm:^7.25.9"
|
||||
checksum: 10c0/966c5242c5e55c8704bf7a7418e7be2703a0afa4d19a8480999d5a4ef13d095dd60686615fe5983cb7593b4b06ba3a7de8d6ca501c1d78bdd233a10d90be787b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@emotion/babel-plugin@npm:^11.13.5":
|
||||
version: 11.13.5
|
||||
resolution: "@emotion/babel-plugin@npm:11.13.5"
|
||||
@@ -840,38 +798,38 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mui/core-downloads-tracker@npm:^6.1.9":
|
||||
version: 6.1.9
|
||||
resolution: "@mui/core-downloads-tracker@npm:6.1.9"
|
||||
checksum: 10c0/f84c48291e6c85bafb60015f0464f041ca3168dcfd7c563cb584bf925495872f0a180ed52e985b544c6cb87297a1686b1d3a90f451d12594765d0811fc7514b0
|
||||
"@mui/core-downloads-tracker@npm:^6.1.10":
|
||||
version: 6.1.10
|
||||
resolution: "@mui/core-downloads-tracker@npm:6.1.10"
|
||||
checksum: 10c0/b94259c7cc8065dfed7ead4250e1bba4e65ec5625d86a11d118d1c22ec05f058d6f93b66d73bba9d787453058a2a05b5a1bbfd01ac53f3410e25358da3e4a571
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mui/icons-material@npm:^6.1.9":
|
||||
version: 6.1.9
|
||||
resolution: "@mui/icons-material@npm:6.1.9"
|
||||
"@mui/icons-material@npm:^6.1.10":
|
||||
version: 6.1.10
|
||||
resolution: "@mui/icons-material@npm:6.1.10"
|
||||
dependencies:
|
||||
"@babel/runtime": "npm:^7.26.0"
|
||||
peerDependencies:
|
||||
"@mui/material": ^6.1.9
|
||||
"@mui/material": ^6.1.10
|
||||
"@types/react": ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
peerDependenciesMeta:
|
||||
"@types/react":
|
||||
optional: true
|
||||
checksum: 10c0/7efc0c4a4c668118252ec0a0bf7ed8e4d9af68d03d92e76d382109aaf8b018bd3512b47c444947c12df25be02615483a5e4889ddf745b42ab0446583b34d59f8
|
||||
checksum: 10c0/970a402962b27219bdff4b7af32e758fea800c6879112887cdc71f0d6869c3ea66e24e320edbc39b704f174511a918a055b96d49b91bdeefb1afe8d753b42d4e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mui/material@npm:^6.1.9":
|
||||
version: 6.1.9
|
||||
resolution: "@mui/material@npm:6.1.9"
|
||||
"@mui/material@npm:^6.1.10":
|
||||
version: 6.1.10
|
||||
resolution: "@mui/material@npm:6.1.10"
|
||||
dependencies:
|
||||
"@babel/runtime": "npm:^7.26.0"
|
||||
"@mui/core-downloads-tracker": "npm:^6.1.9"
|
||||
"@mui/system": "npm:^6.1.9"
|
||||
"@mui/core-downloads-tracker": "npm:^6.1.10"
|
||||
"@mui/system": "npm:^6.1.10"
|
||||
"@mui/types": "npm:^7.2.19"
|
||||
"@mui/utils": "npm:^6.1.9"
|
||||
"@mui/utils": "npm:^6.1.10"
|
||||
"@popperjs/core": "npm:^2.11.8"
|
||||
"@types/react-transition-group": "npm:^4.4.11"
|
||||
clsx: "npm:^2.1.1"
|
||||
@@ -882,7 +840,7 @@ __metadata:
|
||||
peerDependencies:
|
||||
"@emotion/react": ^11.5.0
|
||||
"@emotion/styled": ^11.3.0
|
||||
"@mui/material-pigment-css": ^6.1.9
|
||||
"@mui/material-pigment-css": ^6.1.10
|
||||
"@types/react": ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
react: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
react-dom: ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
@@ -895,16 +853,16 @@ __metadata:
|
||||
optional: true
|
||||
"@types/react":
|
||||
optional: true
|
||||
checksum: 10c0/934be9f17e66ac9944ff970c2a2c67292aadd339f5124e2ec82fbfd25fe713e7716c61005b918dd31836674fb8e327bd87f200276f2ef8930e9ba4e77727bad6
|
||||
checksum: 10c0/501f434aa61b56806cd6d8bc27ddd0cfc6f423ee132bb0cc02ca36af182b251b8d15dd69ed8b90742813039d2bfe1e396f6ddf84f15f453d53bfbf355d18f99a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mui/private-theming@npm:^6.1.9":
|
||||
version: 6.1.9
|
||||
resolution: "@mui/private-theming@npm:6.1.9"
|
||||
"@mui/private-theming@npm:^6.1.10":
|
||||
version: 6.1.10
|
||||
resolution: "@mui/private-theming@npm:6.1.10"
|
||||
dependencies:
|
||||
"@babel/runtime": "npm:^7.26.0"
|
||||
"@mui/utils": "npm:^6.1.9"
|
||||
"@mui/utils": "npm:^6.1.10"
|
||||
prop-types: "npm:^15.8.1"
|
||||
peerDependencies:
|
||||
"@types/react": ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
@@ -912,13 +870,13 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
"@types/react":
|
||||
optional: true
|
||||
checksum: 10c0/d2ed09a50a30496905ba57735c370efa85b00ed0b29b2bd9e7193416d4825659d48abaf2bcf649a80dfaa035262487b81a3396b042fd97646f775ca4d20dd05c
|
||||
checksum: 10c0/1e296d7582b276e7b9de8c9af252b4998ab8343a570ed7ead8c23b3275a218f0722f389d698c45cab9b4b219ad82411af6f71c7678818d3387925db01d1a9ead
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mui/styled-engine@npm:^6.1.9":
|
||||
version: 6.1.9
|
||||
resolution: "@mui/styled-engine@npm:6.1.9"
|
||||
"@mui/styled-engine@npm:^6.1.10":
|
||||
version: 6.1.10
|
||||
resolution: "@mui/styled-engine@npm:6.1.10"
|
||||
dependencies:
|
||||
"@babel/runtime": "npm:^7.26.0"
|
||||
"@emotion/cache": "npm:^11.13.5"
|
||||
@@ -935,19 +893,19 @@ __metadata:
|
||||
optional: true
|
||||
"@emotion/styled":
|
||||
optional: true
|
||||
checksum: 10c0/74d239b2d306b0aa2271d9943cea83ea0a05c16c55cd2239605b0f1cb91fc4aa508891173d1b9bb69e92074d1d4db14d8b85618c639667967a1f608607047e66
|
||||
checksum: 10c0/2e6ad8f1c3de4ce4b6a246de976f304e433e8a5031465bc9614e51eeae2dd308c76dbdfc2b9f95bbcb971c1008bdbc9103d9418313934a9760f6555334997586
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mui/system@npm:^6.1.9":
|
||||
version: 6.1.9
|
||||
resolution: "@mui/system@npm:6.1.9"
|
||||
"@mui/system@npm:^6.1.10":
|
||||
version: 6.1.10
|
||||
resolution: "@mui/system@npm:6.1.10"
|
||||
dependencies:
|
||||
"@babel/runtime": "npm:^7.26.0"
|
||||
"@mui/private-theming": "npm:^6.1.9"
|
||||
"@mui/styled-engine": "npm:^6.1.9"
|
||||
"@mui/private-theming": "npm:^6.1.10"
|
||||
"@mui/styled-engine": "npm:^6.1.10"
|
||||
"@mui/types": "npm:^7.2.19"
|
||||
"@mui/utils": "npm:^6.1.9"
|
||||
"@mui/utils": "npm:^6.1.10"
|
||||
clsx: "npm:^2.1.1"
|
||||
csstype: "npm:^3.1.3"
|
||||
prop-types: "npm:^15.8.1"
|
||||
@@ -963,7 +921,7 @@ __metadata:
|
||||
optional: true
|
||||
"@types/react":
|
||||
optional: true
|
||||
checksum: 10c0/0ae66dbbf183bf6ccefeaf3808699c6ef2dd72928134e3e902716e3f75d6b15ccc41c1478a23f20824b76ff3ca86b0923ebccb58ae11b9e04305988eae74d653
|
||||
checksum: 10c0/ba228faa0a2c3f5b25770faa1484c04846889642eda1d0c3922b324c6de2946fc4debf7ddb994f1ef349bbe260243ab5e1117b624ea5062209ba1898f5dff1a3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -979,9 +937,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mui/utils@npm:^6.1.9":
|
||||
version: 6.1.9
|
||||
resolution: "@mui/utils@npm:6.1.9"
|
||||
"@mui/utils@npm:^6.1.10":
|
||||
version: 6.1.10
|
||||
resolution: "@mui/utils@npm:6.1.10"
|
||||
dependencies:
|
||||
"@babel/runtime": "npm:^7.26.0"
|
||||
"@mui/types": "npm:^7.2.19"
|
||||
@@ -995,7 +953,7 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
"@types/react":
|
||||
optional: true
|
||||
checksum: 10c0/2cd28cc44f9048b2c9b5511f074082da1f5b969c524f08f827aaa5e226392238bb91fbf6c5054290590b5d9a67d7f753a6ee9b7cc7613df7193635b8f63ca577
|
||||
checksum: 10c0/0cecda147b026fbb6f397e54fc08719c5805a7e5fd4255c30a45a7155748345dbbc57fda9181986db222f93da0012f001b1f1f624084e5227ca7814ed1c3dd30
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1291,23 +1249,29 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@trivago/prettier-plugin-sort-imports@npm:^4.3.0":
|
||||
version: 4.3.0
|
||||
resolution: "@trivago/prettier-plugin-sort-imports@npm:4.3.0"
|
||||
"@trivago/prettier-plugin-sort-imports@npm:^5.0.1":
|
||||
version: 5.0.1
|
||||
resolution: "@trivago/prettier-plugin-sort-imports@npm:5.0.1"
|
||||
dependencies:
|
||||
"@babel/generator": "npm:7.17.7"
|
||||
"@babel/parser": "npm:^7.20.5"
|
||||
"@babel/traverse": "npm:7.23.2"
|
||||
"@babel/types": "npm:7.17.0"
|
||||
javascript-natural-sort: "npm:0.7.1"
|
||||
"@babel/generator": "npm:^7.26.2"
|
||||
"@babel/parser": "npm:^7.26.2"
|
||||
"@babel/traverse": "npm:^7.25.9"
|
||||
"@babel/types": "npm:^7.26.0"
|
||||
javascript-natural-sort: "npm:^0.7.1"
|
||||
lodash: "npm:^4.17.21"
|
||||
peerDependencies:
|
||||
"@vue/compiler-sfc": 3.x
|
||||
prettier: 2.x - 3.x
|
||||
prettier-plugin-svelte: 3.x
|
||||
svelte: 4.x
|
||||
peerDependenciesMeta:
|
||||
"@vue/compiler-sfc":
|
||||
optional: true
|
||||
checksum: 10c0/42270fb9c89e54a3f8b6ac8c43e6d0e03350e2857e902cdad4de22c78ef1864da600525595311bc7e94e51c16c7dd3882c2e048a162fdab59761ffa893756aa2
|
||||
prettier-plugin-svelte:
|
||||
optional: true
|
||||
svelte:
|
||||
optional: true
|
||||
checksum: 10c0/2256a2ff06f1809f52e37d609ed04cdb5253f3ee83e959dfff301f4e6f3295cdd4adb5015d5a1ac40ff934f6bde9c0c2bd1e84ee7c0d65e5b755c4ce739bfe08
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1488,7 +1452,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/react@npm:*, @types/react@npm:^18.3.12":
|
||||
"@types/react@npm:*":
|
||||
version: 18.3.12
|
||||
resolution: "@types/react@npm:18.3.12"
|
||||
dependencies:
|
||||
@@ -1498,6 +1462,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/react@npm:^18.3.13":
|
||||
version: 18.3.13
|
||||
resolution: "@types/react@npm:18.3.13"
|
||||
dependencies:
|
||||
"@types/prop-types": "npm:*"
|
||||
csstype: "npm:^3.0.2"
|
||||
checksum: 10c0/91815e00157deb179fa670aa2dfc491952698b7743ffddca0e3e0f16e7a18454f3f5ef72321a07386c49e721563b9d280dbbdfae039face764e2fdd8ad949d4b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/responselike@npm:^1.0.0":
|
||||
version: 1.0.3
|
||||
resolution: "@types/responselike@npm:1.0.3"
|
||||
@@ -1646,15 +1620,15 @@ __metadata:
|
||||
"@emotion/react": "npm:^11.13.5"
|
||||
"@emotion/styled": "npm:^11.13.5"
|
||||
"@eslint/js": "npm:^9.16.0"
|
||||
"@mui/icons-material": "npm:^6.1.9"
|
||||
"@mui/material": "npm:^6.1.9"
|
||||
"@mui/icons-material": "npm:^6.1.10"
|
||||
"@mui/material": "npm:^6.1.10"
|
||||
"@preact/compat": "npm:^18.3.1"
|
||||
"@preact/preset-vite": "npm:^2.9.2"
|
||||
"@table-library/react-table-library": "npm:4.1.7"
|
||||
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
|
||||
"@trivago/prettier-plugin-sort-imports": "npm:^5.0.1"
|
||||
"@types/formidable": "npm:^3"
|
||||
"@types/node": "npm:^22.10.1"
|
||||
"@types/react": "npm:^18.3.12"
|
||||
"@types/react": "npm:^18.3.13"
|
||||
"@types/react-dom": "npm:^18.3.1"
|
||||
alova: "npm:3.2.6"
|
||||
async-validator: "npm:^4.2.5"
|
||||
@@ -1665,18 +1639,18 @@ __metadata:
|
||||
jwt-decode: "npm:^4.0.0"
|
||||
mime-types: "npm:^2.1.35"
|
||||
preact: "npm:^10.25.1"
|
||||
prettier: "npm:^3.4.1"
|
||||
react: "npm:^18.3.1"
|
||||
react-dom: "npm:^18.3.1"
|
||||
react-icons: "npm:^5.3.0"
|
||||
react-router: "npm:^7.0.1"
|
||||
prettier: "npm:^3.4.2"
|
||||
react: "npm:^19.0.0"
|
||||
react-dom: "npm:^19.0.0"
|
||||
react-icons: "npm:^5.4.0"
|
||||
react-router: "npm:^7.0.2"
|
||||
react-toastify: "npm:^10.0.6"
|
||||
rollup-plugin-visualizer: "npm:^5.12.0"
|
||||
terser: "npm:^5.36.0"
|
||||
terser: "npm:^5.37.0"
|
||||
typesafe-i18n: "npm:^5.26.2"
|
||||
typescript: "npm:^5.7.2"
|
||||
typescript-eslint: "npm:8.17.0"
|
||||
vite: "npm:^6.0.2"
|
||||
vite: "npm:^6.0.3"
|
||||
vite-plugin-imagemin: "npm:^0.6.1"
|
||||
vite-tsconfig-paths: "npm:^5.1.3"
|
||||
languageName: unknown
|
||||
@@ -4420,7 +4394,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"javascript-natural-sort@npm:0.7.1":
|
||||
"javascript-natural-sort@npm:^0.7.1":
|
||||
version: 0.7.1
|
||||
resolution: "javascript-natural-sort@npm:0.7.1"
|
||||
checksum: 10c0/340f8ffc5d30fb516e06dc540e8fa9e0b93c865cf49d791fed3eac3bdc5fc71f0066fc81d44ec1433edc87caecaf9f13eec4a1fce8c5beafc709a71eaedae6fe
|
||||
@@ -4477,15 +4451,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"jsesc@npm:^2.5.1":
|
||||
version: 2.5.2
|
||||
resolution: "jsesc@npm:2.5.2"
|
||||
bin:
|
||||
jsesc: bin/jsesc
|
||||
checksum: 10c0/dbf59312e0ebf2b4405ef413ec2b25abb5f8f4d9bc5fb8d9f90381622ebca5f2af6a6aa9a8578f65903f9e33990a6dc798edd0ce5586894bf0e9e31803a1de88
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"jsesc@npm:^3.0.2":
|
||||
version: 3.0.2
|
||||
resolution: "jsesc@npm:3.0.2"
|
||||
@@ -4661,7 +4626,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"loose-envify@npm:^1.1.0, loose-envify@npm:^1.4.0":
|
||||
"loose-envify@npm:^1.4.0":
|
||||
version: 1.4.0
|
||||
resolution: "loose-envify@npm:1.4.0"
|
||||
dependencies:
|
||||
@@ -5578,12 +5543,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"prettier@npm:^3.4.1":
|
||||
version: 3.4.1
|
||||
resolution: "prettier@npm:3.4.1"
|
||||
"prettier@npm:^3.4.2":
|
||||
version: 3.4.2
|
||||
resolution: "prettier@npm:3.4.2"
|
||||
bin:
|
||||
prettier: bin/prettier.cjs
|
||||
checksum: 10c0/2d6cc3101ad9de72b49c59339480b0983e6ff6742143da0c43f476bf3b5ef88ede42ebd9956d7a0a8fa59f7a5990e8ef03c9ad4c37f7e4c9e5db43ee0853156c
|
||||
checksum: 10c0/99e076a26ed0aba4ebc043880d0f08bbb8c59a4c6641cdee6cdadf2205bdd87aa1d7823f50c3aea41e015e99878d37c58d7b5f0e663bba0ef047f94e36b96446
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5678,24 +5643,23 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"react-dom@npm:^18.3.1":
|
||||
version: 18.3.1
|
||||
resolution: "react-dom@npm:18.3.1"
|
||||
"react-dom@npm:^19.0.0":
|
||||
version: 19.0.0
|
||||
resolution: "react-dom@npm:19.0.0"
|
||||
dependencies:
|
||||
loose-envify: "npm:^1.1.0"
|
||||
scheduler: "npm:^0.23.2"
|
||||
scheduler: "npm:^0.25.0"
|
||||
peerDependencies:
|
||||
react: ^18.3.1
|
||||
checksum: 10c0/a752496c1941f958f2e8ac56239172296fcddce1365ce45222d04a1947e0cc5547df3e8447f855a81d6d39f008d7c32eab43db3712077f09e3f67c4874973e85
|
||||
react: ^19.0.0
|
||||
checksum: 10c0/a36ce7ab507b237ae2759c984cdaad4af4096d8199fb65b3815c16825e5cfeb7293da790a3fc2184b52bfba7ba3ff31c058c01947aff6fd1a3701632aabaa6a9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"react-icons@npm:^5.3.0":
|
||||
version: 5.3.0
|
||||
resolution: "react-icons@npm:5.3.0"
|
||||
"react-icons@npm:^5.4.0":
|
||||
version: 5.4.0
|
||||
resolution: "react-icons@npm:5.4.0"
|
||||
peerDependencies:
|
||||
react: "*"
|
||||
checksum: 10c0/a53af0de558f0e2bacfbafc973aa8ca1e6a429006a2f83d70becad5be431726a691e096336c95949bb0d967587b145264c5046d2bc1518969dbae731855d0712
|
||||
checksum: 10c0/698b0c4616870152d86de2585fb709bf3eeb9292d971d689965dade5f0ee71cdc92d2125b728ab220cc39a4c6d6bad1ed526b9b934ab39a7b6001bc23b73ee16
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5713,9 +5677,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"react-router@npm:^7.0.1":
|
||||
version: 7.0.1
|
||||
resolution: "react-router@npm:7.0.1"
|
||||
"react-router@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "react-router@npm:7.0.2"
|
||||
dependencies:
|
||||
"@types/cookie": "npm:^0.6.0"
|
||||
cookie: "npm:^1.0.1"
|
||||
@@ -5727,7 +5691,7 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
react-dom:
|
||||
optional: true
|
||||
checksum: 10c0/aac4c9989ae6b9cf989b5ddcda88f505ba0704a4e4b37ae04c819c2bd02f080361f9eb1793695e3ecf41080d91b79aee454c3163b586d1b19ceca13f6eacec0e
|
||||
checksum: 10c0/f6c04939218a3d7f2b03b215c2299eab4dbb0dea4a16e0acfd8bf181ec69ff42d66abdba10a25cc3297c514f052a0d03bfb80431225eb763bb27e4e5b0b4a106
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -5781,12 +5745,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"react@npm:^18.3.1":
|
||||
version: 18.3.1
|
||||
resolution: "react@npm:18.3.1"
|
||||
dependencies:
|
||||
loose-envify: "npm:^1.1.0"
|
||||
checksum: 10c0/283e8c5efcf37802c9d1ce767f302dd569dd97a70d9bb8c7be79a789b9902451e0d16334b05d73299b20f048cbc3c7d288bbbde10b701fa194e2089c237dbea3
|
||||
"react@npm:^19.0.0":
|
||||
version: 19.0.0
|
||||
resolution: "react@npm:19.0.0"
|
||||
checksum: 10c0/9cad8f103e8e3a16d15cb18a0d8115d8bd9f9e1ce3420310aea381eb42aa0a4f812cf047bb5441349257a05fba8a291515691e3cb51267279b2d2c3253f38471
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -6060,12 +6022,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"scheduler@npm:^0.23.2":
|
||||
version: 0.23.2
|
||||
resolution: "scheduler@npm:0.23.2"
|
||||
dependencies:
|
||||
loose-envify: "npm:^1.1.0"
|
||||
checksum: 10c0/26383305e249651d4c58e6705d5f8425f153211aef95f15161c151f7b8de885f24751b377e4a0b3dd42cce09aad3f87a61dab7636859c0d89b7daf1a1e2a5c78
|
||||
"scheduler@npm:^0.25.0":
|
||||
version: 0.25.0
|
||||
resolution: "scheduler@npm:0.25.0"
|
||||
checksum: 10c0/a4bb1da406b613ce72c1299db43759526058fdcc413999c3c3e0db8956df7633acf395cb20eb2303b6a65d658d66b6585d344460abaee8080b4aa931f10eaafe
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -6263,7 +6223,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"source-map@npm:^0.5.0, source-map@npm:^0.5.7":
|
||||
"source-map@npm:^0.5.7":
|
||||
version: 0.5.7
|
||||
resolution: "source-map@npm:0.5.7"
|
||||
checksum: 10c0/904e767bb9c494929be013017380cbba013637da1b28e5943b566031e29df04fba57edf3f093e0914be094648b577372bd8ad247fa98cfba9c600794cd16b599
|
||||
@@ -6592,9 +6552,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"terser@npm:^5.36.0":
|
||||
version: 5.36.0
|
||||
resolution: "terser@npm:5.36.0"
|
||||
"terser@npm:^5.37.0":
|
||||
version: 5.37.0
|
||||
resolution: "terser@npm:5.37.0"
|
||||
dependencies:
|
||||
"@jridgewell/source-map": "npm:^0.3.3"
|
||||
acorn: "npm:^8.8.2"
|
||||
@@ -6602,7 +6562,7 @@ __metadata:
|
||||
source-map-support: "npm:~0.5.20"
|
||||
bin:
|
||||
terser: bin/terser
|
||||
checksum: 10c0/f4ed2bead19f64789ddcfb85b7cef78f3942f967b8890c54f57d1e35bc7d547d551c6a4c32210bce6ba45b1c738314bbfac6acbc6c762a45cd171777d0c120d9
|
||||
checksum: 10c0/ff0dc79b0a0da821e7f5bf7a047eab6d04e70e88b62339a0f1d71117db3310e255f5c00738fa3b391f56c3571f800a00047720261ba04ced0241c1f9922199f4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -6627,13 +6587,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"to-fast-properties@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "to-fast-properties@npm:2.0.0"
|
||||
checksum: 10c0/b214d21dbfb4bce3452b6244b336806ffea9c05297148d32ebb428d5c43ce7545bdfc65a1ceb58c9ef4376a65c0cb2854d645f33961658b3e3b4f84910ddcdd7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"to-regex-range@npm:^5.0.1":
|
||||
version: 5.0.1
|
||||
resolution: "to-regex-range@npm:5.0.1"
|
||||
@@ -6942,9 +6895,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"vite@npm:^6.0.2":
|
||||
version: 6.0.2
|
||||
resolution: "vite@npm:6.0.2"
|
||||
"vite@npm:^6.0.3":
|
||||
version: 6.0.3
|
||||
resolution: "vite@npm:6.0.3"
|
||||
dependencies:
|
||||
esbuild: "npm:^0.24.0"
|
||||
fsevents: "npm:~2.3.3"
|
||||
@@ -6990,7 +6943,7 @@ __metadata:
|
||||
optional: true
|
||||
bin:
|
||||
vite: bin/vite.js
|
||||
checksum: 10c0/45fc609f2bc5fb5beb5a8e2cad9ad6c2edce229a922f6fc1270ea2a9d75819482edcc0f77c85b4a7abdad7eb69ce6a4f26131925d47cdc0778fc15d1bbc3b6a2
|
||||
checksum: 10c0/764ebed14770426a638575b23a51127c630ace873999ab896b0184484d8107e7255cdf64cfb36c65c1ef1d583e44b70a1d14c0f05b89612e834a5806e3964475
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
@@ -33,6 +33,32 @@ extern "C" {
|
||||
#include "esp_task_wdt.h"
|
||||
#endif
|
||||
|
||||
// Required for:
|
||||
// https://github.com/espressif/arduino-esp32/blob/3.0.3/libraries/Network/src/NetworkInterface.cpp#L37-L47
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
// #include <NetworkInterface.h>
|
||||
#endif
|
||||
|
||||
#define TAG "AsyncTCP"
|
||||
|
||||
// https://github.com/espressif/arduino-esp32/issues/10526
|
||||
#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
|
||||
#define TCP_MUTEX_LOCK() \
|
||||
if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
|
||||
LOCK_TCPIP_CORE(); \
|
||||
}
|
||||
|
||||
#define TCP_MUTEX_UNLOCK() \
|
||||
if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
|
||||
UNLOCK_TCPIP_CORE(); \
|
||||
}
|
||||
#else // CONFIG_LWIP_TCPIP_CORE_LOCKING
|
||||
#define TCP_MUTEX_LOCK()
|
||||
#define TCP_MUTEX_UNLOCK()
|
||||
#endif // CONFIG_LWIP_TCPIP_CORE_LOCKING
|
||||
|
||||
#define INVALID_CLOSED_SLOT -1
|
||||
|
||||
/*
|
||||
* TCP/IP Event Task
|
||||
* */
|
||||
@@ -54,8 +80,8 @@ typedef struct {
|
||||
void * arg;
|
||||
union {
|
||||
struct {
|
||||
void * pcb;
|
||||
int8_t err;
|
||||
tcp_pcb * pcb;
|
||||
int8_t err;
|
||||
} connected;
|
||||
struct {
|
||||
int8_t err;
|
||||
@@ -105,8 +131,7 @@ static uint32_t _closed_index = []() {
|
||||
|
||||
static inline bool _init_async_event_queue() {
|
||||
if (!_async_queue) {
|
||||
_async_queue =
|
||||
xQueueCreate(CONFIG_ASYNC_TCP_QUEUE, sizeof(lwip_event_packet_t *)); // double queue to 128 see https://github.com/emsesp/EMS-ESP32/issues/177
|
||||
_async_queue = xQueueCreate(CONFIG_ASYNC_TCP_QUEUE_SIZE, sizeof(lwip_event_packet_t *));
|
||||
if (!_async_queue) {
|
||||
return false;
|
||||
}
|
||||
@@ -252,7 +277,7 @@ static bool _start_async_task() {
|
||||
"async_tcp",
|
||||
CONFIG_ASYNC_TCP_STACK_SIZE,
|
||||
NULL,
|
||||
CONFIG_ASYNC_TCP_TASK_PRIORITY,
|
||||
CONFIG_ASYNC_TCP_PRIORITY,
|
||||
&_async_service_task_handle,
|
||||
CONFIG_ASYNC_TCP_RUNNING_CORE);
|
||||
if (!_async_service_task_handle) {
|
||||
@@ -410,7 +435,7 @@ typedef struct {
|
||||
static err_t _tcp_output_api(struct tcpip_api_call_data * api_call_msg) {
|
||||
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
|
||||
msg->err = ERR_CONN;
|
||||
if (msg->closed_slot == -1 || !_closed_slots[msg->closed_slot]) {
|
||||
if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {
|
||||
msg->err = tcp_output(msg->pcb);
|
||||
}
|
||||
return msg->err;
|
||||
@@ -430,7 +455,7 @@ static esp_err_t _tcp_output(tcp_pcb * pcb, int8_t closed_slot) {
|
||||
static err_t _tcp_write_api(struct tcpip_api_call_data * api_call_msg) {
|
||||
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
|
||||
msg->err = ERR_CONN;
|
||||
if (msg->closed_slot == -1 || !_closed_slots[msg->closed_slot]) {
|
||||
if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {
|
||||
msg->err = tcp_write(msg->pcb, msg->write.data, msg->write.size, msg->write.apiflags);
|
||||
}
|
||||
return msg->err;
|
||||
@@ -453,7 +478,9 @@ static esp_err_t _tcp_write(tcp_pcb * pcb, int8_t closed_slot, const char * data
|
||||
static err_t _tcp_recved_api(struct tcpip_api_call_data * api_call_msg) {
|
||||
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
|
||||
msg->err = ERR_CONN;
|
||||
if (msg->closed_slot == -1 || !_closed_slots[msg->closed_slot]) {
|
||||
if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {
|
||||
// if(msg->closed_slot != INVALID_CLOSED_SLOT && !_closed_slots[msg->closed_slot]) {
|
||||
// if(msg->closed_slot != INVALID_CLOSED_SLOT) {
|
||||
msg->err = 0;
|
||||
tcp_recved(msg->pcb, msg->received);
|
||||
}
|
||||
@@ -475,7 +502,7 @@ static esp_err_t _tcp_recved(tcp_pcb * pcb, int8_t closed_slot, size_t len) {
|
||||
static err_t _tcp_close_api(struct tcpip_api_call_data * api_call_msg) {
|
||||
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
|
||||
msg->err = ERR_CONN;
|
||||
if (msg->closed_slot == -1 || !_closed_slots[msg->closed_slot]) {
|
||||
if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {
|
||||
msg->err = tcp_close(msg->pcb);
|
||||
}
|
||||
return msg->err;
|
||||
@@ -495,7 +522,7 @@ static esp_err_t _tcp_close(tcp_pcb * pcb, int8_t closed_slot) {
|
||||
static err_t _tcp_abort_api(struct tcpip_api_call_data * api_call_msg) {
|
||||
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
|
||||
msg->err = ERR_CONN;
|
||||
if (msg->closed_slot == -1 || !_closed_slots[msg->closed_slot]) {
|
||||
if (msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {
|
||||
tcp_abort(msg->pcb);
|
||||
}
|
||||
return msg->err;
|
||||
@@ -595,20 +622,22 @@ AsyncClient::AsyncClient(tcp_pcb * pcb)
|
||||
, _tx_last_packet(0)
|
||||
, _rx_timeout(0)
|
||||
, _rx_last_ack(0)
|
||||
, _ack_timeout(ASYNC_MAX_ACK_TIME)
|
||||
, _ack_timeout(CONFIG_ASYNC_TCP_MAX_ACK_TIME)
|
||||
, _connect_port(0)
|
||||
, prev(NULL)
|
||||
, next(NULL) {
|
||||
_pcb = pcb;
|
||||
_closed_slot = -1;
|
||||
_closed_slot = INVALID_CLOSED_SLOT;
|
||||
if (_pcb) {
|
||||
_allocate_closed_slot();
|
||||
_rx_last_packet = millis();
|
||||
tcp_arg(_pcb, this);
|
||||
tcp_recv(_pcb, &_tcp_recv);
|
||||
tcp_sent(_pcb, &_tcp_sent);
|
||||
tcp_err(_pcb, &_tcp_error);
|
||||
tcp_poll(_pcb, &_tcp_poll, 1);
|
||||
if (!_allocate_closed_slot()) {
|
||||
_close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,7 +739,7 @@ void AsyncClient::onPoll(AcConnectHandler cb, void * arg) {
|
||||
|
||||
bool AsyncClient::_connect(ip_addr_t addr, uint16_t port) {
|
||||
if (_pcb) {
|
||||
log_w("already connected, state %d", _pcb->state);
|
||||
log_d("already connected, state %d", _pcb->state);
|
||||
return false;
|
||||
}
|
||||
if (!_start_async_task()) {
|
||||
@@ -718,28 +747,34 @@ bool AsyncClient::_connect(ip_addr_t addr, uint16_t port) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tcp_pcb * pcb = tcp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
if (!pcb) {
|
||||
log_e("pcb == NULL");
|
||||
if (!_allocate_closed_slot()) {
|
||||
log_e("failed to allocate: closed slot full");
|
||||
return false;
|
||||
}
|
||||
|
||||
TCP_MUTEX_LOCK();
|
||||
tcp_pcb * pcb = tcp_new_ip_type(addr.type);
|
||||
if (!pcb) {
|
||||
TCP_MUTEX_UNLOCK();
|
||||
log_e("pcb == NULL");
|
||||
return false;
|
||||
}
|
||||
tcp_arg(pcb, this);
|
||||
tcp_err(pcb, &_tcp_error);
|
||||
tcp_recv(pcb, &_tcp_recv);
|
||||
tcp_sent(pcb, &_tcp_sent);
|
||||
tcp_poll(pcb, &_tcp_poll, 1);
|
||||
_tcp_connect(pcb, _closed_slot, &addr, port, (tcp_connected_fn)&_tcp_connected);
|
||||
return true;
|
||||
TCP_MUTEX_UNLOCK();
|
||||
|
||||
esp_err_t err = _tcp_connect(pcb, _closed_slot, &addr, port, (tcp_connected_fn)&_tcp_connected);
|
||||
return err == ESP_OK;
|
||||
}
|
||||
|
||||
bool AsyncClient::connect(IPAddress ip, uint16_t port) {
|
||||
bool AsyncClient::connect(const IPAddress & ip, uint16_t port) {
|
||||
ip_addr_t addr;
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
// ip_addr_set_ip4_u32(&addr, ip);
|
||||
addr.u_addr.ip4.addr = ip;
|
||||
addr.type = IPADDR_TYPE_V4;
|
||||
ip_clear_no4(&addr);
|
||||
#else
|
||||
ip.to_ip_addr_t(&addr);
|
||||
#endif
|
||||
@@ -748,10 +783,9 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port) {
|
||||
}
|
||||
|
||||
#if LWIP_IPV6 && ESP_IDF_VERSION_MAJOR < 5
|
||||
bool AsyncClient::connect(IPv6Address ip, uint16_t port) {
|
||||
ip_addr_t addr;
|
||||
addr.type = IPADDR_TYPE_V6;
|
||||
memcpy(addr.u_addr.ip6.addr, static_cast<const uint32_t *>(ip), sizeof(uint32_t) * 4);
|
||||
bool AsyncClient::connect(const IPv6Address & ip, uint16_t port) {
|
||||
auto ipaddr = static_cast<const uint32_t *>(ip);
|
||||
ip_addr_t addr = IPADDR6_INIT(ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
|
||||
|
||||
return _connect(addr, port);
|
||||
}
|
||||
@@ -783,7 +817,7 @@ bool AsyncClient::connect(const char * host, uint16_t port) {
|
||||
_connect_port = port;
|
||||
return true;
|
||||
}
|
||||
log_e("error: %d", err);
|
||||
log_d("error: %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -803,7 +837,7 @@ int8_t AsyncClient::abort() {
|
||||
}
|
||||
|
||||
size_t AsyncClient::space() {
|
||||
if ((_pcb != NULL) && (_pcb->state == 4)) {
|
||||
if ((_pcb != NULL) && (_pcb->state == ESTABLISHED)) {
|
||||
return tcp_sndbuf(_pcb);
|
||||
}
|
||||
return 0;
|
||||
@@ -862,17 +896,19 @@ int8_t AsyncClient::_close() {
|
||||
//ets_printf("X: 0x%08x\n", (uint32_t)this);
|
||||
int8_t err = ERR_OK;
|
||||
if (_pcb) {
|
||||
//log_i("");
|
||||
TCP_MUTEX_LOCK();
|
||||
tcp_arg(_pcb, NULL);
|
||||
tcp_sent(_pcb, NULL);
|
||||
tcp_recv(_pcb, NULL);
|
||||
tcp_err(_pcb, NULL);
|
||||
tcp_poll(_pcb, NULL, 0);
|
||||
TCP_MUTEX_UNLOCK();
|
||||
_tcp_clear_events(this);
|
||||
err = _tcp_close(_pcb, _closed_slot);
|
||||
if (err != ERR_OK) {
|
||||
err = abort();
|
||||
}
|
||||
_free_closed_slot();
|
||||
_pcb = NULL;
|
||||
if (_discard_cb) {
|
||||
_discard_cb(_discard_cb_arg, this);
|
||||
@@ -881,40 +917,43 @@ int8_t AsyncClient::_close() {
|
||||
return err;
|
||||
}
|
||||
|
||||
void AsyncClient::_allocate_closed_slot() {
|
||||
bool AsyncClient::_allocate_closed_slot() {
|
||||
if (_closed_slot != INVALID_CLOSED_SLOT) {
|
||||
return true;
|
||||
}
|
||||
xSemaphoreTake(_slots_lock, portMAX_DELAY);
|
||||
uint32_t closed_slot_min_index = 0;
|
||||
for (int i = 0; i < _number_of_closed_slots; ++i) {
|
||||
if ((_closed_slot == -1 || _closed_slots[i] <= closed_slot_min_index) && _closed_slots[i] != 0) {
|
||||
if ((_closed_slot == INVALID_CLOSED_SLOT || _closed_slots[i] <= closed_slot_min_index) && _closed_slots[i] != 0) {
|
||||
closed_slot_min_index = _closed_slots[i];
|
||||
_closed_slot = i;
|
||||
}
|
||||
}
|
||||
if (_closed_slot != -1) {
|
||||
if (_closed_slot != INVALID_CLOSED_SLOT) {
|
||||
_closed_slots[_closed_slot] = 0;
|
||||
}
|
||||
xSemaphoreGive(_slots_lock);
|
||||
return (_closed_slot != INVALID_CLOSED_SLOT);
|
||||
}
|
||||
|
||||
void AsyncClient::_free_closed_slot() {
|
||||
if (_closed_slot != -1) {
|
||||
xSemaphoreTake(_slots_lock, portMAX_DELAY);
|
||||
if (_closed_slot != INVALID_CLOSED_SLOT) {
|
||||
_closed_slots[_closed_slot] = _closed_index;
|
||||
_closed_slot = -1;
|
||||
_closed_slot = INVALID_CLOSED_SLOT;
|
||||
++_closed_index;
|
||||
}
|
||||
xSemaphoreGive(_slots_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Private Callbacks
|
||||
* */
|
||||
|
||||
int8_t AsyncClient::_connected(void * pcb, int8_t err) {
|
||||
int8_t AsyncClient::_connected(tcp_pcb * pcb, int8_t err) {
|
||||
_pcb = reinterpret_cast<tcp_pcb *>(pcb);
|
||||
if (_pcb) {
|
||||
_rx_last_packet = millis();
|
||||
// tcp_recv(_pcb, &_tcp_recv);
|
||||
// tcp_sent(_pcb, &_tcp_sent);
|
||||
// tcp_poll(_pcb, &_tcp_poll, 1);
|
||||
}
|
||||
if (_connect_cb) {
|
||||
_connect_cb(_connect_cb_arg, this);
|
||||
@@ -924,6 +963,7 @@ int8_t AsyncClient::_connected(void * pcb, int8_t err) {
|
||||
|
||||
void AsyncClient::_error(int8_t err) {
|
||||
if (_pcb) {
|
||||
TCP_MUTEX_LOCK();
|
||||
tcp_arg(_pcb, NULL);
|
||||
if (_pcb->state == LISTEN) {
|
||||
tcp_sent(_pcb, NULL);
|
||||
@@ -931,6 +971,8 @@ void AsyncClient::_error(int8_t err) {
|
||||
tcp_err(_pcb, NULL);
|
||||
tcp_poll(_pcb, NULL, 0);
|
||||
}
|
||||
TCP_MUTEX_UNLOCK();
|
||||
_free_closed_slot();
|
||||
_pcb = NULL;
|
||||
}
|
||||
if (_error_cb) {
|
||||
@@ -944,7 +986,7 @@ void AsyncClient::_error(int8_t err) {
|
||||
//In LwIP Thread
|
||||
int8_t AsyncClient::_lwip_fin(tcp_pcb * pcb, int8_t err) {
|
||||
if (!_pcb || pcb != _pcb) {
|
||||
log_e("0x%08x != 0x%08x", (uint32_t)pcb, (uint32_t)_pcb);
|
||||
log_d("0x%08x != 0x%08x", (uint32_t)pcb, (uint32_t)_pcb);
|
||||
return ERR_OK;
|
||||
}
|
||||
tcp_arg(_pcb, NULL);
|
||||
@@ -972,11 +1014,9 @@ int8_t AsyncClient::_fin(tcp_pcb * pcb, int8_t err) {
|
||||
}
|
||||
|
||||
int8_t AsyncClient::_sent(tcp_pcb * pcb, uint16_t len) {
|
||||
_rx_last_packet = millis();
|
||||
_rx_last_ack = millis();
|
||||
//log_i("%u", len);
|
||||
_rx_last_ack = _rx_last_packet = millis();
|
||||
if (_sent_cb) {
|
||||
_sent_cb(_sent_cb_arg, this, len, (millis() - _tx_last_packet));
|
||||
_sent_cb(_sent_cb_arg, this, len, (_rx_last_packet - _tx_last_packet));
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
@@ -1000,19 +1040,19 @@ int8_t AsyncClient::_recv(tcp_pcb * pcb, pbuf * pb, int8_t err) {
|
||||
} else if (_pcb) {
|
||||
_tcp_recved(_pcb, _closed_slot, b->len);
|
||||
}
|
||||
pbuf_free(b);
|
||||
}
|
||||
pbuf_free(b);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int8_t AsyncClient::_poll(tcp_pcb * pcb) {
|
||||
if (!_pcb) {
|
||||
log_w("pcb is NULL");
|
||||
// log_d("pcb is NULL");
|
||||
return ERR_OK;
|
||||
}
|
||||
if (pcb != _pcb) {
|
||||
log_e("0x%08x != 0x%08x", (uint32_t)pcb, (uint32_t)_pcb);
|
||||
log_d("0x%08x != 0x%08x", (uint32_t)pcb, (uint32_t)_pcb);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@@ -1023,7 +1063,7 @@ int8_t AsyncClient::_poll(tcp_pcb * pcb) {
|
||||
const uint32_t one_day = 86400000;
|
||||
bool last_tx_is_after_last_ack = (_rx_last_ack - _tx_last_packet + one_day) < one_day;
|
||||
if (last_tx_is_after_last_ack && (now - _tx_last_packet) >= _ack_timeout) {
|
||||
log_w("ack timeout %d", pcb->state);
|
||||
log_d("ack timeout %d", pcb->state);
|
||||
if (_timeout_cb)
|
||||
_timeout_cb(_timeout_cb_arg, this, (now - _tx_last_packet));
|
||||
return ERR_OK;
|
||||
@@ -1031,7 +1071,7 @@ int8_t AsyncClient::_poll(tcp_pcb * pcb) {
|
||||
}
|
||||
// RX Timeout
|
||||
if (_rx_timeout && (now - _rx_last_packet) >= (_rx_timeout * 1000)) {
|
||||
log_w("rx timeout %d", pcb->state);
|
||||
log_d("rx timeout %d", pcb->state);
|
||||
_close();
|
||||
return ERR_OK;
|
||||
}
|
||||
@@ -1052,7 +1092,9 @@ void AsyncClient::_dns_found(struct ip_addr * ipaddr) {
|
||||
#endif
|
||||
#else
|
||||
if (ipaddr) {
|
||||
connect(IPAddress(ipaddr), _connect_port);
|
||||
IPAddress ip;
|
||||
ip.from_ip_addr_t(ipaddr);
|
||||
connect(ip, _connect_port);
|
||||
#endif
|
||||
} else {
|
||||
if (_error_cb) {
|
||||
@@ -1076,7 +1118,7 @@ bool AsyncClient::free() {
|
||||
if (!_pcb) {
|
||||
return true;
|
||||
}
|
||||
if (_pcb->state == 0 || _pcb->state > 4) {
|
||||
if (_pcb->state == CLOSED || _pcb->state > ESTABLISHED) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1131,6 +1173,18 @@ bool AsyncClient::getNoDelay() {
|
||||
return tcp_nagle_disabled(_pcb);
|
||||
}
|
||||
|
||||
void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt) {
|
||||
if (ms != 0) {
|
||||
_pcb->so_options |= SOF_KEEPALIVE; //Turn on TCP Keepalive for the given pcb
|
||||
// Set the time between keepalive messages in milli-seconds
|
||||
_pcb->keep_idle = ms;
|
||||
_pcb->keep_intvl = ms;
|
||||
_pcb->keep_cnt = cnt; //The number of unanswered probes required to force closure of the socket
|
||||
} else {
|
||||
_pcb->so_options &= ~SOF_KEEPALIVE; //Turn off TCP Keepalive for the given pcb
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t AsyncClient::getMss() {
|
||||
if (!_pcb) {
|
||||
return 0;
|
||||
@@ -1177,11 +1231,21 @@ IPv6Address AsyncClient::localIP6() {
|
||||
}
|
||||
#else
|
||||
IPAddress AsyncClient::remoteIP6() {
|
||||
return _pcb ? IPAddress(dynamic_cast<const ip_addr_t *>(&_pcb->remote_ip)) : IPAddress(IPType::IPv6);
|
||||
if (!_pcb) {
|
||||
return IPAddress(IPType::IPv6);
|
||||
}
|
||||
IPAddress ip;
|
||||
ip.from_ip_addr_t(&(_pcb->remote_ip));
|
||||
return ip;
|
||||
}
|
||||
|
||||
IPAddress AsyncClient::localIP6() {
|
||||
return _pcb ? IPAddress(dynamic_cast<const ip_addr_t *>(&_pcb->local_ip)) : IPAddress(IPType::IPv6);
|
||||
if (!_pcb) {
|
||||
return IPAddress(IPType::IPv6);
|
||||
}
|
||||
IPAddress ip;
|
||||
ip.from_ip_addr_t(&(_pcb->local_ip));
|
||||
return ip;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1215,7 +1279,12 @@ IPAddress AsyncClient::remoteIP() {
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
return IPAddress(getRemoteAddress());
|
||||
#else
|
||||
return _pcb ? IPAddress(dynamic_cast<const ip_addr_t *>(&_pcb->remote_ip)) : IPAddress();
|
||||
if (!_pcb) {
|
||||
return IPAddress();
|
||||
}
|
||||
IPAddress ip;
|
||||
ip.from_ip_addr_t(&(_pcb->remote_ip));
|
||||
return ip;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1227,7 +1296,12 @@ IPAddress AsyncClient::localIP() {
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
return IPAddress(getLocalAddress());
|
||||
#else
|
||||
return _pcb ? IPAddress(dynamic_cast<const ip_addr_t *>(&_pcb->local_ip)) : IPAddress();
|
||||
if (!_pcb) {
|
||||
return IPAddress();
|
||||
}
|
||||
IPAddress ip;
|
||||
ip.from_ip_addr_t(&(_pcb->local_ip));
|
||||
return ip;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1247,35 +1321,35 @@ bool AsyncClient::connected() {
|
||||
if (!_pcb) {
|
||||
return false;
|
||||
}
|
||||
return _pcb->state == 4;
|
||||
return _pcb->state == ESTABLISHED;
|
||||
}
|
||||
|
||||
bool AsyncClient::connecting() {
|
||||
if (!_pcb) {
|
||||
return false;
|
||||
}
|
||||
return _pcb->state > 0 && _pcb->state < 4;
|
||||
return _pcb->state > CLOSED && _pcb->state < ESTABLISHED;
|
||||
}
|
||||
|
||||
bool AsyncClient::disconnecting() {
|
||||
if (!_pcb) {
|
||||
return false;
|
||||
}
|
||||
return _pcb->state > 4 && _pcb->state < 10;
|
||||
return _pcb->state > ESTABLISHED && _pcb->state < TIME_WAIT;
|
||||
}
|
||||
|
||||
bool AsyncClient::disconnected() {
|
||||
if (!_pcb) {
|
||||
return true;
|
||||
}
|
||||
return _pcb->state == 0 || _pcb->state == 10;
|
||||
return _pcb->state == CLOSED || _pcb->state == TIME_WAIT;
|
||||
}
|
||||
|
||||
bool AsyncClient::freeable() {
|
||||
if (!_pcb) {
|
||||
return true;
|
||||
}
|
||||
return _pcb->state == 0 || _pcb->state > 4;
|
||||
return _pcb->state == CLOSED || _pcb->state > ESTABLISHED;
|
||||
}
|
||||
|
||||
bool AsyncClient::canSend() {
|
||||
@@ -1384,7 +1458,7 @@ void AsyncClient::_s_error(void * arg, int8_t err) {
|
||||
reinterpret_cast<AsyncClient *>(arg)->_error(err);
|
||||
}
|
||||
|
||||
int8_t AsyncClient::_s_connected(void * arg, void * pcb, int8_t err) {
|
||||
int8_t AsyncClient::_s_connected(void * arg, struct tcp_pcb * pcb, int8_t err) {
|
||||
return reinterpret_cast<AsyncClient *>(arg)->_connected(pcb, err);
|
||||
}
|
||||
|
||||
@@ -1396,6 +1470,7 @@ AsyncServer::AsyncServer(IPAddress addr, uint16_t port)
|
||||
: _port(port)
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
, _bind4(true)
|
||||
, _bind6(false)
|
||||
#else
|
||||
, _bind4(addr.type() != IPType::IPv6)
|
||||
, _bind6(addr.type() == IPType::IPv6)
|
||||
@@ -1410,6 +1485,7 @@ AsyncServer::AsyncServer(IPAddress addr, uint16_t port)
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
AsyncServer::AsyncServer(IPv6Address addr, uint16_t port)
|
||||
: _port(port)
|
||||
, _bind4(false)
|
||||
, _bind6(true)
|
||||
, _addr6(addr)
|
||||
, _noDelay(false)
|
||||
@@ -1422,7 +1498,7 @@ AsyncServer::AsyncServer(IPv6Address addr, uint16_t port)
|
||||
AsyncServer::AsyncServer(uint16_t port)
|
||||
: _port(port)
|
||||
, _bind4(true)
|
||||
, _bind6(true)
|
||||
, _bind6(false)
|
||||
, _addr((uint32_t)IPADDR_ANY)
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
, _addr6()
|
||||
@@ -1451,17 +1527,10 @@ void AsyncServer::begin() {
|
||||
log_e("failed to start task");
|
||||
return;
|
||||
}
|
||||
int8_t err, bind_type;
|
||||
|
||||
if (_bind4 && _bind6) {
|
||||
bind_type = IPADDR_TYPE_ANY;
|
||||
} else if (_bind6) {
|
||||
bind_type = IPADDR_TYPE_V6;
|
||||
} else {
|
||||
bind_type = IPADDR_TYPE_V4;
|
||||
}
|
||||
|
||||
_pcb = tcp_new_ip_type(bind_type);
|
||||
int8_t err;
|
||||
TCP_MUTEX_LOCK();
|
||||
_pcb = tcp_new_ip_type(_bind4 && _bind6 ? IPADDR_TYPE_ANY : (_bind6 ? IPADDR_TYPE_V6 : IPADDR_TYPE_V4));
|
||||
TCP_MUTEX_UNLOCK();
|
||||
if (!_pcb) {
|
||||
log_e("_pcb == NULL");
|
||||
return;
|
||||
@@ -1469,13 +1538,13 @@ void AsyncServer::begin() {
|
||||
|
||||
ip_addr_t local_addr;
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
// ip_addr_set_ip4_u32(&local_addr, _addr);
|
||||
local_addr.u_addr.ip4.addr = _addr;
|
||||
local_addr.type = IPADDR_TYPE_V4;
|
||||
ip_clear_no4(&local_addr);
|
||||
/* local_addr.type = bind_type;
|
||||
local_addr.u_addr.ip4.addr = (uint32_t) _addr;
|
||||
memcpy(local_addr.u_addr.ip6.addr, static_cast<const uint32_t*>(_addr6), sizeof(uint32_t) * 4); */
|
||||
if (_bind6) { // _bind6 && _bind4 both at the same time is not supported on Arduino 2 in this lib API
|
||||
local_addr.type = IPADDR_TYPE_V6;
|
||||
memcpy(local_addr.u_addr.ip6.addr, static_cast<const uint32_t *>(_addr6), sizeof(uint32_t) * 4);
|
||||
} else {
|
||||
local_addr.type = IPADDR_TYPE_V4;
|
||||
local_addr.u_addr.ip4.addr = _addr;
|
||||
}
|
||||
#else
|
||||
_addr.to_ip_addr_t(&local_addr);
|
||||
#endif
|
||||
@@ -1493,16 +1562,22 @@ void AsyncServer::begin() {
|
||||
log_e("listen_pcb == NULL");
|
||||
return;
|
||||
}
|
||||
TCP_MUTEX_LOCK();
|
||||
tcp_arg(_pcb, (void *)this);
|
||||
tcp_accept(_pcb, &_s_accept);
|
||||
TCP_MUTEX_UNLOCK();
|
||||
}
|
||||
|
||||
void AsyncServer::end() {
|
||||
if (_pcb) {
|
||||
TCP_MUTEX_LOCK();
|
||||
tcp_arg(_pcb, NULL);
|
||||
tcp_accept(_pcb, NULL);
|
||||
if (tcp_close(_pcb) != ERR_OK) {
|
||||
TCP_MUTEX_UNLOCK();
|
||||
_tcp_abort(_pcb, -1);
|
||||
} else {
|
||||
TCP_MUTEX_UNLOCK();
|
||||
}
|
||||
_pcb = NULL;
|
||||
}
|
||||
@@ -1521,7 +1596,7 @@ int8_t AsyncServer::_accept(tcp_pcb * pcb, int8_t err) {
|
||||
if (tcp_close(pcb) != ERR_OK) {
|
||||
tcp_abort(pcb);
|
||||
}
|
||||
log_e("FAIL");
|
||||
log_d("FAIL");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
#ifndef ASYNCTCP_H_
|
||||
#define ASYNCTCP_H_
|
||||
|
||||
#define ASYNCTCP_VERSION "3.2.14"
|
||||
#define ASYNCTCP_VERSION_MAJOR 3
|
||||
#define ASYNCTCP_VERSION_MINOR 2
|
||||
#define ASYNCTCP_VERSION_REVISION 14
|
||||
#define ASYNCTCP_FORK_mathieucarbou
|
||||
|
||||
#include "IPAddress.h"
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
#include "IPv6Address.h"
|
||||
@@ -52,24 +58,26 @@ extern "C" {
|
||||
#define CONFIG_ASYNC_TCP_USE_WDT 1 //if enabled, adds between 33us and 200us per event
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ASYNC_TCP_TASK_PRIORITY
|
||||
#define CONFIG_ASYNC_TCP_TASK_PRIORITY 5
|
||||
#endif
|
||||
|
||||
// EMS-ESP: stack usage measured: ESP32: ~2.3K, ESP32S3: ~3.5k
|
||||
#ifndef CONFIG_ASYNC_TCP_STACK_SIZE
|
||||
#define CONFIG_ASYNC_TCP_STACK_SIZE 5120
|
||||
#define CONFIG_ASYNC_TCP_STACK_SIZE 6144
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ASYNC_TCP_PRIORITY
|
||||
#define CONFIG_ASYNC_TCP_PRIORITY 5
|
||||
#endif
|
||||
|
||||
// EMS-ESP: maybe enlarge queue to 64 or 128 see https://github.com/emsesp/EMS-ESP32/issues/177
|
||||
#ifndef CONFIG_ASYNC_TCP_QUEUE
|
||||
#define CONFIG_ASYNC_TCP_QUEUE 32
|
||||
#ifndef CONFIG_ASYNC_TCP_QUEUE_SIZE
|
||||
#define CONFIG_ASYNC_TCP_QUEUE_SIZE 32
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ASYNC_TCP_MAX_ACK_TIME
|
||||
#define CONFIG_ASYNC_TCP_MAX_ACK_TIME 5000
|
||||
#endif
|
||||
|
||||
class AsyncClient;
|
||||
|
||||
#define ASYNC_MAX_ACK_TIME 5000
|
||||
#define ASYNC_WRITE_FLAG_COPY 0x01 //will allocate new buffer to hold the data while sending (else will hold reference to the data given)
|
||||
#define ASYNC_WRITE_FLAG_MORE 0x02 //will not send PSH flag, meaning that there should be more data to be sent before the application should react.
|
||||
|
||||
@@ -96,9 +104,9 @@ class AsyncClient {
|
||||
bool operator!=(const AsyncClient & other) {
|
||||
return !(*this == other);
|
||||
}
|
||||
bool connect(IPAddress ip, uint16_t port);
|
||||
bool connect(const IPAddress & ip, uint16_t port);
|
||||
#if ESP_IDF_VERSION_MAJOR < 5
|
||||
bool connect(IPv6Address ip, uint16_t port);
|
||||
bool connect(const IPv6Address & ip, uint16_t port);
|
||||
#endif
|
||||
bool connect(const char * host, uint16_t port);
|
||||
void close(bool now = false);
|
||||
@@ -133,6 +141,8 @@ class AsyncClient {
|
||||
void setNoDelay(bool nodelay);
|
||||
bool getNoDelay();
|
||||
|
||||
void setKeepAlive(uint32_t ms, uint8_t cnt);
|
||||
|
||||
uint32_t getRemoteAddress();
|
||||
uint16_t getRemotePort();
|
||||
uint32_t getLocalAddress();
|
||||
@@ -180,7 +190,7 @@ class AsyncClient {
|
||||
static int8_t _s_lwip_fin(void * arg, struct tcp_pcb * tpcb, int8_t err);
|
||||
static void _s_error(void * arg, int8_t err);
|
||||
static int8_t _s_sent(void * arg, struct tcp_pcb * tpcb, uint16_t len);
|
||||
static int8_t _s_connected(void * arg, void * tpcb, int8_t err);
|
||||
static int8_t _s_connected(void * arg, struct tcp_pcb * tpcb, int8_t err);
|
||||
static void _s_dns_found(const char * name, struct ip_addr * ipaddr, void * arg);
|
||||
|
||||
int8_t _recv(tcp_pcb * pcb, pbuf * pb, int8_t err);
|
||||
@@ -222,8 +232,8 @@ class AsyncClient {
|
||||
|
||||
int8_t _close();
|
||||
void _free_closed_slot();
|
||||
void _allocate_closed_slot();
|
||||
int8_t _connected(void * pcb, int8_t err);
|
||||
bool _allocate_closed_slot();
|
||||
int8_t _connected(tcp_pcb * pcb, int8_t err);
|
||||
void _error(int8_t err);
|
||||
int8_t _poll(tcp_pcb * pcb);
|
||||
int8_t _sent(tcp_pcb * pcb, uint16_t len);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eModbus",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.2",
|
||||
"keywords": "Arduino, ESP32, Modbus, RTU, ASCII, ModbusASCII, ModbusRTU, ModbusTCP",
|
||||
"description": "ModbusRTU, ModbusASCII and ModbusTCP functions for ESP32",
|
||||
"homepage": "https://emodbus.github.io",
|
||||
@@ -23,6 +23,25 @@
|
||||
"url": "https://github.com/eModbus/eModbus",
|
||||
"branch": "master"
|
||||
},
|
||||
"dependencies": [
|
||||
{
|
||||
"owner": "me-no-dev",
|
||||
"name": "AsyncTCP",
|
||||
"version": "*",
|
||||
"platforms": ["espressif32"]
|
||||
},
|
||||
{
|
||||
"owner": "me-no-dev",
|
||||
"name": "ESPAsyncTCP",
|
||||
"version": "*",
|
||||
"platforms": ["espressif8266"]
|
||||
},
|
||||
{
|
||||
"name": "Ethernet",
|
||||
"version": "https://github.com/arduino-libraries/Ethernet.git",
|
||||
"platforms": ["espressif32"]
|
||||
}
|
||||
],
|
||||
"export": {
|
||||
"include":
|
||||
[
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name=eModbus
|
||||
version=1.7.0
|
||||
version=1.7.2
|
||||
author=bertmelis,Miq1 <miq1@gmx.de>
|
||||
maintainer=Miq1 <miq1@gmx.de>
|
||||
sentence=eModbus provides Modbus RTU, ASCII and TCP functions for ESP32.
|
||||
|
||||
21
lib/eModbus/src/ModbusBridgeETH.h
Normal file
21
lib/eModbus/src/ModbusBridgeETH.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// =================================================================================================
|
||||
// eModbus: Copyright 2024 by Michael Harwerth, Bert Melis and the contributors to eModbus
|
||||
// MIT license - see license.md for details
|
||||
// =================================================================================================
|
||||
#ifndef _MODBUS_BRIDGE_ETHERNET_H
|
||||
#define _MODBUS_BRIDGE_ETHERNET_H
|
||||
#include "options.h"
|
||||
#if HAS_ETHERNET == 1
|
||||
#include <ETH.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#undef SERVER_END
|
||||
#define SERVER_END // NIL for Ethernet
|
||||
|
||||
#include "ModbusServerTCPtemp.h"
|
||||
#include "ModbusBridgeTemp.h"
|
||||
|
||||
using ModbusBridgeEthernet = ModbusBridge<ModbusServerTCP<WiFiServer, WiFiClient>>;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -29,8 +29,8 @@ public:
|
||||
ModbusBridge();
|
||||
|
||||
// Constructors for the RTU variant. Parameters as are for ModbusServerRTU
|
||||
ModbusBridge(HardwareSerial& serial, uint32_t timeout, int rtsPin = -1);
|
||||
ModbusBridge(HardwareSerial& serial, uint32_t timeout, RTScallback rts);
|
||||
ModbusBridge(uint32_t timeout, int rtsPin = -1);
|
||||
ModbusBridge(uint32_t timeout, RTScallback rts);
|
||||
|
||||
// Destructor
|
||||
~ModbusBridge();
|
||||
@@ -44,6 +44,12 @@ public:
|
||||
// Block a function code (respond with ILLEGAL_FUNCTION error)
|
||||
bool denyFunctionCode(uint8_t aliasID, uint8_t functionCode);
|
||||
|
||||
// Add/remove request/response filters
|
||||
bool addRequestFilter(uint8_t aliasID, MBSworker rF);
|
||||
bool removeRequestFilter(uint8_t aliasID);
|
||||
bool addResponseFilter(uint8_t aliasID, MBSworker rF);
|
||||
bool removeResponseFilter(uint8_t aliasID);
|
||||
|
||||
protected:
|
||||
// ServerData holds all data necessary to address a single server
|
||||
struct ServerData {
|
||||
@@ -52,6 +58,8 @@ protected:
|
||||
ServerType serverType; // TCP_SERVER or RTU_SERVER
|
||||
IPAddress host; // TCP: host IP address, else 0.0.0.0
|
||||
uint16_t port; // TCP: host port number, else 0
|
||||
MBSworker requestFilter; // optional filter requests before forwarding them
|
||||
MBSworker responseFilter; // optional filter responses before forwarding them
|
||||
|
||||
// RTU constructor
|
||||
ServerData(uint8_t sid, ModbusClient *c) :
|
||||
@@ -59,7 +67,9 @@ protected:
|
||||
client(c),
|
||||
serverType(RTU_SERVER),
|
||||
host(IPAddress(0, 0, 0, 0)),
|
||||
port(0) {}
|
||||
port(0),
|
||||
requestFilter(nullptr),
|
||||
responseFilter(nullptr) {}
|
||||
|
||||
// TCP constructor
|
||||
ServerData(uint8_t sid, ModbusClient *c, IPAddress h, uint16_t p) :
|
||||
@@ -67,7 +77,9 @@ protected:
|
||||
client(c),
|
||||
serverType(TCP_SERVER),
|
||||
host(h),
|
||||
port(p) {}
|
||||
port(p),
|
||||
requestFilter(nullptr),
|
||||
responseFilter(nullptr) {}
|
||||
};
|
||||
|
||||
// Default worker functions
|
||||
@@ -85,13 +97,13 @@ ModbusBridge<SERVERCLASS>::ModbusBridge() :
|
||||
|
||||
// Constructors for RTU variant
|
||||
template<typename SERVERCLASS>
|
||||
ModbusBridge<SERVERCLASS>::ModbusBridge(HardwareSerial& serial, uint32_t timeout, int rtsPin) :
|
||||
SERVERCLASS(serial, timeout, rtsPin) { }
|
||||
ModbusBridge<SERVERCLASS>::ModbusBridge(uint32_t timeout, int rtsPin) :
|
||||
SERVERCLASS(timeout, rtsPin) { }
|
||||
|
||||
// Alternate constructors for RTU variant
|
||||
template<typename SERVERCLASS>
|
||||
ModbusBridge<SERVERCLASS>::ModbusBridge(HardwareSerial& serial, uint32_t timeout, RTScallback rts) :
|
||||
SERVERCLASS(serial, timeout, rts) { }
|
||||
ModbusBridge<SERVERCLASS>::ModbusBridge(uint32_t timeout, RTScallback rts) :
|
||||
SERVERCLASS(timeout, rts) { }
|
||||
|
||||
// Destructor
|
||||
template<typename SERVERCLASS>
|
||||
@@ -156,6 +168,62 @@ bool ModbusBridge<SERVERCLASS>::denyFunctionCode(uint8_t aliasID, uint8_t functi
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename SERVERCLASS>
|
||||
bool ModbusBridge<SERVERCLASS>::addRequestFilter(uint8_t aliasID, MBSworker rF) {
|
||||
// Is there already an entry for the aliasID?
|
||||
if (servers.find(aliasID) != servers.end()) {
|
||||
// Yes. Chain in filter function
|
||||
servers[aliasID]->requestFilter = rF;
|
||||
LOG_D("Request filter added for server %02X\n", aliasID);
|
||||
} else {
|
||||
LOG_E("Server %d not attached to bridge, no request filter set!\n", aliasID);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename SERVERCLASS>
|
||||
bool ModbusBridge<SERVERCLASS>::removeRequestFilter(uint8_t aliasID) {
|
||||
// Is there already an entry for the aliasID?
|
||||
if (servers.find(aliasID) != servers.end()) {
|
||||
// Yes. Chain in filter function
|
||||
servers[aliasID]->requestFilter = nullptr;
|
||||
LOG_D("Request filter removed for server %02X\n", aliasID);
|
||||
} else {
|
||||
LOG_E("Server %d not attached to bridge, no request filter set!\n", aliasID);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename SERVERCLASS>
|
||||
bool ModbusBridge<SERVERCLASS>::addResponseFilter(uint8_t aliasID, MBSworker rF) {
|
||||
// Is there already an entry for the aliasID?
|
||||
if (servers.find(aliasID) != servers.end()) {
|
||||
// Yes. Chain in filter function
|
||||
servers[aliasID]->responseFilter = rF;
|
||||
LOG_D("Response filter added for server %02X\n", aliasID);
|
||||
} else {
|
||||
LOG_E("Server %d not attached to bridge, no response filter set!\n", aliasID);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename SERVERCLASS>
|
||||
bool ModbusBridge<SERVERCLASS>::removeResponseFilter(uint8_t aliasID) {
|
||||
// Is there already an entry for the aliasID?
|
||||
if (servers.find(aliasID) != servers.end()) {
|
||||
// Yes. Chain in filter function
|
||||
servers[aliasID]->responseFilter = nullptr;
|
||||
LOG_D("Response filter removed for server %02X\n", aliasID);
|
||||
} else {
|
||||
LOG_E("Server %d not attached to bridge, no response filter set!\n", aliasID);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// bridgeWorker: default worker function to process bridge requests
|
||||
template<typename SERVERCLASS>
|
||||
ModbusMessage ModbusBridge<SERVERCLASS>::bridgeWorker(ModbusMessage msg) {
|
||||
@@ -167,11 +235,17 @@ ModbusMessage ModbusBridge<SERVERCLASS>::bridgeWorker(ModbusMessage msg) {
|
||||
if (servers.find(aliasID) != servers.end()) {
|
||||
// Found it. We may use servers[aliasID] now without allocating a new map slot
|
||||
|
||||
// Request filter hook to be called here
|
||||
if (servers[aliasID]->requestFilter) {
|
||||
LOG_D("Calling request filter\n");
|
||||
msg = servers[aliasID]->requestFilter(msg);
|
||||
}
|
||||
|
||||
// Set real target server ID
|
||||
msg.setServerID(servers[aliasID]->serverID);
|
||||
|
||||
// Issue the request
|
||||
LOG_D("Request (%02X/%02X) sent\n", servers[aliasID]->serverID, functionCode);
|
||||
LOG_D("Request (%02X/%02X) sent\n", servers[aliasID]->serverID, msg.getFunctionCode());
|
||||
// TCP servers have a target host/port that needs to be set in the client
|
||||
if (servers[aliasID]->serverType == TCP_SERVER) {
|
||||
response = reinterpret_cast<ModbusClientTCP *>(servers[aliasID]->client)->syncRequestMT(msg, (uint32_t)millis(), servers[aliasID]->host, servers[aliasID]->port);
|
||||
@@ -179,8 +253,19 @@ ModbusMessage ModbusBridge<SERVERCLASS>::bridgeWorker(ModbusMessage msg) {
|
||||
response = servers[aliasID]->client->syncRequestM(msg, (uint32_t)millis());
|
||||
}
|
||||
|
||||
// Re-set the requested server ID
|
||||
// Response filter hook to be called here
|
||||
if (servers[aliasID]->responseFilter) {
|
||||
LOG_D("Calling response filter\n");
|
||||
response = servers[aliasID]->responseFilter(response);
|
||||
}
|
||||
|
||||
// Re-set the requested server ID and function code (may have been modified by filters)
|
||||
response.setServerID(aliasID);
|
||||
if (response.getError() != SUCCESS) {
|
||||
response.setFunctionCode(functionCode | 0x80);
|
||||
} else {
|
||||
response.setFunctionCode(functionCode);
|
||||
}
|
||||
} else {
|
||||
// If we get here, something has gone wrong internally. We send back an error response anyway.
|
||||
response.setError(aliasID, functionCode, INVALID_SERVER);
|
||||
|
||||
@@ -54,20 +54,20 @@ ModbusClientRTU::~ModbusClientRTU() {
|
||||
}
|
||||
|
||||
// begin: start worker task - general version
|
||||
void ModbusClientRTU::begin(Stream& serial, uint32_t baudRate, int coreID) {
|
||||
void ModbusClientRTU::begin(Stream& serial, uint32_t baudRate, int coreID, uint32_t userInterval) {
|
||||
MR_serial = &serial;
|
||||
doBegin(baudRate, coreID);
|
||||
doBegin(baudRate, coreID, userInterval);
|
||||
}
|
||||
|
||||
// begin: start worker task - HardwareSerial version
|
||||
void ModbusClientRTU::begin(HardwareSerial& serial, int coreID) {
|
||||
void ModbusClientRTU::begin(HardwareSerial& serial, int coreID, uint32_t userInterval) {
|
||||
MR_serial = &serial;
|
||||
uint32_t baudRate = serial.baudRate();
|
||||
serial.setRxFIFOFull(1);
|
||||
doBegin(baudRate, coreID);
|
||||
doBegin(baudRate, coreID, userInterval);
|
||||
}
|
||||
|
||||
void ModbusClientRTU::doBegin(uint32_t baudRate, int coreID) {
|
||||
void ModbusClientRTU::doBegin(uint32_t baudRate, int coreID, uint32_t userInterval) {
|
||||
// Task already running? End it in case
|
||||
end();
|
||||
|
||||
@@ -77,6 +77,11 @@ void ModbusClientRTU::doBegin(uint32_t baudRate, int coreID) {
|
||||
// Set minimum interval time
|
||||
MR_interval = RTUutils::calculateInterval(baudRate);
|
||||
|
||||
// If user defined interval is longer, use that
|
||||
if (MR_interval < userInterval) {
|
||||
MR_interval = userInterval;
|
||||
}
|
||||
|
||||
// Create unique task name
|
||||
char taskName[18];
|
||||
snprintf(taskName, 18, "Modbus%02XRTU", instanceCounter);
|
||||
|
||||
@@ -31,9 +31,9 @@ public:
|
||||
~ModbusClientRTU();
|
||||
|
||||
// begin: start worker task
|
||||
void begin(Stream& serial, uint32_t baudrate, int coreID = -1);
|
||||
void begin(Stream& serial, uint32_t baudrate, int coreID = -1, uint32_t userInterval = 0);
|
||||
// Special variant for HardwareSerial
|
||||
void begin(HardwareSerial& serial, int coreID = -1);
|
||||
void begin(HardwareSerial& serial, int coreID = -1, uint32_t userInterval = 0);
|
||||
|
||||
// end: stop the worker
|
||||
void end();
|
||||
@@ -87,7 +87,7 @@ protected:
|
||||
ModbusMessage receive(const ModbusMessage request);
|
||||
|
||||
// start background task
|
||||
void doBegin(uint32_t baudRate, int coreID);
|
||||
void doBegin(uint32_t baudRate, int coreID, uint32_t userInterval);
|
||||
|
||||
void isInstance() { return; } // make class instantiable
|
||||
queue<RequestEntry> requests; // Queue to hold requests to be processed
|
||||
|
||||
@@ -7,213 +7,210 @@
|
||||
// #undef LOCAL_LOG_LEVEL
|
||||
#include "Logging.h"
|
||||
|
||||
ModbusClientTCPasync::ModbusClientTCPasync(IPAddress address, uint16_t port, uint16_t queueLimit)
|
||||
: ModbusClient()
|
||||
, txQueue()
|
||||
, rxQueue()
|
||||
, MTA_client()
|
||||
, MTA_timeout(DEFAULTTIMEOUT)
|
||||
, MTA_idleTimeout(DEFAULTIDLETIME)
|
||||
, MTA_qLimit(queueLimit)
|
||||
, MTA_maxInflightRequests(queueLimit)
|
||||
, MTA_lastActivity(0)
|
||||
, MTA_state(DISCONNECTED)
|
||||
, MTA_host(address)
|
||||
, MTA_port(port) {
|
||||
// attach all handlers on async tcp events
|
||||
MTA_client.onConnect([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onConnected(); }, this);
|
||||
MTA_client.onDisconnect([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onDisconnected(); }, this);
|
||||
MTA_client.onError([](void * i, AsyncClient * c, int8_t error) { (static_cast<ModbusClientTCPasync *>(i))->onACError(c, error); }, this);
|
||||
// MTA_client.onTimeout([](void* i, AsyncClient* c, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onTimeout(time); }, this);
|
||||
// MTA_client.onAck([](void* i, AsyncClient* c, size_t len, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onAck(len, time); }, this);
|
||||
MTA_client.onData([](void * i,
|
||||
AsyncClient * c,
|
||||
void * data,
|
||||
size_t len) { (static_cast<ModbusClientTCPasync *>(i))->onPacket(static_cast<uint8_t *>(data), len); },
|
||||
this);
|
||||
MTA_client.onPoll([](void * i, AsyncClient * c) { (static_cast<ModbusClientTCPasync *>(i))->onPoll(); }, this);
|
||||
ModbusClientTCPasync::ModbusClientTCPasync(IPAddress address, uint16_t port, uint16_t queueLimit) :
|
||||
ModbusClient(),
|
||||
txQueue(),
|
||||
rxQueue(),
|
||||
MTA_client(),
|
||||
MTA_timeout(DEFAULTTIMEOUT),
|
||||
MTA_idleTimeout(DEFAULTIDLETIME),
|
||||
MTA_qLimit(queueLimit),
|
||||
MTA_maxInflightRequests(queueLimit),
|
||||
MTA_lastActivity(0),
|
||||
MTA_state(DISCONNECTED),
|
||||
MTA_host(address),
|
||||
MTA_port(port)
|
||||
{
|
||||
// attach all handlers on async tcp events
|
||||
MTA_client.onConnect([](void* i, AsyncClient* c) { (static_cast<ModbusClientTCPasync*>(i))->onConnected(); }, this);
|
||||
MTA_client.onDisconnect([](void* i, AsyncClient* c) { (static_cast<ModbusClientTCPasync*>(i))->onDisconnected(); }, this);
|
||||
MTA_client.onError([](void* i, AsyncClient* c, int8_t error) { (static_cast<ModbusClientTCPasync*>(i))->onACError(c, error); }, this);
|
||||
// MTA_client.onTimeout([](void* i, AsyncClient* c, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onTimeout(time); }, this);
|
||||
// MTA_client.onAck([](void* i, AsyncClient* c, size_t len, uint32_t time) { (static_cast<ModbusClientTCPasync*>(i))->onAck(len, time); }, this);
|
||||
MTA_client.onData([](void* i, AsyncClient* c, void* data, size_t len) { (static_cast<ModbusClientTCPasync*>(i))->onPacket(static_cast<uint8_t*>(data), len); }, this);
|
||||
MTA_client.onPoll([](void* i, AsyncClient* c) { (static_cast<ModbusClientTCPasync*>(i))->onPoll(); }, this);
|
||||
|
||||
// disable nagle algorithm ref Modbus spec
|
||||
MTA_client.setNoDelay(true);
|
||||
}
|
||||
// disable nagle algorithm ref Modbus spec
|
||||
MTA_client.setNoDelay(true);
|
||||
}
|
||||
|
||||
// Destructor: clean up queue, task etc.
|
||||
ModbusClientTCPasync::~ModbusClientTCPasync() {
|
||||
// Clean up queue
|
||||
{
|
||||
// Safely lock access
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
LOCK_GUARD(lock2, sLock);
|
||||
// Delete all elements from queues
|
||||
while (!txQueue.empty()) {
|
||||
delete txQueue.front();
|
||||
txQueue.pop_front();
|
||||
}
|
||||
for (auto it = rxQueue.cbegin(); it != rxQueue.cend(); /* no increment */) {
|
||||
delete it->second;
|
||||
it = rxQueue.erase(it);
|
||||
}
|
||||
}
|
||||
// force close client
|
||||
MTA_client.close(true);
|
||||
}
|
||||
|
||||
// optionally manually connect to modbus server. Otherwise connection will be made upon first request
|
||||
void ModbusClientTCPasync::connect() {
|
||||
LOG_D("connecting\n");
|
||||
LOCK_GUARD(lock1, sLock);
|
||||
// only connect if disconnected
|
||||
if (MTA_state == DISCONNECTED) {
|
||||
MTA_state = CONNECTING;
|
||||
MTA_client.connect(MTA_host, MTA_port);
|
||||
}
|
||||
}
|
||||
|
||||
// connect to another modbus server.
|
||||
void ModbusClientTCPasync::connect(IPAddress host, uint16_t port) {
|
||||
// First disconnect, if connected
|
||||
disconnect(true);
|
||||
// Set new host and port
|
||||
MTA_host = host;
|
||||
MTA_port = port;
|
||||
connect();
|
||||
}
|
||||
|
||||
// manually disconnect from modbus server. Connection will also auto close after idle time
|
||||
void ModbusClientTCPasync::disconnect(bool force) {
|
||||
LOG_D("disconnecting\n");
|
||||
MTA_client.close(force);
|
||||
}
|
||||
|
||||
// Set timeout value
|
||||
void ModbusClientTCPasync::setTimeout(uint32_t timeout) {
|
||||
MTA_timeout = timeout;
|
||||
}
|
||||
|
||||
// Set idle timeout value (time before connection auto closes after being idle)
|
||||
void ModbusClientTCPasync::setIdleTimeout(uint32_t timeout) {
|
||||
MTA_idleTimeout = timeout;
|
||||
}
|
||||
|
||||
void ModbusClientTCPasync::setMaxInflightRequests(uint32_t maxInflightRequests) {
|
||||
MTA_maxInflightRequests = maxInflightRequests;
|
||||
}
|
||||
|
||||
// Remove all pending request from queue
|
||||
void ModbusClientTCPasync::clearQueue() {
|
||||
// Clean up queue
|
||||
{
|
||||
// Safely lock access
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
LOCK_GUARD(lock2, sLock);
|
||||
// Delete all elements from queues
|
||||
while (!txQueue.empty()) {
|
||||
delete txQueue.front();
|
||||
txQueue.pop_front();
|
||||
delete txQueue.front();
|
||||
txQueue.pop_front();
|
||||
}
|
||||
for (auto it = rxQueue.cbegin(); it != rxQueue.cend();/* no increment */) {
|
||||
delete it->second;
|
||||
it = rxQueue.erase(it);
|
||||
}
|
||||
}
|
||||
// force close client
|
||||
MTA_client.close(true);
|
||||
}
|
||||
|
||||
// optionally manually connect to modbus server. Otherwise connection will be made upon first request
|
||||
void ModbusClientTCPasync::connect() {
|
||||
LOG_D("connecting\n");
|
||||
LOCK_GUARD(lock1, sLock);
|
||||
// only connect if disconnected
|
||||
if (MTA_state == DISCONNECTED) {
|
||||
MTA_state = CONNECTING;
|
||||
MTA_client.connect(MTA_host, MTA_port);
|
||||
}
|
||||
}
|
||||
|
||||
// connect to another modbus server.
|
||||
void ModbusClientTCPasync::connect(IPAddress host, uint16_t port) {
|
||||
// First disconnect, if connected
|
||||
disconnect(true);
|
||||
// Set new host and port
|
||||
MTA_host = host;
|
||||
MTA_port = port;
|
||||
connect();
|
||||
}
|
||||
|
||||
// manually disconnect from modbus server. Connection will also auto close after idle time
|
||||
void ModbusClientTCPasync::disconnect(bool force) {
|
||||
LOG_D("disconnecting\n");
|
||||
MTA_client.close(force);
|
||||
}
|
||||
|
||||
// Set timeout value
|
||||
void ModbusClientTCPasync::setTimeout(uint32_t timeout) {
|
||||
MTA_timeout = timeout;
|
||||
}
|
||||
|
||||
// Set idle timeout value (time before connection auto closes after being idle)
|
||||
void ModbusClientTCPasync::setIdleTimeout(uint32_t timeout) {
|
||||
MTA_idleTimeout = timeout;
|
||||
}
|
||||
|
||||
void ModbusClientTCPasync::setMaxInflightRequests(uint32_t maxInflightRequests) {
|
||||
MTA_maxInflightRequests = maxInflightRequests;
|
||||
}
|
||||
|
||||
// Remove all pending request from queue
|
||||
void ModbusClientTCPasync::clearQueue()
|
||||
{
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
LOCK_GUARD(lock2, sLock);
|
||||
// Delete all elements from queues
|
||||
while (!txQueue.empty()) {
|
||||
delete txQueue.front();
|
||||
txQueue.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
// Base addRequest for preformatted ModbusMessage and last set target
|
||||
Error ModbusClientTCPasync::addRequestM(ModbusMessage msg, uint32_t token) {
|
||||
Error rc = SUCCESS; // Return value
|
||||
Error rc = SUCCESS; // Return value
|
||||
|
||||
// Add it to the queue, if valid
|
||||
if (msg) {
|
||||
// Queue add successful?
|
||||
if (!addToQueue(token, msg)) {
|
||||
// No. Return error after deleting the allocated request.
|
||||
rc = REQUEST_QUEUE_FULL;
|
||||
}
|
||||
// Add it to the queue, if valid
|
||||
if (msg) {
|
||||
// Queue add successful?
|
||||
if (!addToQueue(token, msg)) {
|
||||
// No. Return error after deleting the allocated request.
|
||||
rc = REQUEST_QUEUE_FULL;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_D("Add TCP request result: %02X\n", rc);
|
||||
return rc;
|
||||
LOG_D("Add TCP request result: %02X\n", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Base syncRequest follows the same pattern
|
||||
ModbusMessage ModbusClientTCPasync::syncRequestM(ModbusMessage msg, uint32_t token) {
|
||||
ModbusMessage response;
|
||||
ModbusMessage response;
|
||||
|
||||
if (msg) {
|
||||
// Queue add successful?
|
||||
if (!addToQueue(token, msg, true)) {
|
||||
// No. Return error after deleting the allocated request.
|
||||
response.setError(msg.getServerID(), msg.getFunctionCode(), REQUEST_QUEUE_FULL);
|
||||
} else {
|
||||
// Request is queued - wait for the result.
|
||||
response = waitSync(msg.getServerID(), msg.getFunctionCode(), token);
|
||||
}
|
||||
if (msg) {
|
||||
// Queue add successful?
|
||||
if (!addToQueue(token, msg, true)) {
|
||||
// No. Return error after deleting the allocated request.
|
||||
response.setError(msg.getServerID(), msg.getFunctionCode(), REQUEST_QUEUE_FULL);
|
||||
} else {
|
||||
response.setError(msg.getServerID(), msg.getFunctionCode(), EMPTY_MESSAGE);
|
||||
// Request is queued - wait for the result.
|
||||
response = waitSync(msg.getServerID(), msg.getFunctionCode(), token);
|
||||
}
|
||||
return response;
|
||||
} else {
|
||||
response.setError(msg.getServerID(), msg.getFunctionCode(), EMPTY_MESSAGE);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
// addToQueue: send freshly created request to queue
|
||||
bool ModbusClientTCPasync::addToQueue(int32_t token, ModbusMessage request, bool syncReq) {
|
||||
// Did we get one?
|
||||
if (request) {
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
if (txQueue.size() + rxQueue.size() < MTA_qLimit) {
|
||||
HEXDUMP_V("Enqueue", request.data(), request.size());
|
||||
RequestEntry * re = new RequestEntry(token, request, syncReq);
|
||||
if (!re)
|
||||
return false; // TODO proper error returning in case allocation fails
|
||||
// inject proper transactionID
|
||||
re->head.transactionID = messageCount++;
|
||||
re->head.len = request.size();
|
||||
// if we're already connected, try to send and push to rxQueue
|
||||
// or else push to txQueue and (re)connect
|
||||
if (MTA_state == CONNECTED && send(re)) {
|
||||
re->sentTime = millis();
|
||||
rxQueue[re->head.transactionID] = re;
|
||||
} else {
|
||||
txQueue.push_back(re);
|
||||
if (MTA_state == DISCONNECTED) {
|
||||
connect();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
// Did we get one?
|
||||
if (request) {
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
if (txQueue.size() + rxQueue.size() < MTA_qLimit) {
|
||||
HEXDUMP_V("Enqueue", request.data(), request.size());
|
||||
RequestEntry *re = new RequestEntry(token, request, syncReq);
|
||||
if (!re) return false; //TODO: proper error returning in case allocation fails
|
||||
// inject proper transactionID
|
||||
re->head.transactionID = messageCount++;
|
||||
re->head.len = request.size();
|
||||
// if we're already connected, try to send and push to rxQueue
|
||||
// or else push to txQueue and (re)connect
|
||||
if (MTA_state == CONNECTED && send(re)) {
|
||||
re->sentTime = millis();
|
||||
rxQueue[re->head.transactionID] = re;
|
||||
} else {
|
||||
txQueue.push_back(re);
|
||||
if (MTA_state == DISCONNECTED) {
|
||||
connect();
|
||||
}
|
||||
LOG_E("queue is full\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
LOG_E("queue is full\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ModbusClientTCPasync::onConnected() {
|
||||
LOG_D("connected\n");
|
||||
LOCK_GUARD(lock1, sLock);
|
||||
MTA_state = CONNECTED;
|
||||
MTA_lastActivity = millis();
|
||||
// from now on onPoll will be called every 500 msec
|
||||
LOG_D("connected\n");
|
||||
LOCK_GUARD(lock1, sLock);
|
||||
MTA_state = CONNECTED;
|
||||
MTA_lastActivity = millis();
|
||||
// from now on onPoll will be called every 500 msec
|
||||
}
|
||||
|
||||
void ModbusClientTCPasync::onDisconnected() {
|
||||
LOG_D("disconnected\n");
|
||||
LOCK_GUARD(lock1, sLock);
|
||||
MTA_state = DISCONNECTED;
|
||||
LOG_D("disconnected\n");
|
||||
LOCK_GUARD(lock1, sLock);
|
||||
MTA_state = DISCONNECTED;
|
||||
|
||||
// empty queue on disconnect, calling errorcode on every waiting request
|
||||
LOCK_GUARD(lock2, qLock);
|
||||
while (!txQueue.empty()) {
|
||||
RequestEntry * r = txQueue.front();
|
||||
if (onError) {
|
||||
onError(IP_CONNECTION_FAILED, r->token);
|
||||
}
|
||||
delete r;
|
||||
txQueue.pop_front();
|
||||
// empty queue on disconnect, calling errorcode on every waiting request
|
||||
LOCK_GUARD(lock2, qLock);
|
||||
while (!txQueue.empty()) {
|
||||
RequestEntry* r = txQueue.front();
|
||||
if (onError) {
|
||||
onError(IP_CONNECTION_FAILED, r->token);
|
||||
}
|
||||
while (!rxQueue.empty()) {
|
||||
RequestEntry * r = rxQueue.begin()->second;
|
||||
if (onError) {
|
||||
onError(IP_CONNECTION_FAILED, r->token);
|
||||
}
|
||||
delete r;
|
||||
rxQueue.erase(rxQueue.begin());
|
||||
delete r;
|
||||
txQueue.pop_front();
|
||||
}
|
||||
while (!rxQueue.empty()) {
|
||||
RequestEntry *r = rxQueue.begin()->second;
|
||||
if (onError) {
|
||||
onError(IP_CONNECTION_FAILED, r->token);
|
||||
}
|
||||
delete r;
|
||||
rxQueue.erase(rxQueue.begin());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ModbusClientTCPasync::onACError(AsyncClient * c, int8_t error) {
|
||||
// onDisconnect will alse be called, so nothing to do here
|
||||
LOG_W("TCP error: %s\n", c->errorToString(error));
|
||||
void ModbusClientTCPasync::onACError(AsyncClient* c, int8_t error) {
|
||||
// onDisconnect will alse be called, so nothing to do here
|
||||
LOG_W("TCP error: %s\n", c->errorToString(error));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -225,178 +222,180 @@ void onAck(size_t len, uint32_t time) {
|
||||
// assuming we don't need this
|
||||
}
|
||||
*/
|
||||
void ModbusClientTCPasync::onPacket(uint8_t * data, size_t length) {
|
||||
LOG_D("packet received (len:%d)\n", length);
|
||||
// reset idle timeout
|
||||
MTA_lastActivity = millis();
|
||||
void ModbusClientTCPasync::onPacket(uint8_t* data, size_t length) {
|
||||
LOG_D("packet received (len:%d)\n", length);
|
||||
// reset idle timeout
|
||||
MTA_lastActivity = millis();
|
||||
|
||||
if (length) {
|
||||
LOG_D("parsing (len:%d)\n", length + 1);
|
||||
if (length) {
|
||||
LOG_D("parsing (len:%d)\n", length + 1);
|
||||
}
|
||||
while (length > 0) {
|
||||
RequestEntry* request = nullptr;
|
||||
ModbusMessage* response = nullptr;
|
||||
uint16_t transactionID = 0;
|
||||
uint16_t protocolID = 0;
|
||||
uint16_t messageLength = 0;
|
||||
bool isOkay = false;
|
||||
|
||||
// 1. Check for valid modbus message
|
||||
|
||||
// MBAP header is 6 bytes, we can't do anything with less
|
||||
// total message should fit MBAP plus remaining bytes (in data[4], data[5])
|
||||
if (length > 6) {
|
||||
transactionID = (data[0] << 8) | data[1];
|
||||
protocolID = (data[2] << 8) | data[3];
|
||||
messageLength = (data[4] << 8) | data[5];
|
||||
if (protocolID == 0 &&
|
||||
length >= (uint32_t)messageLength + 6 &&
|
||||
messageLength < 256) {
|
||||
response = new ModbusMessage(messageLength);
|
||||
response->add(&data[6], messageLength);
|
||||
LOG_D("packet validated (len:%d)\n", messageLength);
|
||||
|
||||
// on next iteration: adjust remaining length and pointer to data
|
||||
length -= 6 + messageLength;
|
||||
data += 6 + messageLength;
|
||||
isOkay = true;
|
||||
}
|
||||
}
|
||||
while (length > 0) {
|
||||
RequestEntry * request = nullptr;
|
||||
ModbusMessage * response = nullptr;
|
||||
uint16_t transactionID = 0;
|
||||
uint16_t protocolID = 0;
|
||||
uint16_t messageLength = 0;
|
||||
bool isOkay = false;
|
||||
|
||||
// 1. Check for valid modbus message
|
||||
if (!isOkay) {
|
||||
// invalid packet, abort function
|
||||
LOG_W("packet invalid\n");
|
||||
return;
|
||||
} else {
|
||||
// 2. we got a valid response, match with a request
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
auto i = rxQueue.find(transactionID);
|
||||
if (i != rxQueue.end()) {
|
||||
// found it, handle it and stop iterating
|
||||
request = i->second;
|
||||
i = rxQueue.erase(i);
|
||||
LOG_D("matched request\n");
|
||||
} else {
|
||||
// TCP packet did not yield valid modbus response, abort function
|
||||
LOG_W("no matching request found\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// MBAP header is 6 bytes, we can't do anything with less
|
||||
// total message should fit MBAP plus remaining bytes (in data[4], data[5])
|
||||
if (length > 6) {
|
||||
transactionID = (data[0] << 8) | data[1];
|
||||
protocolID = (data[2] << 8) | data[3];
|
||||
messageLength = (data[4] << 8) | data[5];
|
||||
if (protocolID == 0 && length >= (uint32_t)messageLength + 6 && messageLength < 256) {
|
||||
response = new ModbusMessage(messageLength);
|
||||
response->add(&data[6], messageLength);
|
||||
LOG_D("packet validated (len:%d)\n", messageLength);
|
||||
// 3. we have a valid request and a valid response, call appropriate callback
|
||||
if (request) {
|
||||
// compare request with response
|
||||
Error error = SUCCESS;
|
||||
if (request->msg.getFunctionCode() != (response->getFunctionCode() & 0x7F)) {
|
||||
error = FC_MISMATCH;
|
||||
} else if (request->msg.getServerID() != response->getServerID()) {
|
||||
error = SERVER_ID_MISMATCH;
|
||||
} else {
|
||||
error = response->getError();
|
||||
}
|
||||
|
||||
// on next iteration: adjust remaining length and pointer to data
|
||||
length -= 6 + messageLength;
|
||||
data += 6 + messageLength;
|
||||
isOkay = true;
|
||||
}
|
||||
if (error != SUCCESS) {
|
||||
LOCK_GUARD(errorCntLock, countAccessM);
|
||||
errorCount++;
|
||||
}
|
||||
|
||||
if (request->isSyncRequest) {
|
||||
{
|
||||
LOCK_GUARD(sL ,syncRespM);
|
||||
syncResponse[request->token] = *response;
|
||||
}
|
||||
|
||||
if (!isOkay) {
|
||||
// invalid packet, abort function
|
||||
LOG_W("packet invalid\n");
|
||||
return;
|
||||
} else if (onResponse) {
|
||||
onResponse(*response, request->token);
|
||||
} else {
|
||||
if (error == SUCCESS) {
|
||||
if (onData) {
|
||||
onData(*response, request->token);
|
||||
}
|
||||
} else {
|
||||
// 2. we got a valid response, match with a request
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
auto i = rxQueue.find(transactionID);
|
||||
if (i != rxQueue.end()) {
|
||||
// found it, handle it and stop iterating
|
||||
request = i->second;
|
||||
i = rxQueue.erase(i);
|
||||
LOG_D("matched request\n");
|
||||
} else {
|
||||
// TCP packet did not yield valid modbus response, abort function
|
||||
LOG_W("no matching request found\n");
|
||||
return;
|
||||
}
|
||||
if (onError) {
|
||||
onError(response->getError(), request->token);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete request;
|
||||
}
|
||||
delete response;
|
||||
|
||||
// 3. we have a valid request and a valid response, call appropriate callback
|
||||
if (request) {
|
||||
// compare request with response
|
||||
Error error = SUCCESS;
|
||||
if (request->msg.getFunctionCode() != (response->getFunctionCode() & 0x7F)) {
|
||||
error = FC_MISMATCH;
|
||||
} else if (request->msg.getServerID() != response->getServerID()) {
|
||||
error = SERVER_ID_MISMATCH;
|
||||
} else {
|
||||
error = response->getError();
|
||||
}
|
||||
} // end processing of incoming data
|
||||
|
||||
if (error != SUCCESS) {
|
||||
LOCK_GUARD(errorCntLock, countAccessM);
|
||||
errorCount++;
|
||||
}
|
||||
|
||||
if (request->isSyncRequest) {
|
||||
{
|
||||
LOCK_GUARD(sL, syncRespM);
|
||||
syncResponse[request->token] = *response;
|
||||
}
|
||||
} else if (onResponse) {
|
||||
onResponse(*response, request->token);
|
||||
} else {
|
||||
if (error == SUCCESS) {
|
||||
if (onData) {
|
||||
onData(*response, request->token);
|
||||
}
|
||||
} else {
|
||||
if (onError) {
|
||||
onError(response->getError(), request->token);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete request;
|
||||
}
|
||||
delete response;
|
||||
|
||||
} // end processing of incoming data
|
||||
|
||||
// check if we have to send the next request
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
handleSendingQueue();
|
||||
// check if we have to send the next request
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
handleSendingQueue();
|
||||
}
|
||||
|
||||
void ModbusClientTCPasync::onPoll() {
|
||||
{
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
{
|
||||
LOCK_GUARD(lock1, qLock);
|
||||
|
||||
// try to send whatever is waiting
|
||||
handleSendingQueue();
|
||||
// try to send whatever is waiting
|
||||
handleSendingQueue();
|
||||
|
||||
// next check if timeout has struck for oldest request
|
||||
if (!rxQueue.empty()) {
|
||||
RequestEntry * request = rxQueue.begin()->second;
|
||||
if (millis() - request->sentTime > MTA_timeout) {
|
||||
LOG_D("request timeouts (now:%lu-sent:%u)\n", millis(), request->sentTime);
|
||||
// oldest element timeouts, call onError and clean up
|
||||
if (onError) {
|
||||
// Handle timeout error
|
||||
onError(TIMEOUT, request->token);
|
||||
}
|
||||
delete request;
|
||||
rxQueue.erase(rxQueue.begin());
|
||||
}
|
||||
}
|
||||
|
||||
} // end lockguard scope
|
||||
|
||||
// if nothing happened during idle timeout, gracefully close connection
|
||||
if (millis() - MTA_lastActivity > MTA_idleTimeout) {
|
||||
disconnect();
|
||||
// next check if timeout has struck for oldest request
|
||||
if (!rxQueue.empty()) {
|
||||
RequestEntry* request = rxQueue.begin()->second;
|
||||
if (millis() - request->sentTime > MTA_timeout) {
|
||||
LOG_D("request timeouts (now:%lu-sent:%u)\n", millis(), request->sentTime);
|
||||
// oldest element timeouts, call onError and clean up
|
||||
if (onError) {
|
||||
// Handle timeout error
|
||||
onError(TIMEOUT, request->token);
|
||||
}
|
||||
delete request;
|
||||
rxQueue.erase(rxQueue.begin());
|
||||
}
|
||||
}
|
||||
|
||||
} // end lockguard scope
|
||||
|
||||
// if nothing happened during idle timeout, gracefully close connection
|
||||
if (millis() - MTA_lastActivity > MTA_idleTimeout) {
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusClientTCPasync::handleSendingQueue() {
|
||||
// ATTENTION: This method does not have a lock guard.
|
||||
// Calling sites must assure shared resources are protected
|
||||
// by mutex.
|
||||
// ATTENTION: This method does not have a lock guard.
|
||||
// Calling sites must assure shared resources are protected
|
||||
// by mutex.
|
||||
|
||||
// try to send everything we have waiting
|
||||
std::list<RequestEntry *>::iterator it = txQueue.begin();
|
||||
while (it != txQueue.end()) {
|
||||
// get the actual element
|
||||
if (send(*it)) {
|
||||
// after sending, update timeout value, add to other queue and remove from this queue
|
||||
(*it)->sentTime = millis();
|
||||
rxQueue[(*it)->head.transactionID] = (*it); // push request to other queue
|
||||
it = txQueue.erase(it); // remove from toSend queue and point i to next request
|
||||
} else {
|
||||
// sending didn't succeed, try next request
|
||||
++it;
|
||||
}
|
||||
// try to send everything we have waiting
|
||||
std::list<RequestEntry*>::iterator it = txQueue.begin();
|
||||
while (it != txQueue.end()) {
|
||||
// get the actual element
|
||||
if (send(*it)) {
|
||||
// after sending, update timeout value, add to other queue and remove from this queue
|
||||
(*it)->sentTime = millis();
|
||||
rxQueue[(*it)->head.transactionID] = (*it); // push request to other queue
|
||||
it = txQueue.erase(it); // remove from toSend queue and point i to next request
|
||||
} else {
|
||||
// sending didn't succeed, try next request
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ModbusClientTCPasync::send(RequestEntry * re) {
|
||||
// ATTENTION: This method does not have a lock guard.
|
||||
// Calling sites must assure shared resources are protected
|
||||
// by mutex.
|
||||
bool ModbusClientTCPasync::send(RequestEntry* re) {
|
||||
// ATTENTION: This method does not have a lock guard.
|
||||
// Calling sites must assure shared resources are protected
|
||||
// by mutex.
|
||||
|
||||
if (rxQueue.size() >= MTA_maxInflightRequests) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if TCP client is able to send
|
||||
if (MTA_client.space() > ((uint32_t)re->msg.size() + 6)) {
|
||||
// Write TCP header first
|
||||
MTA_client.add(reinterpret_cast<const char *>((const uint8_t *)(re->head)), 6, ASYNC_WRITE_FLAG_COPY);
|
||||
// Request comes next
|
||||
MTA_client.add(reinterpret_cast<const char *>(re->msg.data()), re->msg.size(), ASYNC_WRITE_FLAG_COPY);
|
||||
// done
|
||||
MTA_client.send();
|
||||
LOG_D("request sent (msgid:%d)\n", re->head.transactionID);
|
||||
return true;
|
||||
}
|
||||
if (rxQueue.size() >= MTA_maxInflightRequests) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if TCP client is able to send
|
||||
if (MTA_client.space() > ((uint32_t)re->msg.size() + 6)) {
|
||||
// Write TCP header first
|
||||
MTA_client.add(reinterpret_cast<const char *>((const uint8_t *)(re->head)), 6, ASYNC_WRITE_FLAG_COPY);
|
||||
// Request comes next
|
||||
MTA_client.add(reinterpret_cast<const char*>(re->msg.data()), re->msg.size(), ASYNC_WRITE_FLAG_COPY);
|
||||
// done
|
||||
MTA_client.send();
|
||||
LOG_D("request sent (msgid:%d)\n", re->head.transactionID);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,30 +18,48 @@ void ModbusServer::registerWorker(uint8_t serverID, uint8_t functionCode, MBSwor
|
||||
|
||||
// getWorker: if a worker function is registered, return its address, nullptr otherwise
|
||||
MBSworker ModbusServer::getWorker(uint8_t serverID, uint8_t functionCode) {
|
||||
bool serverFound = false;
|
||||
LOG_D("Need worker for %02X-%02X : ", serverID, functionCode);
|
||||
// Search the FC map associated with the serverID
|
||||
auto svmap = workerMap.find(serverID);
|
||||
// Is there one?
|
||||
if (svmap != workerMap.end()) {
|
||||
serverFound = true;
|
||||
// No explicit serverID entry found, but we may have one for ANY_SERVER
|
||||
} else {
|
||||
svmap = workerMap.find(ANY_SERVER);
|
||||
if (svmap != workerMap.end()) {
|
||||
serverFound = true;
|
||||
serverID = ANY_SERVER;
|
||||
}
|
||||
}
|
||||
// Did we find a serverID?
|
||||
if (serverFound) {
|
||||
// Yes. Now look for the function code in the inner map
|
||||
bool functionCodeFound = false;
|
||||
auto fcmap = svmap->second.find(functionCode);;
|
||||
// Found it?
|
||||
if (fcmap != svmap->second.end()) {
|
||||
// Yes. Return the function pointer for it.
|
||||
LOG_D("Worker found for %02X/%02X\n", serverID, functionCode);
|
||||
return fcmap->second;
|
||||
functionCodeFound = true;
|
||||
// No, no explicit worker found, but may be there is one for ANY_FUNCTION_CODE?
|
||||
} else {
|
||||
fcmap = svmap->second.find(ANY_FUNCTION_CODE);;
|
||||
// Found it?
|
||||
if (fcmap != svmap->second.end()) {
|
||||
// Yes. Return the function pointer for it.
|
||||
LOG_D("Worker found for %02X/ANY\n", serverID);
|
||||
return fcmap->second;
|
||||
functionCodeFound = true;
|
||||
functionCode = ANY_FUNCTION_CODE;
|
||||
}
|
||||
}
|
||||
if (functionCodeFound) {
|
||||
// Yes. Return the function pointer for it.
|
||||
LOGRAW_D("Worker found for %02X/%02X\n", serverID, functionCode);
|
||||
return fcmap->second;
|
||||
}
|
||||
}
|
||||
// No matching function pointer found
|
||||
LOG_D("No matching worker found\n");
|
||||
LOGRAW_D("No matching worker found\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -68,16 +86,29 @@ bool ModbusServer::unregisterWorker(uint8_t serverID, uint8_t functionCode) {
|
||||
return (numEntries ? true : false);
|
||||
}
|
||||
|
||||
// isServerFor: if any worker function is registered for the given serverID, return true
|
||||
bool ModbusServer::isServerFor(uint8_t serverID) {
|
||||
// Search the FC map for the serverID
|
||||
auto svmap = workerMap.find(serverID);
|
||||
// Is it there? Then return true
|
||||
if (svmap != workerMap.end()) return true;
|
||||
// No, serverID was not found. Return false
|
||||
// isServerFor: if a worker function is registered for the given serverID, return true
|
||||
// functionCode defaults to ANY_FUNCTION_CODE and will yield true for any function code,
|
||||
// including ANY_FUNCTION_CODE :D
|
||||
bool ModbusServer::isServerFor(uint8_t serverID, uint8_t functionCode) {
|
||||
// Check if there is a non-nullptr function for the given combination
|
||||
if (getWorker(serverID, functionCode)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// isServerFor: short version to look up if the server is known at all
|
||||
bool ModbusServer::isServerFor(uint8_t serverID) {
|
||||
// Check if there is a non-nullptr function for the given combination
|
||||
auto svmap = workerMap.find(serverID);
|
||||
// Is there one?
|
||||
if (svmap != workerMap.end()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// getMessageCount: read number of messages processed
|
||||
uint32_t ModbusServer::getMessageCount() {
|
||||
return messageCount;
|
||||
|
||||
@@ -42,7 +42,10 @@ public:
|
||||
// Returns true if the worker was found and removed
|
||||
bool unregisterWorker(uint8_t serverID, uint8_t functionCode = 0);
|
||||
|
||||
// isServerFor: if any worker function is registered for the given serverID, return true
|
||||
// isServerFor: if a worker function is registered for the given serverID, return true
|
||||
bool isServerFor(uint8_t serverID, uint8_t functionCode);
|
||||
|
||||
// isServerFor: short version to look up if the server is known at all
|
||||
bool isServerFor(uint8_t serverID);
|
||||
|
||||
// getMessageCount: read number of messages processed
|
||||
|
||||
19
lib/eModbus/src/ModbusServerETH.h
Normal file
19
lib/eModbus/src/ModbusServerETH.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// =================================================================================================
|
||||
// eModbus: Copyright 2024 by Michael Harwerth, Bert Melis and the contributors to eModbus
|
||||
// MIT license - see license.md for details
|
||||
// =================================================================================================
|
||||
#ifndef _MODBUS_SERVER_ETH_H
|
||||
#define _MODBUS_SERVER_ETH_H
|
||||
#include "options.h"
|
||||
#if HAS_ETHERNET == 1
|
||||
#include <ETH.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#undef SERVER_END
|
||||
#define SERVER_END // NIL for Ethernet
|
||||
|
||||
#include "ModbusServerTCPtemp.h"
|
||||
using ModbusServerEthernet = ModbusServerTCP<WiFiServer, WiFiClient>;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -12,8 +12,15 @@
|
||||
#undef SERVER_END
|
||||
#define SERVER_END // NIL for Ethernet
|
||||
|
||||
// Create own non-virtual EthernetServer class
|
||||
class EthernetServerEM : public EthernetServer {
|
||||
public:
|
||||
EthernetServerEM(uint16_t port) : EthernetServer(port) { }
|
||||
void begin(uint16_t port = 0) { }
|
||||
};
|
||||
|
||||
#include "ModbusServerTCPtemp.h"
|
||||
using ModbusServerEthernet = ModbusServerTCP<EthernetServer, EthernetClient>;
|
||||
using ModbusServerEthernet = ModbusServerTCP<EthernetServerEM, EthernetClient>;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -64,26 +64,31 @@ ModbusServerRTU::~ModbusServerRTU() {
|
||||
}
|
||||
|
||||
// start: create task with RTU server - general version
|
||||
void ModbusServerRTU::begin(Stream& serial, uint32_t baudRate, int coreID) {
|
||||
void ModbusServerRTU::begin(Stream& serial, uint32_t baudRate, int coreID, uint32_t userInterval) {
|
||||
MSRserial = &serial;
|
||||
doBegin(baudRate, coreID);
|
||||
doBegin(baudRate, coreID, userInterval);
|
||||
}
|
||||
|
||||
// start: create task with RTU server - HardwareSerial versions
|
||||
void ModbusServerRTU::begin(HardwareSerial& serial, int coreID) {
|
||||
void ModbusServerRTU::begin(HardwareSerial& serial, int coreID, uint32_t userInterval) {
|
||||
MSRserial = &serial;
|
||||
uint32_t baudRate = serial.baudRate();
|
||||
serial.setRxFIFOFull(1);
|
||||
doBegin(baudRate, coreID);
|
||||
doBegin(baudRate, coreID, userInterval);
|
||||
}
|
||||
|
||||
void ModbusServerRTU::doBegin(uint32_t baudRate, int coreID) {
|
||||
void ModbusServerRTU::doBegin(uint32_t baudRate, int coreID, uint32_t userInterval) {
|
||||
// Task already running? Stop it in case.
|
||||
end();
|
||||
|
||||
// Set minimum interval time
|
||||
MSRinterval = RTUutils::calculateInterval(baudRate);
|
||||
|
||||
// If user defined interval is longer, use that
|
||||
if (MSRinterval < userInterval) {
|
||||
MSRinterval = userInterval;
|
||||
}
|
||||
|
||||
// Create unique task name
|
||||
char taskName[18];
|
||||
snprintf(taskName, 18, "MBsrv%02XRTU", instanceCounter);
|
||||
@@ -180,10 +185,12 @@ void ModbusServerRTU::serve(ModbusServerRTU *myServer) {
|
||||
}
|
||||
// Is it a broadcast?
|
||||
if (request[0] == 0) {
|
||||
LOG_D("Broadcast!\n");
|
||||
// Yes. Do we have a listener?
|
||||
if (myServer->listener) {
|
||||
// Yes. call it
|
||||
myServer->listener(request);
|
||||
LOG_D("Broadcast served.\n");
|
||||
}
|
||||
// else we simply ignore it
|
||||
} else {
|
||||
|
||||
@@ -32,8 +32,8 @@ public:
|
||||
~ModbusServerRTU();
|
||||
|
||||
// begin: create task with RTU server to accept requests
|
||||
void begin(Stream& serial, uint32_t baudRate, int coreID = -1);
|
||||
void begin(HardwareSerial& serial, int coreID = -1);
|
||||
void begin(Stream& serial, uint32_t baudRate, int coreID = -1, uint32_t userInterval = 0);
|
||||
void begin(HardwareSerial& serial, int coreID = -1, uint32_t userInterval = 0);
|
||||
|
||||
// end: kill server task
|
||||
void end();
|
||||
@@ -64,7 +64,7 @@ protected:
|
||||
inline void isInstance() { } // Make class instantiable
|
||||
|
||||
// internal common begin function
|
||||
void doBegin(uint32_t baudRate, int coreID);
|
||||
void doBegin(uint32_t baudRate, int coreID, uint32_t userInterval);
|
||||
|
||||
static uint8_t instanceCounter; // Number of RTU servers created (for task names)
|
||||
TaskHandle_t serverTask; // task of the started server
|
||||
|
||||
@@ -8,260 +8,261 @@
|
||||
// #undef LOCAL_LOG_LEVEL
|
||||
#include "Logging.h"
|
||||
|
||||
ModbusServerTCPasync::mb_client::mb_client(ModbusServerTCPasync * s, AsyncClient * c)
|
||||
: server(s)
|
||||
, client(c)
|
||||
, lastActiveTime(millis())
|
||||
, message(nullptr)
|
||||
, error(SUCCESS)
|
||||
, outbox() {
|
||||
client->onData([](void * i, AsyncClient * c, void * data, size_t len) { (static_cast<mb_client *>(i))->onData(static_cast<uint8_t *>(data), len); }, this);
|
||||
client->onPoll([](void * i, AsyncClient * c) { (static_cast<mb_client *>(i))->onPoll(); }, this);
|
||||
client->onDisconnect([](void * i, AsyncClient * c) { (static_cast<mb_client *>(i))->onDisconnect(); }, this);
|
||||
ModbusServerTCPasync::mb_client::mb_client(ModbusServerTCPasync* s, AsyncClient* c) :
|
||||
server(s),
|
||||
client(c),
|
||||
lastActiveTime(millis()),
|
||||
message(nullptr),
|
||||
error(SUCCESS),
|
||||
outbox() {
|
||||
client->onData([](void* i, AsyncClient* c, void* data, size_t len) { (static_cast<mb_client*>(i))->onData(static_cast<uint8_t*>(data), len); }, this);
|
||||
client->onPoll([](void* i, AsyncClient* c) { (static_cast<mb_client*>(i))->onPoll(); }, this);
|
||||
client->onDisconnect([](void* i, AsyncClient* c) { (static_cast<mb_client*>(i))->onDisconnect(); }, this);
|
||||
client->setNoDelay(true);
|
||||
}
|
||||
|
||||
ModbusServerTCPasync::mb_client::~mb_client() {
|
||||
// clear outbox, if data is left
|
||||
while (!outbox.empty()) {
|
||||
outbox.pop();
|
||||
}
|
||||
// clear outbox, if data is left
|
||||
while (!outbox.empty()) {
|
||||
outbox.pop();
|
||||
}
|
||||
|
||||
delete client; // will also close connection, if any
|
||||
delete client; // will also close connection, if any
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::mb_client::onData(uint8_t * data, size_t len) {
|
||||
lastActiveTime = millis();
|
||||
LOG_D("data len %d\n", len);
|
||||
void ModbusServerTCPasync::mb_client::onData(uint8_t* data, size_t len) {
|
||||
lastActiveTime = millis();
|
||||
LOG_D("data len %d\n", len);
|
||||
|
||||
Error error = SUCCESS;
|
||||
size_t i = 0;
|
||||
while (i < len) {
|
||||
// 0. start
|
||||
if (!message) {
|
||||
message = new ModbusMessage(8);
|
||||
error = SUCCESS;
|
||||
}
|
||||
Error error = SUCCESS;
|
||||
size_t i = 0;
|
||||
while (i < len) {
|
||||
// 0. start
|
||||
if (!message) {
|
||||
message = new ModbusMessage(8);
|
||||
error = SUCCESS;
|
||||
}
|
||||
|
||||
// 1. get minimal 8 bytes to move on
|
||||
while (message->size() < 8 && i < len) {
|
||||
message->push_back(data[i++]);
|
||||
}
|
||||
// 1. get minimal 8 bytes to move on
|
||||
while (message->size() < 8 && i < len) {
|
||||
message->push_back(data[i++]);
|
||||
}
|
||||
|
||||
// 2. preliminary validation: protocol bytes and message length
|
||||
if ((*message)[2] != 0 || (*message)[3] != 0) {
|
||||
error = TCP_HEAD_MISMATCH;
|
||||
LOG_D("invalid protocol\n");
|
||||
}
|
||||
size_t messageLength = (((*message)[4] << 8) | (*message)[5]) + 6;
|
||||
if (messageLength > 262) { // 256 + MBAP(6) = 262
|
||||
error = PACKET_LENGTH_ERROR;
|
||||
LOG_D("max length error\n");
|
||||
}
|
||||
if (error != SUCCESS) {
|
||||
ModbusMessage response;
|
||||
response.setError(message->getServerID(), message->getFunctionCode(), error);
|
||||
message->resize(4);
|
||||
message->add(static_cast<uint16_t>(3));
|
||||
message->append(response);
|
||||
addResponseToOutbox(message); // outbox has pointer ownership now
|
||||
// reset to starting values and process remaining data
|
||||
message = nullptr;
|
||||
return; // protocol validation, abort further parsing
|
||||
}
|
||||
// 2. preliminary validation: protocol bytes and message length
|
||||
if ((*message)[2] != 0 || (*message)[3] != 0) {
|
||||
error = TCP_HEAD_MISMATCH;
|
||||
LOG_D("invalid protocol\n");
|
||||
}
|
||||
size_t messageLength = (((*message)[4] << 8) | (*message)[5]) + 6;
|
||||
if (messageLength > 262) { // 256 + MBAP(6) = 262
|
||||
error = PACKET_LENGTH_ERROR;
|
||||
LOG_D("max length error\n");
|
||||
}
|
||||
if (error != SUCCESS) {
|
||||
ModbusMessage response;
|
||||
response.setError(message->getServerID(), message->getFunctionCode(), error);
|
||||
message->resize(4);
|
||||
message->add(static_cast<uint16_t>(3));
|
||||
message->append(response);
|
||||
addResponseToOutbox(message); // outbox has pointer ownership now
|
||||
// reset to starting values and process remaining data
|
||||
message = nullptr;
|
||||
return; // protocol validation, abort further parsing
|
||||
}
|
||||
|
||||
// 3. receive until request is complete
|
||||
while (message->size() < messageLength && i < len) {
|
||||
message->push_back(data[i++]);
|
||||
}
|
||||
if (message->size() == messageLength) {
|
||||
LOG_D("request complete (len:%d)\n", message->size());
|
||||
} else {
|
||||
LOG_D("request incomplete (len:%d), waiting for next TCP packet\n", message->size());
|
||||
continue;
|
||||
}
|
||||
// 3. receive until request is complete
|
||||
while (message->size() < messageLength && i < len) {
|
||||
message->push_back(data[i++]);
|
||||
}
|
||||
if (message->size() == messageLength) {
|
||||
LOG_D("request complete (len:%d)\n", message->size());
|
||||
} else {
|
||||
LOG_D("request incomplete (len:%d), waiting for next TCP packet\n", message->size());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 4. request complete, process
|
||||
ModbusMessage request(messageLength - 6); // create request without MBAP, with server ID
|
||||
request.add(message->data() + 6, message->size() - 6);
|
||||
ModbusMessage userData;
|
||||
if (server->isServerFor(request.getServerID())) {
|
||||
MBSworker callback = server->getWorker(request.getServerID(), request.getFunctionCode());
|
||||
if (callback) {
|
||||
// request is well formed and is being served by user API
|
||||
userData = callback(request);
|
||||
// Process Response
|
||||
// One of the predefined types?
|
||||
if (userData[0] == 0xFF && (userData[1] == 0xF0 || userData[1] == 0xF1)) {
|
||||
// Yes. Check it
|
||||
switch (userData[1]) {
|
||||
case 0xF0: // NIL
|
||||
userData.clear();
|
||||
LOG_D("NIL response\n");
|
||||
break;
|
||||
case 0xF1: // ECHO
|
||||
userData = request;
|
||||
if (request.getFunctionCode() == WRITE_MULT_REGISTERS || request.getFunctionCode() == WRITE_MULT_COILS) {
|
||||
userData.resize(6);
|
||||
}
|
||||
LOG_D("ECHO response\n");
|
||||
break;
|
||||
default: // Will not get here!
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// No. User provided data response
|
||||
LOG_D("Data response\n");
|
||||
}
|
||||
error = SUCCESS;
|
||||
} else { // no worker found
|
||||
error = ILLEGAL_FUNCTION;
|
||||
// 4. request complete, process
|
||||
ModbusMessage request(messageLength - 6); // create request without MBAP, with server ID
|
||||
request.add(message->data() + 6, message->size() - 6);
|
||||
ModbusMessage userData;
|
||||
if (server->isServerFor(request.getServerID())) {
|
||||
MBSworker callback = server->getWorker(request.getServerID(), request.getFunctionCode());
|
||||
if (callback) {
|
||||
// request is well formed and is being served by user API
|
||||
userData = callback(request);
|
||||
// Process Response
|
||||
// One of the predefined types?
|
||||
if (userData[0] == 0xFF && (userData[1] == 0xF0 || userData[1] == 0xF1)) {
|
||||
// Yes. Check it
|
||||
switch (userData[1]) {
|
||||
case 0xF0: // NIL
|
||||
userData.clear();
|
||||
LOG_D("NIL response\n");
|
||||
break;
|
||||
case 0xF1: // ECHO
|
||||
userData = request;
|
||||
if (request.getFunctionCode() == WRITE_MULT_REGISTERS ||
|
||||
request.getFunctionCode() == WRITE_MULT_COILS) {
|
||||
userData.resize(6);
|
||||
}
|
||||
} else { // mismatch server ID
|
||||
error = INVALID_SERVER;
|
||||
LOG_D("ECHO response\n");
|
||||
break;
|
||||
default: // Will not get here!
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// No. User provided data response
|
||||
LOG_D("Data response\n");
|
||||
}
|
||||
if (error != SUCCESS) {
|
||||
userData.setError(request.getServerID(), request.getFunctionCode(), error);
|
||||
}
|
||||
// Keep transaction id and protocol id
|
||||
message->resize(4);
|
||||
// Add new payload length
|
||||
message->add(static_cast<uint16_t>(userData.size()));
|
||||
// Append payload
|
||||
message->append(userData);
|
||||
// Transfer message data to outbox
|
||||
addResponseToOutbox(message);
|
||||
message = nullptr;
|
||||
} // end while loop iterating incoming data
|
||||
error = SUCCESS;
|
||||
} else { // no worker found
|
||||
error = ILLEGAL_FUNCTION;
|
||||
}
|
||||
} else { // mismatch server ID
|
||||
error = INVALID_SERVER;
|
||||
}
|
||||
if (error != SUCCESS) {
|
||||
userData.setError(request.getServerID(), request.getFunctionCode(), error);
|
||||
}
|
||||
// Keep transaction id and protocol id
|
||||
message->resize(4);
|
||||
// Add new payload length
|
||||
message->add(static_cast<uint16_t>(userData.size()));
|
||||
// Append payload
|
||||
message->append(userData);
|
||||
// Transfer message data to outbox
|
||||
addResponseToOutbox(message);
|
||||
message = nullptr;
|
||||
} // end while loop iterating incoming data
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::mb_client::onPoll() {
|
||||
LOCK_GUARD(lock1, obLock);
|
||||
handleOutbox();
|
||||
if (server->idle_timeout > 0 && millis() - lastActiveTime > server->idle_timeout) {
|
||||
LOG_D("client idle, closing\n");
|
||||
client->close();
|
||||
}
|
||||
LOCK_GUARD(lock1, obLock);
|
||||
handleOutbox();
|
||||
if (server->idle_timeout > 0 &&
|
||||
millis() - lastActiveTime > server->idle_timeout) {
|
||||
LOG_D("client idle, closing\n");
|
||||
client->close();
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::mb_client::onDisconnect() {
|
||||
LOG_D("client disconnected\n");
|
||||
server->onClientDisconnect(this);
|
||||
LOG_D("client disconnected\n");
|
||||
server->onClientDisconnect(this);
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::mb_client::addResponseToOutbox(ModbusMessage * response) {
|
||||
if (response->size() > 0) {
|
||||
LOCK_GUARD(lock1, obLock);
|
||||
outbox.push(response);
|
||||
handleOutbox();
|
||||
}
|
||||
void ModbusServerTCPasync::mb_client::addResponseToOutbox(ModbusMessage* response) {
|
||||
if (response->size() > 0) {
|
||||
LOCK_GUARD(lock1, obLock);
|
||||
outbox.push(response);
|
||||
handleOutbox();
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::mb_client::handleOutbox() {
|
||||
while (!outbox.empty()) {
|
||||
ModbusMessage * m = outbox.front();
|
||||
if (m->size() <= client->space()) {
|
||||
LOG_D("sending (%d)\n", m->size());
|
||||
client->add(reinterpret_cast<const char *>(m->data()), m->size(), ASYNC_WRITE_FLAG_COPY);
|
||||
client->send();
|
||||
delete m;
|
||||
outbox.pop();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
while (!outbox.empty()) {
|
||||
ModbusMessage* m = outbox.front();
|
||||
if (m->size() <= client->space()) {
|
||||
LOG_D("sending (%d)\n", m->size());
|
||||
client->add(reinterpret_cast<const char*>(m->data()), m->size(), ASYNC_WRITE_FLAG_COPY);
|
||||
client->send();
|
||||
delete m;
|
||||
outbox.pop();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ModbusServerTCPasync::ModbusServerTCPasync()
|
||||
: server(nullptr)
|
||||
, clients()
|
||||
, maxNoClients(5)
|
||||
, idle_timeout(60000) {
|
||||
ModbusServerTCPasync::ModbusServerTCPasync() :
|
||||
server(nullptr),
|
||||
clients(),
|
||||
maxNoClients(5),
|
||||
idle_timeout(60000) {
|
||||
// setup will be done in 'start'
|
||||
}
|
||||
|
||||
|
||||
ModbusServerTCPasync::~ModbusServerTCPasync() {
|
||||
stop();
|
||||
delete server;
|
||||
stop();
|
||||
delete server;
|
||||
}
|
||||
|
||||
|
||||
uint16_t ModbusServerTCPasync::activeClients() {
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
return clients.size();
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
return clients.size();
|
||||
}
|
||||
|
||||
|
||||
bool ModbusServerTCPasync::start(uint16_t port, uint8_t max_clients, uint32_t timeout, int coreID) {
|
||||
// don't restart if already running
|
||||
if (server) {
|
||||
LOG_W("Server already running.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
maxNoClients = max_clients;
|
||||
idle_timeout = timeout;
|
||||
server = new AsyncServer(port);
|
||||
if (server) {
|
||||
server->setNoDelay(true);
|
||||
server->onClient([](void * i, AsyncClient * c) { (static_cast<ModbusServerTCPasync *>(i))->onClientConnect(c); }, this);
|
||||
server->begin();
|
||||
LOG_D("Modbus server started\n");
|
||||
return true;
|
||||
}
|
||||
LOG_E("Could not start server\n");
|
||||
bool ModbusServerTCPasync::start(uint16_t port, uint8_t maxClients, uint32_t timeout, int coreID) {
|
||||
// don't restart if already running
|
||||
if (server) {
|
||||
LOG_W("Server already running.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
maxNoClients = maxClients;
|
||||
idle_timeout = timeout;
|
||||
server = new AsyncServer(port);
|
||||
if (server) {
|
||||
server->setNoDelay(true);
|
||||
server->onClient([](void* i, AsyncClient* c) { (static_cast<ModbusServerTCPasync*>(i))->onClientConnect(c); }, this);
|
||||
server->begin();
|
||||
LOG_D("Modbus server started\n");
|
||||
return true;
|
||||
}
|
||||
LOG_E("Could not start server\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ModbusServerTCPasync::stop() {
|
||||
if (!server) {
|
||||
LOG_W("Server not running.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop server to prevent new clients connecting
|
||||
server->end();
|
||||
if (!server) {
|
||||
LOG_W("Server not running.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// now close existing clients
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
while (!clients.empty()) {
|
||||
// prevent onDisconnect handler to be called, resulting in deadlock
|
||||
clients.front()->client->onDisconnect(nullptr, nullptr);
|
||||
delete clients.front();
|
||||
clients.pop_front();
|
||||
}
|
||||
delete server;
|
||||
server = nullptr;
|
||||
LOG_D("Modbus server stopped\n");
|
||||
return true;
|
||||
// stop server to prevent new clients connecting
|
||||
server->end();
|
||||
|
||||
// now close existing clients
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
while (!clients.empty()) {
|
||||
// prevent onDisconnect handler to be called, resulting in deadlock
|
||||
clients.front()->client->onDisconnect(nullptr, nullptr);
|
||||
delete clients.front();
|
||||
clients.pop_front();
|
||||
}
|
||||
delete server;
|
||||
server = nullptr;
|
||||
LOG_D("Modbus server stopped\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModbusServerTCPasync::isRunning() {
|
||||
if (server)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
if (server) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::onClientConnect(AsyncClient * client) {
|
||||
LOG_D("new client\n");
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
if (clients.size() < maxNoClients) {
|
||||
clients.emplace_back(new mb_client(this, client));
|
||||
LOG_D("nr clients: %d\n", clients.size());
|
||||
} else {
|
||||
LOG_D("max number of clients reached, closing new\n");
|
||||
client->close(true);
|
||||
delete client;
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::onClientDisconnect(mb_client * client) {
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
// delete mb_client from list
|
||||
clients.remove_if([client](mb_client * i) { return i->client == client->client; });
|
||||
// delete client itself
|
||||
delete client;
|
||||
void ModbusServerTCPasync::onClientConnect(AsyncClient* client) {
|
||||
LOG_D("new client\n");
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
if (clients.size() < maxNoClients) {
|
||||
clients.emplace_back(new mb_client(this, client));
|
||||
LOG_D("nr clients: %d\n", clients.size());
|
||||
} else {
|
||||
LOG_D("max number of clients reached, closing new\n");
|
||||
client->close(true);
|
||||
delete client;
|
||||
}
|
||||
}
|
||||
|
||||
void ModbusServerTCPasync::onClientDisconnect(mb_client* client) {
|
||||
LOCK_GUARD(lock1, cListLock);
|
||||
// delete mb_client from list
|
||||
clients.remove_if([client](mb_client* i) { return i->client == client->client; });
|
||||
// delete client itself
|
||||
delete client;
|
||||
LOG_D("nr clients: %d\n", clients.size());
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#endif
|
||||
#include <vector>
|
||||
|
||||
#include <Arduino.h> // for millis()
|
||||
#include <Arduino.h> // for millis()
|
||||
|
||||
#if defined(ESP32)
|
||||
#include <AsyncTCP.h>
|
||||
@@ -29,64 +29,64 @@ using std::lock_guard;
|
||||
#endif
|
||||
|
||||
class ModbusServerTCPasync : public ModbusServer {
|
||||
private:
|
||||
class mb_client {
|
||||
friend class ModbusServerTCPasync;
|
||||
|
||||
public:
|
||||
mb_client(ModbusServerTCPasync * s, AsyncClient * c);
|
||||
~mb_client();
|
||||
private:
|
||||
class mb_client {
|
||||
friend class ModbusServerTCPasync;
|
||||
|
||||
private:
|
||||
void onData(uint8_t * data, size_t len);
|
||||
void onPoll();
|
||||
void onDisconnect();
|
||||
void addResponseToOutbox(ModbusMessage * response);
|
||||
void handleOutbox();
|
||||
ModbusServerTCPasync * server;
|
||||
AsyncClient * client;
|
||||
uint32_t lastActiveTime;
|
||||
ModbusMessage * message;
|
||||
Modbus::Error error;
|
||||
std::queue<ModbusMessage *> outbox;
|
||||
#if USE_MUTEX
|
||||
std::mutex obLock; // outbox protection
|
||||
#endif
|
||||
};
|
||||
public:
|
||||
mb_client(ModbusServerTCPasync* s, AsyncClient* c);
|
||||
~mb_client();
|
||||
|
||||
private:
|
||||
void onData(uint8_t* data, size_t len);
|
||||
void onPoll();
|
||||
void onDisconnect();
|
||||
void addResponseToOutbox(ModbusMessage* response);
|
||||
void handleOutbox();
|
||||
ModbusServerTCPasync* server;
|
||||
AsyncClient* client;
|
||||
uint32_t lastActiveTime;
|
||||
ModbusMessage* message;
|
||||
Modbus::Error error;
|
||||
std::queue<ModbusMessage*> outbox;
|
||||
#if USE_MUTEX
|
||||
std::mutex obLock; // outbox protection
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
ModbusServerTCPasync();
|
||||
public:
|
||||
// Constructor
|
||||
ModbusServerTCPasync();
|
||||
|
||||
// Destructor: closes the connections
|
||||
~ModbusServerTCPasync();
|
||||
// Destructor: closes the connections
|
||||
~ModbusServerTCPasync();
|
||||
|
||||
// activeClients: return number of clients currently employed
|
||||
uint16_t activeClients();
|
||||
// activeClients: return number of clients currently employed
|
||||
uint16_t activeClients();
|
||||
|
||||
// start: create task with TCP server to accept requests
|
||||
bool start(uint16_t port, uint8_t max_clients, uint32_t timeout, int coreID = -1);
|
||||
// start: create task with TCP server to accept requests
|
||||
bool start(uint16_t port, uint8_t maxClients, uint32_t timeout, int coreID = -1);
|
||||
|
||||
// stop: drop all connections and kill server task
|
||||
bool stop();
|
||||
// stop: drop all connections and kill server task
|
||||
bool stop();
|
||||
|
||||
// isRunning: return true is server is running
|
||||
bool isRunning();
|
||||
// isRunning: return true is server is running
|
||||
bool isRunning();
|
||||
|
||||
protected:
|
||||
inline void isInstance() {
|
||||
}
|
||||
void onClientConnect(AsyncClient * client);
|
||||
void onClientDisconnect(mb_client * client);
|
||||
protected:
|
||||
inline void isInstance() { }
|
||||
void onClientConnect(AsyncClient* client);
|
||||
void onClientDisconnect(mb_client* client);
|
||||
|
||||
AsyncServer * server;
|
||||
std::list<mb_client *> clients;
|
||||
uint8_t maxNoClients;
|
||||
uint32_t idle_timeout;
|
||||
#if USE_MUTEX
|
||||
std::mutex cListLock; // client list protection
|
||||
#endif
|
||||
AsyncServer* server;
|
||||
std::list<mb_client*> clients;
|
||||
uint8_t maxNoClients;
|
||||
uint32_t idle_timeout;
|
||||
#if USE_MUTEX
|
||||
std::mutex cListLock; // client list protection
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define _MODBUS_SERVER_TCP_TEMP_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <mutex> // NOLINT
|
||||
#include <mutex> // NOLINT
|
||||
#include "ModbusServer.h"
|
||||
#undef LOCAL_LOG_LEVEL
|
||||
// #define LOCAL_LOG_LEVEL LOG_LEVEL_VERBOSE
|
||||
@@ -17,155 +17,142 @@ extern "C" {
|
||||
#include <freertos/task.h>
|
||||
}
|
||||
|
||||
using std::lock_guard;
|
||||
using std::mutex;
|
||||
using std::vector;
|
||||
using std::mutex;
|
||||
using std::lock_guard;
|
||||
|
||||
template <typename ST, typename CT>
|
||||
class ModbusServerTCP : public ModbusServer {
|
||||
public:
|
||||
// Constructor
|
||||
ModbusServerTCP();
|
||||
public:
|
||||
// Constructor
|
||||
ModbusServerTCP();
|
||||
|
||||
// Destructor: closes the connections
|
||||
~ModbusServerTCP();
|
||||
// Destructor: closes the connections
|
||||
~ModbusServerTCP();
|
||||
|
||||
// activeClients: return number of clients currently employed
|
||||
uint16_t activeClients();
|
||||
// activeClients: return number of clients currently employed
|
||||
uint16_t activeClients();
|
||||
|
||||
// start: create task with TCP server to accept requests
|
||||
bool start(uint16_t port, uint8_t max_clients, uint32_t timeout, int coreID = -1);
|
||||
// start: create task with TCP server to accept requests
|
||||
bool start(uint16_t port, uint8_t maxClients, uint32_t timeout, int coreID = -1);
|
||||
|
||||
// stop: drop all connections and kill server task
|
||||
bool stop();
|
||||
// stop: drop all connections and kill server task
|
||||
bool stop();
|
||||
|
||||
protected:
|
||||
// Prevent copy construction and assignment
|
||||
ModbusServerTCP(ModbusServerTCP & m) = delete;
|
||||
ModbusServerTCP & operator=(ModbusServerTCP & m) = delete;
|
||||
protected:
|
||||
// Prevent copy construction and assignment
|
||||
ModbusServerTCP(ModbusServerTCP& m) = delete;
|
||||
ModbusServerTCP& operator=(ModbusServerTCP& m) = delete;
|
||||
|
||||
inline void isInstance() {
|
||||
inline void isInstance() { }
|
||||
|
||||
uint8_t numClients;
|
||||
TaskHandle_t serverTask;
|
||||
uint16_t serverPort;
|
||||
uint32_t serverTimeout;
|
||||
bool serverGoDown;
|
||||
mutex clientLock;
|
||||
|
||||
struct ClientData {
|
||||
ClientData() : task(nullptr), client(0), timeout(0), parent(nullptr) {}
|
||||
ClientData(TaskHandle_t t, CT& c, uint32_t to, ModbusServerTCP<ST, CT> *p) :
|
||||
task(t), client(c), timeout(to), parent(p) {}
|
||||
~ClientData() {
|
||||
if (client) {
|
||||
client.stop();
|
||||
}
|
||||
if (task != nullptr) {
|
||||
vTaskDelete(task);
|
||||
LOG_D("Killed client task %d\n", (uint32_t)task);
|
||||
}
|
||||
}
|
||||
TaskHandle_t task;
|
||||
CT client;
|
||||
uint32_t timeout;
|
||||
ModbusServerTCP<ST, CT> *parent;
|
||||
};
|
||||
ClientData **clients;
|
||||
|
||||
uint8_t numClients;
|
||||
TaskHandle_t serverTask;
|
||||
uint16_t serverPort;
|
||||
uint32_t serverTimeout;
|
||||
bool serverGoDown;
|
||||
mutex clientLock;
|
||||
// serve: loop function for server task
|
||||
static void serve(ModbusServerTCP<ST, CT> *myself);
|
||||
|
||||
struct ClientData {
|
||||
ClientData()
|
||||
: task(nullptr)
|
||||
, client(0)
|
||||
, timeout(0)
|
||||
, parent(nullptr) {
|
||||
}
|
||||
ClientData(TaskHandle_t t, CT & c, uint32_t to, ModbusServerTCP<ST, CT> * p)
|
||||
: task(t)
|
||||
, client(c)
|
||||
, timeout(to)
|
||||
, parent(p) {
|
||||
}
|
||||
~ClientData() {
|
||||
if (client) {
|
||||
client.stop();
|
||||
}
|
||||
if (task != nullptr) {
|
||||
vTaskDelete(task);
|
||||
LOG_D("Killed client task %d\n", (uint32_t)task);
|
||||
}
|
||||
}
|
||||
TaskHandle_t task;
|
||||
CT client;
|
||||
uint32_t timeout;
|
||||
ModbusServerTCP<ST, CT> * parent;
|
||||
};
|
||||
ClientData ** clients;
|
||||
// worker: loop function for client tasks
|
||||
static void worker(ClientData *myData);
|
||||
|
||||
// serve: loop function for server task
|
||||
static void serve(ModbusServerTCP<ST, CT> * myself);
|
||||
// receive: read data from TCP
|
||||
ModbusMessage receive(CT& client, uint32_t timeWait);
|
||||
|
||||
// worker: loop function for client tasks
|
||||
static void worker(ClientData * myData);
|
||||
// accept: start a task to receive requests and respond to a given client
|
||||
bool accept(CT& client, uint32_t timeout, int coreID = -1);
|
||||
|
||||
// receive: read data from TCP
|
||||
ModbusMessage receive(CT & client, uint32_t timeWait);
|
||||
|
||||
// accept: start a task to receive requests and respond to a given client
|
||||
bool accept(CT & client, uint32_t timeout, int coreID = -1);
|
||||
|
||||
// clientAvailable: return true,. if a client slot is currently unused
|
||||
bool clientAvailable() {
|
||||
return (numClients - activeClients()) > 0;
|
||||
}
|
||||
// clientAvailable: return true,. if a client slot is currently unused
|
||||
bool clientAvailable() { return (numClients - activeClients()) > 0; }
|
||||
};
|
||||
|
||||
// Constructor
|
||||
template <typename ST, typename CT>
|
||||
ModbusServerTCP<ST, CT>::ModbusServerTCP()
|
||||
: ModbusServer()
|
||||
, numClients(0)
|
||||
, serverTask(nullptr)
|
||||
, serverPort(502)
|
||||
, serverTimeout(20000)
|
||||
, serverGoDown(false) {
|
||||
clients = new ClientData *[numClients]();
|
||||
}
|
||||
ModbusServerTCP<ST, CT>::ModbusServerTCP() :
|
||||
ModbusServer(),
|
||||
numClients(0),
|
||||
serverTask(nullptr),
|
||||
serverPort(502),
|
||||
serverTimeout(20000),
|
||||
serverGoDown(false) {
|
||||
clients = new ClientData*[numClients]();
|
||||
}
|
||||
|
||||
// Destructor: closes the connections
|
||||
template <typename ST, typename CT>
|
||||
ModbusServerTCP<ST, CT>::~ModbusServerTCP() {
|
||||
for (uint8_t i = 0; i < numClients; ++i) {
|
||||
if (clients[i] != nullptr) {
|
||||
delete clients[i];
|
||||
}
|
||||
for (uint8_t i = 0; i < numClients; ++i) {
|
||||
if (clients[i] != nullptr) {
|
||||
delete clients[i];
|
||||
}
|
||||
delete[] clients;
|
||||
serverGoDown = true;
|
||||
}
|
||||
delete[] clients;
|
||||
serverGoDown = true;
|
||||
}
|
||||
|
||||
// activeClients: return number of clients currently employed
|
||||
template <typename ST, typename CT>
|
||||
uint16_t ModbusServerTCP<ST, CT>::activeClients() {
|
||||
uint8_t cnt = 0;
|
||||
for (uint8_t i = 0; i < numClients; ++i) {
|
||||
// Current slot could have been previously used - look for cleared task handles
|
||||
if (clients[i] != nullptr) {
|
||||
// Empty task handle?
|
||||
if (clients[i]->task == nullptr) {
|
||||
// Yes. Delete entry and init client pointer
|
||||
lock_guard<mutex> cL(clientLock);
|
||||
delete clients[i];
|
||||
LOG_V("Delete client %d\n", i);
|
||||
clients[i] = nullptr;
|
||||
}
|
||||
}
|
||||
if (clients[i] != nullptr)
|
||||
cnt++;
|
||||
uint8_t cnt = 0;
|
||||
for (uint8_t i = 0; i < numClients; ++i) {
|
||||
// Current slot could have been previously used - look for cleared task handles
|
||||
if (clients[i] != nullptr) {
|
||||
// Empty task handle?
|
||||
if (clients[i]->task == nullptr) {
|
||||
// Yes. Delete entry and init client pointer
|
||||
lock_guard<mutex> cL(clientLock);
|
||||
delete clients[i];
|
||||
LOG_V("Delete client %d\n", i);
|
||||
clients[i] = nullptr;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
if (clients[i] != nullptr) cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
// start: create task with TCP server to accept requests
|
||||
// start: create task with TCP server to accept requests
|
||||
template <typename ST, typename CT>
|
||||
bool ModbusServerTCP<ST, CT>::start(uint16_t port, uint8_t max_clients, uint32_t timeout, int coreID) {
|
||||
bool ModbusServerTCP<ST, CT>::start(uint16_t port, uint8_t maxClients, uint32_t timeout, int coreID) {
|
||||
// Task already running?
|
||||
if (serverTask != nullptr) {
|
||||
// Yes. stop it first
|
||||
stop();
|
||||
// Yes. stop it first
|
||||
stop();
|
||||
}
|
||||
// Does the required number of slots fit?
|
||||
if (numClients != max_clients) {
|
||||
// No. Drop array and allocate a new one
|
||||
delete[] clients;
|
||||
// Now allocate a new one
|
||||
numClients = max_clients;
|
||||
clients = new ClientData *[numClients]();
|
||||
if (numClients != maxClients) {
|
||||
// No. Drop array and allocate a new one
|
||||
delete[] clients;
|
||||
// Now allocate a new one
|
||||
numClients = maxClients;
|
||||
clients = new ClientData*[numClients]();
|
||||
}
|
||||
serverPort = port;
|
||||
serverPort = port;
|
||||
serverTimeout = timeout;
|
||||
serverGoDown = false;
|
||||
serverGoDown = false;
|
||||
|
||||
// Create unique task name
|
||||
char taskName[18];
|
||||
@@ -179,255 +166,255 @@ bool ModbusServerTCP<ST, CT>::start(uint16_t port, uint8_t max_clients, uint32_t
|
||||
delay(2000);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// stop: drop all connections and kill server task
|
||||
// stop: drop all connections and kill server task
|
||||
template <typename ST, typename CT>
|
||||
bool ModbusServerTCP<ST, CT>::stop() {
|
||||
bool ModbusServerTCP<ST, CT>::stop() {
|
||||
// Check for clients still connected
|
||||
for (uint8_t i = 0; i < numClients; ++i) {
|
||||
// Client is alive?
|
||||
if (clients[i] != nullptr) {
|
||||
// Yes. Close the connection
|
||||
delete clients[i];
|
||||
clients[i] = nullptr;
|
||||
}
|
||||
// Client is alive?
|
||||
if (clients[i] != nullptr) {
|
||||
// Yes. Close the connection
|
||||
delete clients[i];
|
||||
clients[i] = nullptr;
|
||||
}
|
||||
}
|
||||
if (serverTask != nullptr) {
|
||||
// Signal server task to stop
|
||||
serverGoDown = true;
|
||||
delay(5000);
|
||||
LOG_D("Killed server task %d\n", (uint32_t)(serverTask));
|
||||
serverTask = nullptr;
|
||||
serverGoDown = false;
|
||||
// Signal server task to stop
|
||||
serverGoDown = true;
|
||||
delay(5000);
|
||||
LOG_D("Killed server task %d\n", (uint32_t)(serverTask));
|
||||
serverTask = nullptr;
|
||||
serverGoDown = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// accept: start a task to receive requests and respond to a given client
|
||||
template <typename ST, typename CT>
|
||||
bool ModbusServerTCP<ST, CT>::accept(CT & client, uint32_t timeout, int coreID) {
|
||||
// Look for an empty client slot
|
||||
for (uint8_t i = 0; i < numClients; ++i) {
|
||||
// Empty slot?
|
||||
if (clients[i] == nullptr) {
|
||||
// Yes. allocate new client data in slot
|
||||
clients[i] = new ClientData(0, client, timeout, this);
|
||||
bool ModbusServerTCP<ST, CT>::accept(CT& client, uint32_t timeout, int coreID) {
|
||||
// Look for an empty client slot
|
||||
for (uint8_t i = 0; i < numClients; ++i) {
|
||||
// Empty slot?
|
||||
if (clients[i] == nullptr) {
|
||||
// Yes. allocate new client data in slot
|
||||
clients[i] = new ClientData(0, client, timeout, this);
|
||||
|
||||
// Create unique task name
|
||||
char taskName[18];
|
||||
snprintf(taskName, 18, "MBsrv%02Xclnt", i);
|
||||
// Create unique task name
|
||||
char taskName[18];
|
||||
snprintf(taskName, 18, "MBsrv%02Xclnt", i);
|
||||
|
||||
// Start task to handle the client
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&worker, taskName, SERVER_TASK_STACK, clients[i], 5, &clients[i]->task, coreID >= 0 ? coreID : NULL);
|
||||
LOG_D("Started client %d task %d\n", i, (uint32_t)(clients[i]->task));
|
||||
// Start task to handle the client
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)&worker, taskName, SERVER_TASK_STACK, clients[i], 5, &clients[i]->task, coreID >= 0 ? coreID : NULL);
|
||||
LOG_D("Started client %d task %d\n", i, (uint32_t)(clients[i]->task));
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
LOG_D("No client slot available.\n");
|
||||
return false;
|
||||
}
|
||||
LOG_D("No client slot available.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename ST, typename CT>
|
||||
void ModbusServerTCP<ST, CT>::serve(ModbusServerTCP<ST, CT> * myself) {
|
||||
// need a local scope here to delete the server at termination time
|
||||
if (1) {
|
||||
// Set up server with given port
|
||||
ST server(myself->serverPort);
|
||||
void ModbusServerTCP<ST, CT>::serve(ModbusServerTCP<ST, CT> *myself) {
|
||||
// need a local scope here to delete the server at termination time
|
||||
if (1) {
|
||||
// Set up server with given port
|
||||
ST server(myself->serverPort);
|
||||
|
||||
// Start it
|
||||
server.begin();
|
||||
// Start it
|
||||
server.begin();
|
||||
|
||||
// Loop until being killed
|
||||
while (!myself->serverGoDown) {
|
||||
// Do we have clients left to use?
|
||||
if (myself->clientAvailable()) {
|
||||
// Yes. accept one, when it connects
|
||||
CT ec = server.accept();
|
||||
// Did we get a connection?
|
||||
if (ec) {
|
||||
// Yes. Forward it to the Modbus server
|
||||
myself->accept(ec, myself->serverTimeout, 0);
|
||||
LOG_D("Accepted connection - %d clients running\n", myself->activeClients());
|
||||
}
|
||||
}
|
||||
// Give scheduler room to breathe
|
||||
delay(10);
|
||||
// Loop until being killed
|
||||
while (!myself->serverGoDown) {
|
||||
// Do we have clients left to use?
|
||||
if (myself->clientAvailable()) {
|
||||
// Yes. accept one, when it connects
|
||||
CT ec = server.accept();
|
||||
// Did we get a connection?
|
||||
if (ec) {
|
||||
// Yes. Forward it to the Modbus server
|
||||
myself->accept(ec, myself->serverTimeout, 0);
|
||||
LOG_D("Accepted connection - %d clients running\n", myself->activeClients());
|
||||
}
|
||||
LOG_E("Server going down\n");
|
||||
// We must go down
|
||||
SERVER_END;
|
||||
}
|
||||
// Give scheduler room to breathe
|
||||
delay(10);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
LOG_E("Server going down\n");
|
||||
// We must go down
|
||||
SERVER_END;
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
template <typename ST, typename CT>
|
||||
void ModbusServerTCP<ST, CT>::worker(ClientData * myData) {
|
||||
// Get own reference data in handier form
|
||||
CT myClient = myData->client;
|
||||
uint32_t myTimeOut = myData->timeout;
|
||||
// TaskHandle_t myTask = myData->task;
|
||||
ModbusServerTCP<ST, CT> * myParent = myData->parent;
|
||||
unsigned long myLastMessage = millis();
|
||||
void ModbusServerTCP<ST, CT>::worker(ClientData *myData) {
|
||||
// Get own reference data in handier form
|
||||
CT myClient = myData->client;
|
||||
uint32_t myTimeOut = myData->timeout;
|
||||
// TaskHandle_t myTask = myData->task;
|
||||
ModbusServerTCP<ST, CT> *myParent = myData->parent;
|
||||
unsigned long myLastMessage = millis();
|
||||
|
||||
LOG_D("Worker started, timeout=%d\n", myTimeOut);
|
||||
LOG_D("Worker started, timeout=%d\n", myTimeOut);
|
||||
|
||||
// loop forever, if timeout is 0, or until timeout was hit
|
||||
while (myClient.connected() && (!myTimeOut || (millis() - myLastMessage < myTimeOut))) {
|
||||
ModbusMessage response; // Data buffer to hold prepared response
|
||||
// Get a request
|
||||
if (myClient.available()) {
|
||||
response.clear();
|
||||
ModbusMessage m = myParent->receive(myClient, 100);
|
||||
// loop forever, if timeout is 0, or until timeout was hit
|
||||
while (myClient.connected() && (!myTimeOut || (millis() - myLastMessage < myTimeOut))) {
|
||||
ModbusMessage response; // Data buffer to hold prepared response
|
||||
// Get a request
|
||||
if (myClient.available()) {
|
||||
response.clear();
|
||||
ModbusMessage m = myParent->receive(myClient, 100);
|
||||
|
||||
// has it the minimal length (6 bytes TCP header plus serverID plus FC)?
|
||||
if (m.size() >= 8) {
|
||||
{
|
||||
LOCK_GUARD(cntLock, myParent->m);
|
||||
myParent->messageCount++;
|
||||
}
|
||||
// Extract request data
|
||||
ModbusMessage request;
|
||||
request.add(m.data() + 6, m.size() - 6);
|
||||
|
||||
// Protocol ID shall be 0x0000 - is it?
|
||||
if (m[2] == 0 && m[3] == 0) {
|
||||
// ServerID shall be at [6], FC at [7]. Check both
|
||||
if (myParent->isServerFor(request.getServerID())) {
|
||||
// Server is correct - in principle. Do we serve the FC?
|
||||
MBSworker callBack = myParent->getWorker(request.getServerID(), request.getFunctionCode());
|
||||
if (callBack) {
|
||||
// Yes, we do.
|
||||
// Invoke the worker method to get a response
|
||||
ModbusMessage data = callBack(request);
|
||||
// Process Response
|
||||
// One of the predefined types?
|
||||
if (data[0] == 0xFF && (data[1] == 0xF0 || data[1] == 0xF1)) {
|
||||
// Yes. Check it
|
||||
switch (data[1]) {
|
||||
case 0xF0: // NIL
|
||||
response.clear();
|
||||
LOG_D("NIL response\n");
|
||||
break;
|
||||
case 0xF1: // ECHO
|
||||
response = request;
|
||||
if (request.getFunctionCode() == WRITE_MULT_REGISTERS || request.getFunctionCode() == WRITE_MULT_COILS) {
|
||||
response.resize(6);
|
||||
}
|
||||
LOG_D("ECHO response\n");
|
||||
break;
|
||||
default: // Will not get here!
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// No. User provided data response
|
||||
response = data;
|
||||
LOG_D("Data response\n");
|
||||
}
|
||||
} else {
|
||||
// No, function code is not served here
|
||||
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_FUNCTION);
|
||||
}
|
||||
} else {
|
||||
// No, serverID is not served here
|
||||
response.setError(request.getServerID(), request.getFunctionCode(), INVALID_SERVER);
|
||||
}
|
||||
} else {
|
||||
// No, protocol ID was something weird
|
||||
response.setError(request.getServerID(), request.getFunctionCode(), TCP_HEAD_MISMATCH);
|
||||
}
|
||||
}
|
||||
delay(1);
|
||||
// Do we have a response to send?
|
||||
if (response.size() >= 3) {
|
||||
// Yes. Do it now.
|
||||
// Cut off length and request data, then update TCP header
|
||||
m.resize(4);
|
||||
m.add(static_cast<uint16_t>(response.size()));
|
||||
// Append response
|
||||
m.append(response);
|
||||
myClient.write(m.data(), m.size());
|
||||
HEXDUMP_V("Response", m.data(), m.size());
|
||||
// count error responses
|
||||
if (response.getError() != SUCCESS) {
|
||||
LOCK_GUARD(cntLock, myParent->m);
|
||||
myParent->errorCount++;
|
||||
}
|
||||
}
|
||||
// We did something communicationally - rewind timeout timer
|
||||
myLastMessage = millis();
|
||||
// has it the minimal length (6 bytes TCP header plus serverID plus FC)?
|
||||
if (m.size() >= 8) {
|
||||
{
|
||||
LOCK_GUARD(cntLock, myParent->m);
|
||||
myParent->messageCount++;
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
// Extract request data
|
||||
ModbusMessage request;
|
||||
request.add(m.data() + 6, m.size() - 6);
|
||||
|
||||
if (millis() - myLastMessage >= myTimeOut) {
|
||||
// Timeout!
|
||||
LOG_D("Worker stopping due to timeout.\n");
|
||||
} else {
|
||||
// Disconnected!
|
||||
LOG_D("Worker stopping due to client disconnect.\n");
|
||||
// Protocol ID shall be 0x0000 - is it?
|
||||
if (m[2] == 0 && m[3] == 0) {
|
||||
// ServerID shall be at [6], FC at [7]. Check both
|
||||
if (myParent->isServerFor(request.getServerID())) {
|
||||
// Server is correct - in principle. Do we serve the FC?
|
||||
MBSworker callBack = myParent->getWorker(request.getServerID(), request.getFunctionCode());
|
||||
if (callBack) {
|
||||
// Yes, we do.
|
||||
// Invoke the worker method to get a response
|
||||
ModbusMessage data = callBack(request);
|
||||
// Process Response
|
||||
// One of the predefined types?
|
||||
if (data[0] == 0xFF && (data[1] == 0xF0 || data[1] == 0xF1)) {
|
||||
// Yes. Check it
|
||||
switch (data[1]) {
|
||||
case 0xF0: // NIL
|
||||
response.clear();
|
||||
LOG_D("NIL response\n");
|
||||
break;
|
||||
case 0xF1: // ECHO
|
||||
response = request;
|
||||
if (request.getFunctionCode() == WRITE_MULT_REGISTERS ||
|
||||
request.getFunctionCode() == WRITE_MULT_COILS) {
|
||||
response.resize(6);
|
||||
}
|
||||
LOG_D("ECHO response\n");
|
||||
break;
|
||||
default: // Will not get here!
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// No. User provided data response
|
||||
response = data;
|
||||
LOG_D("Data response\n");
|
||||
}
|
||||
} else {
|
||||
// No, function code is not served here
|
||||
response.setError(request.getServerID(), request.getFunctionCode(), ILLEGAL_FUNCTION);
|
||||
}
|
||||
} else {
|
||||
// No, serverID is not served here
|
||||
response.setError(request.getServerID(), request.getFunctionCode(), INVALID_SERVER);
|
||||
}
|
||||
} else {
|
||||
// No, protocol ID was something weird
|
||||
response.setError(request.getServerID(), request.getFunctionCode(), TCP_HEAD_MISMATCH);
|
||||
}
|
||||
}
|
||||
delay(1);
|
||||
// Do we have a response to send?
|
||||
if (response.size() >= 3) {
|
||||
// Yes. Do it now.
|
||||
// Cut off length and request data, then update TCP header
|
||||
m.resize(4);
|
||||
m.add(static_cast<uint16_t>(response.size()));
|
||||
// Append response
|
||||
m.append(response);
|
||||
myClient.write(m.data(), m.size());
|
||||
HEXDUMP_V("Response", m.data(), m.size());
|
||||
// count error responses
|
||||
if (response.getError() != SUCCESS) {
|
||||
LOCK_GUARD(cntLock, myParent->m);
|
||||
myParent->errorCount++;
|
||||
}
|
||||
}
|
||||
// We did something communicationally - rewind timeout timer
|
||||
myLastMessage = millis();
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
|
||||
// Read away all that may still hang in the buffer
|
||||
while (myClient.read() != -1) {
|
||||
}
|
||||
// Now stop the client
|
||||
myClient.stop();
|
||||
if (millis() - myLastMessage >= myTimeOut) {
|
||||
// Timeout!
|
||||
LOG_D("Worker stopping due to timeout.\n");
|
||||
} else {
|
||||
// Disconnected!
|
||||
LOG_D("Worker stopping due to client disconnect.\n");
|
||||
}
|
||||
|
||||
{
|
||||
lock_guard<mutex> cL(myParent->clientLock);
|
||||
myData->task = nullptr;
|
||||
}
|
||||
// Read away all that may still hang in the buffer
|
||||
while (myClient.read() != -1) {}
|
||||
// Now stop the client
|
||||
myClient.stop();
|
||||
|
||||
delay(50);
|
||||
vTaskDelete(NULL);
|
||||
{
|
||||
lock_guard<mutex> cL(myParent->clientLock);
|
||||
myData->task = nullptr;
|
||||
}
|
||||
|
||||
delay(50);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
// receive: get request via Client connection
|
||||
template <typename ST, typename CT>
|
||||
ModbusMessage ModbusServerTCP<ST, CT>::receive(CT & client, uint32_t timeWait) {
|
||||
unsigned long lastMillis = millis(); // Timer to check for timeout
|
||||
ModbusMessage m; // to take read data
|
||||
uint16_t lengthVal = 0;
|
||||
uint16_t cnt = 0;
|
||||
const uint16_t BUFFERSIZE(300);
|
||||
uint8_t buffer[BUFFERSIZE];
|
||||
ModbusMessage ModbusServerTCP<ST, CT>::receive(CT& client, uint32_t timeWait) {
|
||||
unsigned long lastMillis = millis(); // Timer to check for timeout
|
||||
ModbusMessage m; // to take read data
|
||||
uint16_t lengthVal = 0;
|
||||
uint16_t cnt = 0;
|
||||
const uint16_t BUFFERSIZE(300);
|
||||
uint8_t buffer[BUFFERSIZE];
|
||||
|
||||
// wait for sufficient packet data or timeout
|
||||
while ((millis() - lastMillis < timeWait) && ((cnt < 6) || (cnt < lengthVal)) && (cnt < BUFFERSIZE)) {
|
||||
// Is there data waiting?
|
||||
if (client.available()) {
|
||||
buffer[cnt] = client.read();
|
||||
// Are we at the TCP header length field byte #1?
|
||||
if (cnt == 4)
|
||||
lengthVal = buffer[cnt] << 8;
|
||||
// Are we at the TCP header length field byte #2?
|
||||
if (cnt == 5) {
|
||||
lengthVal |= buffer[cnt];
|
||||
lengthVal += 6;
|
||||
}
|
||||
cnt++;
|
||||
// Rewind EOT and timeout timers
|
||||
lastMillis = millis();
|
||||
} else {
|
||||
delay(1); // Give scheduler room to breathe
|
||||
// wait for sufficient packet data or timeout
|
||||
while ((millis() - lastMillis < timeWait) && ((cnt < 6) || (cnt < lengthVal)) && (cnt < BUFFERSIZE))
|
||||
{
|
||||
// Is there data waiting?
|
||||
if (client.available()) {
|
||||
buffer[cnt] = client.read();
|
||||
// Are we at the TCP header length field byte #1?
|
||||
if (cnt == 4) lengthVal = buffer[cnt] << 8;
|
||||
// Are we at the TCP header length field byte #2?
|
||||
if (cnt == 5) {
|
||||
lengthVal |= buffer[cnt];
|
||||
lengthVal += 6;
|
||||
}
|
||||
cnt++;
|
||||
// Rewind EOT and timeout timers
|
||||
lastMillis = millis();
|
||||
} else {
|
||||
delay(1); // Give scheduler room to breathe
|
||||
}
|
||||
// Did we receive some data?
|
||||
if (cnt) {
|
||||
// Yes. Is it too much?
|
||||
if (cnt >= BUFFERSIZE) {
|
||||
// Yes, likely a buffer overflow of some sort
|
||||
// Adjust message size in TCP header
|
||||
buffer[4] = (cnt >> 8) & 0xFF;
|
||||
buffer[5] = cnt & 0xFF;
|
||||
LOG_E("Potential buffer overrun (>%d)!\n", cnt);
|
||||
}
|
||||
// Get as much buffer as was read
|
||||
m.add(buffer, cnt);
|
||||
}
|
||||
// Did we receive some data?
|
||||
if (cnt) {
|
||||
// Yes. Is it too much?
|
||||
if (cnt >= BUFFERSIZE) {
|
||||
// Yes, likely a buffer overflow of some sort
|
||||
// Adjust message size in TCP header
|
||||
buffer[4] = (cnt >> 8) & 0xFF;
|
||||
buffer[5] = cnt & 0xFF;
|
||||
LOG_E("Potential buffer overrun (>%d)!\n", cnt);
|
||||
}
|
||||
return m;
|
||||
// Get as much buffer as was read
|
||||
m.add(buffer, cnt);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -50,7 +50,7 @@ FCType FCT::getType(uint8_t functionCode) {
|
||||
return table[functionCode & 0x7F];
|
||||
}
|
||||
|
||||
// setType: change the type of a function code.
|
||||
// redefineType: change the type of a function code.
|
||||
// This is possible only for the codes undefined yet and will return
|
||||
// the effective type
|
||||
FCType FCT::redefineType(uint8_t functionCode, const FCType type) {
|
||||
|
||||
@@ -84,6 +84,9 @@ enum Error : uint8_t {
|
||||
UNDEFINED_ERROR = 0xFF // otherwise uncovered communication error
|
||||
};
|
||||
|
||||
// Readable expression for the "illegal" server ID of 0
|
||||
#define ANY_SERVER 0x00
|
||||
|
||||
#ifndef MINIMAL
|
||||
|
||||
// Constants for float and double re-ordering
|
||||
|
||||
@@ -537,14 +537,14 @@ bool Command::list(const uint8_t device_type, JsonObject output) {
|
||||
output[F_(entities)] = Helpers::translated_word(FL_(entities_cmd));
|
||||
|
||||
if (device_type == EMSdevice::DeviceType::SYSTEM) {
|
||||
output["settings/showertimer"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["settings/showeralert"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["settings/hideled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["settings/showertimer"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["settings/showeralert"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["settings/hideled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["settings/analogenabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["mqtt/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["ntp/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["ap/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["syslog/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["mqtt/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["ntp/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["ap/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
output["syslog/enabled"] = Helpers::translated_word(FL_(system_cmd));
|
||||
}
|
||||
// create a list of commands we have registered, and sort them
|
||||
std::list<std::string> sorted_cmds;
|
||||
@@ -670,11 +670,7 @@ bool Command::device_has_commands(const uint8_t device_type) {
|
||||
|
||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_type)) {
|
||||
for (const auto & cf : cmdfunctions_) {
|
||||
if (cf.device_type_ == device_type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_DEFAULT_MODBUS_TIMEOUT
|
||||
#define EMSESP_DEFAULT_MODBUS_TIMEOUT 10000
|
||||
#define EMSESP_DEFAULT_MODBUS_TIMEOUT 300
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_DEFAULT_BOARD_PROFILE
|
||||
|
||||
@@ -133,6 +133,7 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
|
||||
monitor_typeids = {0x0A};
|
||||
set_typeids = {};
|
||||
register_telegram_type(monitor_typeids[0], "EasyMonitor", true, MAKE_PF_CB(process_EasyMonitor));
|
||||
register_telegram_type(0x02A5, "EasyMonitor", false, MAKE_PF_CB(process_EasyMonitor));
|
||||
|
||||
// CRF
|
||||
} else if (model == EMSdevice::EMS_DEVICE_FLAG_CRF) {
|
||||
@@ -840,13 +841,30 @@ void Thermostat::process_RC20Monitor(std::shared_ptr<const Telegram> telegram) {
|
||||
|
||||
// type 0x0A - data from the Nefit Easy/TC100 thermostat (0x18) - 31 bytes long
|
||||
void Thermostat::process_EasyMonitor(std::shared_ptr<const Telegram> telegram) {
|
||||
auto hc = heating_circuit(telegram);
|
||||
monitor_typeids[0] = telegram->type_id;
|
||||
auto hc = heating_circuit(telegram);
|
||||
if (hc == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
has_update(telegram, hc->roomTemp, 8); // is * 100
|
||||
has_update(telegram, hc->selTemp, 10); // is * 100
|
||||
if (telegram->type_id == 0x0A) {
|
||||
int16_t temp = hc->roomTemp;
|
||||
if (telegram->read_value(temp, 8) && temp != 0) {
|
||||
has_update(telegram, hc->roomTemp, 8); // is * 100
|
||||
has_update(telegram, hc->selTemp, 10); // is * 100
|
||||
toggle_fetch(0x0A, true);
|
||||
}
|
||||
} else if (telegram->type_id == 0x02A5) { // see #2277
|
||||
int16_t temp = hc->roomTemp / 10;
|
||||
if (telegram->read_value(temp, 0)) { // is * 10
|
||||
has_update(hc->roomTemp, temp * 10); // * 100
|
||||
toggle_fetch(0x0A, false);
|
||||
}
|
||||
int16_t sel = hc->selTemp / 50;
|
||||
if (telegram->read_value(sel, 6, 1)) { // is * 2
|
||||
has_update(hc->selTemp, sel * 50); // * 100
|
||||
}
|
||||
}
|
||||
|
||||
add_ha_climate(hc);
|
||||
}
|
||||
|
||||
@@ -1547,7 +1547,7 @@ void EMSdevice::get_value_json(JsonObject json, DeviceValue & dv) {
|
||||
json["circuit"] = tag_to_mqtt(dv.tag);
|
||||
}
|
||||
|
||||
char val[10];
|
||||
char val[20];
|
||||
switch (dv.type) {
|
||||
case DeviceValueType::ENUM: {
|
||||
if (*(uint8_t *)(dv.value_p) < dv.options_size) {
|
||||
@@ -1785,7 +1785,7 @@ bool EMSdevice::generate_values(JsonObject output, const int8_t tag_filter, cons
|
||||
: (dv.uom == DeviceValueUOM::DEGREES) ? 2
|
||||
: (dv.uom == DeviceValueUOM::DEGREES_R) ? 1
|
||||
: 0;
|
||||
char val[10] = {'\0'};
|
||||
char val[20] = {'\0'};
|
||||
if (dv.type == DeviceValueType::INT8) {
|
||||
json[name] = serialized(Helpers::render_value(val, *(int8_t *)(dv.value_p), dv.numeric_operator, fahrenheit));
|
||||
} else if (dv.type == DeviceValueType::UINT8) {
|
||||
|
||||
@@ -174,6 +174,14 @@ class EMSdevice {
|
||||
}
|
||||
}
|
||||
|
||||
void has_update(int16_t & value, int16_t newvalue) {
|
||||
if (value != newvalue) {
|
||||
value = newvalue;
|
||||
has_update_ = true;
|
||||
publish_value((void *)&value);
|
||||
}
|
||||
}
|
||||
|
||||
void has_update(uint32_t & value, uint32_t newvalue) {
|
||||
if (value != newvalue) {
|
||||
value = newvalue;
|
||||
|
||||
@@ -1689,7 +1689,7 @@ void EMSESP::start() {
|
||||
// start services
|
||||
if (system_.modbus_enabled()) {
|
||||
modbus_ = new Modbus;
|
||||
modbus_->start(1, system_.modbus_port(), system_.modbus_max_clients(), system_.modbus_timeout());
|
||||
modbus_->start(1, system_.modbus_port(), system_.modbus_max_clients(), system_.modbus_timeout() * 1000);
|
||||
}
|
||||
mqtt_.start(); // mqtt init
|
||||
system_.start(); // starts commands, led, adc, button, network (sets hostname), syslog & uart
|
||||
|
||||
@@ -254,13 +254,19 @@ char * Helpers::render_value(char * result, const double value, const int8_t for
|
||||
|
||||
char * ret = result;
|
||||
double v = value < 0 ? value - 1.0 / (2 * p[format]) : value + 1.0 / (2 * p[format]);
|
||||
auto whole = (int32_t)v;
|
||||
auto whole = (long long)v;
|
||||
|
||||
if (whole == 0 && v < 0) {
|
||||
if (whole <= 0 && v < 0) {
|
||||
result[0] = '-';
|
||||
result++;
|
||||
whole = -whole;
|
||||
v = -v;
|
||||
}
|
||||
itoa(whole, result, 10);
|
||||
#ifndef EMSESP_STANDALONE
|
||||
lltoa(whole, result, 10);
|
||||
#else
|
||||
ultostr(result, whole, 10);
|
||||
#endif
|
||||
|
||||
while (*result != '\0') {
|
||||
result++;
|
||||
@@ -354,16 +360,16 @@ char * Helpers::render_value(char * result, const uint32_t value, const int8_t f
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if (!format) {
|
||||
strlcpy(result, ltoa(new_value, s, 10), sizeof(s)); // format is 0
|
||||
strlcpy(result, lltoa(new_value, s, 10), sizeof(s)); // format is 0
|
||||
} else if (format > 0) {
|
||||
strlcpy(result, ltoa(new_value / format, s, 10), sizeof(s));
|
||||
strlcpy(result, lltoa(new_value / format, s, 10), sizeof(s));
|
||||
strlcat(result, ".", sizeof(s));
|
||||
strlcat(result, itoa(((new_value % format) * 10) / format, s, 10), sizeof(s));
|
||||
if (format == 100) {
|
||||
strlcat(result, itoa(new_value % 10, s, 10), sizeof(s));
|
||||
}
|
||||
} else {
|
||||
strlcpy(result, ltoa(new_value * format * -1, s, 10), sizeof(s));
|
||||
strlcpy(result, lltoa(new_value * format * -1, s, 10), sizeof(s));
|
||||
}
|
||||
#else
|
||||
if (!format) {
|
||||
@@ -458,26 +464,22 @@ int Helpers::atoint(const char * value) {
|
||||
// fahrenheit=0 - off, no conversion
|
||||
// fahrenheit=1 - relative, 1.8t
|
||||
// fahrenheit=2 - absolute, 1.8t + 32(fahrenheit-1)
|
||||
float Helpers::transformNumFloat(float value, const int8_t numeric_operator, const uint8_t fahrenheit) {
|
||||
float val;
|
||||
double Helpers::transformNumFloat(double value, const int8_t numeric_operator, const uint8_t fahrenheit) {
|
||||
double val;
|
||||
|
||||
if (numeric_operator == 0) { // DV_NUMOP_NONE
|
||||
val = value * 100 + 0.5;
|
||||
val = value * 100;
|
||||
} else if (numeric_operator > 0) { // DV_NUMOP_DIVxx
|
||||
val = value * 100 / numeric_operator + 0.5;
|
||||
val = value * 100 / numeric_operator;
|
||||
} else { // DV_NUMOP_MULxx
|
||||
val = value * -100 * numeric_operator;
|
||||
}
|
||||
|
||||
if (value < 0) { // negative rounding
|
||||
val = val - 1;
|
||||
}
|
||||
|
||||
if (fahrenheit) {
|
||||
val = val * 1.8 + 3200 * (fahrenheit - 1);
|
||||
}
|
||||
|
||||
return ((int32_t)val) / 100.0;
|
||||
return (round(val)) / 100.0;
|
||||
}
|
||||
|
||||
// abs of a signed 32-bit integer
|
||||
|
||||
@@ -51,7 +51,7 @@ class Helpers {
|
||||
static uint16_t string2minutes(const std::string & str);
|
||||
static float numericoperator2scalefactor(int8_t numeric_operator);
|
||||
|
||||
static float transformNumFloat(float value, const int8_t numeric_operator, const uint8_t fahrenheit = 0);
|
||||
static double transformNumFloat(double value, const int8_t numeric_operator, const uint8_t fahrenheit = 0);
|
||||
|
||||
static std::string toLower(std::string const & s);
|
||||
static std::string toUpper(std::string const & s);
|
||||
|
||||
@@ -414,9 +414,9 @@ ModbusMessage Modbus::handleWrite(const ModbusMessage & request) {
|
||||
|
||||
std::string path;
|
||||
if (tag < DeviceValueTAG::TAG_HC1) {
|
||||
path = std::string("ems-esp/") + std::string(EMSdevice::device_type_2_device_name(device_type)) + "/" + modbusInfo->short_name;
|
||||
path = std::string("api/") + std::string(EMSdevice::device_type_2_device_name(device_type)) + "/" + modbusInfo->short_name;
|
||||
} else {
|
||||
path = std::string("ems-esp/") + std::string(EMSdevice::device_type_2_device_name(device_type)) + "/" + EMSdevice::tag_to_mqtt(tag) + "/"
|
||||
path = std::string("api/") + std::string(EMSdevice::device_type_2_device_name(device_type)) + "/" + EMSdevice::tag_to_mqtt(tag) + "/"
|
||||
+ modbusInfo->short_name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.7.2-dev.2"
|
||||
#define EMSESP_APP_VERSION "3.7.2-dev.4"
|
||||
@@ -56,7 +56,7 @@ void WebCustomEntity::read(WebCustomEntity & webEntity, JsonObject root) {
|
||||
ei["offset"] = entityItem.offset;
|
||||
ei["factor"] = entityItem.factor;
|
||||
ei["name"] = entityItem.name;
|
||||
ei["uom"] = entityItem.uom;
|
||||
ei["uom"] = entityItem.value_type == DeviceValueType::BOOL ? 0 : entityItem.uom;
|
||||
ei["value_type"] = entityItem.value_type;
|
||||
ei["writeable"] = entityItem.writeable;
|
||||
EMSESP::webCustomEntityService.render_value(ei, entityItem, true, true);
|
||||
@@ -97,7 +97,6 @@ StateUpdateResult WebCustomEntity::update(JsonObject root, WebCustomEntity & web
|
||||
if (entityItem.ram == 1) {
|
||||
entityItem.device_id = 0;
|
||||
entityItem.type_id = 0;
|
||||
entityItem.uom = 0;
|
||||
entityItem.value_type = DeviceValueType::STRING;
|
||||
entityItem.writeable = true;
|
||||
}
|
||||
@@ -107,6 +106,7 @@ StateUpdateResult WebCustomEntity::update(JsonObject root, WebCustomEntity & web
|
||||
entityItem.data = "";
|
||||
} else if (entityItem.value_type == DeviceValueType::BOOL) {
|
||||
entityItem.value = EMS_VALUE_DEFAULT_BOOL;
|
||||
entityItem.uom = 0;
|
||||
} else if (entityItem.value_type == DeviceValueType::INT8) {
|
||||
entityItem.value = EMS_VALUE_DEFAULT_INT8;
|
||||
} else if (entityItem.value_type == DeviceValueType::UINT8) {
|
||||
@@ -180,7 +180,7 @@ bool WebCustomEntityService::command_setvalue(const char * value, const int8_t i
|
||||
if (!Helpers::value2bool(value, v)) {
|
||||
return false;
|
||||
}
|
||||
EMSESP::send_write_request(entityItem.type_id, entityItem.device_id, entityItem.offset, v ? 0xFF : 0, 0);
|
||||
EMSESP::send_write_request(entityItem.type_id, entityItem.device_id, entityItem.offset, v ? (uint8_t)entityItem.factor : 0, 0);
|
||||
} else {
|
||||
float f;
|
||||
if (!Helpers::value2float(value, f)) {
|
||||
@@ -214,7 +214,7 @@ bool WebCustomEntityService::command_setvalue(const char * value, const int8_t i
|
||||
// output of a single value
|
||||
// if add_uom is true it will add the UOM string to the value
|
||||
void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem & entity, const bool useVal, const bool web, const bool add_uom) {
|
||||
char payload[12];
|
||||
char payload[20];
|
||||
std::string name = useVal ? "value" : entity.name;
|
||||
switch (entity.value_type) {
|
||||
case DeviceValueType::BOOL:
|
||||
@@ -266,7 +266,7 @@ void WebCustomEntityService::render_value(JsonObject output, CustomEntityItem &
|
||||
default:
|
||||
// if no type treat it as a string
|
||||
if (entity.data.length() > 0) {
|
||||
output[name] = entity.data;
|
||||
output[name] = add_uom ? entity.data + ' ' + EMSdevice::uom_to_string(entity.uom) : entity.data;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -490,13 +490,15 @@ void WebCustomEntityService::generate_value_web(JsonObject output, const bool is
|
||||
}
|
||||
|
||||
obj["id"] = "00" + entity.name;
|
||||
obj["u"] = entity.uom;
|
||||
if (entity.value_type != DeviceValueType::BOOL) {
|
||||
obj["u"] = entity.uom;
|
||||
}
|
||||
|
||||
if (entity.writeable) {
|
||||
obj["c"] = entity.name;
|
||||
include = true;
|
||||
if (entity.value_type != DeviceValueType::BOOL && entity.value_type != DeviceValueType::STRING) {
|
||||
char s[10];
|
||||
char s[20];
|
||||
obj["s"] = Helpers::render_value(s, entity.factor, 1);
|
||||
}
|
||||
}
|
||||
@@ -630,6 +632,10 @@ bool WebCustomEntityService::get_value(std::shared_ptr<const Telegram> telegram)
|
||||
for (uint8_t i = 0; i < len[entity.value_type]; i++) {
|
||||
value = (value << 8) + telegram->message_data[i + entity.offset - telegram->offset];
|
||||
}
|
||||
// mask bits for bool values
|
||||
if (entity.value_type == DeviceValueType::BOOL && entity.factor > 0) {
|
||||
value = (value & (uint8_t)entity.factor) ? 1 : 0;
|
||||
}
|
||||
if (value != entity.value) {
|
||||
entity.value = value;
|
||||
if (Mqtt::publish_single()) {
|
||||
|
||||
@@ -267,10 +267,10 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
||||
if (data.is<const char *>()) {
|
||||
return_code = Command::call(device_type, cmd, data.as<const char *>(), true, id, output);
|
||||
} else if (data.is<int>()) {
|
||||
char s[10];
|
||||
char s[20];
|
||||
return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as<int32_t>(), 0), true, id, output);
|
||||
} else if (data.is<float>()) {
|
||||
char s[10];
|
||||
char s[20];
|
||||
return_code = Command::call(device_type, cmd, Helpers::render_value(s, data.as<float>(), 1), true, id, output);
|
||||
} else if (data.is<bool>()) {
|
||||
return_code = Command::call(device_type, cmd, data.as<bool>() ? "true" : "false", true, id, output);
|
||||
|
||||
Reference in New Issue
Block a user