Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many improvements #8

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
aa90f43
chore: Remove trailing whitespace
magicus Nov 7, 2023
243e52d
feat: Add additional commands
magicus Nov 7, 2023
8be9836
feat: Add get firmware/alarm commands
magicus Nov 7, 2023
5bdbde0
fix: sendCMDGetDeviceParameters was already implemented
magicus Nov 7, 2023
299ffc8
feat: add one more command and some documentation
magicus Nov 7, 2023
7300e63
refactor: Remove duplication when sending commands
magicus Nov 7, 2023
baaef4a
refactor: Extract knowledge about commands into constants, and simpli…
magicus Nov 7, 2023
fd20d75
refactor: Move documentation to better place
magicus Nov 7, 2023
550009a
Add named constants for PTZ motor control
magicus Nov 8, 2023
d28359d
Add new commands: set_cypush, edit_user, set_alarm, set_datetime and …
magicus Nov 13, 2023
6cc69dd
fix: Only send close if we actually opened the connection
magicus Nov 13, 2023
4b95eda
Fix syntax error
magicus Nov 22, 2023
7c433e0
* Refactor: extract handlePacket()
magicus Nov 22, 2023
398b9e2
Refactor code to improve readability and add new functionality
Bluscream Jan 15, 2024
1785304
Refactor PPPP class and add debug logs
Bluscream Jan 16, 2024
d486eda
[ImgBot] Optimize images
ImgBotApp Jan 16, 2024
cfcd0d7
Refactor PPPP class and add new functionality
Bluscream Jan 16, 2024
6a2a676
Add eval mode option to run.js
Bluscream Jan 16, 2024
57fe274
t
Jan 16, 2024
e44f860
Merge pull request #1 from Bluscream/imgbot
Bluscream Jan 16, 2024
d647afd
- add speaker back as optionalDependency this time
Jan 17, 2024
3ed4cf8
Merge branch 'master' of https://github.com/Bluscream/PPPP
Jan 17, 2024
4e5993e
add increasing reconnectDelay to socket
Jan 17, 2024
af40d0f
fix paths for query parameters and fix /func/ for pw param
Jan 17, 2024
8e5e66d
index template
Bluscream Jan 17, 2024
3a1391e
Merge branch 'master' of https://github.com/Bluscream/PPPP
Bluscream Jan 17, 2024
562dd0f
Refactor URL generation and usage
Bluscream Jan 17, 2024
1e89920
Refactor sendBroadcast method to handle error cases
Bluscream Jan 17, 2024
5422a8f
Refactor makeUrl function and add missing require statement
Bluscream Jan 17, 2024
b941143
a
Jan 17, 2024
ba52802
update
Jan 17, 2024
f72b205
d
Jan 17, 2024
21edcb0
final fixes yay, simple control panel works
Jan 17, 2024
90b0012
mhm
Jan 17, 2024
d654fe7
Update launch.json and pppp.js
Bluscream Jan 17, 2024
fdacc32
add `--video <lq,hq>` argument
Bluscream Jan 17, 2024
1721a30
add sendCMDPtzStop command
Jan 17, 2024
fa9fcff
fix typos
Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor PPPP class and add debug logs
Bluscream committed Jan 16, 2024
commit 178530468093a5fa174bdc4520ac435429c6bc1c
41 changes: 27 additions & 14 deletions pppp.js
Original file line number Diff line number Diff line change
@@ -169,42 +169,42 @@ class PPPP extends EventEmitter {

handlePacket(p, msg, rinfo) {
//console.log(TYPE_DICT[p.type], p.size, p.channel, p.index)
let logmsg = ""
if (p.type == MSG_DRW) {
this.emit(
'log',
`Received ${TYPE_DICT[p.type]} size: ${p.size} channel: ${
logmsg = `Received ${TYPE_DICT[p.type]} size: ${p.size} channel: ${
p.channel
} index: ${p.index}`
)
} else {
this.emit('log', `Received ${TYPE_DICT[p.type]} size: ${p.size}`)
logmsg = `Received ${TYPE_DICT[p.type]} size: ${p.size}`
}
// console.log(logmsg)
this.emit('debug', logmsg)

//reply to MSG_PUNCH to establish connection
if (p.type == MSG_PUNCH) {
console.log('MSG_PUNCH received')
if (this.punchCount++ < 5) {
this.socket.send(msg, rinfo.port, rinfo.address)
this.emit('log', `Sent ${TYPE_DICT[MSG_PUNCH]}`)
}
}

if (p.type == MSG_P2P_RDY) {
console.log('MSG_P2P_RDY received')
this.IP_CAM = rinfo.address
this.PORT_CAM = rinfo.port

if (!this.isConnected) {
this.isConnected = true
setTimeout(() => {
this.emit('connected', {
address: rinfo.address,
port: rinfo.port,
})
this.emit('connected', rinfo.address, rinfo.port)
}, 500)
}
}

// reply to MSG_ALIVE
if (p.type == MSG_ALIVE) {
console.log('MSG_ALIVE received')
let buf = Buffer.alloc(4)
buf.writeUint8(MCAM, 0)
buf.writeUInt8(MSG_ALIVE_ACK, 1)
@@ -217,6 +217,15 @@ class PPPP extends EventEmitter {

// reply to MSG_CLOSE
if (p.type == MSG_CLOSE) {
console.log('MSG_CLOSE received')
// wait 4 seconds and if connection is still down, reconnect
// setTimeout(function() {
if (this.isConnected) {
this.isConnected = false
this.emit('disconnected', this.IP_CAM, this.PORT_CAM)
this.sendBroadcast()
}
// }, 3000, we);
let buf = Buffer.alloc(4)
buf.writeUint8(MCAM, 0)
buf.writeUInt8(MSG_ALIVE, 1)
@@ -242,6 +251,7 @@ class PPPP extends EventEmitter {

//handle MSG_DRW
if (p.type == MSG_DRW) {
// console.log('MSG_DRW received')
//send MSG_DRW_ACK
let buf = Buffer.alloc(10)
buf.writeUint8(MCAM, 0)
@@ -261,14 +271,16 @@ class PPPP extends EventEmitter {
this.send(crypt.encrypt(buf).toString('hex'))
this.send(crypt.encrypt(buf).toString('hex'))
this.send(crypt.encrypt(buf).toString('hex'))
this.emit('log', `Sent ${TYPE_DICT[MSG_DRW_ACK]} x3`)
this.emit('debug', `Sent ${TYPE_DICT[MSG_DRW_ACK]} x3`)


//handle CMD Response
if (p.channel == 0) {
console.log('CMD Response received')
if (0 == p.data.indexOf(Buffer.from('060a', 'hex'))) {
let data = p.data.subarray(8)
this.emit('cmd', data.toString('ascii'))
let _msg = data.toString('ascii')
this.emit('cmd', _msg)
}
}

@@ -336,7 +348,8 @@ class PPPP extends EventEmitter {

data.copy(buf, 8)
this.sendDRWPacket(0, buf)
this.emit('log', `CMD sent: ${data.toString('ascii')}`)
let __msg = `CMD sent: ${data.toString('ascii')}`;
this.emit('log', __msg)
}

sendDRWPacket(channel, data) {
@@ -348,15 +361,15 @@ class PPPP extends EventEmitter {
buf.writeUInt8(channel, 5)
buf.writeUInt16BE(this.DRW_PACKET_INDEX++, 6)
data.copy(buf, 8)

this.sendEnc(buf)
console.log('DRW packet sent (len: ' + buf.length + ')')
}

sendCommand(command, args) {
let fixed_data = {
user: 'admin',
pwd: '6666',
devmac:'0000'
// devmac:'0000'
}
/* incorrect password:
{
47 changes: 32 additions & 15 deletions run.js
Original file line number Diff line number Diff line change
@@ -11,24 +11,41 @@ commander
const options = commander.opts()
console.log(options)
const PPPP = require('./pppp')
const p = new PPPP(options)

p.on('connected', (data) => {
console.log('connected!', data)
// p.sendCMDgetParams()
// p.sendCMDGetDeviceFirmwareInfo()
p.sendCMDrequestVideo1()
})
let p = null

p.on('videoFrame', (videoFrame) => {
// console.log(videoFrame)
let s = '--xxxxxxkkdkdkdkdkdk__BOUNDARY\r\n'
s += 'Content-Type: image/jpeg\r\n\r\n'
videoStream.write(Buffer.from(s))
videoStream.write(videoFrame.frame)
})
function setupPPPP() {
p = new PPPP(options)

p.on('log', console.log)

p.on('connected', (address, port) => {
console.log(`Connected to camera at ${address}:${port}`)
setTimeout(() => {
p.sendCMDgetParams()
}, 1000, p)
// p.sendCMDGetDeviceFirmwareInfo()
p.sendCMDrequestVideo1()
})

p.on('disconnected', (address, port) => {
console.log(`Disconnected from camera at ${address}:${port}`)

})

p.on('videoFrame', (videoFrame) => {
// console.log(videoFrame)
let s = '--xxxxxxkkdkdkdkdkdk__BOUNDARY\r\n'
s += 'Content-Type: image/jpeg\r\n\r\n'
videoStream.write(Buffer.from(s))
videoStream.write(videoFrame.frame)
})

p.on('cmd', console.log)
}

setupPPPP()

p.on('cmd', console.log)

//http server with mjpeg
const PassThrough = require('stream').PassThrough