Skip to content

Commit

Permalink
v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed Nov 10, 2022
1 parent deb4c09 commit d1b5c62
Show file tree
Hide file tree
Showing 5 changed files with 578 additions and 580 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pn532.js",
"version": "0.1.1",
"version": "0.1.2",
"author": "taichunmin <[email protected]>",
"browser": "dist/pn532.min.js",
"description": "pn532.js is a JavaScript library for PN532 base on Web Bluetooth and Web Serial.",
Expand All @@ -25,29 +25,29 @@
"web-serial-polyfill": "^1.0.14"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^23.0.0",
"@rollup/plugin-json": "^5.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-json": "^5.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"cross-env": "^7.0.3",
"dayjs": "^1.11.5",
"dayjs": "^1.11.6",
"documentation": "^14.0.0",
"dotenv": "^16.0.3",
"eslint": "^8.25.0",
"eslint": "^8.27.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.3.0",
"eslint-plugin-n": "^15.5.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-pug": "^1.2.4",
"fast-glob": "^3.2.12",
"finalhandler": "^1.2.0",
"html-minifier": "^4.0.0",
"jest": "^29.2.1",
"jest": "^29.3.1",
"jstransformer-sass": "^1.0.0",
"livereload": "^0.9.3",
"node-watch": "^0.7.3",
"pug": "^3.0.2",
"rollup": "^3.2.3",
"rollup": "^3.2.5",
"rollup-plugin-terser": "^7.0.2",
"serve-static": "^1.15.0",
"web-streams-polyfill": "^3.2.1"
Expand Down
18 changes: 13 additions & 5 deletions src/plugin/Hf14a.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ export default class Pn532Hf14a {
* @param {Packet} args.key 6 bytes key to authenticate the block.
* @param {number} args.tg A byte containing the logical number of the relevant target.
* @param {Packet} args.uid Uid of the target to be authenticated. Currently only accepted 4 bytes uid.
* @param {number} args.blocksPerSector A integer represent how many blocks per sector.
* @returns {Promise<null>} Resolve after finish.
*/
async function mfAuthBlock ({ block = 0, isKb = 0, key, tg = 1, uid } = {}) {
async function mfAuthBlock ({ block = 0, isKb = 0, key, tg = 1, uid, blocksPerSector = 4 } = {}) {
if (!Packet.isLen(key, 6)) throw new TypeError('invalid key')
if (!Packet.isLen(uid, 4)) throw new TypeError('invalid uid')
isKb = isKb ? 1 : 0
block += blocksPerSector - (block % blocksPerSector) - 1
try {
await pn532.inDataExchange({ tg, data: new Packet([0x60 + isKb, block, ...key, ...uid]) })
} catch (err) {
Expand Down Expand Up @@ -175,7 +177,7 @@ export default class Pn532Hf14a {
}

function mfBlockRespValidator (resp) {
return Packet.isLen(resp.data, 17)
return resp.data[0] !== 0x00 || Packet.isLen(resp.data, 17)
}

/**
Expand Down Expand Up @@ -343,7 +345,7 @@ export default class Pn532Hf14a {
keys = mfKeysUniq(keys)
if (!keys.length) throw new TypeError('invalid keys')
try {
const uid = (await inListPassiveTarget())?.[0]?.uid
let uid = (await inListPassiveTarget())?.[0]?.uid
if (!uid) throw new Error('Failed to select card')
const data = new Packet(sectorMax * 64)
const success = { key: _.times(sectorMax * 2, () => null), read: _.times(sectorMax * 4, () => 0) }
Expand All @@ -366,7 +368,10 @@ export default class Pn532Hf14a {
} catch (err) {}
}
break
} catch (err) {}
} catch (err) {
await pn532.inRelease().catch(() => {})
uid = (await inListPassiveTarget())?.[0]?.uid
}
}
}
for (let j = 0; j < 2; j++) { // fill key
Expand Down Expand Up @@ -640,7 +645,10 @@ export default class Pn532Hf14a {
} catch (err) {}
}
break
} catch (err) {}
} catch (err) {
await pn532.inRelease().catch(() => {})
uid = (await inListPassiveTarget())?.[0]?.uid
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/LoggerRxTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ export default class Pn532LoggerRxTx {
}

pn532.addMiddleware('writePacket', async (ctx, next) => {
utils.logTime(`tx = ${inspectPn532Frame(ctx.pack)}`)
utils.logTime(`send = ${inspectPn532Frame(ctx.pack)}`)
return await next()
})

pn532.addMiddleware('skipRespLogger', async (ctx, next) => {
const { message, resp } = ctx
utils.logTime(`rx skipped, message = ${message}, resp = ${resp.pack.inspect}`)
utils.logTime(`resp skipped, message = ${message}, resp = ${resp.pack.inspect}`)
return await next()
})

pn532.addMiddleware('readRespTimeout', async (ctx, next) => {
const resp = await next()
if (!resp.pack.isEqual(frameAck)) utils.logTime(`rx = ${inspectPn532Frame(resp.pack)}`)
if (!resp.pack.isEqual(frameAck)) utils.logTime(`resp = ${inspectPn532Frame(resp.pack)}`)
return resp
})
}
Expand Down
2 changes: 2 additions & 0 deletions web/m1-eml-toolkit.pug
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ block script
return await Swal.fire({ icon: 'error', title: `${failed.length} 個 block 讀取失敗`, text: `失敗的 block: ${failed.join()}` })
}
await Swal.fire({ icon: 'success', title: '讀取成功' })
await this.btnEditEml()
} catch (err) {
console.error(err)
await Swal.fire({ icon: 'error', title: '讀取失敗', text: err.message })
Expand Down Expand Up @@ -182,6 +183,7 @@ block script
return await Swal.fire({ icon: 'error', title: `${failed.length} 個 block 讀取失敗`, text: `失敗的 block: ${failed.join()}` })
}
await Swal.fire({ icon: 'success', title: '讀取成功' })
await this.btnEditEml()
} catch (err) {
console.error(err)
await Swal.fire({ icon: 'error', title: '讀取失敗', text: err.message })
Expand Down
Loading

0 comments on commit d1b5c62

Please sign in to comment.