Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re860_factory
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
waterword
re860_factory
Commits
9415cdea
Commit
9415cdea
authored
Oct 13, 2025
by
lyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:1、优化授权写入文件方式为二进制写入 2、获取mac方式改为lic的mac和无线网卡mac校验匹配后返回mac
parent
9f36c54c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
175 additions
and
19 deletions
+175
-19
factoryTest_plugin/factory_autoFactoryTest.js
factoryTest_plugin/factory_autoFactoryTest.js
+8
-3
factoryTest_plugin/factory_autoFactoryTestUtil.js
factoryTest_plugin/factory_autoFactoryTestUtil.js
+75
-12
factoryTest_plugin/factory_uartUtil.js
factoryTest_plugin/factory_uartUtil.js
+12
-2
lib/factory/factory_uartUtil.c
lib/factory/factory_uartUtil.c
+80
-2
lib/factory/factory_uartUtil.so
lib/factory/factory_uartUtil.so
+0
-0
No files found.
factoryTest_plugin/factory_autoFactoryTest.js
View file @
9415cdea
...
...
@@ -126,9 +126,14 @@ function doTempHum(fd) {
send
(
fd
,
tempHum
);
}
function
doGetMac
(
fd
)
{
var
mac
=
"
+
"
+
autoUtil
.
getWifiInfo
(
"
address
"
);
console
.
log
(
"
!!get mac:
"
+
mac
);
send
(
fd
,
mac
);
var
wifimac
=
autoUtil
.
getWifiInfo
(
"
address
"
);
var
licmac
=
autoUtil
.
getMacAddressFromLicenseFile
();
console
.
log
(
"
wifimac:
"
+
wifimac
+
"
licmac:
"
+
licmac
);
var
mac
=
"
+
"
+
wifimac
if
(
wifimac
===
licmac
)
{
send
(
fd
,
mac
);
}
else
send
(
fd
,
"
+FAIL
"
);
}
function
doGetSn
(
fd
)
{
var
sn
=
"
+
"
+
autoUtil
.
getSn
();
...
...
factoryTest_plugin/factory_autoFactoryTestUtil.js
View file @
9415cdea
...
...
@@ -8,6 +8,7 @@ var handleSNDataBinFile = require("handleSNDataBinFile.js");
var
router
=
require
(
"
@system.router
"
);
var
bglight
=
require
(
"
bglight.js
"
);
var
envTemp
=
require
(
"
environmentTemperature.js
"
);
var
uart
=
require
(
"
factory_uartUtil.js
"
);
var
resultsWifiList
=
[];
var
SECURE_APP_PATH
=
"
/mnt/app/eOpteeCtrl
"
var
that
;
...
...
@@ -230,11 +231,46 @@ function getTempHum() {
return
getTemp
()
+
"
,
"
+
getHumid
();
}
function
writeLic
(
lic
)
{
handleSNDataBinFile
.
writeLicenseToBinFile
(
lic
)
handleSNDataBinFile
.
writeSNDataToBinFile
(
lic
)
handleSNDataBinFile
.
writeInnerSNDataToBinFile
(
lic
)
function
writeLic
(
hexStr
)
{
var
filePath
=
"
/tmp/test_license.txt
"
;
// inner_sn_data.bin
// operation_license
// sn_data.bin
var
filePath1
=
"
/tmp/operation_license
"
;
var
filePath2
=
"
/tmp/sn_data.bin
"
;
const
SECURE_APP_PATH
=
"
/mnt/app/eOpteeCtrl
"
console
.
log
(
'
Full license written:
'
+
hexStr
);
var
hexLen
=
hexStr
.
length
;
// console.log("Writing data: " + hexStr + " to " + filePath);
var
result
=
uart
.
writeData
(
hexStr
,
hexLen
,
filePath1
);
if
(
result
==
1
)
{
console
.
log
(
"
Data written successfully.
"
);
}
else
{
console
.
log
(
"
Failed to write data.
"
);
}
system
(
"
sync
"
);
system
(
SECURE_APP_PATH
+
"
-b
"
+
filePath1
);
var
result
=
uart
.
writeData
(
hexStr
,
hexLen
,
filePath2
);
if
(
result
==
1
)
{
console
.
log
(
"
Data written successfully.
"
);
}
else
{
console
.
log
(
"
Failed to write data.
"
);
}
system
(
"
sync
"
);
system
(
SECURE_APP_PATH
+
"
-b
"
+
filePath2
);
// console.log('Full license asciiText:' + asciiText);
// handleSNDataBinFile.writeLicenseToBinFile(asciiText)
// handleSNDataBinFile.writeSNDataToBinFile(asciiText)
// system("echo " + asciiText + " > /tmp/test_license.txt")
// handleSNDataBinFile.writeInnerSNDataToBinFile(lic)
system
(
"
cp /tmp/operation_license /mnt/userdataA/files/
"
);
system
(
"
/mnt/app/eMideaSetMac
"
);
}
/**
...
...
@@ -365,7 +401,7 @@ function getpectedHexLen(seg) {
function
licParce
(
recvBuf
)
{
var
comallArrLicVal
=
'
4954455F4C4943
'
;
// var allArrLicVal = '3332'; // 外部可改,总段号(16 进制字符串)
// var allArrLicVal = '3332'; // 外部可改,总段号(16 进制字符串)
var
equal
=
'
3D
'
;
// console.log('licParce recv:' + recvBuf);
var
buf
=
recvBuf
;
...
...
@@ -404,7 +440,7 @@ function licParce(recvBuf) {
//总长度数据4096
var
expectedHexLen
=
getpectedHexLen
(
totSeg
);
if
(
core
.
length
!==
expectedHexLen
)
{
console
.
log
(
`长度错误:期望
${
expectedHexLen
}
,实际
${
core
.
length
}
`
);
return
-
2
;
...
...
@@ -438,12 +474,12 @@ function gotoWriteLic() {
// 清理之前的定时器
if
(
gotoWriteLic
.
_timeOutId
)
{
clearTimeout
(
gotoWriteLic
.
_timeOutId
);
gotoWriteLic
.
_timeOutId
=
null
;
clearTimeout
(
gotoWriteLic
.
_timeOutId
);
gotoWriteLic
.
_timeOutId
=
null
;
}
// 设置新的定时器
gotoWriteLic
.
_timeOutId
=
setTimeout
(()
=>
{
gotoWriteLic
.
_timeOutId
=
setTimeout
(()
=>
{
console
.
log
(
"
!!!!!!!!!!!!!!!!!!!!gotoWriteLic
"
);
// 检查 licSegArray 是否包含所有段的数据
if
(
licSegArray
.
length
>
0
&&
licSegArray
.
every
(
v
=>
v
))
{
...
...
@@ -453,8 +489,6 @@ function gotoWriteLic() {
// 写入许可证
writeLic
(
fullLic
);
console
.
log
(
'
Full license written:
'
+
fullLic
);
// 计算校验和
var
cksum
=
figureChecksum
(
recLic
,
2048
);
console
.
log
(
'
checksum =
'
+
cksum
);
...
...
@@ -551,6 +585,34 @@ function getWifiInfo(options) {
}
return
"
FAil
"
;
}
function
getMacAddressFromLicenseFile
()
{
// 生成 hexdump 命令
var
hexdumpCmd
=
"
hexdump -s 0x0001 -n 6 -C /tmp/operation_license > /tmp/lic_status.txt
"
;
system
(
hexdumpCmd
);
// 读取 /tmp/lic_status.txt 文件内容
const
statusContent
=
fs
.
read
(
"
/tmp/lic_status.txt
"
,
"
r
"
);
if
(
!
statusContent
)
{
console
.
log
(
"
Failed to read /tmp/lic_status.txt
"
);
return
"
FAIL
"
;
}
// 解析 hexdump 输出
const
statusLines
=
statusContent
.
split
(
'
\n
'
);
for
(
let
i
=
0
;
i
<
statusLines
.
length
;
i
++
)
{
const
line
=
statusLines
[
i
].
trim
();
if
(
line
.
startsWith
(
"
00000001
"
))
{
// 提取 MAC 地址部分
const
macPart
=
line
.
slice
(
10
,
28
).
trim
();
// 替换空格为冒号并转换为小写
const
formattedMac
=
macPart
.
replace
(
/
\s
/g
,
'
:
'
).
toLowerCase
();
return
formattedMac
;
}
}
// 如果没有找到有效的 MAC 地址,返回 FAIL
return
"
FAIL
"
;
}
function
system
(
cmd
)
{
systemCtrl
.
executeSystemCommand
(
cmd
)
...
...
@@ -586,5 +648,6 @@ module.exports = {
getssid
:
getssid
,
initautoFactorySetting
:
initautoFactorySetting
,
getWifiInfo
:
getWifiInfo
,
gotoWriteLic
:
gotoWriteLic
gotoWriteLic
:
gotoWriteLic
,
getMacAddressFromLicenseFile
:
getMacAddressFromLicenseFile
}
factoryTest_plugin/factory_uartUtil.js
View file @
9415cdea
...
...
@@ -9,7 +9,8 @@ var funcs = [
[
"
kill_tty_user
"
,
"
is
"
],
[
"
pwm_uart_init
"
,
"
vv
"
],
[
"
uart_set_canonical
"
,
"
vi
"
],
[
"
uart_set_raw
"
,
"
vi
"
]
[
"
uart_set_raw
"
,
"
vi
"
],
[
"
writeData
"
,
"
isis
"
]
];
...
...
@@ -74,6 +75,14 @@ function uart_set_raw(fd) {
// 串口设为 raw 模式
uartUtil
.
uart_set_raw
(
fd
);
}
function
writeData
(
hexStr
,
hexLen
,
filePath
)
{
// int writeData(const char *hexStr, int hexLen, const char *filePath)
// console.log("!!writeData:" + hexStr + " " + hexLen + " " + filePath);
console
.
log
(
"
!!writeData
"
);
return
uartUtil
.
writeData
(
hexStr
,
hexLen
,
filePath
);
}
...
...
@@ -86,6 +95,7 @@ module.exports = {
kill_tty_user
:
kill_tty_user
,
pwm_uart_init
:
pwm_uart_init
,
uart_set_canonical
:
uart_set_canonical
,
uart_set_raw
:
uart_set_raw
uart_set_raw
:
uart_set_raw
,
writeData
:
writeData
}
lib/factory/factory_uartUtil.c
View file @
9415cdea
...
...
@@ -31,14 +31,86 @@ static int g_rxlen = 0; /* 有效长度
static
int
g_rxHexlen
=
0
;
/* 有效长度 */
static
pthread_mutex_t
g_rx_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
/* 互斥锁 */
/**
* @brief 将十六进制字符串转换为原始二进制数据
* @param hexStr 十六进制字符串
* @param hexLen 十六进制字符串的长度
* @param outBuf 输出的二进制数据缓冲区
* @return 转换后的二进制数据长度
*/
int
hexToBytes
(
const
char
*
hexStr
,
int
hexLen
,
uint8_t
*
outBuf
)
{
int
len
=
hexLen
/
2
;
// 每两个十六进制字符表示一个字节
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
char
byteStr
[
3
]
=
{
hexStr
[
i
*
2
],
hexStr
[
i
*
2
+
1
],
'\0'
};
outBuf
[
i
]
=
(
uint8_t
)
strtol
(
byteStr
,
NULL
,
16
);
}
return
len
;
}
/**
* @brief 将原始二进制数据写入文件
* @param data 原始二进制数据
* @param dataLen 原始二进制数据的长度
* @param filePath 文件路径
* @return 0 成功,-1 失败
*/
int
writeDataToFile
(
const
uint8_t
*
data
,
int
dataLen
,
const
char
*
filePath
)
{
// 打开文件并写入数据
int
fd
=
open
(
filePath
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
if
(
fd
<
0
)
{
perror
(
"open"
);
return
-
1
;
}
if
(
write
(
fd
,
data
,
dataLen
)
!=
dataLen
)
{
perror
(
"write"
);
close
(
fd
);
return
-
1
;
}
void
set_realtime_priority
(
pthread_t
thread
,
int
priority
)
{
close
(
fd
);
return
0
;
}
int
writeData
(
const
char
*
hexStr
,
int
hexLen
,
const
char
*
filePath
)
{
int
ret
=
0
;
uint8_t
*
data
=
(
uint8_t
*
)
malloc
(
hexLen
/
2
);
if
(
!
data
)
{
perror
(
"malloc"
);
return
-
1
;
}
DBG
(
"writeData: hexStr=%s, hexLen=%d, filePath=%s
\n
"
,
hexStr
,
hexLen
,
filePath
);
int
dataLen
=
hexToBytes
(
hexStr
,
hexLen
,
data
);
DBG
(
"writeData: Converted dataLen=%d
\n
"
,
dataLen
);
if
(
writeDataToFile
(
data
,
dataLen
,
filePath
)
==
0
)
{
DBG
(
"Data written to %s successfully.
\n
"
,
filePath
);
ret
=
1
;
}
else
{
DBG
(
"Failed to write data to %s.
\n
"
,
filePath
);
ret
=
0
;
}
free
(
data
);
return
ret
;
}
void
set_realtime_priority
(
pthread_t
thread
,
int
priority
)
{
struct
sched_param
param
;
param
.
sched_priority
=
priority
;
pthread_setschedparam
(
thread
,
SCHED_FIFO
,
&
param
);
}
/* ---------------- 串口底层 ---------------- */
/**
* @brief 接收数据
...
...
@@ -531,6 +603,9 @@ int main(void)
/* ******** 在这里切 canonical ******** */
// uart_set_canonical(fd);
uart_set_raw
(
fd
);
uint8_t
originalData
[
BUFFER_SIZE
];
// 用于存储还原后的二进制数据
for
(;;)
{
sleep
(
1
);
...
...
@@ -546,6 +621,9 @@ int main(void)
{
DBG
(
"TXTHEX : %s
\n
"
,
txthex
);
}
// 将十六进制字符串还原为原始二进制数据
int
len
=
hexToBytes
(
txthex
,
strlen
(
txthex
),
originalData
);
DBG
(
"Original Data Length: %d
\n
"
,
len
);
if
(
strstr
(
txt
,
"TEST_START"
))
uart_send
(
fd
,
"+START
\r\n
"
,
8
);
/* 回 AT */
...
...
lib/factory/factory_uartUtil.so
View file @
9415cdea
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment