Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Dim bc As ByteConverter
Dim s() As Byte = "+abc\/., "
Dim buffer(s.Length * 3) As Byte
Dim length As Int = UrlEncode(s, buffer)
Log(bc.SubString2(buffer, 0, length))
End Sub
Private Sub UrlEncode (s() As Byte, Buffer() As Byte) As Int
Dim index As Int = 0
For i = 0 To s.Length - 1
Dim c As Byte = s(i)
Log(c)
If c = 32 Then
Buffer(index) = Asc("+")
index = index + 1
Else if (c >= Asc("0") And c <= Asc("9")) Or (c >= Asc("A") And c <= Asc("Z")) Or (c >= Asc("a") And c <= Asc("z")) Then
Buffer(index) = c
index = index + 1
Else
Dim code1 As Byte = Bit.And(c, 0xf) + Asc("0")
If Bit.And(c, 0xf) > 9 Then
code1 = Bit.And(c, 0xf) - 10 + Asc("A")
End If
c = Bit.And(Bit.ShiftRight(c, 4), 0xf)
Dim code0 As Byte = c + Asc("0")
If c > 9 Then
code0 = c - 10 + Asc("A")
End If
Buffer(index) = Asc("%")
index = index + 1
Buffer(index) = code0
index = index + 1
Buffer(index) = code1
index = index + 1
End If
Next
Return index
End Sub