Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.
Kevin Ma edited this page Jan 31, 2017 · 15 revisions

File Locations Mapped

State Container: Redux and redux-saga

In short, Redux imagines all data will reside in a store, which basically an object (similar to Python dictionaries, Java Maps, Ruby Hashes). Actions are called to initiate changes, and reducers actually create the changes. redux-saga creates threads to deal better with asynchronous reducers.

Actions define the information to be transmitted to the store, and they are defined as objects. A related concept is an Action Creator, which are functions that create Actions (i.e. fill in values for object attributes). Normally, Actions need to be dispatched to actually make changes. However, thanks to redux-react, action creation can implicitly call dispatch; this is done for Dawn's actions.

Note: In Dawn colloquially uses the word action for both regular Actions and Action Creators, given how most Actions in Dawn are created by Action Creators.

Note 2: Actions is also the main way the Main process can communicate to the renderer. This is done through RendererBridge.js.

Reducers handle state/store changes. In Dawn, we use TYPE attributes in actions to allow for switch statements, and reducers are combined in dawnApp.js for easier usage. Reducers take in (state, action) as its input and return a new state. This new state is not a mutated version of the old one; it does copy everything from the old state using ...state syntax. All normal reducers are pure functions.

Any changes to the state can be monitored with listeners, though that is not currently used in Dawn. The state can be directly accessed with getState(), though Dawn normally uses React props to pass in information for code cleanliness.

Sagas provide more features to Redux; in particular, it allows for impure functions and asynchronous operations. It actually spins off as a separate process and intercepts actions. For Dawn, we use it to deal with Main process communications, Runtime heartbeats, and File operations.

Dawn - Runtime Communication

Current updates to the communication's protocol can be found in this doc.

Manual Communications: Student Code and Update Files

Due to complexities in guaranteeing file integrity, it has been resolved to use an SFTP implementation to deal with larger files. To do so, we currently use the ssh2 package's SFTP-streams implementation as it is relatively OS-independent.

Background Communications

Currently, the main mechanism for background communication is through sockets created from the Node.js Dgram (UDP) and Net (TCP) modules. To reduce latency, most data will be passed as Protocol Buffers, implemented through the protobuf.js package. This means that data, commonly represented as objects, will need to be converted to and from protobufs throughout the communication process; the current implementation can be found in Ansible.js. The schema for what is to be sent to and received from the robot is found in the ansible-protos folder. Any changes made to this must be clearly communicated to all, as changes here will affect implementation on both Dawn and Runtime's sides.

Testing and Linting

Chai and Mocha

The Test-Driven Development framework for JavaScript, Mocha is used to test Dawn for edge cases. Chai is included to allow for greater flexibility on how to test items. We currently test various actions, or IPC messages, and reducers, or state changes. It can be run through make dawn-test in the top dawn directory.

Given the high probability that there will be only one working test robot, Fake Runtime is created to test protocol and APIs. It tests to make sure both sides can decode and encode protobufs as defined here. It also tests how Dawn deals with different kinds of sensor data and message amount, with the latter customizable (SENDRATE measured in ms).

To maintain code quality, Dawn uses ESLint to enforce good practices. In doing so, it will fail to compile one's work unless it is fully complaint with current rules, which is currently based off of AirBnb's best practices. Any modifications for the rules can be created in .eslintrc or .eslintignore. Please try to minimize changes on these as extensive changes may negate the benefits of linting.

Bugs

Folders/Pictures Missing in File Dialog

This is a tmux-related error in the Electron stack. Solution is to run make dawn-start/npm start in anything except a tmux session.