Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
feat: show device and roaming information
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Aug 13, 2019
1 parent 7df9228 commit 6b7467f
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 56 deletions.
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"fast-deep-equal": "^2.0.1",
"intro.js": "^2.9.3",
"leaflet": "^1.5.1",
"mcc-mnc-list": "git+https://github.com/bifravst/mcc-mnc-list.git#add-typescript-declarations",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-leaflet": "^2.4.0",
Expand Down
13 changes: 11 additions & 2 deletions src/Cat/Cat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,26 @@
justify-content: space-between;
font-size: 85%;
opacity: 0.75;
span.time {
span.reportedTime {
font-size: 85%;
opacity: 0.75;
}
& + div {
margin-top: 0.5rem;
}
}
}
.card-body {
h3 {
font-size: 115%;
margin: 0;
}
h4 {
font-size: 105%;
}
.device-information {
margin-top: 1rem;
}
}
}
div.noMap {
Expand All @@ -42,4 +51,4 @@ div.noMap {
height: 250px;
justify-content: space-around;
align-items: center;
}
}
96 changes: 43 additions & 53 deletions src/Cat/Cat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import Athena from 'aws-sdk/clients/athena'
import { Loading } from '../Loading/Loading'
import { Error } from '../Error/Error'
import { device } from 'aws-iot-device-sdk'
import { RelativeTime } from '../RelativeTime/RelativeTime'
import { Map } from '../Map/Map'
import {
AccessTimeRounded as TimeIcon,
BatteryStdRounded as BatteryIcon,
CloudDone as CloudIcon,
DirectionsRun as SpeedIcon,
FitnessCenter as ActivityIcon,
Flight as AltitudeIcon,
Settings as SettingsIcon,
GpsOff as NoPositionIcon,
Settings as SettingsIcon,
Info as InfoIcon,
} from '@material-ui/icons'
import { AvatarPicker } from '../Avatar/AvatarPicker'
import { uploadAvatar } from './uploadAvatar'
Expand All @@ -28,43 +26,15 @@ import * as introJs from 'intro.js'
import { HistoricalDataChart } from '../HistoricalData/HistoricalDataChart'
import { Collapsable } from '../Collapsable/Collapsable'
import { HistoricalDataLoader } from '../HistoricalData/HistoricalDataLoader'
import { ConnectionInformation } from './ConnectionInformation'
import { DeviceInfo } from './DeviceInformation'
import { Settings } from './Settings'
import { ReportedTime } from './ReportedTime'

import './Cat.scss'

const intro = introJs()

const ReportedTime = ({
reportedAt,
receivedAt,
}: {
reportedAt: Date
receivedAt: Date
}) => {
try {
return (
<>
<TimeIcon />{' '}
<RelativeTime ts={reportedAt} key={reportedAt.toISOString()} />
{(receivedAt.getTime() - reportedAt.getTime()) / 1000 > 300 && (
<>
{' '}
<CloudIcon />{' '}
<RelativeTime ts={receivedAt} key={receivedAt.toISOString()} />
</>
)}
</>
)
} catch {
return (
<>
<CloudIcon />{' '}
<RelativeTime ts={receivedAt} key={receivedAt.toISOString()} />
</>
)
}
}

