第三章:使用你的JayBox 主板

2020, Oct 19    

这篇文章是介器开源十一章节PlayBook的一部分,欢迎来给我们的提PR,我们的git地址是:https://github.com/Jieqiio/BaseJay/wiki


如何使用您的工业边缘计算单元:第三章:使用你的JayBox 主板

JayBox的主板和其他的linux主板类似,都是基于linux内核开发的系统,这个系统我们称之为BlueJayOS。使用的是高通的4G处理器,因此使用的是内核是基于高通定制的linux内核。

1. 登录终端

如果您是使用Linux,Mac电脑,则将电脑的网线接口插入到JayBox 主板,如果没有的话,需要购买一个USB/Type-C转千兆网口的转接器,电脑会自动获得IP地址,JayBox 主板的默认IP是10.100.1.254,用户名是xguard或者root,密码都是jieqi

登录后可以查看JayBox嵌入式系统的相关信息:

CPU信息

root@localhost:~# cat /proc/cpuinfo
processor	: 0
model name	: ARMv7 Processor rev 5 (v7l)
BogoMIPS	: 38.40
Features	: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xc07
CPU revision	: 5

Hardware	: Qualcomm Technologies, Inc MDM9607
Revision	: 0000
Serial		: 0000000000000000
Processor	: ARMv7 Processor rev 5 (v7l)

系统信息

root@localhost:~# uname -a
Linux localhost 3.18.20 #1 PREEMPT Mon Sep 2 14:34:31 CST 2019 armv7l GNU/Linux
root@localhost:~# cat /proc/version
Linux version 3.18.20 (release@jieqi.io) (gcc version 4.9.2 (GCC) ) #1 PREEMPT Mon Sep 2 14:34:31 CST 2019

内存信息

root@localhost:~# free
             total         used         free       shared      buffers
Mem:        157012       108964        48048          172            0
-/+ buffers:             108964        48048
Swap:            0            0            0
root@localhost:~# cat /proc/meminfo
MemTotal:         157012 kB
MemFree:           48080 kB
MemAvailable:     106732 kB
Buffers:               0 kB
Cached:            58704 kB
SwapCached:            0 kB
Active:            66416 kB
Inactive:           9496 kB
Active(anon):      17232 kB
Inactive(anon):      148 kB
Active(file):      49184 kB
Inactive(file):     9348 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:         17232 kB
Mapped:             8100 kB
Shmem:               172 kB
Slab:              15384 kB
SReclaimable:       6024 kB
SUnreclaim:         9360 kB
KernelStack:        2176 kB
PageTables:         1488 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:       78504 kB
Committed_AS:     992240 kB
VmallocTotal:     761856 kB
VmallocUsed:       30464 kB
VmallocChunk:     722940 kB

存储空间

root@localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
ubi0:rootfs              72.1M     46.1M     26.0M  64% /
tmpfs                    64.0K      4.0K     60.0K   6% /dev
tmpfs                    76.3M     32.0K     76.3M   0% /run
tmpfs                    76.3M     72.0K     76.3M   0% /var/volatile
tmpfs                    76.3M         0     76.3M   0% /media/ram
ubi0:usrfs                8.6M     36.0K      8.6M   0% /data
/dev/ubi1_0              38.8M     31.3M      7.5M  81% /firmware
ubi2:appfs               15.2M     24.0K     15.2M   0% /vendor/app
ubi2:datafs              63.6M     10.4M     53.2M  16% /vendor/data
ubi0:cachefs             58.3M     24.0K     55.3M   0% /cache

网络信息

JayBox主板不带Wifi,含有两个网络端口LAN和WAN,同时自带4G,标准版的主板不带eSIM,用户可以自己使用SIM卡,有没有4G,会体现在rmnet_data0这个网络适配器上,以下的的状态说明4G是正常连接中,JayBox检查到eSIM或者SIM卡后,会自动连接。

root@localhost:/bin# ifconfig
bridge0   Link encap:Ethernet  HWaddr 22:0C:E6:EC:B7:4F
          inet addr:192.168.1.254  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::200c:e6ff:fee9:b44c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2770 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2596 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:231954 (226.5 KiB)  TX bytes:196048 (191.4 KiB)

