my array:
Code: Select all
Const PACKET AS BYTE[15]= (0x0E,0x00,0x03,0x11,0x0A,0x00,0x01,0x00,0x01,0x00,0x00,0x63,0xC7,0x00,0x00)
Jerry
Code: Select all
Const PACKET AS BYTE[15]= (0x0E,0x00,0x03,0x11,0x0A,0x00,0x01,0x00,0x01,0x00,0x00,0x63,0xC7,0x00,0x00)
Code: Select all
Const PKT1 AS BYTE[14]= (0x00,0x03,0x11,0x0A,0x00,0x02,0x00,0x02,0x00,0x00,0x63,0x93,0x00,0x00)
Const PKT2 AS BYTE[8]= (0x00,0x02,0x01,0x04,0x00,0x04,0x00,0x00)
Const PKT3 as byte[10] = (0x00,0x02,0x05,0x06,0x08,0x00,0x00,0x02,0x00,0x00)
'..etc, maybe 20-30 different packets, all less than 15 words
dim Dest_Packet[15] as word
'Copy one of many source packets to the destination packet
sub procedure CopyPacket(dim source_packet as word)
dim x as byte
for x = 0 to sizeof(pktname)-1 'length of array
Dest_Packet[x] = pktname[x] 'copy array
next x
end sub
main:
CopyPacket(PKT1)
end.
Code: Select all
program Led_Blinking
Const PKT1 as byte[14]= (0x00,0x03,0x11,0x0A,0x00,0x02,0x00,0x02,0x00,0x00,0x63,0x93,0x00,0x00)
dim Dest_Packet as byte[14]
sub procedure CopyPacket(dim source_packet as ^ const byte)
dim x as byte
for x = 0 to (sizeof(PKT1) - 1)
Dest_Packet[x] = source_packet^
Inc(source_packet)
next x
end sub
main:
CopyPacket(@PKT1)
nop
end.
Code: Select all
program constarraytest
Const PKT1 as byte[14]= (0x00,0x03,0x11,0x0A,0x00,0x02,0x00,0x02,0x00,0x00,0x63,0x93,0x00,0x00)
Const PKT2 AS BYTE[8]= (0x00,0x02,0x01,0x04,0x00,0x04,0x00,0x00)
Const PKT3 as byte[10] = (0x00,0x02,0x05,0x06,0x08,0x00,0x00,0x02,0x00,0x00)
'...etc...maybe 20 different packet 'templates'
dim Dest_Packet as byte[14]
dim pktlen as byte
sub procedure CopyPacket(dim source_packet as ^ const byte)
dim x as byte
pktlen = sizeof(source_packet) 'this doesn't work, but needs to be something like
'this instead of 'sizeof(PKT1)', because the length of the source
'packet can vary. Also, I need to know this length in order to use it in the SEND routine later.
for x = 0 to (pktlen - 1)
Dest_Packet[x] = source_packet^
Inc(source_packet)
next x
end sub
sub procedure SendPacket(dim sendlength as byte)
dim x as byte
for x= 0 to sendlength-1
' send the packet out over a serial line (after replacing a few 'placeholder' bytes in Dest_Packet)
next x
end sub
main:
CopyPacket(@PKT1) 'copy packet template to Dest_Packet
SendPacket(pktlen) 'format and send
nop
CopyPacket(@PKT2)
SendPacket(pktlen)
nop
CopyPacket(@PKT3)
SendPacket(pktlen)
' etc...
end.