Skip to content

Commit

Permalink
Merge dev to master (#117)
Browse files Browse the repository at this point in the history
* Refactor release.ts and update electron-packager

* Change yarn build and yarn start

* Add dist to .gitignore

* Remove dist

* Fixed run mode sagas connection, cleaned up other bits

* Changed ./main/MenuTemplate

* Changed ./main/networking

* Changed main-process.js and RendererBridge.js

* Changed ./renderer/actions

* Changed ./renderer/components/periperals and App.js and ConfigBox.js

* Changed ./renderer/components

* Changed ./renderer/reducers

* Changed ./renderer/utils

* Added packet header functions, add comments and modifications

* Update tsconfig.json, change ts to tsx, and add @types/react

* Implemented typescript parser for ESLint

* Add more build options in tsconfig.json

* Remove dist from .gitignore

* Revert DNav.tsx changes

* Remove extra spaces in DNav.tsx

* Progress towards fake runtime fix

* Remove ansible-protos folder - already on dev branch

* Fixed null quit bug and params proto bug, brought back console logs

* Fixing restart fc null bug

* Refactor .eslintrc.json

* Fixed fake runtime to now be functional

* Caching protobuf root

* More updates to .eslintrc.json

* Add .prettierrc.js

* Updates in dependencies and tsconfig.json

* Add object params for FieldActions updateTimer

* Add temporary rules for linting and lint fixing actions and types in renderer folder

* Move types from actions to parent directory (renderer)

* Add example for new action/reducer pattern - alerts and console

* Add lint support for reducers

* Remove types that were originally derived from actions folder

* Remove .prettierrc.js - already in package.json

* Modified EditorActions and FieldActions + Fixed any types in FieldActions

* Update utf-8-validate and socket.io-client dependencies

* Fixing package json

* Fixed Capitalization and GamepadsAction

* Finished InfoActions

* Finished PeripheralAction

* Finished SettingsAction

* Lint actions

* Rename some parameters for some action dispatch functions

* Remove export defaults in reducers

* Upgrade redux to version 4.0.5

* Minor fixes in reducers

* Lint reducers

* Rename dawnApp to rootReducer

* Refactor constants folder

* Lint consts

* Lint types

* Edit in webpack.config.babel.ts

* Add 1st round of .eslintrc.json config

* More updates to .eslintrc.json

* Updates in tsconfig.json, package.json, yarn.lock, and .eslintrc.json

* Add prettier to package.json

* Update eslint and .eslintrc.json edit

* Lowercase files for fieldStore and timerStore

* Adding starter typing for ansible

* Added proto Typescript defs. Changed Ansible to Runtime and added most types. Changed gamepad and peripherals

* Fixed the build-protos yarn script

* Add types in ConfigBox.tsx

* Small edit to componentDidMount in ConfigBox component

* Fix electron-json-storage types

* Edited Dashboard.tsx

* Edited DNav.tsx

* Type return type of info reducer

* Add blueMasterTeamNumber and goldMasterTeamNumber to field store state

* Edited EditorContainer.ts

* Edited TooltipButton.tsx

* Fixed minor import errors

* Edited Gamepad.tsx

* Adding typescript types and fixes for compilation

* Fixing sensor data typing

* Changed ConsoleOutput.tsx

* Divided the props interface for reuse in GamepadList.tsx

* Edited StatusLabel.tsx

* Fixed any type for state generic type

* Edited UpdateBox.tsx

* Change the type of gamepads to GamepadObject array

* - Updated gamepad and peripherals with Protobuf definition

- Updated sagas and removed ansible disconnect
- Updated lodash to new version

* Getting battery params with indexes now. Commented version peripheral

* Added types to menus. Installed more types packages. Made webpack file js

* Edited App.tsx

* Fixing version peripheral again.

* Fixed socket typing in FieldControl

* Changed the types of the props and made some parameters optional

* Deleted redundant props

* Worked on editors.tsx. Didn't fix all the type mismatches yet

* Fix imports in FakeRuntime and delete line in App.tsx

* Adding types to params in FakeRuntime

* Fixing typing issues UDP recv of runtime ts

* Upgrade redux saga

* Fix types in sagas.ts

* Add underscore prefix to unused parameters in main-process and Runtime

* Fixed gamepad buttons in sagas

* Add types in ConfigBox.tsx

* Small edit to componentDidMount in ConfigBox component

* Fix electron-json-storage types

* Edited Dashboard.tsx

* Edited DNav.tsx

* Type return type of info reducer

* Add blueMasterTeamNumber and goldMasterTeamNumber to field store state

* Edited EditorContainer.ts

* Edited TooltipButton.tsx

* Fixed minor import errors

* Edited Gamepad.tsx

* Changed ConsoleOutput.tsx

* Divided the props interface for reuse in GamepadList.tsx

* Edited StatusLabel.tsx

* Fixed any type for state generic type

* Edited UpdateBox.tsx

* Change the type of gamepads to GamepadObject array

* Edited App.tsx

* Changed the types of the props and made some parameters optional

* Deleted redundant props

* Worked on editors.tsx. Didn't fix all the type mismatches yet

* Changed the type of gamepadobject to GPstate

* Changed the class name and fixed some props

* Changed types of props

* Changed the types of some function parameters to react events

* Fixed merge conflicts

* Add FieldControlConfig interfaces

* Fixed typing for onFCUpdate

* Add FieldControlConfig to export

* Add types for numeral module

* Refactor Gamepad.tsx

* Allow gamepads to be undefined

* Add outerDiv property to ConsoleOutput class component

* Fixed typing errors:

* Edited the param names and added proto interface to types

* Edited Peripheral.tsx

* Started working on PeripheralList.tsx

* Added Joyride

* Changed import and optional typings

* Started working on Editor.tsx

* Changed prop names and typings

* Rename types.d.ts for ApplicationState to app-state.d.ts

* Update some dependencies

* Fix webpack loading

* Fix types in FakeRuntime, protos, index.tsx

* Add module resolution for smalltalk dependency

* Fix react joyride typing

* Add peripheral list type

* Fixed type issues (changing OwnProps and mapStatetoProps)

* Fix storage.get for editorFontSize and editorTheme

* Changed React FormEvent

* Fixed bootstrap issue:

* Fix PeripheralList type and refactor PeripheralList.tsx

* Fixed dialog.showmessagebox

* Fixed import issue

* Fixed typing and bootstrap issue

* Remove I* proto types from renderer and FakeRuntime

* Lint and refactor protos.d.ts

* package.json and lint App.tsx

* Remove brace imports and use ace-builds

* Fix onEditorPaste function argument type

* Added types for AceEditor

* Fixed typing for onEditorPaste

* Fix Dawn runtime errors

* Merge Conflict changes

* Fix smalltalk import error

* Fix electron build

* Add brace back as dependency

* Fix electron-json-storage typing

* Fix storage.get FieldControlConfig

* Fix yarn build command

* Updated Runtime.ts wsocket architecture, fixed gamepad state

* Refactor networking module and tweak Runtime object variables/methods

* Refactor TCPConn and related methods

* Refactor UDPConn

* Change RendererBridge methods to arrow functions

* Added error handler for TCP socket

* Fix default export

* Update ssh2

* Fix runtime disconnect bug

* Fix TCP connection

* Added check for only connecting after first IP update. Added socket.pending back

* Fix uid bug

* Changed Runtime update location. UI has bugs

* Fixed UpdateBox choosing .zip package

* Working run modes and code upload

* Updates in UpdateBox.tsx

* Removed unnecessary code and imports

* Ignore pending socket error

* Use patch package to fix pending socket type error

* Remove unnecessary changes in Runtime.ts

* Fix peripheral display bug and fake runtime (#46)

* Create and use Peripheral type and add peripheral logging

* Working peripheral list, still UI issues

* Change Peripheral component prop id to uid

* Change exec style for FakeRuntime.ts

* Fix fake runtime

* Tweaks

* Add comment about Peripheral type

Co-authored-by: Ashwin Vangipuram <ashwinvangipuram@gmail.com>

* Fixed run mode starting and stopping (#58)

* Added IDLE mode in dropdown

* Removed ESTOP button and enums

* Added isRunning and fixed play buttons

* Fix some spacing

Co-authored-by: ewc340 <edwardc1028@berkeley.edu>

* Fixed crash when loading a file from filesystem (#57)

* Fixed crash when loading a file from filesystem

* Fixing other readFile calls for downloadCode and dragFile

* Fix eslint config (#54)

* Fix eslint config

* Tweak

* Fixed Runtime TCP connection and moved run_mode to reducer callback (#67)

* DNav - converted to functional component (#50)

* DNav - converted to functional component

* Remove unused createMaster function and linting

Co-authored-by: ewc340 <edwardc1028@berkeley.edu>

* Converted ConfigBox Class to Functional Component (#49)

* Converted classes to hooks

* Lint and small changes

Co-authored-by: ewc340 <edwardc1028@berkeley.edu>

* Install rimraf and mkdirp

* Fix release script and packaged app errors (#51)

* Fix release script

* Fix release script

* Some tweaks

* Shift some dependencies to be dev

* Update electron-packager and add back better-npm-run build

* fix gamepad bitmask

* fix package scripts & gamepad bitmask

* Fix ipAddress local storage issue

* Remove string casting for peripheral uid and key

* Revert backslashes on start and build commands

* Add rimraf and mkdirp

* Fix script commands with rimraf and mkdirp

* Fix peripheral uid and peripheral type display bug

* Fix peripheral param val display issues

* Fix device type 0 display error

* Add ParamComponent memoized

* Add comments and small code styling fixes

* Disable animation on modals due to performance reasons on long list of peripherals

* Change FakeRuntime device send frequency to 20Hz

* Lint Dashboard

* Small refactor in peripherals reducer

* Remove unneeded type assertion for connect in PeripheralList component

* Add comment about param argument for getParamValue function in Peripheral.tsx

* Remove input.proto

* Change FakeRuntime send interval variable name

* Fix some styling in Gamepad.tsx

* Tweak comment

Co-authored-by: Lance Jackson <lanceisajackson@berkeley.edu>

* Convert Gamepad proto to Input proto to match Runtime update (#70)

* WIP: Replaced gamepad.proto with input.proto. pbts isn't autogenerating properly

* Fixed input interfaces by moving enum. See protobufjs #1222

* Properly fixed proto generation using jsdoc patch

* Refactored GpState into Input proto

* Fixed bugs with displaying robot state. Fixed IP handling for ngrok. Fixed log decode bug

* Merging and squashing branch origin/dev into input_proto

* Moved dawn package to inside repo

* Fixed ngrok IP splitting and IP changing

* Addressed PR comments

* Tweaks

Co-authored-by: ewc340 <edwardc1028@berkeley.edu>

* Added argument passing and fixed zipping for release.ts (#72)

* Added argument passing and fixed zipping for release.ts

* Add eslint disable to release.ts

Co-authored-by: ewc340 <edwardc1028@berkeley.edu>

* Add udp tunneling connection for Sp21 Comp (#73)

* Add TCPTunneledConn

* Change TCPTunneledConn to �[200~UDPTunneledConn~

* Add Inputs msg type and tweaks

* Add udpTunnelingIpAddress to redux state

* Add UDP Tunneling field in ConfigBox

* Add udpTunnelIpAddress change listener and add propert TCP packet splitting

* Perform some cleanup and add ipcMain.on ip address change listener to BaseTCPConn

* Add custom numbering to MsgType enum

* Tweak comment to span 2 lines

* Tweak comment

* Tweak some logic for on data handler for reg TCP conn

* Removed BaseTCPConn and added SSH address to ConfigBox and Redux

* Linting

* Add try/catch for udpForwarder send to UDP connection

* Add comment

* Remove comment

* Fix message length

Co-authored-by: Ashwin Vangipuram <ashwinvangipuram@gmail.com>

* Implement keyboard handler (#74)

* Added map for the buttons and the file for keyboard

* store key being pressed with hooks

* uncommented handleButtonChange to get rid of angry red lines

* Delete Keyboard and add toggleKeyboardControl beta version

* Add the keyboard button dictionary

* Add imports

* togglekeyboard

* minor warnings fixed

* addEventListener debug

* Added Redux

* send characters on interval

* keyboard input refreshes after interval

* change keyboard input from interval to event based, send single character on press

* Working on the sagas

* Set it as array

* Fixed the sendInput

* updated keyboard input bool for keyup/down

* added bitmap to redux

* Fix merge conflict

* Fixed the editorSavedState

* Fixed the button alignment issue

* Delete unused line

* moved bitmap logix to editor.tsx

* Removed Bool and KeyboardChar from the redux

* remove bitmap logic from sagas

* remove characterBool from state

* remove characterBool from state

* Remove unused vars

* StatusLabel unused

* change bitmap from number to bigint

* Changing color of the button

* updated arrow key names in mapping

* update proto to include big int

* Added KeyboardToggle to Redux

* Ok idk what I am doing but here we go

* reset to bigint have to convert to long

* Spliced the bits

* Fixed the bitmap error

* Oh oops

* Fixed intermittent input msgs, but keyboard doesn't disconnect

* Fixed counting of keyboard keys

* made changes that Edward said to

* fixed bitmap on/off

* Linting and various small fixes

* Fix Redux isKeyboardModeToggled

* Fix isKeyboardModeToggled name change in sagas

* Small tweak

Co-authored-by: Hailey Jang <hailey_jang@berkeley.edu>
Co-authored-by: Thomas Lee <tcl171@gmail.com>
Co-authored-by: Hailey Jang <hailey.jang.01@gmail.com>
Co-authored-by: Ashish Pandian <pandianashish0@gmail.com>
Co-authored-by: uthmanmomen13 <livininthemomen13@gmail.com>
Co-authored-by: Ashwin Vangipuram <ashwinvangipuram@gmail.com>

* Fix keyboard connected (#79)

* updated keyboard connect/disconnect

* removed unnecessary bitmap change in editor.tsx

* Change buttons back to 0

* Tweaks

Co-authored-by: ewc340 <edwardc1028@berkeley.edu>

* Bump y18n from 3.2.1 to 3.2.2

Bumps [y18n](https://github.com/yargs/y18n) from 3.2.1 to 3.2.2.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/commits)

Signed-off-by: dependabot[bot] <support@github.com>

* Implement latency check for communication with Runtime  (#85)

* need to display latency on ui

* worked on displaying latency on ui

* added some prints

* it was runtimes fault >:(

* Add Latency status label

* Add the delay and color changes

* Modify the latency seconds

* Accidentally deleted something

* Probably 5 seconds is better

* Style fixes

* More minor style fixes and remove unused import

* Add TODO

Co-authored-by: uthmanmomen13 <livininthemomen13@gmail.com>
Co-authored-by: Hailey Jang <hailey.jang.01@gmail.com>

* Fixed the negative latency issue (#89)

* Change latency calculations to be one-way as per Runtime's request (#91)

* Change latency calculations to be one-way

* Remove rounding

* Remove extra spaces

* Add units for latency display (#92)

* Add units for latency display

* Variable renaming

* Refactor RendererBridge (#94)

* Fix merge conflicts

* Some styling fixes

* Added staff code button (#95)

* button works need to test

* change button text

* Small tweaks

Co-authored-by: ewc340 <edwardc1028@berkeley.edu>

* updated staff code from akshit (#98)

* Add new robot staff code (#99)

* Bump lodash from 4.17.20 to 4.17.21 (#106)

Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.20...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump hosted-git-info from 2.8.8 to 2.8.9 (#107)

Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](npm/hosted-git-info@v2.8.8...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ua-parser-js from 0.7.22 to 0.7.28 (#104)

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.22 to 0.7.28.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Commits](faisalman/ua-parser-js@0.7.22...0.7.28)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump codecov from 3.6.5 to 3.7.1 (#19)

Bumps [codecov](https://github.com/codecov/codecov-node) from 3.6.5 to 3.7.1.
- [Release notes](https://github.com/codecov/codecov-node/releases)
- [Commits](codecov/codecov-node@v3.6.5...v3.7.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ini from 1.3.5 to 1.3.8 (#62)

Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8.
- [Release notes](https://github.com/isaacs/ini/releases)
- [Commits](npm/ini@v1.3.5...v1.3.8)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump postcss from 7.0.34 to 7.0.36 (#113)

Bumps [postcss](https://github.com/postcss/postcss) from 7.0.34 to 7.0.36.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](postcss/postcss@7.0.34...7.0.36)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Changed the version number to 3.0.0

Co-authored-by: Lawrence Chen <lawrencechen14@gmail.com>
Co-authored-by: Hailey Jang <hailey_jang@berkeley.edu>
Co-authored-by: HaileyJang <55821834+HaileyJang@users.noreply.github.com>
Co-authored-by: Ashwin Vangipuram <ashwinvangipuram@gmail.com>
Co-authored-by: Ashwin Vangipuram <AVSurfer123@users.noreply.github.com>
Co-authored-by: Meshan Khosla <meshan02@gmail.com>
Co-authored-by: andrewecd <46904210+andrewecd@users.noreply.github.com>
Co-authored-by: lancejackson <ltjackson32@gmail.com>
Co-authored-by: Lance Jackson <lanceisajackson@berkeley.edu>
Co-authored-by: Thomas Lee <tcl171@gmail.com>
Co-authored-by: Hailey Jang <hailey.jang.01@gmail.com>
Co-authored-by: Ashish Pandian <pandianashish0@gmail.com>
Co-authored-by: uthmanmomen13 <livininthemomen13@gmail.com>
Co-authored-by: Uthman Momen <34070661+uthmanmomen13@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Meshan Khosla <meshankhosla@gmail.com>
  • Loading branch information
17 people authored Jun 17, 2021
1 parent 076a5f8 commit af4e5fa
Show file tree
Hide file tree
Showing 124 changed files with 10,288 additions and 3,816 deletions.
73 changes: 54 additions & 19 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,65 @@
{
"root": true,
"extends": "airbnb",
"globals": {
"VERSION": true,
"io": true
},
"env": {
"browser": true,
"mocha": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/errors",
"plugin:import/warnings",
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:react/recommended",
"prettier/react",
"prettier/standard",
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jsdoc",
"import",
"prettier",
"react-hooks"
],
"parserOptions": {
"project": ["tsconfig.json"],
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
"experimentalObjectRestSpread": true,
"jsx": true // Allows for the parsing of JSX
},
"sourceType": "module", // Allows for the use of imports
"ecmaVersion": 2020 // Allows for the parsing of modern ECMAScript features
},
"rules": {
"react/forbid-prop-types": "off",
"react/jsx-filename-extension": "off",
"react/no-string-refs": "off",
"react/require-default-props": "off",
"no-console": "off",
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies,

"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/require-await": "off",

// "comma-dangle": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"default-case": "off",
"import/extensions": "off",
"no-constant-condition": ["error", { "checkLoops": false }],
"no-param-reassign": "off",
"no-restricted-syntax": "off",
"no-underscore-dangle": "off",
"default-case": "off",
"react/jsx-closing-tag-location": "off"
"prettier/prettier": "error"
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".ts", ".tsx"]
}
},
"react": {
"version": "detect"
}
}
}
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ node_modules
.project
.settings
.idea/*

build
.vscode/

*.log
*~

# Dawn build
build/
dawn-packaged/
123 changes: 0 additions & 123 deletions fake-runtime/FakeRuntime.js

This file was deleted.

94 changes: 94 additions & 0 deletions fake-runtime/FakeRuntime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Fake Runtime is not handled by webpack like most of the other JS code but instead
* will be run "as is" as a child-process of the rest of the application.
* See DebugMenu.js for handling FakeRuntime within Dawn
*/

/* eslint-disable camelcase */
import { DevData, IParam, IDevice, IDevData } from '../protos/protos';
import { createSocket, Socket as UDPSocket } from 'dgram';
import { createServer, Server as TCPServer } from 'net';

const TCP_PORT = 8101;
const UDP_SEND_PORT = 9001;
const UDP_LISTEN_PORT = 9000;
const MSG_INTERVAL_MSEC = 50;

const randomFloat = (min: number, max: number) => (max - min) * Math.random() + min;
const sensor = (name: string, type: number, params: IParam[], uid: number): IDevice => ({
name,
type,
params,
uid,
});

const param = (name: string, type: string, value: any): IParam => ({
// eslint-disable-line no-shadow
name,
fval: type === 'float' ? value : undefined,
ival: type === 'int' ? value : undefined,
bval: type === 'bool' ? value : undefined,
});

const print = (output: string) => {
console.log(`Fake Runtime: ${output}`);
};

class FakeRuntime {
sendSocket: UDPSocket;
listenSocket: UDPSocket;
tcpServer: TCPServer;

constructor() {
this.sendSocket = createSocket({ type: 'udp4', reuseAddr: true });
this.listenSocket = createSocket({ type: 'udp4', reuseAddr: true });

this.listenSocket.on('message', (_msg: any) => {
// TODO: Handle UDP gamepad recv
});
this.listenSocket.bind(UDP_LISTEN_PORT);

this.tcpServer = createServer((_c: any) => {
print('client connected');
});
this.tcpServer.listen(TCP_PORT, () => {
print('server bound');
})

setInterval(this.onInterval, MSG_INTERVAL_MSEC);
}

generateFakeData = () => {
return {
devices: [
sensor('MOTOR_SCALAR', 0, [param('Val', 'float', randomFloat(-100, 100))], 100),
sensor('MOTOR_SCALAR', 0, [param('Val', 'float', randomFloat(-100, 100))], 101),
sensor('LimitSwitch', 3, [param('Val', 'int', Math.round(randomFloat(0, 1)))], 102),
sensor('SENSOR_SCALAR', 2, [param('Val', 'float', randomFloat(-100, 100))], 103),
sensor(
'SENSOR_SCALAR',
2,
[
param('Val 1', 'float', randomFloat(-100, 100)),
param('Val 2', 'float', randomFloat(-100, 100)),
param('Val 3', 'float', randomFloat(-100, 100)),
],
104
),
sensor('SENSOR_BOOLEAN', 1, [param('Val', 'bool', Math.random() < 0.5)], 105),

// Special Cases handled in dawn/renderer/reducers/peripherals.js
// sensor('Ignored', 5, [param('major', 'int', 1), param('minor', 'int', 2), param('patch', 'int', 3)], -1),
// sensor('Ignored', 5, [param('is_unsafe', 'bool', Math.random() < 0.5), param('v_batt', 'float', randomFloat(0, 15))], 0),
],
};
}

onInterval = () => {
const fakeData: IDevData = this.generateFakeData();
this.sendSocket.send(DevData.encode(fakeData).finish(), UDP_SEND_PORT, 'localhost');
// TODO: Handle TCP writes to console
}
}

new FakeRuntime();
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Defines the Dawn menu
*/

import { app } from 'electron';
import { app, MenuItemConstructorOptions } from 'electron';
import RendererBridge from '../RendererBridge';

const DawnMenu = {
const DawnMenu: MenuItemConstructorOptions = {
label: 'Dawn',
submenu: [
{
Expand Down
25 changes: 15 additions & 10 deletions main/MenuTemplate/DebugMenu.js → main/MenuTemplate/DebugMenu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { fork } from 'child_process';
import { fork, ChildProcess } from 'child_process';
import RendererBridge from '../RendererBridge';
import FCObject from '../networking/FieldControl';
import { FCObject } from '../networking/FieldControl';
import { MenuItemConstructorOptions } from 'electron';

let fakeRuntime = null;
let fakeRuntime: ChildProcess | null = null;

export function killFakeRuntime() {
if (fakeRuntime) {
Expand All @@ -12,13 +13,13 @@ export function killFakeRuntime() {
}
}

const DebugMenu = {
const DebugMenu: MenuItemConstructorOptions = {
label: 'Debug',
submenu: [
{
label: 'Toggle DevTools',
click() {
RendererBridge.registeredWindow.webContents.toggleDevTools();
RendererBridge.toggleWindowDevtools('main');
},
accelerator: 'CommandOrControl+alt+I',
},
Expand All @@ -33,8 +34,12 @@ const DebugMenu = {
{
label: 'Restart FC',
click() {
FCObject.FCInternal.quit();
FCObject.setup();
if (FCObject.FCInternal !== null) {
FCObject.FCInternal.quit();
FCObject.setup();
} else {
console.log('Field Control not active');
}
},
},
{
Expand All @@ -50,7 +55,7 @@ const DebugMenu = {
label: 'Reload',
accelerator: 'CommandOrControl+R',
click() {
RendererBridge.registeredWindow.reload();
RendererBridge.reloadWindow('main');
},
},

Expand All @@ -66,13 +71,13 @@ const DebugMenu = {
};

if (process.env.NODE_ENV === 'development') {
DebugMenu.submenu.push({
(DebugMenu.submenu as MenuItemConstructorOptions[]).push({ // Need to type cast since submenu's type isn't always array
label: 'Toggle Fake Runtime',
click() {
if (fakeRuntime) {
killFakeRuntime();
} else {
fakeRuntime = fork('./fake-runtime/FakeRuntime');
fakeRuntime = fork('./fake-runtime/FakeRuntime.ts', [], { execArgv: ['-r', 'ts-node/register']});
}
},
});
Expand Down
Loading

0 comments on commit af4e5fa

Please sign in to comment.