eth0      Link encap:Ethernet  HWaddr 6E:80:A8:BA:D1:30
          inet6 addr: fe80::6c80:a8ff:feba:d130/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3051 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3701 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:350829 (342.6 KiB)  TX bytes:339391 (331.4 KiB)
          Interrupt:108

eth0.1    Link encap:Ethernet  HWaddr 6E:80:A8:BA:D1:31
          inet addr:169.254.4.1  Bcast:169.254.4.255  Mask:255.255.255.0
          inet6 addr: fe80::6c80:a8ff:feba:d131/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3051 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2556 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:295911 (288.9 KiB)  TX bytes:228848 (223.4 KiB)

eth0.3    Link encap:Ethernet  HWaddr 6E:80:A8:BA:D1:33
          inet addr:169.254.5.1  Bcast:169.254.5.255  Mask:255.255.255.0
          inet6 addr: fe80::6c80:a8ff:feba:d133/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1136 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:65975 (64.4 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:33 errors:0 dropped:0 overruns:0 frame:0
          TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2604 (2.5 KiB)  TX bytes:2604 (2.5 KiB)

rmnet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          UP RUNNING  MTU:2000  Metric:1
          RX packets:622 errors:0 dropped:0 overruns:0 frame:0
          TX packets:745 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:81236 (79.3 KiB)  TX bytes:71936 (70.2 KiB)

rmnet_data0 Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.42.120.164  Mask:255.255.255.248
          inet6 addr: fe80::ea9c:f228:6c01:2574/64 Scope:Link
          UP RUNNING  MTU:1500  Metric:1
          RX packets:622 errors:0 dropped:0 overruns:0 frame:0
          TX packets:745 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:75522 (73.7 KiB)  TX bytes:71936 (70.2 KiB)

2. 格式化EMMC

JayBox 标准配备有一颗8GB Toshiba 出品的工业级 Premium 级别的eMMC, 版本是5.1, 采用15nm工艺制造,最大数据传输速度是400MB/s ,工作温度是工业级的 -25 ̊C~85 ̊C, 目前的初始化系统没有格式化EMMC,首次使用需要先进行格式化,并制作文件系统后才能挂载使用。

2.1 确认EMMC已加载

ls /dev/mmcb*
/dev/mmcblk0      /dev/mmcblk0rpmb

2.2 创建分区

fdisk /dev/mmcblk0

The number of cylinders for this disk is set to 238592.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n (输入n,添加新分区)

Command action
   e   extended
   p   primary partition (1-4)
p (输入p,添加新分区为主分区)
Partition number (1-4): 1 (输入1,添加分区号为1)

First cylinder (1-238592, default 1): (回车,使用默认值)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-238592, default 238592): (回车,使用默认值)
Using default value 238592

Command (m for help): w (输入w,回写分区信息并退出程序)

The partition table has been altered.
Calling ioctl() to re-read partition table

2.3 查看块设备

上一步骤完成后会新生成一个mmcblk0p1的块设备,如下

ls /dev/mmc*
/dev/mmcblk0      /dev/mmcblk0p1    /dev/mmcblk0rpmb

2.4.制作ext4文件系统

mkfs.ext4 /dev/mmcblk0p1
root@localhost:~# mkfs.ext4 /dev/mmcblk0p1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
477664 inodes, 1908734 blocks
95436 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1954545664
59 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done

2.5.挂载

手动挂载命令,

mount -t ext4 /dev/mmcblk0p1 /media/card
root@localhost:~# df -h
Filesystem                Size      Used Available Use% Mounted on
ubi0:rootfs              72.1M     45.8M     26.3M  63% /
tmpfs                    64.0K      4.0K     60.0K   6% /dev
tmpfs                    76.3M     32.0K     76.3M   0% /run
tmpfs                    76.3M     72.0K     76.3M   0% /var/volatile
tmpfs                    76.3M         0     76.3M   0% /media/ram
ubi0:usrfs                8.6M     36.0K      8.6M   0% /data
/dev/ubi1_0              38.8M     31.3M      7.5M  81% /firmware
ubi2:appfs               15.2M     24.0K     15.2M   0% /vendor/app
ubi2:datafs              63.6M     10.4M     53.2M  16% /vendor/data
ubi0:cachefs             58.3M     24.0K     55.3M   0% /cache
/dev/mmcblk0p1            7.0G     16.4M      6.6G   0% /media/card

或重启设备,由系统开机自动挂载。

