Problem with some spin code (serial CSV parser)
crabbypup
Posts: 1
I have some code that I'm working on (posted below). it's function is to take a line of a CSV file that has been input via UART (serial object in use is pcFullDuplexSerial4FC) and split it at the commas.
the problem I'm having with this code is that when it is launched (in another cog) a lot of data starts getting dumped to the serial terminal. not the data I want - just seemingly random strings. it will do this for a few minutes, and then the propeller appears to go into a reset loop. the function is below. thank you in advance!
full list of objects in use:
uarts : "pcFullDuplexSerial4FC.spin"
str : "STRINGS.spin"
numbrs :"numbers.spin"
the problem I'm having with this code is that when it is launched (in another cog) a lot of data starts getting dumped to the serial terminal. not the data I want - just seemingly random strings. it will do this for a few minutes, and then the propeller appears to go into a reset loop. the function is below. thank you in advance!
full list of objects in use:
uarts : "pcFullDuplexSerial4FC.spin"
str : "STRINGS.spin"
numbrs :"numbers.spin"
PUB CSV | f,r,count count := 1 f := str.StrPos(@csv_str,comma,0) 'position of first comma mode := numbrs.FromStr(str.strParse(@csv_str,0,f),%1010) {{uarts.dec(uart_debug,mode) uarts.linefeed(uart_debug) uarts.dec(uart_debug,f) uarts.linefeed(uart_debug)} repeat until count == 5 w := 0 r := f + 1 f := str.StrPos(@csv_str,comma,r) case count 'sort data types by location in string 1 : 'date bytemove(@date_full,str.strParse(@csv_str,r,f - r),15) coginit(cid,date,@stack3) repeat while w == 0 'wait for process to finish longmove (@date_conf, @date_end, 3) 'move date to proper variable longfill(@date_end,0,3) 'blank var so next process has a clean slate longfill(@stack2,0,128) 'blank stack so next process has a clean slate 2 : bytemove(@date_full,str.strParse(@csv_str,r,f - r),15) coginit(cid,date,@stack3) 'start the date parser on the same cog as before repeat while w == 0 'wait for process to finish longfill(@date_end,0,3) 'blank var so next process has a clean slate longfill(@stack2,0,128) 'blank stack so next process has a clean slate 3 : uarts.strln(uart_debug,str.strParse(@csv_str,r,f - r)) 4 : uarts.strln(uart_debug,str.strParse(@csv_str,r,f - r)) 'uarts.dec(uart_debug,(f - r)) 'size of var 'uarts.linefeed(uart_debug) count++ x := 1 cogstop(cog_csv)