General area when it fits no where else

Moderator: Mmiscool

User avatar
By cicciocb
#44809 Hi,
maybe this can help you :

Code: Select allin = "4D4D4953434F4F4C"
gosub [sub.from.hex]
print out
end


'input variable in
'output variable out
[sub.from.hex]
out = ""
for i = 1 to len(in)
a = asc(mid(in,i,1)) - 48
if (a > 9) then a = a - 7
i = i + 1
b = asc(mid(in,i,1)) - 48
if (b > 9) then b = b - 7
c = a << 4 or b
out = out & chr(c)
next i
return


This is a simple function that converts a string containing hex chars in text format to a string that contains the equivalent chars in binary format.
fill the string in the variable 'in' (ex. in = "C30D0A") ; the chars must be upper case and in couple (multiple of 2)
then call the sub (gosub [sub.from.hex])
the result will be in the variable out (ex. serialprint out)

Hoping this can be useful also to other people

CiccioCB
Last edited by cicciocb on Tue Apr 05, 2016 1:32 am, edited 1 time in total.
User avatar
By Electroguard
#44815 Each command starts with byte 0x7E, followed by a length byte indicating the number of bytes that follow, followed by a byte indicating the command to execute (there are about 28 different possible commands - Play, VolUP, Next etc), followed by an optional first argument byte, followed by an optional second argument byte, followed by the 'end' byte 0xEF as the terminator.

For example, the command ”PLAY” (0x0D) is constructed with the following 4 bytes

0x7E – Start Byte
0x02 – 2 Bytes Follow
0x0D – Command Byte
0xEF – Termination Byte

Once I looked up all the hex to dec conversions on an ascii chart I was able to get it to work with your chr() suggestion, eg:
let vstart = 126
let vlen = 2
let vplay = 13
let vend = 239
serialprintln chr(vstart) & chr(vlen) & chr(vplay) & chr(vend)

So thanks for that.

When done, this will allow people to add super-simple 2-wire voice capability to ESP Basic using a £5 JQ6500 mp3 module or similar. I'll get things working as a browser controlled music player first, but the real intention is to provide udp network controlled voice messaging for triggered alarm announcements etc.