Skip to content

Commit

Permalink
Merge pull request #8 from lromeraj/dev
Browse files Browse the repository at this point in the history
Logger improvements
  • Loading branch information
lromeraj authored Nov 22, 2023
2 parents c5a9a9f + 3eb2d2b commit 836a9b9
Show file tree
Hide file tree
Showing 84 changed files with 11,002 additions and 1,007 deletions.
9,927 changes: 9,927 additions & 0 deletions -la

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
variables:
# GIT_CLONE_PATH: $CI_BUILDS_DIR/cloudflare-dns # https://stackoverflow.com/questions/64089704/gitlab-runner-change-builds-dir
# GIT_CLEAN_FLAGS: none # https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4154
# GIT_SUBMODULE_STRATEGY: recursive # https://docs.gitlab.com/ee/ci/git_submodules.html#use-git-submodules-in-cicd-jobs

stages:
- build
- test
- deploy

tests:
stage: test
image: node:16-slim
script:
- npm i
- npm run test
only:
- dev
tags:
- docker
1 change: 0 additions & 1 deletion 960x.js

This file was deleted.

100 changes: 48 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,36 @@ The core of this emulator is also exposed in order to be reused for more specifi
> **NOTE**: currently, there is no documentation available for core utils. Depending on how useful this emulator is for the community, I will consider adding extra documentation for that purpose.
# Building the emulator
Before building this emulator you'll need to install `NodeJS` environment (which you probably have already installed) but in case you don't, you can simply do:

> **NOTE**: the following instructions assume you are working from Ubuntu. If you need specific instructions for your OS, search in Google how to install `Node JS v16.x`.
> **NOTE**: before building this emulator, ensure you have the Node JS environment installed (which you likely already have). In case it's not installed, you can [follow these instructions](https://github.com/nodesource/distributions#installation-instructions) for Debian-based systems. For other systems, please search on Google for instructions on how to install Node JS on your specific platform.
If `node` and `npm` are accessible from your path, now you can install all required dependencies:
``` bash
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
npm install
```

If you don't feel comfortable with a direct "blind" install, please check the content:
After install succeeds, build all application scripts with the following command:
``` bash
nano nodesource_setup.sh
npm run build
```

Finally install it:
``` bash
sudo bash nodesource_setup.sh
```

If `node` and `npm` are accesible from your path, now you can build the entire project by going to the root of this repository and executing:
``` bash
npm i
```
Thats all. Now, the symlinks named `gss.js` and `960x.js` should be pointing to a valid JavaScript file inside the `build/` directory.
Thats all. Now, under the `exe/` directory all symlinks should be pointing to a valid JavaScript file inside the `build/` directory.

If you want to run those scripts simply tell `node` to execute them, like:
``` bash
node gss.js
node exe/gss.js
```

