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

Add simulator #253

Merged
merged 3 commits into from
Jan 15, 2019
Merged

Add simulator #253

merged 3 commits into from
Jan 15, 2019

Conversation

achow101
Copy link
Contributor

This PR adds a simulator for the Digital Bitbox. The simulator binds to port 35345 and listens for UDP packets. Whatever it receives is passed directly to the commander as what it receives should be exactly the command string that the commander needs. The response is then sent back to the sender using UDP. For the files in the sd card, the simulator requires that the path to the location for the fake sd card folder is specified when the simulator is started.

To build the simulator, an additional build type is added. cmake must use the simulator build type so that the simulator is built.

Closes #252

@TheCharlatan
Copy link

tACK

src/simulator.c Outdated
exit(1);
}
}
}

Choose a reason for hiding this comment

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

Small nit: Some compilers complain about not having a newline.

Copy link
Member

Choose a reason for hiding this comment

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

My local build environment (OSX, clang) does complain and aborts the build here. Would appreciate a newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

@douglasbakkum douglasbakkum left a comment

Choose a reason for hiding this comment

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

Thanks a lot @achow101 !
This is great. I added some small nits in the review.

CMakeLists.txt Outdated
set(ELF ${MYPROJECT}.elf)
set(CMAKE_TOOLCHAIN_FILE arm.cmake)
include(${CMAKE_TOOLCHAIN_FILE})
elseif(BUILD_TYPE STREQUAL "simulator")
set(ELF ${MYPROJECT})
Copy link
Member

Choose a reason for hiding this comment

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

This is not necessary and can be deleted. Elf files are only used in firmware builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/simulator.c Outdated
exit(1);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

My local build environment (OSX, clang) does complain and aborts the build here. Would appreciate a newline.

src/sd.c Outdated
void set_root_dir(const char* path, size_t path_len)
{
memset(ROOTDIR, 0, 256);
memcpy(ROOTDIR, path, path_len);
Copy link
Member

Choose a reason for hiding this comment

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

nit:
It is not so important since it is a simulator, but instead of memcpy, using:

snprintf(ROOTDIR, sizeof(ROOTDIR), "%s", path);

protects against potential buffer overflows. path_len would then not be needed.

(Also in the line above, a sizeof(ROOTDIR) is preferred over 256.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

achow101 added a commit to bitcoin-core/HWI that referenced this pull request Jan 14, 2019
0b870d8 Document how to build the simulator (Andrew Chow)
8f1dff2 Change Digital Bitbox test to use simulator (Andrew Chow)
07c9771 Build digital bitbox simulator in setup_environment.sh (Andrew Chow)
814d02d Implement support for communicating with a dbb simulator (Andrew Chow)

Pull request description:

  This PR changes the current manual Digital Bitbox tests into an automated test. This uses the [simulator that I wrote](https://github.com/achow101/mcu/blob/simulator/src/simulator.c) (which is also [PR'd](BitBoxSwiss/mcu#253) to Digital Bitbox).

  Built on #104

Tree-SHA512: 582afa5e045c1e222064958b1b9dda17db7025dd5ff3f8a64a826abe92631b0dd808fcded501bedec7fc1d8ef4c386c99212ff1b182d149e182ea472f65d92ea
Copy link
Member

@douglasbakkum douglasbakkum left a comment

Choose a reason for hiding this comment

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

tACK

@douglasbakkum douglasbakkum merged commit a3cb77e into BitBoxSwiss:master Jan 15, 2019
douglasbakkum added a commit that referenced this pull request Jan 15, 2019
a3cb77e Simulator must have the directory for sd card files be specified (Andrew Chow)
f9864d9 Add a simulator program (Andrew Chow)
c3783b6 Add achow101 pgp key (Andrew Chow)
@achow101 achow101 deleted the simulator branch January 15, 2019 14:57
@achow101 achow101 restored the simulator branch January 15, 2019 14:57
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.

3 participants