const ShowCat = ({
catId,
iot,
Expand Down Expand Up @@ -273,6 +243,12 @@ const ShowCat = ({
</h2>
{reported && (
<>
{reported.dev && reported.roam && (
<ConnectionInformation
device={reported.dev}
roaming={reported.roam}
/>
)}
{reported.gps && reported.gps.v && (
<div>
{reported.gps.v.spd && (
Expand All @@ -287,12 +263,10 @@ const ShowCat = ({
{Math.round(reported.gps.v.alt.value)}m
</span>
)}
<span className={'time'}>
<ReportedTime
receivedAt={reported.gps.v.lat.receivedAt}
reportedAt={new Date(reported.gps.ts.value)}
/>
</span>
<ReportedTime
receivedAt={reported.gps.v.lat.receivedAt}
reportedAt={new Date(reported.gps.ts.value)}
/>
</div>
)}
{reported.bat && reported.bat.v && (
Expand All @@ -301,12 +275,10 @@ const ShowCat = ({
<BatteryIcon />
{reported.bat.v.value / 1000}V
</span>
<span className={'time'}>
<ReportedTime
receivedAt={reported.bat.v.receivedAt}
reportedAt={new Date(reported.bat.ts.value)}
/>
</span>
<ReportedTime
receivedAt={reported.bat.v.receivedAt}
reportedAt={new Date(reported.bat.ts.value)}
/>
</div>
)}
</>
Expand Down Expand Up @@ -356,6 +328,26 @@ const ShowCat = ({
}}
/>
</Collapsable>
{reported && reported.dev && (
<>
<hr />
<Collapsable
id={'cat:information'}
title={
<h3>
<InfoIcon />
<span>Device Information</span>
</h3>
}
>
<DeviceInfo
key={`${cat.version}`}
device={reported.dev}
roaming={reported.roam}
/>
</Collapsable>
</>
)}
{reported && reported.acc && reported.acc.v && (
<>
<hr />
Expand All @@ -373,12 +365,10 @@ const ShowCat = ({
({ value }: { value: number }) => value,
)}
/>
<small>
<ReportedTime
reportedAt={new Date(reported.acc.ts.value)}
receivedAt={reported.acc.v[0].receivedAt}
/>
</small>
<ReportedTime
reportedAt={new Date(reported.acc.ts.value)}
receivedAt={reported.acc.v[0].receivedAt}
/>
</Collapsable>
</>
)}
Expand Down
104 changes: 104 additions & 0 deletions src/Cat/ConnectionInformation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from 'react'
import {
SignalCellularNull as SignalNotDetectedIcon,
SignalCellular0Bar as NoSignalIcon,
SignalCellular1Bar as OneBarIcon,
SignalCellular2Bar as TwoBarIcon,
SignalCellular3Bar as ThreeBarIcon,
SignalCellular4Bar as FourBarIcon,
SignalCellularConnectedNoInternet0Bar as InvalidRSRPIcon,
ImportExport as NetworkTypeIcon,
} from '@material-ui/icons'
import { filter as filterOperator, Operator as Op } from 'mcc-mnc-list'
import { ReportedTime } from './ReportedTime'
import { DeviceInformation, RoamingInformation } from './DeviceInformation'

/**
* Renders the Reference Signal Received Power (RSRP).
*
* RSRP is the average power level received from a single reference signal in an LTE (Long-term Evolution) network.
*
* 0: RSRP < −140 dBm
* 1: – When −140 dBm ≤ RSRP < −139 dBm
* 2: When −139 dBm ≤ RSRP < −138 dBm
* ..95: When −46 dBm ≤ RSRP < −45 dBm
* 96: When −45 dBm ≤ RSRP < −44 dBm
* 97: When −44 dBm ≤ RSRP
* 255: Not known or not detectable
*/
export const RSRP = ({
rsrp: { value, receivedAt },
}: {
rsrp: { value: number; receivedAt: Date }
}) => {
if (value === 255) {
return (
<abbr title={'Not known or not detectable'}>
<SignalNotDetectedIcon />
</abbr>
)
}
if (value >= 0 && value <= 140) {
const dbm = -140 + value
let icon = <FourBarIcon />
if (dbm <= 80) {
icon = <ThreeBarIcon />
} else if (dbm <= 90) {
icon = <TwoBarIcon />
} else if (dbm <= 100) {
icon = <OneBarIcon />
} else if (dbm <= 110) {
icon = <NoSignalIcon />
}
return <abbr title={`${dbm}dBm`}>{icon}</abbr>
}
return (
<abbr title={`Unexpected value ${value} reported!`}>
<InvalidRSRPIcon />
</abbr>
)
}

export const Operator = ({ op }: { op?: Op }) => (
<span className={'operator'}>
{!op && 'Unknown'}
{op && op.brand}
</span>
)

export const ConnectionInformation = ({
device,
roaming,
}: {
device: DeviceInformation
roaming: RoamingInformation
}) => {
console.log(roaming)
const {
v: {
rsrp,
mccmnc: { value: mccmnc },
},
} = roaming
const {
v: {
nw: { value: nw },
},
} = device
return (
<div className={'connection-information'}>
<span>
<RSRP rsrp={rsrp} />
<Operator op={filterOperator({ mccmnc: `${mccmnc}` })[0]} />
</span>
<span>
<NetworkTypeIcon />
{nw}
</span>
<ReportedTime
receivedAt={roaming.v.rsrp.receivedAt}
reportedAt={new Date(roaming.ts.value)}
/>
</div>
)
}
16 changes: 16 additions & 0 deletions src/Cat/DeviceInformation.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.device-information {
dl {
display: grid;
grid-template: auto / 1fr 3fr;
dt, dd {
font-weight: normal;
padding: 0;
margin: 0;
border-bottom: 1px solid #f0f0f0;
}
}
.reportedTime {
font-size: 85%;
opacity: 0.75;
}
}
Loading

0 comments on commit 6b7467f

Please sign in to comment.