Skip to content

Added checksum calculator option for microcontroller.#1

Open
smlkdev wants to merge 1 commit into
LoEE:masterfrom
smlkdev:master
Open

Added checksum calculator option for microcontroller.#1
smlkdev wants to merge 1 commit into
LoEE:masterfrom
smlkdev:master

Conversation

@smlkdev

@smlkdev smlkdev commented Mar 12, 2019

Copy link
Copy Markdown

Hello!

I would love to add this small functionality into your project!

Cheers,
smlkdev

@nazriel nazriel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noice.

Comment thread lpc17prl.lua Outdated
if opts.mode == 'calculate' then
if not opts.fname then D.abort(2, "Binary file not provided") end

local f, err = io.open(opts.fname, "r+b")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually you see such order for open-mode.

Suggested change
local f, err = io.open(opts.fname, "r+b")
local f, err = io.open(opts.fname, "rb")

but what you wrote seems to be good as well :)

Comment thread lpc17prl.lua Outdated
local bytes = f:read(4)
local int32 = B.dec32LE(bytes)
sum = sum + int32
D.yellow''(byteno,int32,B.hex(int32))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it's convenient for development purposes - I think user is not interested in those values

Comment thread lpc17prl.lua Outdated

local sum = 0

for byteno=1,7,1 do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you can omit tailing 1:
for byteno=1,7 do

Comment thread lpc17prl.lua Outdated
f:write(B.enc32LE(sum))
f:close()

D.green'File saved! Checksum:'(sum,B.hex(sum))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again - not sure if it's really needed.

Comment thread lpc17prl.lua Outdated

D.green'File saved! Checksum:'(sum,B.hex(sum))

os.exit()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I'd like patch the file and write it to flash in one go?
Maybe we can think of supporting syntax like ./lpc17prl.lua -XW FILE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants