forked from hootrhino/rulex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
328 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package rulexlib | ||
|
||
/* | ||
* | ||
* 这里规定一些LUA和golang的类型映射 | ||
* local t = { | ||
* ["type"] = 5, | ||
* ["params"] = { | ||
* ["address"] = 1, | ||
* ["quantity"] = 1, | ||
* ["value"] = 0xFF00 | ||
* } | ||
* } | ||
* | ||
*/ | ||
type ModbusW struct { | ||
SlaverId byte // 从机ID | ||
Function int // 功能码 | ||
Address uint16 // 地址 | ||
Quantity uint16 // 读写数量 | ||
Value []byte // 值 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package rulexlib | ||
|
||
import ( | ||
"github.com/i4de/rulex/glogger" | ||
"github.com/i4de/rulex/typex" | ||
|
||
lua "github.com/yuin/gopher-lua" | ||
) | ||
|
||
// | ||
// rulexlib:WriteInStream('INEND', rulexlib:T2J(t)) | ||
// | ||
var sourceReadBuffer []byte = []byte{} | ||
|
||
/* | ||
* | ||
* 向资源写入数据 | ||
* | ||
*/ | ||
func WriteSource(rx typex.RuleX) func(l *lua.LState) int { | ||
return func(l *lua.LState) int { | ||
uuid := l.ToString(2) | ||
data := l.ToString(3) | ||
|
||
if value, ok := rx.AllInEnd().Load(uuid); ok { | ||
n, err := value.(*typex.InEnd).Source.DownStream([]byte(data)) | ||
if err != nil { | ||
glogger.GLogger.Error(err) | ||
l.Push(lua.LNil) | ||
l.Push(lua.LString(err.Error())) | ||
return 2 | ||
} | ||
l.Push(lua.LNumber(n)) | ||
l.Push(lua.LNil) | ||
return 2 | ||
} | ||
l.Push(lua.LNil) | ||
l.Push(lua.LString("source not exists:" + uuid)) | ||
return 2 | ||
} | ||
} | ||
|
||
/* | ||
* | ||
* 从资源里面读数据出来 | ||
* | ||
*/ | ||
func ReadSource(rx typex.RuleX) func(*lua.LState) int { | ||
|
||
return func(l *lua.LState) int { | ||
uuid := l.ToString(2) | ||
InEnd := rx.GetInEnd(uuid) | ||
if InEnd != nil { | ||
n, err := InEnd.Source.UpStream(sourceReadBuffer) | ||
if err != nil { | ||
glogger.GLogger.Error(err) | ||
l.Push(lua.LNil) | ||
l.Push(lua.LString(err.Error())) | ||
return 2 | ||
} | ||
l.Push(lua.LString(sourceReadBuffer[:n])) | ||
l.Push(lua.LNil) | ||
return 2 | ||
} | ||
l.Push(lua.LNil) | ||
l.Push(lua.LString("source not exists:" + uuid)) | ||
return 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.