挂载完毕后,可以看到一个/media/card的分区,可用大小是6.6GB,接下就可以使用了。

3. 使用python

BlueJayOS内置2个版本的python,系统默认的是python2.7.9:

root@localhost:~# python
python             python2            python2.7          python3            python3.4          python3.4m

Python2.7.9的相关信息和默认安装包

root@localhost:~# python
Python 2.7.9 (default, Sep  2 2019, 14:41:50)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys as s
>>> s.modules.keys()
['copy_reg', 'sre_compile', '_sre', 'site', '__builtin__', 'sysconfig', 'atexit', '__main__', 'abc', 'posixpath', '_weakrefset', 'errno', 'sre_constants', 're', '_abcoll', 'types', '_warnings', 'genericpath', 'stat', 'zipimport', '_sysconfigdata', 'warnings', 'UserDict', 'sys', 'readline', 'os.path', 'sitecustomize', 'rlcompleter', 'signal', 'traceback', 'linecache', 'posix', 'exceptions', 'sre_parse', 'os', '_weakref']

Python3.4.3 的相关信息和默认安装包

root@localhost:~# python3
Python 3.4.3 (default, Sep  2 2019, 14:41:56)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys as s
>>> s.moduels.keys()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'moduels'
>>> s.modules.keys()
dict_keys(['encodings.latin_1', '_imp', 'zipimport', 'marshal', '_weakref', 'sysconfig', 'os', 'encodings.utf_8', 'genericpath', '_stat', 'sitecustomize', 'io', 'errno', 'signal', '_sysconfigdata', '_frozen_importlib', 'encodings.aliases', 'posix', 'codecs', 'abc', 'os.path', 'encodings.ascii', '_weakrefset', 'sys', '_io', 'readline', '_collections_abc', '_thread', 'encodings', 'rlcompleter', 'site', '_codecs', 'stat', '_warnings', '_sitebuiltins', 'builtins', '__main__', 'posixpath', 'atexit'])

4. 使用Perl

BlueJayOS内置Perl,版本是Perl 5.20.0

root@localhost:~# perl
perl        perl5.20.0
root@localhost:~# perl -version

This is perl 5, version 20, subversion 0 (v5.20.0) built for arm-linux-gnueabi

Copyright 1987-2014, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

##ß 5 使用GPIO

5.1 引脚编号

JayBox motherboard GPIO

5.2 使有电平转换:

echo 11 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio11/direction
echo 1 > /sys/class/gpio/gpio11/value

5.3 打开GPIO0

echo 0 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio0/direction
echo 1 > /sys/class/gpio/gpio0/value

5.4 关闭GPIO_0

echo 0 > /sys/class/gpio/gpio0/value

5.5 再次打开

echo 1 > /sys/class/gpio/gpio0/value

6. 使用SIM/eSIM

默认情况下系统会自行识别到eSIM或者SIM卡,自动拨号启动,如果没有启动,可以用以下命令检查状态:

cat /dev/smd11 &
echo -e "at+cfun?\r" > /dev/smd11

如果输出不是1,则需要设置为1,执行:

echo -e "at+cfun=1\r" > /dev/smd11

如果已经是1了,则用以下命令查询一下当前状态:

echo -e "at+cops?\r" > /dev/smd11
echo -e "at+cpin?\r" > /dev/smd11
echo -e "at^sysinfo\r" > /dev/smd11
echo -e "at+csq\r" > /dev/smd11

以上为第三章节内容,我们陆续会推出以下新章节:

如何使用您的工业边缘计算单元

内容

第一章:了解您的JayBox 主板

第二章:开始使用您的JayBox 主板(仅需连接以太网电缆,24V电源)

第三章:使用你的JayBox 主板

第四章:使用易于编译的BaseJay开始编写程序

第五章:使用用Python编程

第六章:使用用C语言编程

第七章:使用BaseJay并编译你的应用

第八章:使用GPIO引脚进行物理计算

第九章:编程使用Modbus

第十章:编程使用OPC-UA

第十一章:使用MQTT的编程。

附录

附录A:命令行界面

附录B:JayBox 主板规格

附录C:JayBox主板4G及以太网带宽测试


联系我们

复杂的交给我们,简单的带给你们

hello@jieqi.io +86 (571) 8618 5263

地址

中国(杭州)人工智能小镇
文一西路1818-2号,杭州市
浙江,中国

申请试用