# lu1cm0xx

> 京セラ製GPSマルチユニット'LU1CM0xx'シリーズをUART2系統無手順接続にて扱うためのライブラリです。

Latest version **0.4.0** (published 2020-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install lu1cm0xx
pnpm add lu1cm0xx
yarn add lu1cm0xx
bun add lu1cm0xx
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2020-04-16 |
| First published | 2020-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 48 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | TAL |
| Maintainers | talch |
| Keywords | LU1CM012, LU1CM013 |

## Links

- npm: https://www.npmjs.com/package/lu1cm0xx
- Repository: https://github.com/talch218/lu1cm0xx
- Homepage: https://github.com/talch218/lu1cm0xx#readme
- Issues: https://github.com/talch218/lu1cm0xx/issues
- npm.io page: https://npm.io/package/lu1cm0xx

## Dependencies (3)

- [rpi-gpio](https://npm.io/package/rpi-gpio.md) ^2.1.5
- [serialport](https://npm.io/package/serialport.md) ^8.0.7
- [@serialport/parser-readline](https://npm.io/package/@serialport/parser-readline.md) ^8.0.6

## Recent versions

- 0.4.0 (latest) — 2020-04-16
- 0.3.2 — 2020-04-16
- 0.3.1 — 2020-04-16

## README

# LU1CM0xx library for UART

[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)

This library is used for products that can be used only in Japan. Therefore, please forgive the explanation in Japanese.

## Summary
[京セラ製GPSマルチユニット][unit] 「LU1CM0xx」シリーズをUART2系統制御にて利用するためのライブラリです。


## Supported platforms
Raspberry Pi, Node.js v10.15.2で確認。
[serialport][serialport]で動作するUARTが2系統と、[rpi-gpio][gpio]で制御可能なGPIOが8本必要です。

## Getting started
### Hardware
UART2系統モデムモードでキッティングされたLU1CM0xxシリーズを下図のように配線してください。
キッティングに関しては、メーカーサポートでお願いします。

なおサンプルでは、下表のようにGPIOと接続し、Raspberry Piのブートコンフィグを次のように行っています。
各自の環境に合わせて、[マニュアル][manual]をもとにカスタムしてください。
特にRaspberry Piのバージョンが異なるとピン配置が異なるので注意してください。

|LU1CM側制御信号|Pin|Raspberry Pi側ピン番号（GPIO番号ではありません）|
|----------:|----|------|
|GND        | 1  | GND  |  
|UART1_CTS  | 2  | 23   |      
|UART1_DSR  | 3  | 12   |       
|UART1_RX   | 4  | 24   |      
|PSM_DISABLE| 5  | 11   |         
|(NC)       | 6  | (NC) |    
|UART2_RX   | 7  | 7    |     
|(NC)       | 8  | (NC) |    
|(NC)       | 9  | (NC) |    
|UART2_TX   | 10 | 29   |      
|UART1_TX   | 11 | 21   |       
|UART1_RTS  | 12 | 19   |        
|UART1_DCD  | 13 | 16   |        
|UART1_DTR  | 14 | 15   |        
|(NC)       | 15 | (NC) |     
|TE_UP      | 16 | 38   |    
|RESET_CHK  | 17 | 40   |        
|(NC)       | 18 | (NC) |     
|PSM_MON    | 19 | (NC) |        
|FUNC_SW    | 20 | 35   |      
|RESET      | 21 | 36   |    
|GND        | 22 | GND  |   


```bash:/boot/config.txt
# [all]セクションに下記を追加
enable_uart=1
dtoverlay=uart4,ctsrts
dtoverlay=uart3
```

### Setup
```bash
npm install --save lu1cm0xx
```

ポートコンフィグファイル
```json:port_config.json
{
	"UART1_DTR": 15,
	"UART1_DCD": 16,
	"TE_UP": 38,
	"RESET_CHK": 40,

	"PSM_DISABLE": 11,
	"UART1_DSR": 12,
	"FUNC_SW": 35,
	"RESET": 36,
	
	"signal_uart": "/dev/ttyAMA1",
	"data_uart": "/dev/ttyAMA2"
}
```

### Get Location
精度5m以内、タイムアウト120秒として、位置情報を取得する

```node
const { Status, By2UART } = require('lu1cm0xx');
const config = require('./port_config.json');

const status = new Status(config);

const print_pin_status_message = (value, pin) => log(pin.description[value + 0]);

status.on('UART1_DCD', print_pin_status_message);
status.on('RESET_CHK', print_pin_status_message);

const signal_port = config.signal_uart;
const data_port = config.data_uart;

const gps_unit = new By2UART(signal_port, data_port, status, { echo: { command: true, location: false, result: true } });

(async () => {
    console.log('GPIOの初期化: ' + await status.wait().then(_ => _).catch(_ => _));
    console.log('UARTの初期化: ' + await gps_unit.wait().then(_ => _).catch(_ => _));

    console.log(
        await gps_unit.getLocation(2, 2 * 60 * 1000).then(location => {
            return `[${location.success}](${location.datetime.toISOString()}) `
                 + `緯度: ${location.latitude}°, 経度: ${location.longitude}°, `
                 + `精度: ${location.accuracy}m`;
        }).catch(err => `位置情報取得失敗: ${err}`));
    await gps_unit.close();
})();
```

### Write SSL Certificates
HTTPS通信を行うのに必要です。（整備中）

### Post Http(s) Request
POSTメソッドでWebサーバーにデータを送信する。
（実際に[Google][google]へアクセスすると8kb程度の通信が発生します。）

```node
const { Status, By2UART } = require('lu1cm0xx');
const config = require('./port_config.json');

const status = new Status(config);

const log = text => console.log(`[${new Date().toISOString()}] ${text}`);


const print_pin_status_message = (value, pin) => log(pin.description[value + 0]);

status.on('UART1_DCD', print_pin_status_message);
status.on('RESET_CHK', print_pin_status_message);

const gps_unit = new By2UART(config.signal_uart, config.data_uart, status, { echo: true });

(async () => {
    console.log('GPIOの初期化: ' + await status.wait().then(_ => _).catch(_ => _));
    console.log('UARTの初期化: ' + await gps_unit.wait().then(_ => _).catch(_ => _));

    console.log(await status.wait().then(_ => true).catch(_ => false));

    console.log(await gps_unit.getUserDatetime().catch(_ => _));
    await gps_unit.setUserDatetime(new Date());
    console.log(await gps_unit.getNetworkDatetime().catch(_ => _));
    console.log(await gps_unit.getUserDatetime().catch(_ => _));

    console.log(await gps_unit.getSignalQuality().catch(_ => _));

    console.log(await gps_unit.isRadioDisabled().catch(_ => _));
    const temperature = await gps_unit.getTemperature().catch(_ => _);

    console.log(await gps_unit.getModelName().catch(_ => _));
    console.log(await gps_unit.getVersion().catch(_ => _));
    console.log(await gps_unit.getIMEI().catch(_ => 'IMEI取得エラー'));

    console.log(await gps_unit.requestHttp('https://www.google.com', 'POST', {
        message:'Hello, world',
        temperature,
      }).then(data => {
        data.body.content = data.body.content.toString('utf8');
        return data;
      }).catch(err => `HTTPリクエスト失敗: ${err}`));

    await gps_unit.close();
})();
```


[unit]:https://www.kyocera.co.jp/prdct/telecom/office/iot/products/gps_multiunit.html
[serialport]:https://www.npmjs.com/package/serialport
[gpio]:https://www.npmjs.com/package/rpi-gpio
[manual]:https://www.kyocera.co.jp/prdct/telecom/office/iot/development/download/index.html

---
_Source: https://npm.io/package/lu1cm0xx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