For more details, see [how to run the emulator](#running-the-emulator).

# Setting up the environment
Apart from the emulator itself, this repository also includes additional _CLI_ tools as you'll see in the following sections, so, instead of having to specify the full path of the different scripts or making additional installation steps, you can use the `isbd-env.sh` script located in the root of this repository to load all required environment variables and bash completions. Use the following command to load the Iridium SBD environment:
Apart from the emulator itself, this repository also contains additional _CLI_ tools, as detailed in the following sections. Instead of specifying the full path for various scripts or undergoing additional installation steps, utilize the `isbd-env.sh` script found at the repository's root to load all necessary environment variables and bash completions. Execute the following command to load the Iridium SBD environment:

``` bash
source isbd-env.sh
```

> **NOTE**: if you want to avoid to load the environment each time you open a new terminal, you can use `.bashrc` file located in the home directory of your current user and automatically load the Iridium SBD environment.
> **NOTE**: to avoid loading the environment each time you open a new terminal, you can utilize the `.bashrc` file located in the home directory of your current user. This allows for the automatic loading of the Iridium SBD environment.
Now you should be able to execute things like:
``` bash
Expand Down Expand Up @@ -116,13 +108,14 @@ Usage: 960x [options]
A simple emulator for Iridium SBD 960X transceivers
Options:
-V, --version output the version number
-p, --path <string> serial port path
-i, --imei <string> set ISU IMEI (default: "527695889002193")
--gss-host <string> GSS Socket host (default: "localhost")
--gss-port <string> GSS Socket port (default: 10801)
--gss-uri <string> GSS Socket URI
-h, --help display help for command
-V, --version output the version number
-l, --log-level <number> Set logging level: 1, 2, 3, 4 (default: 3)
-d, --device <string> Serial port path
--imei <string> Configure custom IMEI (default: "527695889002193")
--gss-host <string> GSS Socket host (default: "localhost")
--gss-port <string> GSS Socket port (default: 10802)
--gss-uri <string> GSS Socket URI
-h, --help display help for command
```

To finally run the `960x.js` emulator you need to create a virtual serial port in order to communicate with it, you can use `socat` to achieve that:
Expand All @@ -133,12 +126,12 @@ socat -dd pty,link=/tmp/tty,raw,echo=0 pty,link=/tmp/960x,raw,echo=0

Leave this executing in the foreground or in a different terminal. Now you can execute:
``` bash
isbd 960x -vvv -p /tmp/960x
isbd 960x -l4 -d /tmp/960x
```

You should see an output like:
``` txt
2023-04-28T18:16:57.373Z [ OK ] @ at-interface: AT Interface ready
[INF] ../at/interface.js: AT interface ready on /tmp/960x
```
Now you can communicate with it, using, for example, `minicom`:
``` bash
Expand Down Expand Up @@ -166,14 +159,14 @@ OK

Now we have to start the _GSS_ in order to allow the modem to send (_MO_) and receive (_MT_) messages.
``` bash
isbd gss -vvv
isbd gss -l4
```

This will output something like:
``` bash
2023-04-28T18:21:31.871Z [WARN] @ main: No MO transports defined
2023-04-28T18:21:31.877Z [ OK ] @ isu-server: ISU server ready, port=10802
2023-04-28T18:21:31.877Z [ OK ] @ mt-server: MT server ready, port=10800
[INF] ../scripts/gss.js: Using MO TCP transport: localhost:10801
[INF] ../gss/servers/isu/index.js: ISU server ready, port: 10802
[INF] ../gss/servers/mt/index.js: MT server ready, port: 10800
```

If you are still running the `960x` program the _ISU_ will connect automatically to the _GSS_ (like if a satellite was reachable).
Expand All @@ -184,17 +177,17 @@ This emulator **supports two types of _MO_ transports**: `TCP` and `SMTP` (same
``` txt
Usage: gss [options]
A simple emulator for Iridium GSS
A simple emulator for Iridium SBD GSS
Options:
-V, --version output the version number
-v, --verbose Verbosity level
-l, --log-level <number> Set logging level: 1, 2, 3, 4 (default: 3)
--mo-smtp-host <string> MO SMTP transport host
--mo-smtp-port <number> MO SMTP transport port (default: 25)
--mo-smtp-user <string> MO SMTP transport username
--mo-smtp-password <string> MO SMTP transport password
--mo-smtp-to <string> MO SMTP transport destination address
--mo-tcp-host <string> MO TCP transport host
--mo-tcp-host <string> MO TCP transport host (default: "localhost")
--mo-tcp-port <number> MO TCP transport port (default: 10801)
--mt-server-port <number> MT server port (default: 10800)
--mo-server-port <number> MO server port (default: 10802)
Expand All @@ -203,7 +196,7 @@ Options:

If you want to setup _MO_ transport as _SMTP_ you'll have to specify (at least): `--mo-smtp-host` and `--mo-smtp-user` options:
``` bash
isbd gss -vvv \
isbd gss -l4 \
--mo-smtp-host smtp.domain.com \
--mo-smtp-user your@email.com
```
Expand All @@ -213,7 +206,7 @@ isbd gss -vvv \

If you want to use the _MO_ transport as _TCP_, you'll need a running instance of [Iridium Direct IP compatible server](https://github.com/lromeraj/isbd-server). The required option to enable _TCP_ transport is `--mo-tcp-host`, the port is `10801` by default. For example:
``` bash
isbd gss -vvv \
isbd gss -l4 \
--mo-tcp-host localhost \
--mo-tcp-port 10801
```
Expand All @@ -228,7 +221,7 @@ Currently you can achieve the same, but requires a few extra steps:

Now you can execute the Iridium GSS using Gmail's _SMTP_:
``` bash
isbd gss -vvv \
isbd gss -l4 \
--mo-smtp-host smtp.gmail.com \
--mo-smtp-user example@gmail.com \
--mo-smtp-password XXXXXXXXXXXXXXXX
Expand Down Expand Up @@ -282,18 +275,19 @@ Usage: encode [options] [file]
Message encoder for Iridium SBD
Arguments:
file JSON message file
file JSON message file
Options:
-V, --version output the version number
-h, --help display help for command
-V, --version output the version number
-l, --log-level <number> Set logging level: 1, 2, 3, 4 (default: 3)
-h, --help display help for command
```
This script expects an input formatted in JSON, depending on the attributes of the given JSON it will detect if it is a _MO_ message or a _MT_ message.
### Encoding MT messages
If you want to encode a _MT_ message with payload you'll have to specify at least the header and the payload:
If you want to encode a _MT_ message with a payload you'll have to specify at least the header and the payload Information Elements (IEs):
``` json
{
"header": {
Expand Down Expand Up @@ -346,7 +340,7 @@ This message will flush the _MT_ message queue in the GSS.
You can invoke to the decoder using the following command:
``` bash
isbd decoder --help
isbd decode --help
```
This will result in:
Expand All @@ -356,12 +350,13 @@ Usage: decode [options] [file]
Message decoder for Iridium SBD
Arguments:
file SBD message file path
file SBD message file path
Options:
-V, --version output the version number
--pretty Output will be more human readable
-h, --help display help for command
-V, --version output the version number
-l, --log-level <number> Set logging level: 1, 2, 3, 4 (default: 3)
--pretty Output will be more human readable
-h, --help display help for command
```
If you want to decode a message, just give the binary file to the decoder and it will detect automatically if it is a _MT_ message or a _MO_ message.
Expand Down Expand Up @@ -419,13 +414,14 @@ Usage: transport [options] [file]
Iridium SBD message transporter
Arguments:
file SBD binary message file
file SBD binary message file
Options:
-V, --version output the version number
--tcp-host <string> TCP transport host (default: "localhost")
--tcp-port <number> TCP transport port (default: 10800)
-h, --help display help for command
-V, --version output the version number
-l, --log-level <number> Set logging level: 1, 2, 3, 4 (default: 3)
--tcp-host <string> TCP transport host (default: "localhost")
--tcp-port <number> TCP transport port (default: 10800)
-h, --help display help for command
```
## Sending a MT message
Expand Down Expand Up @@ -495,7 +491,7 @@ If all of the execution chain succeeds, you should see an output like the follow
2023-05-02T21:55:16.957Z [ OK ] decoder main: Message successfully decoded
```

# General GSS behavior
# General GSS and ISU behaviors

Here we'll describe how the Iridium SBD emulator operates depending on different conditions:
Expand Down
14 changes: 0 additions & 14 deletions ascii/gss.txt

This file was deleted.

1 change: 0 additions & 1 deletion decode.js

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion dist/src/at/cmd.js → dist/at/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.ATCmd = void 0;
const logger = __importStar(require("../logger"));
const log = logger.create('at-cmd');
const log = logger.create(__filename);
class ATCmd {
constructor(name, context) {
this.cmdHandlers = {};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions dist/src/at/interface.js → dist/at/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var ATIStatus;
ATIStatus[ATIStatus["PROCESSING"] = 1] = "PROCESSING";
})(ATIStatus || (ATIStatus = {}));
;
const log = logger.create('at-interface');
const log = logger.create(__filename);
class ATInterface {
constructor(serialPortOpts) {
this.commands = [];
Expand All @@ -52,15 +52,15 @@ class ATInterface {
this.requestBuffer = [];
this.enqueuedLines = {};
this.sp = new serialport_1.SerialPort({
path: serialPortOpts.path || '/dev/null',
path: serialPortOpts.path || '/tmp/tty',
baudRate: serialPortOpts.baudRate || 115200,
autoOpen: typeof serialPortOpts.path === 'string',
}, err => {
if (err) {
log.error(err.message);
log.error(`AT interface failed on ${colors_1.default.red(this.sp.path)}: ${err.message}`);
}
else {
log.success(`AT Interface ready`);
log.info(`AT interface ready on ${colors_1.default.yellow(this.sp.path)}`);
}
});
this.sp.on('data', (buffer) => {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/src/gss/index.js → dist/gss/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const colors_1 = __importDefault(require("colors"));
const isu_1 = require("./servers/isu");
const mt_1 = require("./servers/mt");
const msg_1 = require("./msg");
const log = logger.create('gss');
const log = logger.create(__filename);
class GSS {
constructor(options) {
this.autoId = 0;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const socket_io_1 = __importDefault(require("socket.io"));
const colors_1 = __importDefault(require("colors"));
const events_1 = __importDefault(require("events"));
const logger = __importStar(require("../../../logger"));
const log = logger.create('isu-server');
const log = logger.create(__filename);
// https://stackoverflow.com/a/39145058
// export declare interface SUServer {
// on(
Expand All @@ -54,7 +54,7 @@ class ISUServer extends events_1.default {
this.httpServer = http_1.default.createServer();
this.socketServer = new socket_io_1.default.Server(this.httpServer);
this.httpServer.listen(options.port, () => {
log.success(`ISU server ready, port: ${colors_1.default.yellow(options.port.toString())}`);
log.info(`ISU server ready, port: ${colors_1.default.yellow(options.port.toString())}`);
});
this.socketServer.on('connect', socket => {
const imei = socket.handshake.query.imei;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const logger = __importStar(require("../../../logger"));
const fastq_1 = __importDefault(require("fastq"));
const decoder_1 = require("../../msg/decoder");
const encoder_1 = require("../../msg/encoder");
const log = logger.create('mt-server');
const log = logger.create(__filename);
class MTServer extends events_1.EventEmitter {
constructor(options) {
super();
Expand All @@ -54,7 +54,7 @@ class MTServer extends events_1.EventEmitter {
this.mtMsgQueue = fastq_1.default.promise(this.mtMsgWorker.bind(this), 1);
this.tcpServer = net_1.default.createServer();
this.tcpServer.listen(options.port, () => {
log.success(`MT server ready, port: ${colors_1.default.yellow(options.port.toString())}`);
log.info(`MT server ready, port: ${colors_1.default.yellow(options.port.toString())}`);
});
this.tcpServer.on('connection', this.socketHandler.bind(this));
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/src/isu/960x.js → dist/isu/960x.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const logger = __importStar(require("../logger"));
const interface_1 = require("../at/interface");
const commands_1 = require("./commands");
const sio = __importStar(require("socket.io-client"));
const log = logger.create(__filename);
;
const log = logger.create('960x');
// TODO: create a parent class named Modem and rename this to SBDModem
class Modem {
updateCIEV(ciev) {
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions dist/src/logger.d.ts → dist/logger.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { LeveledLogMethod, Logger } from "winston";
import { Logger } from "winston";
interface CustomLogger extends Logger {
success: LeveledLogMethod;
setLevel: (lvl: number | string) => CustomLogger;
}
export declare const levels: {
[key: string]: number;
};
declare const logger: CustomLogger;
export declare function disableTTY(): CustomLogger;
export declare function setLevel(targetLevel: number | string): CustomLogger;
export declare function create(moduleName?: string): CustomLogger;
export declare function setProgramName(name: string): void;
export declare function create(moduleName: string): CustomLogger;
export default logger;
Loading

0 comments on commit 836a9b9

Please sign in to comment.