lora mesh 发送即收到
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -24,3 +24,4 @@ vendor/
|
|||||||
|
|
||||||
bin/
|
bin/
|
||||||
app_logs/
|
app_logs/
|
||||||
|
tmp/
|
||||||
@@ -113,6 +113,13 @@ func (g *GeneralDeviceService) Switch(device *models.Device, action DeviceAction
|
|||||||
DeviceID: areaController.ID,
|
DeviceID: areaController.ID,
|
||||||
SentAt: time.Now(),
|
SentAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
if sendResult.AcknowledgedAt != nil {
|
||||||
|
logRecord.AcknowledgedAt = sendResult.AcknowledgedAt
|
||||||
|
}
|
||||||
|
if sendResult.ReceivedSuccess != nil {
|
||||||
|
logRecord.ReceivedSuccess = *sendResult.ReceivedSuccess
|
||||||
|
}
|
||||||
|
|
||||||
if err := g.deviceCommandLogRepo.Create(logRecord); err != nil {
|
if err := g.deviceCommandLogRepo.Create(logRecord); err != nil {
|
||||||
// 记录日志失败是一个需要关注的问题,但可能不应该中断主流程。
|
// 记录日志失败是一个需要关注的问题,但可能不应该中断主流程。
|
||||||
// 我们记录一个错误日志,然后成功返回。
|
// 我们记录一个错误日志,然后成功返回。
|
||||||
|
|||||||
@@ -265,7 +265,10 @@ func (t *LoRaMeshUartPassthroughTransport) executeSend(req *sendRequest) (*trans
|
|||||||
}
|
}
|
||||||
|
|
||||||
msgID := uuid.New().String()
|
msgID := uuid.New().String()
|
||||||
return &transport.SendResult{MessageID: msgID}, nil
|
// LoRa mesh 是单向通信, 发送方不知道也不关心接收方是否收到, 所以发送成功就当作接收成功
|
||||||
|
acknowledgedAt := time.Now()
|
||||||
|
receivedSuccess := true
|
||||||
|
return &transport.SendResult{MessageID: msgID, AcknowledgedAt: &acknowledgedAt, ReceivedSuccess: &receivedSuccess}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleFrame 处理一个从串口解析出的完整物理帧
|
// handleFrame 处理一个从串口解析出的完整物理帧
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package transport
|
package transport
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Communicator 用于其他设备通信
|
// Communicator 用于其他设备通信
|
||||||
type Communicator interface {
|
type Communicator interface {
|
||||||
// Send 用于发送一条单向数据(不等待回信)
|
// Send 用于发送一条单向数据(不等待回信)
|
||||||
@@ -12,6 +14,14 @@ type SendResult struct {
|
|||||||
// MessageID 是通信服务为此次发送分配的唯一标识符。
|
// MessageID 是通信服务为此次发送分配的唯一标识符。
|
||||||
// 调用方需要保存此 ID,以便后续关联 ACK 等事件。
|
// 调用方需要保存此 ID,以便后续关联 ACK 等事件。
|
||||||
MessageID string
|
MessageID string
|
||||||
|
|
||||||
|
// AcknowledgedAt 记录设备确认收到下行消息的时间。
|
||||||
|
// 并非所有发送实现都会同步返回收到时间
|
||||||
|
AcknowledgedAt *time.Time
|
||||||
|
|
||||||
|
// ReceivedSuccess 表示设备是否成功接收到下行消息。
|
||||||
|
// 并非所有发送实现都会同步返回是否送达
|
||||||
|
ReceivedSuccess *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listener 用于监听其他设备发送过来的数据
|
// Listener 用于监听其他设备发送过来的数据
|
||||||
|
|||||||
Reference in New Issue
Block a user