Hi D,If it finds the match it exits, if not it runs through the entire chain looking for it.
In this specific case, yours seems like the best choice.
Hi,The items searched for means that the code will only work in the northern and western hemispheres. A better solution would be to capture the entire string, check CRC and if OK then process it. A quick check at the start of the string could be done and invalid strings rejected earlier.
Mike.
ByRef can only be used in procedures.Hi,
Here is a PROCEDURE from one of my programs:
'These extract characters from the raw RX buffer array to OSH string types
===================================
'AddChar: adds passed character to passed string at
'passed StrIx. Terminates result with 0 to keep it a string
Proc Addchar(ByRef str As String, ByRef StrIX As Byte, char As Byte)
str(StrIX) = char
StrIX = StrIX + 1
str(StrIX) = 0
End Proc
===================================
it uses 'byref'
I would like to know if 'byref' can also be used in an Oshonsoft FUNCTION please?
Camerart
Hi D,ByRef can only be used in procedures.
To do the same thing that ByRef does in the procedures you have to work with pointers in the functions, if you want later I will give an example and you can pass it on to your friend so that he can analyze it, it is not very difficult.
I've been looking at some photographs of Harrison clocks and they really are impressive.P.S. I hope to go to The https://en.wikipedia.org/wiki/Prime_meridian_(Greenwich)
To show a friend of mine the Harrison clocks, which are worth a visit.
I hope to take a PCB, and save the output on the E and W of the line.
C
Hi D,I've been looking at some photographs of Harrison clocks and they really are impressive.
Hi D,Curiosity: I have simplified the function, leaving this new version taking 1.47mSec to execute and yours taking 1.90mSec.
Input:
String1 = "!AIVDM,1,1"
String3 = "AIVDM"
'8Mhz
'The corresponding match function
Function match(ByVal input_str As String, ByVal str_ix As Byte, ByVal match_str As String) As Bit ' these variable names can be changes as wished
Symbol _Return = match
Dim position_counter As Byte ' the index pointer for the character to be checked
Dim shortposition As Byte 'the current position in the short string
position_counter = position_counter + str_ix
While match_str(shortposition) > 0
If input_str(position_counter) = match_str(shortposition) Then
_Return = 1 ' set the match indicator to valid
shortposition = shortposition + 1 ' increment the short string position counter
Else
_Return = 0 'set the match indicator To Not valid
Exit ' jump out of the loop
Endif
position_counter++
Wend
End Function'the corresponding match function
Hi D,I don't understand what you mean, I tried the following in the simulator:
'Amicus18
'***********************************************************************
'Match function
'Pic18F26k22, OshonSoft Pic18 Basic Compiler v5.17
'***********************************************************************
#define CLOCK_FREQUENCY = 64 'Clock 64Mhz
#define STRING_MAX_LENGTH = 100
#define SINGLE_DECIMAL_PLACES = 1
'#define SIMULATION_WAITMS_VALUE = 1
'***********************************************************************
'***********************************************************************
'Include "_FuncionesPic18F26K22.bas"
'Include "_SetUpAmicus18.bas"
'Include "_FuncionesTmrBase.bas"
'Include "_FuncionesUartRingBuffer.bas"
'Include "_Funciones_Buffer_RS232.Bas"
'***********************************************************************
main:
'********************************************************************
UART1_Init 115200
'UART2_Init 4800
WaitMs 1
Dim String1 As String
Dim String2 As String
Dim String3 As String
String1 = "$GNRMC,000000.00,A,3723.02837,N,00150.39853,W,0.820,188.36,110706,,,A*74"
String2 = "!AIVDO,1,1,,,100000?P?w<tSF0l4Q@>4?wv0000,0*53"
String3 = "GNRMC"
While True
UART_Write #match(String1, 1, String3), CrLf
If match(String1, 1, String3) > 0 Then
UART_Write "Ok"
Else
UART_Write "No Match"
Endif
While True
Wend
Wend
End
'The corresponding match function
Function match(input_str As String, str_ix As Byte, match_str As String) As Byte ' these variable names can be changes as wished
Symbol _Return = match
Dim position_counter As Byte ' the index pointer for the character to be checked
Dim shortposition As Byte 'the current position in the short string
position_counter = 0
shortposition = 0
position_counter = position_counter + str_ix
While match_str(shortposition) > 0
If input_str(position_counter) = match_str(shortposition) Then
_Return = 1 ' set the match indicator to valid
shortposition++ ' increment the short string position counter
Else
_Return = 0 'set the match indicator To Not valid
Exit ' jump out of the loop
Endif
position_counter++
Wend
End Function'the corresponding match function
Hi D,You can also leave memory free by shortening the value of #define
100. If the problem is lack of sram.STRING_MAX_LENGTH =
Hi D,Ok, anyway if you want to continue having the advantage of using Functions, you can switch to using pointers. It is not difficult, it is just getting used to the fact that the first element of the string is not zero, the first element is now the memory address of the first element and to access the memory addresses a command or a function is used.
I leave the example:
'Amicus18
'***********************************************************************
'Match function
'Pic18F26k22, OshonSoft Pic18 Basic Compiler v5.17
'***********************************************************************
#define CLOCK_FREQUENCY = 64 'Clock 64Mhz
#define STRING_MAX_LENGTH = 100
#define SINGLE_DECIMAL_PLACES = 1
'#define SIMULATION_WAITMS_VALUE = 1
'***********************************************************************
'***********************************************************************
'Include "_FuncionesPic18F26K22.bas"
'Include "_SetUpAmicus18.bas"
'Include "_FuncionesTmrBase.bas"
'Include "_FuncionesUartRingBuffer.bas"
'Include "_Funciones_Buffer_RS232.Bas"
'***********************************************************************
main:
'********************************************************************
UART1_Init 115200
'UART2_Init 4800
WaitMs 1
Dim String1 As String
Dim P_String1 As Word
Dim String2 As String
Dim P_String2 As Word
'Pointer assignment up to 12bit for Pic18 series
Dim _Address As Word
Symbol _Address_HB = _Address.HB
Symbol _Address_LB = _Address.LB
ASM: LFSR 2,String1
ASM: MOVFW FSR2H
ASM: MOVWF _Address_HB
ASM: MOVFW FSR2L
ASM: MOVWF _Address_LB
P_String1 = _Address '-> String1 (Array)
'Pointer assignment up to 12bit for Pic18 series
ASM: LFSR 2,String2
ASM: MOVFW FSR2H
ASM: MOVWF _Address_HB
ASM: MOVFW FSR2L
ASM: MOVWF _Address_LB
P_String2 = _Address '-> String2 (Array)
String1 = "$GNRMC,000000.00,A,3723.02837,N,00150.39853,W,0.820,188.36,110706,,,A*74"
String2 = "GNRMC"
While True
'UART_Write #match(String1, 1, String2), CrLf
If match(P_String1, 1, P_String2) > 0 Then
UART_Write "Ok"
Else
UART_Write "No Match"
Endif
While True
Wend
Wend
End
'The corresponding match function
Function match(input_str As Word, str_ix As Byte, match_str As Word) As Byte ' these variable names can be changes as wished
Symbol _Return = match
Symbol position_counter = input_str
Symbol shortposition = match_str
position_counter = input_str + str_ix
While Peek(shortposition) > 0
If Peek(position_counter) = Peek1(shortposition) Then
_Return = 1 'set the match indicator to valid
shortposition++ 'increment the short string position counter
Else
_Return = 0 'set the match indicator To Not valid
Exit 'jump out of the function
Endif
position_counter++
Wend
End Function 'the corresponding match function
'*******************************************************************************************
'Peek function of the traditional Basic language to work with memory addresses (read).
'*******************************************************************************************
'Returns the value (Byte) containing the specified memory address (Word).
'It can be used in compound conditional structures and mathematical operations.
'For example: If Peek(_Address) > 0 And PeeK(_Address + 1) = 0.
'Restrictions until v5.17 (PSI 18): cannot be used in simple conditionals with itselfs.
'For example: If Peek(_Address) = PeeK(_Address +1) -> in this type or similar (And, Or)
'always returns true.
'Bypassing restrictions: If Peek(_Address) = Peek1(_Address +1)
'********************************************************************************************
'Peek
Function Peek(_Address As Word) As Byte
Symbol _Return = Peek
_Return = Pointer(_Address)
End Function
'Peek1
Function Peek1(_Address As Word) As Byte
Symbol _Return = Peek1
_Return = Pointer(_Address)
End Function
On High Interrupt
Save System
'OVERRUN ERROR
If PIE1.RCIE = 1 Then 'EUSART Receive Interrupt Enable bit
If RCSTA.OERR = 1 Then
Gosub irqinitbuf 're-init buffer, discard bad sentence
Goto RXIRQdone 'done, wait for next character
Endif 'OERR
'FRAMING ERROR
If RCSTA.FERR = 1 Then
dumpchar = RCREG 'Read char to clear RCIF and FERR
Gosub irqinitbuf 'Re-init buffer, discard bad sentence
Goto RXIRQdone 'wait for next
Endif 'FERR
'No UART errors, process character
If PIR1.RCIF = 1 Then
RXIRQchar = RCREG 'read the received char, clears RCIF
'Look for $, start/restart filling buf when found
If RXIRQchar = "$" Then 'Start (re)filling buf on any $
'Gosub IRQinitBuf 'init buffer, index and flags@
gnrmc_buf(gnrmcpsn) = RXIRQchar 'store $ $ ADDED instead of RXIRQchar, because no $ was being stored
gnrmc_buf_filling = 1 'start storing the sentence
Goto RXIRQdone 'done with this character
Endif 'char was $
'no UART errors and character was not $
'If $ was found previously, process character looking for W and no buffer overflow.
'If haven't found $ yet, just ignore character.
If gnrmc_buf_filling = 1 Then 'if filling buffer, see if there is room in buf
If gnrmcpsn >= (rxbufsize - 1) Then 'last char was at end of buf - buffer overflow so..
Gosub irqinitbuf 'restart buffer, discard sentence
RXerr = 1 'let main know that the buffer overflowed and is restarting
Goto RXIRQdone 'done, resume looking for next $
Endif 'buffer overflow
gnrmcpsn = gnrmcpsn + 1 'else, there's room in buf so bump index and store character, might be W
gnrmc_buf(gnrmcpsn) = RXIRQchar
If RXIRQchar = "W" Then 'if end of sentence..
RCSTA.CREN = 0 'shut down UART
PIE1.RCIE = 0 'Enable off
gnrmc_buf_filling = 0
gnrmc_buf_full = 1
Goto RXIRQdone 'and bye!
Endif 'RXIRQchar was W
Endif 'If gnrmc_buf_filling = 1
Endif 'RCIF=1
Endif 'RCIE=1
'Exit point for each RXinterrupt. Process timers
RXIRQdone:
Resume
Hi D,Ok, anyway if you want to continue having the advantage of using Functions, you can switch to using pointers. It is not difficult, it is just getting used to the fact that the first element of the string is not zero, the first element is now the memory address of the first element and to access the memory addresses a command or a function is used.
I leave the example:
'Amicus18
'***********************************************************************
'Match function
'Pic18F26k22, OshonSoft Pic18 Basic Compiler v5.17
'***********************************************************************
#define CLOCK_FREQUENCY = 64 'Clock 64Mhz
#define STRING_MAX_LENGTH = 100
#define SINGLE_DECIMAL_PLACES = 1
'#define SIMULATION_WAITMS_VALUE = 1
'***********************************************************************
'***********************************************************************
'Include "_FuncionesPic18F26K22.bas"
'Include "_SetUpAmicus18.bas"
'Include "_FuncionesTmrBase.bas"
'Include "_FuncionesUartRingBuffer.bas"
'Include "_Funciones_Buffer_RS232.Bas"
'***********************************************************************
main:
'********************************************************************
UART1_Init 115200
'UART2_Init 4800
WaitMs 1
Dim String1 As String
Dim P_String1 As Word
Dim String2 As String
Dim P_String2 As Word
'Pointer assignment up to 12bit for Pic18 series
Dim _Address As Word
Symbol _Address_HB = _Address.HB
Symbol _Address_LB = _Address.LB
ASM: LFSR 2,String1
ASM: MOVFW FSR2H
ASM: MOVWF _Address_HB
ASM: MOVFW FSR2L
ASM: MOVWF _Address_LB
P_String1 = _Address '-> String1 (Array)
'Pointer assignment up to 12bit for Pic18 series
ASM: LFSR 2,String2
ASM: MOVFW FSR2H
ASM: MOVWF _Address_HB
ASM: MOVFW FSR2L
ASM: MOVWF _Address_LB
P_String2 = _Address '-> String2 (Array)
String1 = "$GNRMC,000000.00,A,3723.02837,N,00150.39853,W,0.820,188.36,110706,,,A*74"
String2 = "GNRMC"
While True
'UART_Write #match(String1, 1, String2), CrLf
If match(P_String1, 1, P_String2) > 0 Then
UART_Write "Ok"
Else
UART_Write "No Match"
Endif
While True
Wend
Wend
End
'The corresponding match function
Function match(input_str As Word, str_ix As Byte, match_str As Word) As Byte ' these variable names can be changes as wished
Symbol _Return = match
Symbol position_counter = input_str
Symbol shortposition = match_str
position_counter = input_str + str_ix
While Peek(shortposition) > 0
If Peek(position_counter) = Peek1(shortposition) Then
_Return = 1 'set the match indicator to valid
shortposition++ 'increment the short string position counter
Else
_Return = 0 'set the match indicator To Not valid
Exit 'jump out of the function
Endif
position_counter++
Wend
End Function 'the corresponding match function
'*******************************************************************************************
'Peek function of the traditional Basic language to work with memory addresses (read).
'*******************************************************************************************
'Returns the value (Byte) containing the specified memory address (Word).
'It can be used in compound conditional structures and mathematical operations.
'For example: If Peek(_Address) > 0 And PeeK(_Address + 1) = 0.
'Restrictions until v5.17 (PSI 18): cannot be used in simple conditionals with itselfs.
'For example: If Peek(_Address) = PeeK(_Address +1) -> in this type or similar (And, Or)
'always returns true.
'Bypassing restrictions: If Peek(_Address) = Peek1(_Address +1)
'********************************************************************************************
'Peek
Function Peek(_Address As Word) As Byte
Symbol _Return = Peek
_Return = Pointer(_Address)
End Function
'Peek1
Function Peek1(_Address As Word) As Byte
Symbol _Return = Peek1
_Return = Pointer(_Address)
End Function
Hi D,I am testing a beta with many improvements that I proposed, so the code I put in could be reduced much more.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?