-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(adapter-tcp): add more packet event handlers
- Loading branch information
Showing
22 changed files
with
434 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...cp/src/event-handlers/packet-event-handlers/device-clean-map-data-report.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { PacketEventHandler } from '../../packet.event-handler'; | ||
import type { PacketMessage } from '../../packet.message'; | ||
|
||
export class DeviceCleanMapDataReportEventHandler implements PacketEventHandler { | ||
readonly eventName = 'DEVICE_CLEANMAP_BINDATA_REPORT_REQ'; | ||
|
||
async handle(message: PacketMessage<'DEVICE_CLEANMAP_BINDATA_REPORT_REQ'>): Promise<void> { | ||
if (!message.device) { | ||
throw new DomainException('Device not found'); | ||
} | ||
|
||
const data = message.packet.payload.object; | ||
|
||
// TODO: save device clean map data | ||
|
||
await message.respond('DEVICE_CLEANMAP_BINDATA_REPORT_RSP', { result: 0, cleanId: data.cleanId }); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ter-tcp/src/event-handlers/packet-event-handlers/device-clean-map-report.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { PacketEventHandler } from '../../packet.event-handler'; | ||
import type { PacketMessage } from '../../packet.message'; | ||
|
||
export class DeviceCleanMapReportEventHandler implements PacketEventHandler { | ||
readonly eventName = 'DEVICE_EVENT_REPORT_CLEANMAP'; | ||
|
||
async handle(message: PacketMessage<'DEVICE_EVENT_REPORT_CLEANMAP'>): Promise<void> { | ||
if (!message.device) { | ||
throw new DomainException('Device not found'); | ||
} | ||
|
||
const data = message.packet.payload.object; | ||
|
||
// TODO: save device clean map data | ||
|
||
await message.respond('DEVICE_EVENT_REPORT_RSP', { result: 0, body: { cleanId: data.cleanId } }); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...er-tcp/src/event-handlers/packet-event-handlers/device-clean-task-report.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { PacketEventHandler } from '../../packet.event-handler'; | ||
import type { PacketMessage } from '../../packet.message'; | ||
|
||
export class DeviceCleanTaskReportEventHandler implements PacketEventHandler { | ||
readonly eventName = 'DEVICE_EVENT_REPORT_CLEANTASK'; | ||
|
||
async handle(message: PacketMessage<'DEVICE_EVENT_REPORT_CLEANTASK'>): Promise<void> { | ||
if (!message.device) { | ||
throw new DomainException('Device not found'); | ||
} | ||
|
||
// TODO: save device clean task data | ||
|
||
await message.respond('UNK_11A4', { unk1: 0 }); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...r-tcp/src/event-handlers/packet-event-handlers/device-get-all-global-map.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { PacketEventHandler } from '../../packet.event-handler'; | ||
import type { PacketMessage } from '../../packet.message'; | ||
|
||
export class DeviceGetAllGlobalMapEventHandler implements PacketEventHandler { | ||
readonly eventName = 'DEVICE_GET_ALL_GLOBAL_MAP_INFO_RSP'; | ||
|
||
async handle(message: PacketMessage<'DEVICE_GET_ALL_GLOBAL_MAP_INFO_RSP'>): Promise<void> { | ||
if (!message.device) { | ||
throw new DomainException('Device not found'); | ||
} | ||
|
||
// TODO: investigate the meaning of this packet. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../event-handlers/packet-event-handlers/device-map-charger-position-update.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { MapPosition } from '@agnoc/domain'; | ||
import { DomainException } from '@agnoc/toolkit'; | ||
import type { PacketEventHandler } from '../../packet.event-handler'; | ||
import type { PacketMessage } from '../../packet.message'; | ||
|
||
export class DeviceMapChargerPositionUpdateEventHandler implements PacketEventHandler { | ||
readonly eventName = 'DEVICE_MAPID_PUSH_CHARGE_POSITION_INFO'; | ||
|
||
async handle(message: PacketMessage<'DEVICE_MAPID_PUSH_CHARGE_POSITION_INFO'>): Promise<void> { | ||
if (!message.device) { | ||
throw new DomainException('Device not found'); | ||
} | ||
|
||
const data = message.packet.payload.object; | ||
|
||
message.device.map?.updateCharger( | ||
new MapPosition({ | ||
x: data.poseX, | ||
y: data.poseY, | ||
phi: data.posePhi, | ||
}), | ||
); | ||
|
||
// TODO: save entity and publish domain event | ||
} | ||
} |
197 changes: 197 additions & 0 deletions
197
...s/adapter-tcp/src/event-handlers/packet-event-handlers/device-map-update.event-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
import { | ||
DeviceCleanWork, | ||
CleanSize, | ||
DeviceTime, | ||
DeviceMap, | ||
MapCoordinate, | ||
MapPixel, | ||
MapPosition, | ||
Room, | ||
Zone, | ||
} from '@agnoc/domain'; | ||
import { DomainException, ID, isPresent } from '@agnoc/toolkit'; | ||
import type { DeviceBatteryMapper } from '../../mappers/device-battery.mapper'; | ||
import type { DeviceErrorMapper } from '../../mappers/device-error.mapper'; | ||
import type { DeviceFanSpeedMapper } from '../../mappers/device-fan-speed.mapper'; | ||
import type { DeviceModeMapper } from '../../mappers/device-mode.mapper'; | ||
import type { DeviceStateMapper } from '../../mappers/device-state.mapper'; | ||
import type { PacketEventHandler } from '../../packet.event-handler'; | ||
import type { PacketMessage } from '../../packet.message'; | ||
|
||
export class DeviceMapUpdateEventHandler implements PacketEventHandler { | ||
readonly eventName = 'DEVICE_MAPID_GET_GLOBAL_INFO_RSP'; | ||
|
||
constructor( | ||
private readonly deviceBatteryMapper: DeviceBatteryMapper, | ||
private readonly deviceModeMapper: DeviceModeMapper, | ||
private readonly deviceStateMapper: DeviceStateMapper, | ||
private readonly deviceErrorMapper: DeviceErrorMapper, | ||
private readonly deviceFanSpeedMapper: DeviceFanSpeedMapper, | ||
) {} | ||
|
||
async handle(message: PacketMessage<'DEVICE_MAPID_GET_GLOBAL_INFO_RSP'>): Promise<void> { | ||
if (!message.device) { | ||
throw new DomainException('Device not found'); | ||
} | ||
|
||
const { | ||
statusInfo, | ||
mapHeadInfo, | ||
mapGrid, | ||
historyHeadInfo, | ||
robotPoseInfo, | ||
robotChargeInfo, | ||
cleanRoomList, | ||
roomSegmentList, | ||
wallListInfo, | ||
spotInfo, | ||
cleanPlanList, | ||
currentPlanId, | ||
} = message.packet.payload.object; | ||
|
||
if (statusInfo) { | ||
const { | ||
batteryPercent: battery, | ||
faultType: type, | ||
workingMode: workMode, | ||
chargeState: chargeStatus, | ||
cleanPreference, | ||
faultCode, | ||
} = statusInfo; | ||
|
||
message.device.updateCurrentClean( | ||
new DeviceCleanWork({ | ||
size: new CleanSize(statusInfo.cleanSize), | ||
time: DeviceTime.fromMinutes(statusInfo.cleanTime), | ||
}), | ||
); | ||
message.device.updateBattery(this.deviceBatteryMapper.toDomain(battery)); | ||
message.device.updateMode(this.deviceModeMapper.toDomain(workMode)); | ||
message.device.updateState(this.deviceStateMapper.toDomain({ type, workMode, chargeStatus })); | ||
message.device.updateError(this.deviceErrorMapper.toDomain(faultCode)); | ||
message.device.updateFanSpeed(this.deviceFanSpeedMapper.toDomain(cleanPreference)); | ||
} | ||
|
||
let map = message.device.map; | ||
|
||
if (mapHeadInfo && mapGrid) { | ||
const props = { | ||
id: new ID(mapHeadInfo.mapHeadId), | ||
size: new MapPixel({ | ||
x: mapHeadInfo.sizeX, | ||
y: mapHeadInfo.sizeY, | ||
}), | ||
min: new MapCoordinate({ | ||
x: mapHeadInfo.minX, | ||
y: mapHeadInfo.minY, | ||
}), | ||
max: new MapCoordinate({ | ||
x: mapHeadInfo.maxX, | ||
y: mapHeadInfo.maxY, | ||
}), | ||
resolution: mapHeadInfo.resolution, | ||
grid: mapGrid, | ||
rooms: [], | ||
restrictedZones: [], | ||
robotPath: [], | ||
}; | ||
|
||
map = map ? map.clone(props) : new DeviceMap(props); | ||
|
||
message.device.updateMap(map); | ||
} | ||
|
||
if (map) { | ||
if (historyHeadInfo) { | ||
const currentIndex = map.robotPath.length; | ||
|
||
map.updateRobotPath( | ||
map.robotPath.concat( | ||
historyHeadInfo.pointList.slice(currentIndex).map(({ x, y }) => new MapCoordinate({ x, y })), | ||
), | ||
); | ||
} | ||
|
||
if (robotPoseInfo) { | ||
map.updateRobot( | ||
new MapPosition({ | ||
x: robotPoseInfo.poseX, | ||
y: robotPoseInfo.poseY, | ||
phi: robotPoseInfo.posePhi, | ||
}), | ||
); | ||
} | ||
|
||
if (robotChargeInfo) { | ||
map.updateCharger( | ||
new MapPosition({ | ||
x: robotChargeInfo.poseX, | ||
y: robotChargeInfo.poseY, | ||
phi: robotChargeInfo.posePhi, | ||
}), | ||
); | ||
} | ||
|
||
if (spotInfo) { | ||
map.updateCurrentSpot( | ||
new MapPosition({ | ||
x: spotInfo.poseX, | ||
y: spotInfo.poseY, | ||
phi: spotInfo.posePhi, | ||
}), | ||
); | ||
} | ||
|
||
if (wallListInfo) { | ||
map.updateRestrictedZones( | ||
wallListInfo.cleanAreaList.map((cleanArea) => { | ||
return new Zone({ | ||
id: new ID(cleanArea.cleanAreaId), | ||
coordinates: cleanArea.coordinateList.map(({ x, y }) => { | ||
return new MapCoordinate({ | ||
x, | ||
y, | ||
}); | ||
}), | ||
}); | ||
}), | ||
); | ||
} | ||
|
||
if (cleanRoomList && roomSegmentList && cleanPlanList) { | ||
const currentPlan = cleanPlanList.find((plan) => plan.planId === currentPlanId); | ||
|
||
map.updateRooms( | ||
cleanRoomList | ||
.map((cleanRoom) => { | ||
const segment = roomSegmentList.find((roomSegment) => roomSegment.roomId === cleanRoom.roomId); | ||
const roomInfo = currentPlan?.cleanRoomInfoList.find((r) => r.roomId === cleanRoom.roomId); | ||
|
||
if (!segment) { | ||
return undefined; | ||
} | ||
|
||
return new Room({ | ||
id: new ID(cleanRoom.roomId), | ||
name: cleanRoom.roomName, | ||
isEnabled: Boolean(roomInfo?.enable), | ||
center: new MapCoordinate({ | ||
x: cleanRoom.roomX, | ||
y: cleanRoom.roomY, | ||
}), | ||
pixels: segment?.roomPixelList.map((pixel) => { | ||
return new MapPixel({ | ||
x: pixel.x, | ||
y: pixel.y, | ||
}); | ||
}), | ||
}); | ||
}) | ||
.filter(isPresent), | ||
); | ||
} | ||
} | ||
|
||
// TODO: save entities and publish domain events | ||
} | ||
} |
Oops, something went wrong.