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

feat:コードチェック機能の実装 #362

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

Suzune2741
Copy link
Member

@Suzune2741 Suzune2741 commented Dec 18, 2024

close #295

ページに検証というボタンを追加
押すとverifyをマイコン側へ送信する

書き込み終了時の+DONEを+OK [ハッシュ値]に変更しているマイコンに対しては、書き込んだ時に合わせてコードチェックをするようにした

Copy link

cloudflare-workers-and-pages bot commented Dec 18, 2024

Deploying kaniwriter with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8529e9e
Status: ✅  Deploy successful!
Preview URL: https://811197f5.kaniwriter.pages.dev
Branch Preview URL: https://feat-verify.kaniwriter.pages.dev

View logs

@Suzune2741 Suzune2741 enabled auto-merge December 18, 2024 13:13
@Suzune2741 Suzune2741 self-assigned this Dec 18, 2024
@@ -23,7 +24,7 @@ const enterWriteModeKeyword: Record<Target, RegExp> = {
} as const;

const exitWriteModeKeyword: Record<Target, RegExp> = {
ESP32: /mrubyc-esp32: End mrbwrite mode/,
ESP32: /mruby\/c v\d(.\d+)* start/,
Copy link
Member

Choose a reason for hiding this comment

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

意図が分かりづらいので何かしらのコメントが欲しいです。

src/utils/crc8Calculator.ts Show resolved Hide resolved
@@ -262,7 +263,11 @@ export class MrubyWriterConnector {
await this.sendCommand("execute");
}

return Success.value(null);
const crc = crc8Calculator(binary);
const crcRes = writeRes.value.split("+OK")[1];
Copy link
Member

Choose a reason for hiding this comment

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

意図が分かりづらいので、"".match(//)を使って正規表現で取得するのがよさそうです。

Suggested change
const crcRes = writeRes.value.split("+OK")[1];
const crcRes = writeRes.value.match(/^\+OK (?<hash>[0-9a-zA-Z]+)$/)?.groups?.hash;

のような感じでしょうか?(テキトーに書いたのでちゃんと検証していません)

Comment on lines +268 to +270
if (crc !== undefined && crcRes !== undefined)
this.verify(crc, parseInt(crcRes, 16));
return Success.value(writeRes.value);
Copy link
Member

Choose a reason for hiding this comment

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

crcResundefinedでないこともそうですが、parseInt(crcRes, 16)NaNでないことも検証するべきでしょう。crcResが常に数値に変換できるとは限らないからです。

Comment on lines +500 to +508
async verify(culcHash: number, retHash: number) {
if (culcHash === retHash) {
this.handleText("\r\n Verify Success\r\n");
return true;
} else {
this.handleText("\r\n Verify Failed\r\n");
return false;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

verifyに持たせる機能が少なすぎると思います。バイナリからハッシュ値を作って、verifyコマンドを送信して結果を受けとって検証する一連の流れを抽象化すべきです。

@@ -2,6 +2,7 @@ import {
CheckCircleRounded as CheckCircleRoundedIcon,
Edit as EditIcon,
Flag as FlagIcon,
Plagiarism,
Copy link
Member

Choose a reason for hiding this comment

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

流石にPlagiarism(=盗作)はよくない気がします。Document SearchData Checkはどうでしょうか?

src/pages/home.tsx Show resolved Hide resolved
src/pages/home.tsx Show resolved Hide resolved
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.

feat: コードチェック機能の追加
2 participants