├── kcs ├── .gitignore ├── junk.py ├── scripts │ ├── 00-dnsmasq-force-reload.sh │ ├── getxports │ └── 01-parse-hosts.sh ├── shared.c ├── examples │ ├── sens.c │ ├── simpleudp.c │ └── asyncconnect.c ├── Makefile ├── r2demo.kcl ├── subprocess.c └── kcserver.c ├── sq ├── .gitignore └── Makefile ├── cmd ├── .gitignore ├── README └── Makefile ├── con ├── .gitignore └── Makefile ├── dmon ├── .gitignore └── Makefile ├── fmon ├── .gitignore └── Makefile ├── fpg ├── .gitignore ├── Makefile └── README ├── log ├── .gitignore └── Makefile ├── mpx ├── .gitignore └── Makefile ├── msg ├── .gitignore ├── Makefile └── msg.c ├── par ├── .gitignore └── Makefile ├── run ├── .gitignore ├── README └── Makefile ├── sgw ├── .gitignore └── Makefile ├── smon ├── .gitignore └── Makefile ├── tmon ├── .gitignore └── Makefile ├── bulkread ├── .gitignore └── Makefile ├── delay ├── .gitignore ├── Makefile └── delay.c ├── xport ├── .gitignore └── Makefile ├── wss ├── README ├── create_certs.sh ├── Makefile └── server.h ├── tcpborphserver3 ├── .gitignore ├── tapper.h ├── loadbof.h ├── tg.h ├── Makefile ├── tapper.c ├── bof.h ├── subprocess.c ├── main.c └── README ├── gmon ├── .gitignore ├── cmdhandler.h ├── reg.h ├── Makefile ├── fpga.h ├── reg.c ├── fpga.c ├── sensor.h ├── gmon.h ├── main.c ├── sensor.c ├── gmon.c └── cmdhandler.c ├── examples ├── .gitignore ├── README ├── Makefile └── new-client-example.c ├── scripts ├── check-sys ├── k7-logs ├── corr ├── capture-status ├── k7-test ├── test-reload-rf-gain ├── k7-quant-snap-shot ├── restart-mode-ready ├── restart ├── halt ├── restart-dummy ├── sync-now ├── k7-beam-passband ├── k7-frequency-select ├── k7-gain ├── k7-accumulation-length ├── k7-channel-select ├── label-clear ├── k7-snap-shot ├── k7-beam-weights ├── xport ├── tcpborphserver-read-tests ├── capture-destination-data ├── capture-destination-meta ├── restart-mode-bwbc4a ├── restart-mode-twbc4a ├── capture-stop ├── restart-mode-c16n400M1k ├── restart-mode-c16n400M8k ├── restart-mode-c16n2M4k ├── restart-mode-c16n3M8k ├── restart-mode-c16n7M4k ├── restart-mode-c16n13M4k ├── restart-mode-c16n25M4k ├── k7-adc-snap-shot ├── restart-mode-c8n25M4k_top ├── restart-mode-c8n7M4k_top ├── restart-mode-c8n7M4k_bottom ├── restart-mode-c8n25M4k_bottom ├── Makefile ├── restart-mode-bc16n400M1k ├── restart-mode-bc8n400M1k_bottom ├── k7-delay ├── restart-mode-bc8n400M1k_top ├── mappings.sh ├── tcpborphserver-write-tests ├── label-input ├── enable-sensors ├── capture-destination ├── capture-start ├── capture-list ├── beamformer.sh ├── functions.sh └── sensors.sh ├── misc ├── kcs.logrotate ├── init.spead ├── Makefile ├── kcs.initscript └── init.katcp ├── .gitignore ├── katcp ├── parse-queue.c ├── README ├── fork-parent.h ├── netc.h ├── TODO ├── loop.c ├── Makefile ├── services.c ├── event.c ├── client.c ├── Makefile.test ├── fork-parent.c ├── avltree.h ├── misc.c ├── API ├── time.c ├── spointer.c └── dpx-misc.c ├── wops └── Makefile ├── modules ├── Makefile └── mod_dsorcer.c ├── TODO ├── Makefile ├── INSTALL ├── README └── Makefile.inc /kcs/.gitignore: -------------------------------------------------------------------------------- 1 | kcs 2 | -------------------------------------------------------------------------------- /sq/.gitignore: -------------------------------------------------------------------------------- 1 | kcpsq 2 | -------------------------------------------------------------------------------- /cmd/.gitignore: -------------------------------------------------------------------------------- 1 | kcpcmd 2 | -------------------------------------------------------------------------------- /con/.gitignore: -------------------------------------------------------------------------------- 1 | kcpcon 2 | -------------------------------------------------------------------------------- /dmon/.gitignore: -------------------------------------------------------------------------------- 1 | dmon 2 | -------------------------------------------------------------------------------- /fmon/.gitignore: -------------------------------------------------------------------------------- 1 | kcpfmon 2 | -------------------------------------------------------------------------------- /fpg/.gitignore: -------------------------------------------------------------------------------- 1 | kcpfpg 2 | -------------------------------------------------------------------------------- /log/.gitignore: -------------------------------------------------------------------------------- 1 | kcplog 2 | -------------------------------------------------------------------------------- /mpx/.gitignore: -------------------------------------------------------------------------------- 1 | kcpmpx 2 | -------------------------------------------------------------------------------- /msg/.gitignore: -------------------------------------------------------------------------------- 1 | kcpmsg 2 | -------------------------------------------------------------------------------- /par/.gitignore: -------------------------------------------------------------------------------- 1 | kcppar 2 | -------------------------------------------------------------------------------- /run/.gitignore: -------------------------------------------------------------------------------- 1 | kcprun 2 | -------------------------------------------------------------------------------- /sgw/.gitignore: -------------------------------------------------------------------------------- 1 | kcpsgw 2 | -------------------------------------------------------------------------------- /smon/.gitignore: -------------------------------------------------------------------------------- 1 | smon 2 | -------------------------------------------------------------------------------- /tmon/.gitignore: -------------------------------------------------------------------------------- 1 | tmon 2 | -------------------------------------------------------------------------------- /bulkread/.gitignore: -------------------------------------------------------------------------------- 1 | kcpbr 2 | -------------------------------------------------------------------------------- /delay/.gitignore: -------------------------------------------------------------------------------- 1 | k7-delay 2 | -------------------------------------------------------------------------------- /xport/.gitignore: -------------------------------------------------------------------------------- 1 | kcpxport 2 | -------------------------------------------------------------------------------- /wss/README: -------------------------------------------------------------------------------- 1 | IPv6 / TLS Websocket server 2 | -------------------------------------------------------------------------------- /tcpborphserver3/.gitignore: -------------------------------------------------------------------------------- 1 | tcpborphserver3 2 | -------------------------------------------------------------------------------- /gmon/.gitignore: -------------------------------------------------------------------------------- 1 | # files to be ignore by git 2 | kcpgmon 3 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | client-example 2 | new-client-example 3 | server-example 4 | -------------------------------------------------------------------------------- /scripts/check-sys: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source functions.sh 3 | katcpcmd -t 60 check-sys 4 | -------------------------------------------------------------------------------- /scripts/k7-logs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | source functions.sh 4 | kcs_corr_log 5 | -------------------------------------------------------------------------------- /scripts/corr: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | exec kcpfmon ${KATCP_SERVER} 7 | -------------------------------------------------------------------------------- /tcpborphserver3/tapper.h: -------------------------------------------------------------------------------- 1 | #ifndef TAPPER_H_ 2 | #define TAPPER_H_ 3 | 4 | int tap_open(char *name); 5 | int tap_close(int fd); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /misc/kcs.logrotate: -------------------------------------------------------------------------------- 1 | /var/log/kcs.kcplog { 2 | rotate 52 3 | weekly 4 | postrotate 5 | /usr/bin/killall -HUP kcplog 6 | endscript 7 | } 8 | 9 | -------------------------------------------------------------------------------- /scripts/capture-status: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcpcmd -t 10 -i -k tx-status $* | sed -e 's/^!tx-status/#return/' 7 | -------------------------------------------------------------------------------- /kcs/junk.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | print "#log warn $(date +%s)000 junk example\\_log\\_capture" 4 | for n in range(0,100): 5 | print "#log warn 00 junk.py "+str(n); 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # files to be ignored by git 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # ignore eclipse project files 7 | .cproject 8 | .project 9 | .settings/ 10 | 11 | # ignore ctags 12 | tags 13 | core 14 | -------------------------------------------------------------------------------- /scripts/k7-test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source functions.sh 4 | 5 | sleep 1 6 | echo "#log info $(date +%s)000 k7-test simple\_test\_script" 7 | sleep 1 8 | kcs_error "some error test example" 9 | 10 | exit 0 11 | -------------------------------------------------------------------------------- /scripts/test-reload-rf-gain: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source functions.sh 4 | 5 | kcpmsg -l debug -s reload "about to reload roach monitors" 6 | 7 | kill -HUP $(ps axo comm,pid | tr -s ' ' | grep roach | cut -f2 -d\ ) || exit 0 8 | -------------------------------------------------------------------------------- /kcs/scripts/00-dnsmasq-force-reload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | case $1 in 4 | force-reload) 5 | /etc/init.d/dnsmasq force-reload 6 | ;; 7 | *) 8 | echo "usage $0: [force-reload]" 9 | exit 1 10 | ;; 11 | esac 12 | -------------------------------------------------------------------------------- /scripts/k7-quant-snap-shot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | source functions.sh 6 | 7 | kcs_arg_check $# 1 8 | 9 | kcpcmd -t 27 -r -k get-quant-snapshot $* | sed -e 's/^#get-quant-snapshot/#k7-quant-snap-shot/' 10 | -------------------------------------------------------------------------------- /kcs/scripts/getxports: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | grep roach.*x /etc/hosts | tr -s \ | while read myip myhost; do /home/adam/katcp-git/cmd/kcpcmd -s localhost:7147 roach add $(echo xport://$myhost:10001/ | cut -f1 -d.) $myip xport ; done 4 | 5 | -------------------------------------------------------------------------------- /scripts/restart-mode-ready: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | await_mode_sensors 9 | disable_bf_count 10 | 11 | change_mode_sensors ${KATCP_MODE} ready 12 | 13 | 14 | -------------------------------------------------------------------------------- /scripts/restart: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_info "initiating restart" 7 | shutdown -r -t 10 now "katcp restart from ${KATCP_CLIENT}. Use shutdown -c to cancel" < /dev/console >& /dev/console 8 | 9 | exit 0 10 | -------------------------------------------------------------------------------- /cmd/README: -------------------------------------------------------------------------------- 1 | 2 | This is a commandline tool to speak katcp to a remote server. 3 | Invoke it with -h to see usage information. It is not necessary 4 | to specify a ? in the requests given to it 5 | 6 | Example use 7 | 8 | $ kcpcmd -s some-roach:7147 help 9 | -------------------------------------------------------------------------------- /scripts/halt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_info "initiating halt" 7 | xport stop 8 | shutdown -h -t 10 now "katcp halt from ${KATCP_CLIENT}. Use shutdown -c to cancel" < /dev/console >& /dev/console 9 | 10 | exit 0 11 | -------------------------------------------------------------------------------- /misc/init.spead: -------------------------------------------------------------------------------- 1 | ?setenv PATH /usr/local/lib/kcs/scripts:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/sbin:/usr/sbin 2 | ?chdir /usr/local/lib/kcs 3 | ?job process ss-a exec://speadrx -p 8888 -r /tmp/pol-01 4 | ?job process ss-b exec://speadrx -p 9999 -r /tmp/pol-02 5 | 6 | -------------------------------------------------------------------------------- /scripts/restart-dummy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | source functions.sh 6 | 7 | TARGET_MODE=b16n400M1k 8 | 9 | kcs_load_config ${TARGET_MODE} 10 | 11 | kcppar -n -v -m -s ${var_servers_f} -x progdev ${var_bitstream_f} -s ${var_servers_x} -x progdev ${var_bitstream_x} 12 | 13 | -------------------------------------------------------------------------------- /scripts/sync-now: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_debug "about to run resync" 7 | 8 | status=1 9 | 10 | if kcpcmd -k -r -t 10 resync ; then 11 | status=0 12 | else 13 | kcs_error "corr resync failed" 14 | fi 15 | 16 | kcs_corr_log 17 | exit $status 18 | -------------------------------------------------------------------------------- /wss/create_certs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CERTDIR=./certs 4 | 5 | KEY=$CERTDIR/server.key 6 | CSR=$CERTDIR/server.csr 7 | CRT=$CERTDIR/server.crt 8 | 9 | set -xe 10 | 11 | openssl genrsa -out $KEY 4096 12 | 13 | openssl req -new -key $KEY -out $CSR 14 | 15 | openssl x509 -req -days 365 -in $CSR -signkey $KEY -out $CRT 16 | -------------------------------------------------------------------------------- /run/README: -------------------------------------------------------------------------------- 1 | 2 | kcprun is a wrapper for an arbitrary executable which will, by 3 | default, 4 | 5 | - rewrite messages to stdout as katcp info messages 6 | - rewrite messages to stderr as katcp error messages 7 | - terminate the process on encountering an eof on stdin 8 | 9 | example use: 10 | 11 | $ kcprun ls 12 | 13 | $ kcprun ls something-nonexistant 14 | -------------------------------------------------------------------------------- /scripts/k7-beam-passband: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 3 7 | 8 | if kcs_is_beamformer ${KATCP_MODE} ; then 9 | if kcs_set_passband $* ; then 10 | exit 0 11 | fi 12 | else 13 | echo "#return fail unavailable" 14 | kcs_error "beam selection not available in mode ${KATCP_MODE}" 15 | fi 16 | 17 | exit 1 18 | 19 | -------------------------------------------------------------------------------- /scripts/k7-frequency-select: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 1 7 | 8 | if kcs_is_narrowband ${KATCP_MODE} ; then 9 | if kcs_set_frequency $* ; then 10 | exit 0 11 | fi 12 | else 13 | echo "#return fail unavailable" 14 | kcs_error "frequency selection not available in ${KATCP_MODE} mode" 15 | fi 16 | 17 | exit 1 18 | -------------------------------------------------------------------------------- /gmon/cmdhandler.h: -------------------------------------------------------------------------------- 1 | /* TODO Add more information 2 | * 3 | * 4 | * 5 | */ 6 | 7 | #ifndef _KATCP_CMDHANDLER_H_ 8 | #define _KATCP_CMDHANDLER_H_ 9 | 10 | #include "gmon.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | int cmdhandler(struct gmon_lib *g); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* _KATCP_CMDHANDLER_H_ */ 23 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | server-example.c - an example of a server listening to connections, 2 | accepting them and processing requests from 3 | clients 4 | 5 | client-example.c - an example of something connecting to a process, 6 | reading requests and sending replies. Probably 7 | a less common application than server-example.c 8 | 9 | -------------------------------------------------------------------------------- /katcp/parse-queue.c: -------------------------------------------------------------------------------- 1 | #ifdef KATCP_EXPERIMENTAL 2 | 3 | #include 4 | #include 5 | 6 | void void_destroy_parse_katcl(void *v) 7 | { 8 | struct katcl_parse *px; 9 | 10 | px = v; 11 | 12 | destroy_parse_katcl(px); 13 | } 14 | 15 | struct katcl_gueue *create_parse_gueue_katcl() 16 | { 17 | return create_gueue_katcl(&void_destroy_parse_katcl); 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /scripts/k7-gain: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 1 7 | 8 | if [ "$#" -le 1 ] ; then 9 | kcpcmd -i -k eq-get $1 | tr -d '()' | sed -e 's/^!eq-get/#return/' 10 | else 11 | status=1 12 | 13 | kcs_debug "setting gain to $*" 14 | 15 | if kcpcmd -k -m eq-set $* ; then 16 | status=0 17 | fi 18 | 19 | kcs_corr_log 20 | exit $status 21 | fi 22 | -------------------------------------------------------------------------------- /kcs/shared.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "kcs.h" 6 | 7 | #if 0 8 | char *create_str(char *s){ 9 | char *nstr; 10 | if (!s) 11 | return NULL; 12 | nstr = NULL; 13 | nstr = malloc(sizeof(char)*(strlen(s)+1)); 14 | if (!nstr) 15 | return NULL; 16 | nstr = strcpy(nstr,s); 17 | nstr[strlen(s)] = '\0'; 18 | return nstr; 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /gmon/reg.h: -------------------------------------------------------------------------------- 1 | /* TODO Add more information 2 | * 3 | * 4 | * 5 | */ 6 | 7 | #ifndef _GMON_REGISTER_H_ 8 | #define _GMON_REGISTER_H_ 9 | 10 | #include 11 | 12 | #include "katcp.h" 13 | #include "katcl.h" 14 | #include "katpriv.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | int reg_req_wordread(struct katcl_line *l, char *reg); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif /* _GMON_REGISTER_H_ */ 27 | -------------------------------------------------------------------------------- /katcp/README: -------------------------------------------------------------------------------- 1 | KATCP: KAT control protocol 2 | --------------------------- 3 | 4 | Type 5 | 6 | make 7 | 8 | to build 9 | 10 | Type 11 | 12 | make install 13 | 14 | to install the library into /usr/local/ 15 | 16 | Type 17 | 18 | make PREFIX=/some/where/else install 19 | 20 | to pick a different install path. The subdirectories include/ 21 | and lib/ will be created in this directory. 22 | 23 | API 24 | 25 | described in the file API 26 | 27 | -------------------------------------------------------------------------------- /log/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | 8 | EXE = kcplog 9 | SRC = log.c 10 | 11 | OBJ = $(patsubst %.c,%.o,$(SRC)) 12 | 13 | all: $(EXE) 14 | 15 | $(EXE): $(OBJ) 16 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 17 | 18 | install: all 19 | $(INSTALL) $(EXE) $(PREFIX)/bin 20 | 21 | %.o: %.c $(wildcard *.h) 22 | $(CC) $(CFLAGS) -c $< $(INC) 23 | 24 | clean: 25 | $(RM) $(OBJ) core $(EXE) 26 | -------------------------------------------------------------------------------- /sq/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | 8 | EXE = kcpsq 9 | SRC = sq.c 10 | 11 | OBJ = $(patsubst %.c,%.o,$(SRC)) 12 | 13 | all: $(EXE) 14 | 15 | $(EXE): $(OBJ) 16 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 17 | 18 | install: all 19 | $(INSTALL) $(EXE) $(PREFIX)/bin 20 | 21 | %.o: %.c $(wildcard *.h) 22 | $(CC) $(CFLAGS) -c $< $(INC) 23 | 24 | clean: 25 | $(RM) $(OBJ) core $(EXE) 26 | -------------------------------------------------------------------------------- /wops/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | 8 | EXE = kcpwops 9 | SRC = wops.c 10 | 11 | OBJ = $(patsubst %.c,%.o,$(SRC)) 12 | 13 | all: $(EXE) 14 | 15 | $(EXE): $(OBJ) 16 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 17 | 18 | %.o: %.c $(wildcard *.h) 19 | $(CC) $(CFLAGS) -c $< $(INC) 20 | 21 | clean: 22 | $(RM) $(OBJ) core $(EXE) 23 | 24 | install: all 25 | $(INSTALL) $(EXE) $(PREFIX)/bin 26 | -------------------------------------------------------------------------------- /fmon/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp -lm 7 | 8 | EXE = kcpfmon 9 | SRC = fmon.c 10 | 11 | OBJ = $(patsubst %.c,%.o,$(SRC)) 12 | 13 | all: $(EXE) 14 | 15 | $(EXE): $(OBJ) 16 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 17 | 18 | %.o: %.c $(wildcard *.h) 19 | $(CC) $(CFLAGS) -c $< $(INC) 20 | 21 | clean: 22 | $(RM) $(OBJ) core $(EXE) 23 | 24 | install: all 25 | $(INSTALL) $(EXE) $(PREFIX)/bin 26 | -------------------------------------------------------------------------------- /tcpborphserver3/loadbof.h: -------------------------------------------------------------------------------- 1 | #ifndef LOAD_BOF_H_ 2 | #define LOAD_BOF_H_ 3 | 4 | struct bof_state; 5 | 6 | struct bof_state *open_bof(struct katcp_dispatch *d, char *name); 7 | struct bof_state *open_bof_fd(struct katcp_dispatch *d, int fd); 8 | void close_bof(struct katcp_dispatch *d, struct bof_state *bs); 9 | 10 | int program_bof(struct katcp_dispatch *d, struct bof_state *bs, char *device); 11 | int index_bof(struct katcp_dispatch *d, struct bof_state *bs); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /bulkread/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | 8 | EXE = kcpbr 9 | SRC = br.c 10 | 11 | OBJ = $(patsubst %.c,%.o,$(SRC)) 12 | 13 | all: $(EXE) 14 | 15 | $(EXE): $(OBJ) $(KATCP)/libkatcp.a 16 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 17 | 18 | install: all 19 | $(INSTALL) $(EXE) $(PREFIX)/bin 20 | 21 | %.o: %.c $(wildcard *.h) 22 | $(CC) $(CFLAGS) -c $< $(INC) 23 | 24 | clean: 25 | $(RM) $(OBJ) core $(EXE) 26 | -------------------------------------------------------------------------------- /scripts/k7-accumulation-length: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 1 7 | 8 | if [ "${1%%.*}" -lt "10" ] ; then 9 | kcs_warn "accumulation length ${1} set outside requirement" 10 | fi 11 | 12 | kcs_corr_log 13 | kcpcmd -t 17 -i -k acc-time $(echo ${1}/1000 | bc -l | sed -e 's/^\./0./' ) | (read cmd code value ; if [ ${code} != "ok" ] ; then echo "#return ${code} ${value}" ; else echo "#return ok $(echo ${value}*1000 | bc -l | sed -e 's/^\./0./' )" ; fi) 14 | 15 | -------------------------------------------------------------------------------- /dmon/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | 8 | EXE = dmon 9 | SRC = dmon.c 10 | 11 | # CFLAGS += -DSTANDALONE 12 | # CFLAGS += -DDEBUG 13 | 14 | OBJ = $(patsubst %.c,%.o,$(SRC)) 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) $(KATCP)/libkatcp.a 18 | $(CC) -o $@ $^ $(LIB) 19 | 20 | clean: 21 | $(RM) -f $(EXE) *.o 22 | 23 | %.o: %.c 24 | $(CC) $(CFLAGS) -c $< -o $@ $(INC) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/sbin 28 | -------------------------------------------------------------------------------- /gmon/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp -lm 7 | 8 | EXE = kcpgmon 9 | SRC = main.c gmon.c cmdhandler.c fpga.c sensor.c reg.c 10 | 11 | OBJ = $(patsubst %.c,%.o,$(SRC)) 12 | 13 | all: $(EXE) 14 | 15 | $(EXE): $(OBJ) 16 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 17 | 18 | %.o: %.c $(wildcard *.h) 19 | $(CC) $(CFLAGS) -c $< $(INC) 20 | 21 | clean: 22 | $(RM) $(OBJ) core $(EXE) 23 | 24 | install: all 25 | $(INSTALL) $(EXE) $(PREFIX)/bin 26 | -------------------------------------------------------------------------------- /smon/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | 8 | EXE = smon 9 | SRC = smon.c 10 | 11 | # CFLAGS += -DSTANDALONE 12 | # CFLAGS += -DDEBUG 13 | 14 | OBJ = $(patsubst %.c,%.o,$(SRC)) 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) $(KATCP)/libkatcp.a 18 | $(CC) -o $@ $^ $(LIB) 19 | 20 | clean: 21 | $(RM) -f $(EXE) *.o 22 | 23 | %.o: %.c 24 | $(CC) $(CFLAGS) -c $< -o $@ $(INC) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/sbin 28 | -------------------------------------------------------------------------------- /tmon/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | 8 | EXE = tmon 9 | SRC = tmon.c 10 | 11 | # CFLAGS += -DSTANDALONE 12 | # CFLAGS += -DDEBUG 13 | 14 | OBJ = $(patsubst %.c,%.o,$(SRC)) 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) $(KATCP)/libkatcp.a 18 | $(CC) -o $@ $^ $(LIB) 19 | 20 | clean: 21 | $(RM) -f $(EXE) *.o 22 | 23 | %.o: %.c 24 | $(CC) $(CFLAGS) -c $< -o $@ $(INC) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/sbin 28 | -------------------------------------------------------------------------------- /con/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcpcon 11 | SRC = con.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /fpg/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcpfpg 11 | SRC = fpg.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /gmon/fpga.h: -------------------------------------------------------------------------------- 1 | /* TODO Add more information 2 | * 3 | * 4 | * 5 | */ 6 | 7 | #ifndef _FPGA_H_ 8 | #define _FPGA_H_ 9 | 10 | #include "katcp.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | enum fpga_req_cmd { 17 | FPGA_REQ_STATUS, ///< ?fpgastatus 18 | FPGA_REQ_LISTDEV, ///< ?listdev 19 | FPGA_REQ_META ///< ?meta 20 | }; 21 | 22 | int fpga_req_cmd(struct katcl_line *l, enum fpga_req_cmd cmd); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* _FPGA_H_ */ 29 | -------------------------------------------------------------------------------- /mpx/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcpmpx 11 | SRC = mpx.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /msg/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcpmsg 11 | SRC = msg.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /par/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcppar 11 | SRC = par.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /run/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcprun 11 | SRC = run.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /sgw/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcpsgw 11 | SRC = sgw.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /xport/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp 9 | 10 | EXE = kcpxport 11 | SRC = xport.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /delay/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | 7 | INC = -I$(KATCP) 8 | LIB = -L$(KATCP) -lkatcp -lm 9 | 10 | EXE = k7-delay 11 | SRC = delay.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | 15 | all: $(EXE) 16 | 17 | $(EXE): $(OBJ) 18 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 19 | 20 | %.o: %.c $(wildcard *.h) 21 | $(CC) $(CFLAGS) -c $< $(INC) 22 | 23 | clean: 24 | $(RM) $(OBJ) core $(EXE) 25 | 26 | install: all 27 | $(INSTALL) $(EXE) $(PREFIX)/bin 28 | -------------------------------------------------------------------------------- /scripts/k7-channel-select: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 1 7 | 8 | channel=$1 9 | mixed=0 10 | 11 | if [ $# -ge 2 ] ; then 12 | if [ "$2" = "mixed" ] ; then 13 | mixed=1 14 | fi 15 | fi 16 | 17 | kcs_config_numeric coarse_chans 18 | 19 | if [ ${channel} -gt ${coarse_chans} ] ; then 20 | kcs_error "coarse channel count ${channel} out of range" 21 | fi 22 | 23 | kcs_debug "chansel with ${channel} ${mixed}" 24 | 25 | corr_nb_chansel.py -c ${channel} -m ${mixed} >& /dev/null 26 | -------------------------------------------------------------------------------- /scripts/label-clear: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # TODO: should update files atomically 4 | 5 | set -e 6 | source functions.sh 7 | source mappings.sh 8 | 9 | if [ ! -s ${MAIN_MAPPING} -o $# -lt 1 ] ; then 10 | kcs_info "generating new mapping" 11 | make_mapping 2 12 | fi 13 | 14 | if [ $# -ge 1 ] ; then 15 | inp=${1} 16 | alias=${1} 17 | 18 | kcs_debug "setting label for ${inp} to ${alias}" 19 | 20 | sed -i -e "s/^.*:${inp}:\(.*\)$/${alias}:${inp}:\1/" ${MAIN_MAPPING} 21 | fi 22 | 23 | update_aliases 24 | 25 | exit 0 26 | 27 | -------------------------------------------------------------------------------- /cmd/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 6 | CFLAGS += -DVERSION=\"$(GITVER)\" 7 | 8 | 9 | INC = -I$(KATCP) 10 | LIB = -L$(KATCP) -lkatcp 11 | 12 | EXE = kcpcmd 13 | SRC = cmd.c 14 | 15 | OBJ = $(patsubst %.c,%.o,$(SRC)) 16 | 17 | all: $(EXE) 18 | 19 | $(EXE): $(OBJ) 20 | $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIB) 21 | 22 | %.o: %.c $(wildcard *.h) 23 | $(CC) $(CFLAGS) -c $< $(INC) 24 | 25 | clean: 26 | $(RM) $(OBJ) core $(EXE) 27 | 28 | install: all 29 | $(INSTALL) $(EXE) $(PREFIX)/bin 30 | -------------------------------------------------------------------------------- /gmon/reg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "reg.h" 5 | 6 | #define REG_KATCP_WORDREAD "?wordread" 7 | 8 | int reg_req_wordread(struct katcl_line *l, char *reg) 9 | { 10 | int ret = 0; 11 | 12 | if (l == NULL) { 13 | fprintf(stderr, "NULL katcl_line pointer"); 14 | return -1; 15 | } 16 | 17 | ret += append_string_katcl(l, KATCP_FLAG_FIRST | KATCP_FLAG_STRING, REG_KATCP_WORDREAD); 18 | ret += append_string_katcl(l, KATCP_FLAG_LAST | KATCP_FLAG_STRING, reg); 19 | 20 | return ret; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /kcs/scripts/01-parse-hosts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #workingdir=~/work/katcp-git 4 | workingdir=~/katcp-git 5 | 6 | #hostsfile=$workingdir/kcs/scripts/hosts 7 | hostfile=/etc/hosts 8 | #kcpcmd="$workingdir/cmd/kcpcmd -q -s localhost:7147 roach add" 9 | kcpcmd=echo 10 | 11 | grep roach.*x $hostsfile | tr -s \ | (while read myip myhost; do $kcpcmd $(echo xport://$myhost:10001/ | cut -f1 -d.) $myip xport ; done) 12 | 13 | #grep 'roach[[:digit:]]*\.' $hostsfile | tr -s \ | (while read myip myhost; do $kcpcmd $(echo katcp://$myhost:7147/ | cut -f1 -d.) $myip spare ; done) 14 | -------------------------------------------------------------------------------- /scripts/k7-snap-shot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | source functions.sh 6 | 7 | if [ $# -lt 1 ] ; then 8 | exit 1 9 | fi 10 | 11 | case "$1" in 12 | adc) 13 | kcpcmd -t 10 -k get-adc-snapshot ${2} | sed -e 's/^!get-adc-snapshot/#return/' 14 | ;; 15 | quant) 16 | #kcpcmd -k get-quant-snapshot ${2} | sed -e 's/^!get-quant-snapshot/#return/' 17 | kcpcmd -t 10 -r -k get-quant-snapshot ${2} | sed -e 's/^#get-quant-snapshot/#return ok/' 18 | ;; 19 | *) 20 | kcs_error "unknown snap shot ${1}" 21 | exit 1 22 | 23 | ;; 24 | esac 25 | 26 | -------------------------------------------------------------------------------- /scripts/k7-beam-weights: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 2 7 | 8 | if kcs_is_beamformer ${KATCP_MODE} ; then 9 | if [ "$#" -eq 2 ] ; then 10 | kcpcmd -i -k weights-get $1 $2 | tr -d '()' | sed -e 's/^!weights-get/#return/' 11 | else 12 | status=1 13 | 14 | kcs_debug "setting $*" 15 | 16 | if kcpcmd -k -t 300 -m weights-set $* ; then 17 | status=0 18 | fi 19 | 20 | kcs_corr_log 21 | exit $status 22 | fi 23 | else 24 | echo "#return fail unavailable" 25 | kcs_error "beam selection not available in mode ${KATCP_MODE}" 26 | fi 27 | -------------------------------------------------------------------------------- /katcp/fork-parent.h: -------------------------------------------------------------------------------- 1 | #ifndef FORK_PARENT_H_ 2 | #define FORK_PARENT_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* example use: 9 | * 10 | * fork_parent(); 11 | * 12 | * perform setup routines. write errors to stderr 13 | * 14 | * ... 15 | * 16 | * write_pid_file(); 17 | * chdir("/"); 18 | * 19 | * ... 20 | * 21 | * fflush(stderr); 22 | * close(STDERR_FILENO); 23 | * 24 | * optionally: 25 | * point STDERR_FILENO at /dev/null or a logfile 26 | * 27 | */ 28 | 29 | /* returns zero on success, nonzero otherwise */ 30 | int fork_parent(); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /scripts/xport: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | source functions.sh 6 | 7 | ROACHES=$(grep '^ *servers_' /etc/corr/* | cut -f2 -d= | tr , '\n' | tr -d ' ' | sort -u) 8 | declare -a vector 9 | 10 | if [ "$1" = "stop" -o "$1" = "start" ] ; then 11 | i=0; for name in ${ROACHES} ; do vector[$i]=$(echo kcpxport -D ${name}x) ; i=$[i+1] ; done 12 | if ! kcpcon "${vector[@]}" ; then 13 | sleep 1 14 | fi 15 | 16 | if [ "$1" = "start" ] ; then 17 | i=0; for name in ${ROACHES} ; do vector[$i]=$(echo kcpxport -U ${name}x) ; i=$[i+1] ; done 18 | kcpcon "${vector[@]}" 19 | fi 20 | else 21 | kcs_error "invalid argument" 22 | exit 1 23 | fi 24 | 25 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp 7 | BUILD = unknown-0.1 8 | 9 | EXE = new-client-example client-example server-example 10 | 11 | all: $(EXE) 12 | 13 | new-client-example: new-client-example.c 14 | $(CC) -DBUILD=\"$(BUILD)\" $(CFLAGS) $(INC) -o $@ $^ $(LIB) 15 | 16 | client-example: client-example.c 17 | $(CC) -DBUILD=\"$(BUILD)\" $(CFLAGS) $(INC) -o $@ $^ $(LIB) 18 | 19 | server-example: server-example.c 20 | $(CC) -DBUILD=\"$(BUILD)\" $(CFLAGS) $(INC) -o $@ $^ $(LIB) 21 | 22 | clean: 23 | $(RM) $(EXE) 24 | 25 | install: $(EXE) 26 | $(ECHO) "not installing examples" 27 | 28 | -------------------------------------------------------------------------------- /misc/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.inc 2 | 3 | # in theory this should live in /etc/kcs 4 | CMDSDIR = $(PREFIX)/lib/kcs 5 | CMDS = init.katcp 6 | 7 | # startup routines 8 | INITDIR = /etc/init.d 9 | INITSCRIPT = kcs.initscript 10 | 11 | # log rotation 12 | LOGROTATEDIR = /etc/logrotate.d 13 | LOGROTATE = kcs.logrotate 14 | 15 | 16 | all: 17 | 18 | clean: 19 | 20 | install: all 21 | $(INSTALL) -d $(CMDSDIR) 22 | $(INSTALL) $(CMDS) $(CMDSDIR)/$(CMDS) 23 | 24 | $(INSTALL) -d $(INITDIR) 25 | $(INSTALL) $(INITSCRIPT) $(INITDIR)/$(basename $(INITSCRIPT)) 26 | 27 | $(INSTALL) -d $(LOGROTATEDIR) 28 | $(INSTALL) $(LOGROTATE) $(LOGROTATEDIR)/$(basename $(LOGROTATE)) 29 | -------------------------------------------------------------------------------- /scripts/tcpborphserver-read-tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | function read_check() 6 | { 7 | value=$(kcpcmd -p 2 -i read sys_scratchpad "$1" "$2") 8 | if [ "${value}" != "$3" ] ; then 9 | echo "read test failed: expected ${1}, got ${value}" 10 | return 1; 11 | else 12 | echo "test ok: result is ${value}" 13 | return 0; 14 | fi 15 | } 16 | 17 | kcpcmd -i write sys_scratchpad 0 'UOf0' 18 | 19 | read_check 0 4 'UOf0' 20 | read_check 1 3 'Of0' 21 | read_check 2 2 'f0' 22 | read_check 3 1 '0' 23 | 24 | read_check 0:4 1 'T' 25 | read_check 2:4 1 'c' 26 | read_check 0:2 1 'U' 27 | read_check 0:10 0:8 '=' 28 | read_check 0:25 0:7 '`' 29 | 30 | -------------------------------------------------------------------------------- /gmon/fpga.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "fpga.h" 5 | #include "katpriv.h" 6 | #include "katcl.h" 7 | 8 | /* IMPORTANT: This shall map to 'enum fpga_req_cmd' */ 9 | static char *FPGA_REQ_CMD_STR[] = {"?fpgastatus", "?listdev", "?meta"}; 10 | 11 | int fpga_req_cmd(struct katcl_line *l, enum fpga_req_cmd cmd) 12 | { 13 | int ret = 0; 14 | 15 | if (l == NULL) { 16 | fprintf(stderr, "NULL katcl_line ptr"); 17 | return -1; 18 | } 19 | 20 | ret += append_string_katcl(l, KATCP_FLAG_FIRST | KATCP_FLAG_STRING 21 | | KATCP_FLAG_LAST, FPGA_REQ_CMD_STR[cmd]); 22 | 23 | return ret; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /wss/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | #SSLBUILD = /home/adam/build/openssl-1.0.0e 3 | include ../Makefile.inc 4 | 5 | #INC = -I$(SSLBUILD)/include,$(KATCP) 6 | #LIB = -L$(KATCP) -lkatcp 7 | #LIB = -L$(SSLBUILD) -lssl -lcrypto -lz -ldl 8 | LIB = -lssl 9 | 10 | EXE = wss 11 | SRC = server.c wss.c 12 | HDR = server.h 13 | 14 | # CFLAGS += -DSTANDALONE 15 | # CFLAGS += -DDEBUG 16 | 17 | OBJ = $(patsubst %.c,%.o,$(SRC)) 18 | all: $(EXE) 19 | 20 | #$(EXE): $(OBJ) $(KATCP)/libkatcp.a 21 | $(EXE): $(OBJ) 22 | $(CC) -o $@ $^ $(LIB) 23 | 24 | clean: 25 | $(RM) -f $(EXE) *.o 26 | 27 | %.o: %.c 28 | $(CC) $(CFLAGS) -c $< -o $@ $(INC) 29 | 30 | install: all 31 | $(INSTALL) $(EXE) $(PREFIX)/sbin 32 | -------------------------------------------------------------------------------- /scripts/capture-destination-data: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source functions.sh 4 | source beamformer.sh 5 | 6 | if ! kcs_is_beamformer ${KATCP_MODE} ; then 7 | kcs_error "no beams available in this mode" 8 | exit 1 9 | fi 10 | 11 | if [ $# -lt 3 ] ; then 12 | kcs_error "require three parameters: stream ip port" 13 | exit 1 14 | fi 15 | 16 | output=$1 17 | host=$2 18 | port=$3 19 | 20 | case "${output}" in 21 | bf0|bf1) 22 | kcpcmd -s localhost:7147 -k -i -r setenv KCS_${output^^*}DATA_RX $host:$port 23 | kcs_info "set ${output} data destination to $host:$port" 24 | ;; 25 | *) 26 | kcs_error "unsupported data stream ${output}" 27 | exit 1 28 | ;; 29 | esac 30 | 31 | exit 0 32 | -------------------------------------------------------------------------------- /scripts/capture-destination-meta: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source functions.sh 4 | source beamformer.sh 5 | 6 | if ! kcs_is_beamformer ${KATCP_MODE} ; then 7 | kcs_error "no beams available in this mode" 8 | exit 1 9 | fi 10 | 11 | if [ $# -lt 3 ] ; then 12 | kcs_error "require three parameters: stream ip port" 13 | exit 1 14 | fi 15 | 16 | output=$1 17 | host=$2 18 | port=$3 19 | 20 | case "${output}" in 21 | bf0|bf1) 22 | kcpcmd -s localhost:7147 -k -i -r setenv KCS_${output^^*}META_RX $host:$port 23 | kcs_info "set ${output} meta destination to $host:$port" 24 | ;; 25 | *) 26 | kcs_error "unsupported data stream ${output}" 27 | exit 1 28 | ;; 29 | esac 30 | 31 | exit 0 32 | -------------------------------------------------------------------------------- /katcp/netc.h: -------------------------------------------------------------------------------- 1 | #ifndef NETC_H_ 2 | #define NETC_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define NETC_VERBOSE_ERRORS 0x01 9 | #define NETC_VERBOSE_STATS 0x02 10 | #define NETC_ASYNC 0x04 11 | #define NETC_TCP_KEEP_ALIVE 0x08 12 | #define NETC_AUTO_PORT 0x10 13 | #define NETC_TCP_USR_TIMEOUT 0x20 14 | 15 | #define NETC_DEFAULT_PORT 7147 16 | 17 | #include 18 | #include 19 | 20 | int net_connect(char *name, int port, int flags); 21 | int net_listen(char *name, int port, int flags); 22 | int net_address(struct sockaddr *sa, char *name, int port, int flags); 23 | unsigned int net_port_fixup(unsigned int port); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /modules/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) -I../kcs 6 | LIB = -L$(KATCP) -lkatcp -lcrypt 7 | CFLAGS += -fPIC 8 | CFLAGS += -DVERSION=\"$(GITVER)\" 9 | LDFLAGS += -shared 10 | vpath %.c ../kcs 11 | 12 | DEPENDS = statemachine.c actor.c statemachine_base.c 13 | SRC = mod_dsorcer.c mod_conf_parser.c mod_simple_ops.c mod_roach_comms.c 14 | 15 | DOBJ = $(patsubst %.c,%.o,$(DEPENDS)) 16 | OBJ = $(patsubst %.c,%.o,$(SRC)) $(DOBJ) 17 | MOD = $(patsubst %.c,%.so,$(SRC)) 18 | 19 | all: $(MOD) 20 | 21 | %.so: %.o $(DOBJ) 22 | $(CC) $(LDFLAGS) -Wl,-soname=$@ $^ -o $@ $(LIB) 23 | 24 | %.o: %.c $(wildcard *.h) 25 | $(CC) $(CFLAGS) -c $< $(INC) -o $@ 26 | 27 | clean: 28 | $(RM) $(OBJ) core $(MOD) 29 | 30 | -------------------------------------------------------------------------------- /misc/kcs.initscript: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: kcs 5 | # Required-Start: $network $local_fs 6 | # Required-Stop: $network $local_fs 7 | # Default-Start: S 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: KAT7 Control Server 10 | # Description: Provides a KATCP control server listening on port 7147 11 | ### END INIT INFO 12 | 13 | ulimit -c unlimited 14 | export PATH=/usr/local/sbin:/usr/local/bin:$PATH 15 | 16 | case "$1" in 17 | start) 18 | kcs -i /usr/local/lib/kcs/init.katcp 19 | kcplog -a 5 -d -o /var/log/kcs.kcplog -s localhost:7147 20 | ;; 21 | stop) 22 | #kcpcmd -s localhost:7147 halt 23 | killall kcs 24 | exit 0 25 | ;; 26 | *) 27 | echo "Usage: $0 {start|stop}" >&2 28 | exit 3 29 | ;; 30 | esac 31 | 32 | -------------------------------------------------------------------------------- /scripts/restart-mode-bwbc4a: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to wideband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr bwbc4a 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/bwbc4a ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} bwbc4a 33 | exit 0 34 | fi 35 | 36 | kcs_corr_log 37 | kcs_error "corr initialise failed" 38 | 39 | exit 1 40 | -------------------------------------------------------------------------------- /scripts/restart-mode-twbc4a: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to wideband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr twbc4a 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/twbc4a ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} twbc4a 33 | exit 0 34 | fi 35 | 36 | kcs_corr_log 37 | kcs_error "corr initialise failed" 38 | 39 | exit 1 40 | -------------------------------------------------------------------------------- /scripts/capture-stop: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 1 7 | stream=$1 8 | 9 | kcs_debug "about to run tx-stop" 10 | 11 | if kcs_is_beamformer ${KATCP_MODE} ; then 12 | option=${stream} 13 | fi 14 | 15 | case "${stream}" in 16 | k7) 17 | kcs_info "stopping correlator stream ${stream}" 18 | ;; 19 | bf0|bf1) 20 | if kcs_is_beamformer ${KATCP_MODE} ; then 21 | kcs_info "stopping beam stream ${stream}" 22 | else 23 | kcs_error "datastream ${stream} not available in this mode" 24 | fi 25 | ;; 26 | *) 27 | kcs_error "unknown data stream ${stream}" 28 | ;; 29 | esac 30 | 31 | if kcpcmd -k -m tx-stop ${option}; then 32 | status=0 33 | else 34 | kcs_warn "${stream} stop failed" 35 | status=1 36 | fi 37 | 38 | kcs_corr_log 39 | exit $status 40 | -------------------------------------------------------------------------------- /scripts/restart-mode-c16n400M1k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to wideband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr c16n400M1k 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/c16n400M1k ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} c16n400M1k 33 | exit 0 34 | fi 35 | 36 | kcs_corr_log 37 | kcs_error "corr initialise failed" 38 | 39 | exit 1 40 | -------------------------------------------------------------------------------- /scripts/restart-mode-c16n400M8k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to wideband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr c16n400M8k 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/c16n400M8k ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} c16n400M8k 33 | exit 0 34 | fi 35 | 36 | kcs_corr_log 37 | kcs_error "corr initialise failed" 38 | 39 | exit 1 40 | -------------------------------------------------------------------------------- /scripts/restart-mode-c16n2M4k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to narrowband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr c16n2M4k 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/c16n2M4k ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} c16n2M4k 33 | kcs_set_frequency 150000000 34 | exit 0 35 | fi 36 | 37 | kcs_corr_log 38 | kcs_error "corr initialise failed" 39 | 40 | exit 1 41 | -------------------------------------------------------------------------------- /scripts/restart-mode-c16n3M8k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to narrowband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr c16n3M8k 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/c16n3M8k ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} c16n3M8k 33 | kcs_set_frequency 150000000 34 | exit 0 35 | fi 36 | 37 | kcs_corr_log 38 | kcs_error "corr initialise failed" 39 | 40 | exit 1 41 | -------------------------------------------------------------------------------- /scripts/restart-mode-c16n7M4k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to narrowband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr c16n7M4k 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/c16n7M4k ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} c16n7M4k 33 | kcs_set_frequency 150000000 34 | exit 0 35 | fi 36 | 37 | kcs_corr_log 38 | kcs_error "corr initialise failed" 39 | 40 | exit 1 41 | -------------------------------------------------------------------------------- /scripts/restart-mode-c16n13M4k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to narrowband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr c16n13M4k 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/c16n13M4k ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} c16n13M4k 33 | kcs_set_frequency 150000000 34 | exit 0 35 | fi 36 | 37 | kcs_corr_log 38 | kcs_error "corr initialise failed" 39 | 40 | exit 1 41 | -------------------------------------------------------------------------------- /scripts/restart-mode-c16n25M4k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | now=$(date +%s) 9 | timeout=150 10 | 11 | limit=$[now+timeout] 12 | 13 | kcs_debug "changing mode to narrowband" 14 | 15 | await_mode_sensors 16 | disable_bf_count 17 | 18 | kcs_change_corr c16n25M4k 19 | 20 | kcs_debug "running connect" 21 | 22 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/c16n25M4k ; do 23 | kcs_check_timeout ${limit} 24 | kcs_corr_log 25 | sleep 1 26 | kcs_info "still trying to get corr to connect" 27 | done 28 | 29 | kcs_info "running initialise" 30 | if kcpcmd -k -m -t 120 initialise 2 ; then 31 | kcs_corr_log 32 | change_mode_sensors ${KATCP_MODE} c16n25M4k 33 | kcs_set_frequency 150000000 34 | exit 0 35 | fi 36 | 37 | kcs_corr_log 38 | kcs_error "corr initialise failed" 39 | 40 | exit 1 41 | -------------------------------------------------------------------------------- /tcpborphserver3/tg.h: -------------------------------------------------------------------------------- 1 | #ifndef TG_H_ 2 | #define TG_H_ 3 | 4 | int tap_stop_cmd(struct katcp_dispatch *d, int argc); 5 | int tap_start_cmd(struct katcp_dispatch *d, int argc); 6 | 7 | int tap_info_cmd(struct katcp_dispatch *d, int argc); 8 | int tap_reload_cmd(struct katcp_dispatch *d, int argc); 9 | int tap_config_cmd(struct katcp_dispatch *d, int argc); 10 | 11 | int tap_ip_config_cmd(struct katcp_dispatch *d, int argc); 12 | 13 | int tap_multicast_add_group_cmd(struct katcp_dispatch *d, int argc); 14 | int tap_multicast_remove_group_cmd(struct katcp_dispatch *d, int argc); 15 | 16 | int tap_route_add_cmd(struct katcp_dispatch *d, int argc); 17 | 18 | int tap_multicast_add_group_cmd(struct katcp_dispatch *d, int argc); 19 | int tap_multicast_remove_group_cmd(struct katcp_dispatch *d, int argc); 20 | 21 | void stop_all_getap(struct katcp_dispatch *d, int final); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | - complete kcs 3 | 4 | - state machine logic 5 | 6 | - data path sensors. Not yet done. Could be done in 7 | two ways: Either on tcpborphserver, or polling 8 | registers from kcs itself 9 | 10 | ******************************** 11 | 12 | - add timestamp to client connect 13 | - maybe report disconnects too 14 | - improve center frequency selection 15 | - searchable arb structures so that we can clear tgtaps on progdev 16 | 17 | 18 | 19 | *** NEW DPX todos *** 20 | 21 | - device changed messages, particularly regarding sensors 22 | - device connected/disconnected messages 23 | - some default device-status handling 24 | - expand version-list, etc to also display build state, etc 25 | - parse #sensor-list, #sensor-status messages 26 | 27 | - either array type, or a way to print avl tree while honouring _LAST and first, maybe even both 28 | -------------------------------------------------------------------------------- /katcp/TODO: -------------------------------------------------------------------------------- 1 | Todo: 2 | 3 | Provide signed integer 4 | 5 | Use BNF syntax for help messages 6 | 7 | more supporting functions 8 | 9 | block EPIPE or use send with nosignal 10 | 11 | make file descriptors nonblocking (safer in production, but masks logic errors ) 12 | 13 | possible shutdown/restart logic 14 | 15 | 16 | 17 | Fix reporting unset sensor values for getvalue if sensor not enabled 18 | 19 | Provide better help for commands 20 | 21 | Do mode broadcasts and general broadcast functions 22 | 23 | Fix sensor api to include max fd, so that select has a chance 24 | of working properly 25 | 26 | 27 | 28 | Wed Jul 21 13:37:17 SAST 2010 29 | 30 | Add tags to requests, replies and related inform messages 31 | 32 | Fix version detail: Version command, with messages different 33 | to inform at startup. 34 | 35 | Fix semantics of unknown sensor status. 36 | -------------------------------------------------------------------------------- /scripts/k7-adc-snap-shot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | source functions.sh 6 | 7 | kcs_arg_check $# 3 8 | 9 | pps=0 10 | level=0 11 | 12 | kcs_info "about to request adc snap shot" 13 | 14 | case "$1" in 15 | pps) 16 | pps=1 17 | ;; 18 | now) 19 | pps=0 20 | ;; 21 | *) 22 | kcs_error "understand pps or now not ${1}" 23 | exit 1 24 | ;; 25 | esac 26 | 27 | if [ -z "$2" ] ; then 28 | level=0 29 | elif [ "$2" -gt 1024 ] ; then 30 | level=1024 31 | else 32 | level="$2" 33 | fi 34 | 35 | shift 2 36 | 37 | if kcs_is_narrowband ${KATCP_MODE} ; then 38 | if [ "${level}" -gt 0 ] ; then 39 | kcs_error "threshold triggering not currently supported in narrowband mode" 40 | exit 1 41 | fi 42 | pps=1 43 | level=-1 44 | fi 45 | 46 | kcpcmd -t 10 -r -k get-adc-snapshots ${pps} ${level} $* | sed -e 's/^\#get-adc-snapshots/#k7-adc-snap-shot/' 47 | -------------------------------------------------------------------------------- /scripts/restart-mode-c8n25M4k_top: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | TARGET_MODE=c8n25M4k_top 9 | 10 | now=$(date +%s) 11 | timeout=150 12 | 13 | limit=$[now+timeout] 14 | 15 | kcs_debug "changing mode to narrowband" 16 | 17 | await_mode_sensors 18 | disable_bf_count 19 | 20 | kcs_change_corr ${TARGET_MODE} 21 | 22 | kcs_debug "running connect" 23 | 24 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/${TARGET_MODE} ; do 25 | kcs_check_timeout ${limit} 26 | kcs_corr_log 27 | sleep 1 28 | kcs_info "still trying to get corr to connect" 29 | done 30 | 31 | kcs_info "running initialise" 32 | if kcpcmd -k -m -t 120 initialise 2 ; then 33 | kcs_corr_log 34 | change_mode_sensors ${KATCP_MODE} ${TARGET_MODE} 35 | kcs_set_frequency 150000000 36 | exit 0 37 | fi 38 | 39 | kcs_corr_log 40 | kcs_error "corr initialise failed" 41 | 42 | exit 1 43 | -------------------------------------------------------------------------------- /scripts/restart-mode-c8n7M4k_top: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | TARGET_MODE=c8n7M4k_top 9 | 10 | now=$(date +%s) 11 | timeout=150 12 | 13 | limit=$[now+timeout] 14 | 15 | kcs_debug "changing mode to narrowband" 16 | 17 | await_mode_sensors 18 | disable_bf_count 19 | 20 | kcs_change_corr ${TARGET_MODE} 21 | 22 | kcs_debug "running connect" 23 | 24 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/${TARGET_MODE} ; do 25 | kcs_check_timeout ${limit} 26 | kcs_corr_log 27 | sleep 1 28 | kcs_info "still trying to get corr to connect" 29 | done 30 | 31 | kcs_info "running initialise" 32 | if kcpcmd -k -m -t 120 initialise 2 ; then 33 | kcs_corr_log 34 | change_mode_sensors ${KATCP_MODE} ${TARGET_MODE} 35 | kcs_set_frequency 150000000 36 | exit 0 37 | fi 38 | 39 | kcs_corr_log 40 | kcs_error "corr initialise failed" 41 | 42 | exit 1 43 | -------------------------------------------------------------------------------- /scripts/restart-mode-c8n7M4k_bottom: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | TARGET_MODE=c8n7M4k_bottom 9 | 10 | now=$(date +%s) 11 | timeout=150 12 | 13 | limit=$[now+timeout] 14 | 15 | kcs_debug "changing mode to narrowband" 16 | 17 | await_mode_sensors 18 | disable_bf_count 19 | 20 | kcs_change_corr ${TARGET_MODE} 21 | 22 | kcs_debug "running connect" 23 | 24 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/${TARGET_MODE} ; do 25 | kcs_check_timeout ${limit} 26 | kcs_corr_log 27 | sleep 1 28 | kcs_info "still trying to get corr to connect" 29 | done 30 | 31 | kcs_info "running initialise" 32 | if kcpcmd -k -m -t 120 initialise 2 ; then 33 | kcs_corr_log 34 | change_mode_sensors ${KATCP_MODE} ${TARGET_MODE} 35 | kcs_set_frequency 150000000 36 | exit 0 37 | fi 38 | 39 | kcs_corr_log 40 | kcs_error "corr initialise failed" 41 | 42 | exit 1 43 | -------------------------------------------------------------------------------- /scripts/restart-mode-c8n25M4k_bottom: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | TARGET_MODE=c8n25M4k_bottom 9 | 10 | now=$(date +%s) 11 | timeout=150 12 | 13 | limit=$[now+timeout] 14 | 15 | kcs_debug "changing mode to narrowband" 16 | 17 | await_mode_sensors 18 | disable_bf_count 19 | 20 | kcs_change_corr ${TARGET_MODE} 21 | 22 | kcs_debug "running connect" 23 | 24 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/${TARGET_MODE} ; do 25 | kcs_check_timeout ${limit} 26 | kcs_corr_log 27 | sleep 1 28 | kcs_info "still trying to get corr to connect" 29 | done 30 | 31 | kcs_info "running initialise" 32 | if kcpcmd -k -m -t 120 initialise 2 ; then 33 | kcs_corr_log 34 | change_mode_sensors ${KATCP_MODE} ${TARGET_MODE} 35 | kcs_set_frequency 150000000 36 | exit 0 37 | fi 38 | 39 | kcs_corr_log 40 | kcs_error "corr initialise failed" 41 | 42 | exit 1 43 | -------------------------------------------------------------------------------- /tcpborphserver3/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | #LIB = -L$(KATCP) -lkatcp -ldl -lz -lmagic 7 | LIB = -L$(KATCP) -lkatcp -ldl -lz 8 | CFLAGS += -fPIC 9 | CFLAGS += -ggdb 10 | #CFLAGS += -DDEBUG=2 11 | CFLAGS += -DDEBUG 12 | #CFLAGS += -DPROFILE 13 | # crash rather than limp on 14 | #CFLAGS += -DFAILFAST 15 | # use internal hardware monitor 16 | #CFLAGS += -DINTERNAL_HWMON 17 | 18 | SERVER = tcpborphserver3 19 | SRC = main.c raw.c loadbof.c tg.c tapper.c hwmon.c upload.c subprocess.c ev.c 20 | 21 | OBJ = $(patsubst %.c,%.o,$(SRC)) 22 | all: $(SERVER) 23 | 24 | #$(SERVER): $(OBJ) 25 | $(SERVER): $(OBJ) $(KATCP)/libkatcp.a 26 | $(CC) -o $@ $(OBJ) $(LIB) 27 | 28 | clean: 29 | $(RM) -f $(SERVER) *.o test-* 30 | 31 | %.o: %.c 32 | $(CC) $(CFLAGS) -c $< -o $@ $(INC) 33 | 34 | install: all 35 | $(INSTALL) $(SERVER) $(PREFIX)/sbin 36 | 37 | test-bof: bof.c 38 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ -I../katcp 39 | 40 | -------------------------------------------------------------------------------- /scripts/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.inc 2 | 3 | DST = $(PREFIX)/lib/kcs/scripts 4 | VAR = $(PREFIX)/var/lib/kcs 5 | 6 | SRC = functions.sh mappings.sh sensors.sh beamformer.sh capture-start capture-stop capture-list capture-destination capture-status sync-now k7-accumulation-length k7-adc-snap-shot k7-quant-snap-shot k7-snap-shot k7-gain k7-frequency-select halt restart xport label-input label-clear enable-sensors corr test-reload-rf-gain restart-mode-ready restart-mode-c16n400M1k restart-mode-c16n400M8k restart-mode-bc16n400M1k restart-mode-bc8n400M1k_top restart-mode-bc8n400M1k_bottom restart-mode-c16n13M4k restart-mode-c16n25M4k restart-mode-c16n2M4k restart-mode-c16n3M8k restart-mode-c16n7M4k restart-mode-bwbc4a restart-mode-twbc4a restart-mode-c8n25M4k_bottom restart-mode-c8n25M4k_top restart-mode-c8n7M4k_bottom restart-mode-c8n7M4k_top k7-beam-passband k7-beam-weights 7 | 8 | all: 9 | 10 | clean: 11 | 12 | install: all 13 | $(INSTALL) -d $(DST) 14 | $(INSTALL) $(SRC) $(DST) 15 | -------------------------------------------------------------------------------- /scripts/restart-mode-bc16n400M1k: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | TARGET_MODE=bc16n400M1k 9 | 10 | now=$(date +%s) 11 | timeout=150 12 | 13 | limit=$[now+timeout] 14 | 15 | kcs_debug "changing mode to wideband" 16 | 17 | await_mode_sensors 18 | 19 | kcs_change_corr ${TARGET_MODE} 20 | 21 | kcs_debug "running connect" 22 | 23 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/${TARGET_MODE} ; do 24 | kcs_check_timeout ${limit} 25 | kcs_corr_log 26 | sleep 1 27 | kcs_info "still trying to get corr to connect" 28 | done 29 | 30 | kcs_info "running correlator initialise" 31 | if ! kcpcmd -k -m -t 300 initialise 2 ; then 32 | kcs_corr_log 33 | kcs_error "correlator initialise failed" 34 | exit 1 35 | fi 36 | 37 | kcs_corr_log 38 | 39 | for name in bf0 bf1 ; do 40 | kcs_set_passband ${name} 400000000 200000000 41 | done 42 | 43 | change_mode_sensors ${KATCP_MODE} ${TARGET_MODE} 44 | exit 0 45 | -------------------------------------------------------------------------------- /scripts/restart-mode-bc8n400M1k_bottom: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | TARGET_MODE=bc8n400M1k_bottom 9 | 10 | now=$(date +%s) 11 | timeout=150 12 | 13 | limit=$[now+timeout] 14 | 15 | kcs_debug "changing mode to wideband" 16 | 17 | await_mode_sensors 18 | 19 | kcs_change_corr ${TARGET_MODE} 20 | 21 | kcs_debug "running connect" 22 | 23 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/${TARGET_MODE} ; do 24 | kcs_check_timeout ${limit} 25 | kcs_corr_log 26 | sleep 1 27 | kcs_info "still trying to get corr to connect" 28 | done 29 | 30 | kcs_info "running correlator initialise" 31 | if ! kcpcmd -k -m -t 300 initialise 2 ; then 32 | kcs_corr_log 33 | kcs_error "correlator initialise failed" 34 | exit 1 35 | fi 36 | 37 | kcs_corr_log 38 | 39 | for name in bf0 bf1 ; do 40 | kcs_set_passband ${name} 400000000 200000000 41 | done 42 | 43 | change_mode_sensors ${KATCP_MODE} ${TARGET_MODE} 44 | exit 0 45 | -------------------------------------------------------------------------------- /scripts/k7-delay: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 6 7 | 8 | antpol=${1} 9 | # ms to s 10 | time=$(echo ${2}/1000 | bc -l | sed -e 's/^\./0./') 11 | # ms to s 12 | delay=$(echo ${3}/1000 | bc -l | sed -e 's/^\./0./') 13 | # seconds/seconds to ms/ms 14 | drate=${4} 15 | # rad to deg: 180/3.14159265358979323846 16 | fringe=$(echo 57.29578*${5} | bc -l | sed -e 's/^\./0./') 17 | # rads/ms to rotations/second: 1000/(2*3.14159265358979323846 18 | frate=$(echo 159.154943091*${6} | bc -l | sed -e 's/^\./0./') 19 | 20 | kcpmsg -s delay -l debug "${antpol} load time ${2}ms mapped to ${time}s" 21 | kcpmsg -s delay -l debug -m "delay ${3}ms mapped to ${delay}s" "delay rate is ${4}s/s or ms/ms" "fringe offset ${5}rad mapped to ${fringe}deg" "fringe rate ${6}rads/ms mapped to ${frate}rotations/s" 22 | 23 | status=1 24 | if kcpcmd -k -r fr-delay-set $antpol $fringe $frate $delay $drate $time now ; then 25 | status=0 26 | fi 27 | 28 | kcs_corr_log 29 | exit $status 30 | -------------------------------------------------------------------------------- /kcs/examples/sens.c: -------------------------------------------------------------------------------- 1 | /* setup routines, simple, but doesn't check for existing sensors */ 2 | 3 | struct katcp_acquire *a; 4 | 5 | snprintf(name, ... "%s.lur", roach); 6 | 7 | sn = find_sensor_katcp(d, name); 8 | if(sn){ /* sensor already exists */ 9 | a = acquire_from_sensor_katcp(d, sn); 10 | if(a == NULL){ 11 | /* logic failure, marc messed up */ 12 | } 13 | 14 | } else { /* sensor needs to be created */ 15 | 16 | a = setup_boolean_acquire_katcp(d, NULL, NULL, NULL); 17 | 18 | if(a == NULL){ 19 | return -1; 20 | } 21 | 22 | register_direct_multi_boolean_sensor_katcp(d, 0, name, "roach is functional" , "none", a); 23 | #if 0 24 | register_direct_multi_boolean_sensor_katcp(d, 0, "roachxxx.lru", "roach is functional" , "none", a); 25 | #endif 26 | 27 | } 28 | 29 | /* now squirrel away *a, so that it can be updated later */ 30 | 31 | free(name); 32 | 33 | 34 | 35 | /* updating the sensor value */ 36 | 37 | set_boolean_acquire_katcp(d, a, 1); 38 | 39 | set_boolean_acquire_katcp(d, a, 0); 40 | -------------------------------------------------------------------------------- /katcp/loop.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "katpriv.h" 18 | #include "katcl.h" 19 | #include "katcp.h" 20 | #include "netc.h" 21 | 22 | int run_katcp(struct katcp_dispatch *d, int server, char *host, int port) 23 | { 24 | if(server == 0){ 25 | return run_client_katcp(d, host, port); 26 | } else{ 27 | return run_server_katcp(d, host, port); 28 | } 29 | } 30 | 31 | int run_server_katcp(struct katcp_dispatch *d, char *host, int port) 32 | { 33 | return run_config_server_katcp(d, NULL, 1, host, port); 34 | } 35 | 36 | int run_multi_server_katcp(struct katcp_dispatch *d, int count, char *host, int port) 37 | { 38 | return run_config_server_katcp(d, NULL, count, host, port); 39 | } 40 | -------------------------------------------------------------------------------- /tcpborphserver3/tapper.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | int tap_open(char *name) 23 | { 24 | #if 0 25 | return open("/dev/tap0", O_RDWR); 26 | #else 27 | int fd; 28 | struct ifreq ifr; 29 | 30 | fd = open("/dev/net/tun", O_RDWR); 31 | if(fd < 0){ 32 | return -1; 33 | } 34 | 35 | memset(&ifr, 0, sizeof(ifr)); 36 | 37 | ifr.ifr_flags = IFF_TUN | IFF_NO_PI; 38 | /* ifr.ifr_flags = IFF_TAP; */ 39 | 40 | if(name){ 41 | strncpy(ifr.ifr_name, name, IFNAMSIZ); 42 | } 43 | 44 | if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) { 45 | return -1; 46 | } 47 | 48 | return fd; 49 | #endif 50 | } 51 | 52 | int tap_close(int fd) 53 | { 54 | return close(fd); 55 | } 56 | -------------------------------------------------------------------------------- /gmon/sensor.h: -------------------------------------------------------------------------------- 1 | /* TODO Add more information 2 | * 3 | * 4 | * 5 | */ 6 | 7 | #ifndef _GMON_SENSOR_H_ 8 | #define _GMON_SENSOR_H_ 9 | 10 | #include 11 | 12 | #include "katcp.h" 13 | #include "katcl.h" 14 | #include "katpriv.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | struct sensor { 21 | char *name; ///< sensor name in dotted notation 22 | char *desc; ///< description of the information provided by the sensor 23 | char *units; ///< short form of the units for the sensor value, may be blank 24 | char *type; ///< [integer, float, boolean, timestamp, discrete, address, string] 25 | char *status; ///< [unknown, nominal, warn, error, failure] 26 | uint32_t val; ///< value 27 | }; 28 | 29 | struct sensor *sensor_create(char *name, char *desc, char *units, char *type, char *status); 30 | 31 | int sensor_destroy(struct sensor *s); 32 | 33 | int sensor_katcp_add(struct katcl_line *l, struct sensor *s); 34 | 35 | int sensor_katcp_update(struct katcl_line *l, struct sensor *s); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* _GMON_SENSOR_H_ */ 42 | -------------------------------------------------------------------------------- /scripts/restart-mode-bc8n400M1k_top: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | source sensors.sh 6 | source beamformer.sh 7 | 8 | TARGET_MODE=bc8n400M1k_top 9 | 10 | now=$(date +%s) 11 | timeout=150 12 | 13 | limit=$[now+timeout] 14 | 15 | kcs_debug "changing mode to wideband" 16 | 17 | await_mode_sensors 18 | 19 | kcs_change_corr ${TARGET_MODE} 20 | 21 | kcs_debug "running connect" 22 | 23 | while ! kcpcmd -k -m -t 120 connect ${CORR_CONFIG}/${TARGET_MODE} ; do 24 | kcs_check_timeout ${limit} 25 | kcs_corr_log 26 | sleep 1 27 | kcs_info "still trying to get corr to connect" 28 | done 29 | 30 | kcs_info "running correlator initialise" 31 | if ! kcpcmd -k -m -t 300 initialise 2 ; then 32 | kcs_corr_log 33 | kcs_error "correlator initialise failed" 34 | exit 1 35 | fi 36 | 37 | kcs_corr_log 38 | 39 | for name in bf0 bf1 ; do 40 | kcs_set_passband ${name} 400000000 200000000 41 | done 42 | 43 | # 44 | # if ! detect_bf_count $(grep ^servers_x.*roach ${CORR_CONFIG}/${TARGET_MODE} | cut -f2 -d= ) ; then 45 | # kcs_error "beamformer detection logic failed" 46 | # exit 1 47 | # fi 48 | 49 | change_mode_sensors ${KATCP_MODE} ${TARGET_MODE} 50 | exit 0 51 | -------------------------------------------------------------------------------- /scripts/mappings.sh: -------------------------------------------------------------------------------- 1 | 2 | make_mapping() 3 | { 4 | pols=(x y) 5 | pol=$1 6 | 7 | if [ ! -f ${CORR_CONFIG}/c16n400M1k ] ; then 8 | kcs_error "unable to locate configuration c16n400M1k" 9 | return 1 10 | fi 11 | 12 | i=0 13 | declare -a roachposmap 14 | for name in $(grep ^servers_f.*roach ${CORR_CONFIG}/c16n400M1k | cut -f2 -d= | tr '[, ]' '\n' ) ; do 15 | roachposmap[$i]=$name 16 | i=$[i+1] 17 | done 18 | 19 | inp=$i 20 | 21 | : > ${MAIN_MAPPING} 22 | 23 | i=0 24 | while [ $i -lt $inp ] ; do 25 | j=0 26 | while [ $j -lt $pol ] ; do 27 | echo ${i}${pols[$j]}:${i}${pols[$j]}:${roachposmap[$i]} >> ${MAIN_MAPPING} 28 | j=$[j+1] 29 | done 30 | i=$[i+1] 31 | done 32 | 33 | return 0 34 | } 35 | 36 | update_aliases() 37 | { 38 | for fullname in $(grep -l '^servers_f' ${CORR_CONFIG}/*) ; do 39 | name=${fullname##*/} 40 | kcs_info "updating config for $name" 41 | : > ${CORR_MAPPING}.${name} 42 | for roach in $(grep '^servers_f' ${fullname} | cut -f2 -d= | tr '[, ]' '\n') ; do 43 | grep ${roach} ${MAIN_MAPPING} | cut -f1 -d: | tr '\n' ',' >> ${CORR_MAPPING}.${name} 44 | done 45 | done 46 | } 47 | 48 | -------------------------------------------------------------------------------- /scripts/tcpborphserver-write-tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function expectation() 4 | { 5 | value=$(kcpcmd -p 2 -i wordread sys_scratchpad 0) 6 | if [ "${value}" != "$1" ] ; then 7 | echo "test failed: expected ${1}, got ${value}" 8 | return 1; 9 | else 10 | echo "test ok: result is ${value}" 11 | return 0; 12 | fi 13 | } 14 | 15 | kcpcmd -i write sys_scratchpad 0 3333 16 | 17 | kcpcmd -i write sys_scratchpad 0 D 18 | expectation 0x44333333 19 | 20 | kcpcmd -i write sys_scratchpad 1 U 21 | expectation 0x44553333 22 | 23 | kcpcmd -i write sys_scratchpad 2 f 24 | expectation 0x44556633 25 | 26 | kcpcmd -i write sys_scratchpad 3 w 27 | expectation 0x44556677 28 | 29 | kcpcmd -i write sys_scratchpad 0 3333 30 | 31 | kcpcmd -i write sys_scratchpad 0 DD 32 | expectation 0x44443333 33 | 34 | kcpcmd -i write sys_scratchpad 1 UU 35 | expectation 0x44555533 36 | 37 | kcpcmd -i write sys_scratchpad 2 ff 38 | expectation 0x44556666 39 | 40 | kcpcmd -i write sys_scratchpad 0 3333 41 | 42 | kcpcmd -i write sys_scratchpad 0 DDD 43 | expectation 0x44444433 44 | 45 | kcpcmd -i write sys_scratchpad 1 UUU 46 | expectation 0x44555555 47 | 48 | kcpcmd -i write sys_scratchpad 1 fffff 2:7 49 | expectation 0x44666667 50 | -------------------------------------------------------------------------------- /fpg/README: -------------------------------------------------------------------------------- 1 | 2 | This is the programming utility which parses an .fpg file. It requires 3 | tcpborphserver3 to do the actual programming 4 | 5 | An fpg file consists of the following sections 6 | 7 | #!/bin/kcpfpg - a header making it possible to execute an .fpg file 8 | with chmod +x and the correct KATCP_SERVER variable 9 | this permits remote programming 10 | ?uploadbin - boilerplate to trigger the bitstream upload 11 | ?register - register definitions: map a name to a memory region 12 | ... 13 | ?meta - other information describing the bistream 14 | ... 15 | ?quit - an end of katcp messages marker 16 | - the bitstream to be programmed into the fpga 17 | 18 | 19 | The astute reader will notice that an .fpg file bears some resemblance 20 | a shar archive and also to a "frozen" http post request. Shoulders of 21 | giants 'n stuff 22 | 23 | Also: It is quite possible to add extra things to this .fpg file, maybe even 24 | tap-start requests, just note that you will have to edit the file in binary 25 | mode (eg vim -b) lest your editor munges the binary parts of the bitstream 26 | 27 | -------------------------------------------------------------------------------- /scripts/label-input: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # TODO: should update files atomically 4 | 5 | set -e 6 | source functions.sh 7 | source mappings.sh 8 | 9 | if [ ! -s ${MAIN_MAPPING} ] ; then 10 | kcs_info "generating initial mapping" 11 | make_mapping 2 12 | update_aliases 13 | fi 14 | 15 | if [ $# -lt 1 ] ; then 16 | 17 | if [ ! -s ${MAIN_MAPPING} ] ; then 18 | kcs_error "no correlator mapping found" 19 | fi 20 | 21 | if [ ! -s ${CORR_MAPPING}.${KATCP_MODE} ] ; then 22 | if [ -f ${CORR_CONFIG}/${KATCP_MODE} ] ; then 23 | update_aliases 24 | fi 25 | fi 26 | 27 | if kcs_is_beamformer ${KATCP_MODE} ; then 28 | cat ${MAIN_MAPPING} | sed -e 's/\(:.x:.*\)/& bf0/' -e 's/\(:.y:.*\)/& bf1/' | tr -s : ' ' | sed -s 's/^/#label-input /' 29 | else 30 | cat ${MAIN_MAPPING} | tr -s : ' ' | sed -s 's/^/#label-input /' 31 | fi 32 | 33 | exit 0 34 | fi 35 | 36 | inp=${1} 37 | 38 | if [ $# -eq 1 ] ; then 39 | cat ${MAIN_MAPPING} | grep ${inp} | cut -f1 -d: | sed -s 's/^/#return ok /' 40 | exit 0 41 | fi 42 | 43 | alias=${2} 44 | 45 | kcs_debug "setting label for ${inp} to ${alias}" 46 | 47 | sed -i -e "s/^.*:${inp}:\(.*\)$/${alias}:${inp}:\1/" ${MAIN_MAPPING} 48 | 49 | update_aliases 50 | 51 | echo "#return ok $(grep ${inp} ${MAIN_MAPPING} | cut -f1 -d:)" 52 | 53 | exit 0 54 | 55 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.inc 2 | 3 | ############################################################################### 4 | 5 | LIBRARY = katcp 6 | APPS = kcs cmd examples sq bulkread tmon log fmon tcpborphserver3 msg delay par sgw xport con dmon smon fpg run mpx gmon 7 | ifeq ($(findstring KATCP_DEPRECATED,$(CFLAGS)),KATCP_DEPRECATED) 8 | APPS += modules 9 | endif 10 | 11 | MISC = scripts misc 12 | 13 | SELECTED = kcs cmd tmon log msg par con fpg run mpx 14 | EVERYTHING = $(LIBRARY) $(APPS) 15 | 16 | ############################################################################### 17 | 18 | all: $(patsubst %,%-all,$(EVERYTHING)) 19 | clean: $(patsubst %,%-clean,$(EVERYTHING)) 20 | install: $(patsubst %,%-install,$(SELECTED)) 21 | 22 | $(patsubst %,%-all,$(APPS)): $(patsubst %,%-all,$(LIBRARY)) 23 | 24 | %-all %-clean %-install: 25 | $(MAKE) -C $(shell echo $@ | cut -f1 -d- ) KATCP=../$(KATCP) $(shell echo $@ | cut -f2 -d-) 26 | 27 | ############################################################################### 28 | # old style build, can not be run in parallel 29 | # 30 | # all: all-dir 31 | # clean: clean-dir 32 | # install: install-dir 33 | # 34 | # warning: below rewrites KATCP for subdirectory 35 | # all-dir clean-dir install-dir: 36 | # @for d in $(SUB); do if ! $(MAKE) -C $$d KATCP=../$(KATCP) $(subst -dir,,$@) ; then exit; fi; done 37 | -------------------------------------------------------------------------------- /scripts/enable-sensors: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source functions.sh 4 | source sensors.sh 5 | 6 | export KATCP_SERVER=localhost:7147 7 | 8 | if [ ! -f ${CORR_CONFIG}/c16n400M1k ] ; then 9 | kcs_error "unable to locate configuration file ${CORR_CONFIG}/c16n400M1k" 10 | exit 1 11 | fi 12 | 13 | if [ "$1" = "static" ] ; then 14 | setup_static_sensors 15 | else 16 | i=0 17 | for name in $(grep ^servers_f.*roach ${CORR_CONFIG}/c16n400M1k | cut -f2 -d= | tr '[, ]' '\n' ) ; do 18 | if [ ! -f /usr/local/lib/kcs/scripts/${name} ] ; then 19 | ln -s /usr/local/bin/kcpfmon /usr/local/lib/kcs/scripts/${name} >& /dev/null || kcs_error "unable to alias ${name}" 20 | fi 21 | kcpcmd -q -k job process $name exec://${name} ${name}:7147 $i || kcs_error "unable to launch lru monitor for ${name}" 22 | i=$[i+1] 23 | done 24 | 25 | for name in $(grep ^servers_x.*roach ${CORR_CONFIG}/c16n400M1k | cut -f2 -d= | tr '[, ]' '\n' ) ; do 26 | if [ ! -f /usr/local/lib/kcs/scripts/${name} ] ; then 27 | ln -s /usr/local/bin/kcpfmon /usr/local/lib/kcs/scripts/${name} >& /dev/null || kcs_error "unable to alias ${name}" 28 | fi 29 | kcpcmd -q -k job process $name exec://${name} || kcs_error "unable to launch lru monitor for ${name}" 30 | done 31 | 32 | kcpcmd -q -k job process corr exec://corr || kcs_error "unable to launch corr monitoring logic" 33 | fi 34 | 35 | exit 0 36 | -------------------------------------------------------------------------------- /scripts/capture-destination: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source functions.sh 4 | source beamformer.sh 5 | 6 | if [ $# -lt 3 ] ; then 7 | kcs_error "require three parameters: stream ip port" 8 | exit 1 9 | fi 10 | 11 | output=$1 12 | 13 | datahost=$2 14 | dataport=$3 15 | 16 | if [ $# -lt 5 ] ; then 17 | metahost=$datahost 18 | metaport=$dataport 19 | else 20 | metahost=$4 21 | metaport=$5 22 | fi 23 | 24 | case "${output}" in 25 | k7) 26 | if [ "$metahost" != "$datahost" -o "$metaport" != "$dataport" ] ; then 27 | kcs_error "correlator stream does not support separate meta(data) destinations" 28 | exit 1 29 | fi 30 | 31 | kcpcmd -s localhost:7147 -k -i -r setenv KCS_CORR_RX $datahost:$dataport 32 | kcs_info "set k7 destination to $datahost:$dataport" 33 | ;; 34 | bf0|bf1) 35 | if kcs_is_beamformer ${KATCP_MODE} ; then 36 | kcpcmd -s localhost:7147 -k -i -r setenv KCS_${output^^*}DATA_RX $datahost:$dataport 37 | kcpcmd -s localhost:7147 -k -i -r setenv KCS_${output^^*}META_RX $metahost:$metaport 38 | kcs_info "set data ${output} destination to $datahost:$dataport" 39 | kcs_info "set meta ${output} destination to $metahost:$metaport" 40 | else 41 | kcs_error "beamformer streams not available in this mode" 42 | exit 1 43 | fi 44 | ;; 45 | *) 46 | kcs_error "unsupported data stream ${output}" 47 | exit 1 48 | ;; 49 | esac 50 | 51 | exit 0 52 | -------------------------------------------------------------------------------- /kcs/Makefile: -------------------------------------------------------------------------------- 1 | KATCP ?= ../katcp 2 | 3 | include ../Makefile.inc 4 | 5 | INC = -I$(KATCP) 6 | LIB = -L$(KATCP) -lkatcp -ldl 7 | CFLAGS += -fPIC 8 | 9 | SERVER = kcs 10 | SRCSHARED = shared.c 11 | SRC = $(SRCSHARED) watchannounce.c subprocess.c actor.c statemachine.c statemachine_base.c roachpool.c execpy.c parser.c kcserver.c basic.c 12 | 13 | OBJ = $(patsubst %.c,%.o,$(SRC)) 14 | all: $(SERVER) 15 | 16 | #$(SERVER): $(OBJ) 17 | $(SERVER): $(OBJ) $(KATCP)/libkatcp.a 18 | $(CC) -o $@ $(OBJ) $(LIB) 19 | 20 | clean: 21 | $(RM) -f $(SERVER) *.o test-* 22 | 23 | %.o: %.c 24 | $(CC) $(CFLAGS) -c $< -o $@ $(INC) 25 | 26 | install: all 27 | $(INSTALL) $(SERVER) $(PREFIX)/sbin 28 | 29 | test-parser: parser.c 30 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ -I../katcp 31 | 32 | test-execpy: execpy.c 33 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ -I../katcp -L../katcp -lkatcp 34 | 35 | test-roachpool: $(SRCSHARED) roachpool.c 36 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ -I../katcp 37 | 38 | test-kurl: $(SRCSHARED) kurl.c 39 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ -I../katcp 40 | 41 | test-statemachine: statemachine.c 42 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ -I../katcp 43 | 44 | test-avltree: avltree.c 45 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ 46 | 47 | test-type: ktype.c 48 | $(CC) $(CFLAGS) -DSTANDALONE -o $@ $^ $(INC) $(LIB) 49 | 50 | test-actor: actor.c statemachine.c 51 | $(CC) $(CFLAGS) -D__ACTOR_UNIT_TEST -o $@ $^ $(INC) $(LIB) 52 | 53 | -------------------------------------------------------------------------------- /katcp/Makefile: -------------------------------------------------------------------------------- 1 | include ../Makefile.inc 2 | 3 | #.SUFFIXES: 4 | 5 | VERSION = 0.1 6 | 7 | BUILD = $(shell date -u +%Y-%m-%dT%H:%M:%S) 8 | VERSION = $(GITVER) 9 | 10 | INC = -I. 11 | LIB = libkatcp.a 12 | SHARED = libkatcp.so 13 | 14 | #CFLAGS := $(filter-out -DDEBUG,$(CFLAGS)) 15 | 16 | CFLAGS += -fPIC 17 | CFLAGS += -DVERSION=\"$(VERSION)\" 18 | CFLAGS += -DBUILD=\"$(BUILD)\" 19 | 20 | SUB = examples utils 21 | SRC = line.c netc.c dispatch.c loop.c log.c time.c shared.c misc.c server.c client.c ts.c nonsense.c notice.c job.c parse.c rpc.c queue.c map.c kurl.c version.c fork-parent.c avltree.c ktype.c stack.c services.c dbase.c arb.c spointer.c event.c bytebit.c endpoint.c generic-queue.c dpx-core.c dpx-forward.c dpx-katcp.c dpx-mgmt.c dpx-listen.c dpx-misc.c dpx-cmds.c dpx-vrbl.c dpx-info.c dpx-sensor.c parse-queue.c 22 | HDR = katcp.h katcl.h katpriv.h fork-parent.h avltree.h netc.h 23 | 24 | OBJ = $(patsubst %.c,%.o,$(SRC)) 25 | 26 | all: $(LIB) 27 | 28 | both: $(LIB) $(SHARED) 29 | 30 | $(LIB): $(OBJ) 31 | $(AR) rcs $(LIB) $(OBJ) 32 | 33 | $(SHARED): $(OBJ) 34 | $(CC) $(CFLAGS) -shared -Wl,-x,-soname=$(SHARED) -o $(SHARED) $(OBJ) 35 | 36 | %.o: %.c $(wildcard *.h) 37 | $(CC) $(CFLAGS) -c $< -o $@ $(INC) 38 | 39 | show: 40 | @echo 'VERSION="$(VERSION)"' 41 | @echo 'BUILD="$(BUILD)"' 42 | 43 | clean: 44 | $(RM) $(LIB) $(SHARED) *.o core 45 | 46 | install: all 47 | $(INSTALL) -d $(PREFIX)/include $(PREFIX)/lib 48 | $(INSTALL) $(LIB) $(PREFIX)/lib 49 | $(INSTALL) $(HDR) $(PREFIX)/include 50 | -------------------------------------------------------------------------------- /kcs/r2demo.kcl: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ?sm loadmod ../modules/mod_roach_comms.so 3 | 4 | ?sm node start 5 | ?sm node spawner 6 | ?sm node program 7 | ?sm node done 8 | ?sm node error 9 | ?sm node writeval1 10 | ?sm node writeval2 11 | ?sm node sleep1 12 | ?sm node sleep2 13 | 14 | ?sm error op push string ERROR 15 | 16 | ?sm done op push string DONE 17 | 18 | ?sm start op push url katcp://localhost:7145 19 | ?sm start op push url katcp://localhost:7146 20 | ?sm start edge spawner 21 | #?sm start edge program 22 | 23 | ?sm spawner edge done is_stackempty 24 | ?sm spawner op spawn program 25 | ?sm spawner edge spawner 26 | 27 | ?sm program op roachconnect 28 | ?sm program op push string ?progdev 29 | ?sm program op push string lots_of_registers_2011_Nov_01_1803.bof 30 | ?sm program edge writeval1 relaykatcp 31 | ?sm program edge error 32 | 33 | ?sm writeval1 op push string ?write 34 | ?sm writeval1 op push string sys_scratchpad 35 | ?sm writeval1 op push string 0:0 36 | ?sm writeval1 op push string PPPP 37 | ?sm writeval1 op push string 4:0 38 | ?sm writeval1 edge sleep1 relaykatcp 39 | ?sm writeval1 edge error 40 | 41 | ?sm sleep1 op push int 1000 42 | ?sm sleep1 edge writeval2 msleep 43 | 44 | ?sm writeval2 op push string ?write 45 | ?sm writeval2 op push string sys_scratchpad 46 | ?sm writeval2 op push string 0:0 47 | ?sm writeval2 op push string GCUA 48 | ?sm writeval2 op push string 4:0 49 | ?sm writeval2 edge sleep2 relaykatcp 50 | ?sm writeval2 edge error 51 | 52 | ?sm sleep2 op push int 1000 53 | ?sm sleep2 edge writeval1 msleep 54 | -------------------------------------------------------------------------------- /katcp/services.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "katcp.h" 10 | #include "katcl.h" 11 | #include "katpriv.h" 12 | #include "netc.h" 13 | 14 | int startup_services_katcp(struct katcp_dispatch *d) 15 | { 16 | int rtn; 17 | 18 | rtn = 0; 19 | 20 | #ifdef KATCP_DEPRECATED 21 | rtn += register_name_type_katcp(d, KATCP_TYPE_STRING, KATCP_DEP_BASE, &print_string_type_katcp, &destroy_string_type_katcp, NULL, NULL, &parse_string_type_katcp, NULL); 22 | 23 | rtn += register_name_type_katcp(d, KATCP_TYPE_DBASE, KATCP_DEP_BASE, &print_dbase_type_katcp, &destroy_dbase_type_katcp, NULL, NULL, &parse_dbase_type_katcp, &getkey_dbase_type_katcp); 24 | 25 | rtn += register_name_type_katcp(d, KATCP_TYPE_DICT, KATCP_DEP_BASE, &print_dict_type_katcp, &destroy_dict_type_katcp, NULL, NULL, &parse_dict_type_katcp, NULL); 26 | 27 | rtn += register_name_type_katcp(d, KATCP_TYPE_TAG, KATCP_DEP_BASE, &print_tag_katcp, &destroy_tag_katcp, NULL, &compare_tag_katcp, &parse_tag_katcp, &getkey_tag_katcp); 28 | 29 | rtn += register_katcp(d, KATCP_DICT_REQUEST, "dict [key] {key0:value0,key1:value1,...}", &dict_cmd_katcp); 30 | 31 | rtn += register_katcp(d, KATCP_GET_REQUEST, "get [key] (n) from database (n optional)", &get_dbase_cmd_katcp); 32 | rtn += register_katcp(d, KATCP_SET_REQUEST, "set [key] [value value ...] to database", &set_dbase_cmd_katcp); 33 | 34 | rtn += register_katcp(d, KATCP_SEARCH_REQUEST, "search [tag1 tag2 ...]", &search_cmd_katcp); 35 | #endif 36 | 37 | return rtn; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /gmon/gmon.h: -------------------------------------------------------------------------------- 1 | /* TODO Add more information 2 | * 3 | * 4 | * 5 | */ 6 | 7 | #ifndef _KATCP_GMON_H_ 8 | #define _KATCP_GMON_H_ 9 | 10 | #include "fpga.h" 11 | #include "sensor.h" 12 | #include "katcp.h" 13 | #include "katcl.h" 14 | #include "katpriv.h" 15 | 16 | #define GMON_PROG ("kcpgmon") 17 | 18 | /* version information */ 19 | #define GMON_VER_MAJOR (0) 20 | #define GMON_VER_MINOR (0) 21 | #define GMON_VER_BUGFIX (0) 22 | 23 | #define GMON_POLL_TIME_S (5) ///< default register polling time in seconds 24 | #define GMON_POLL_QUEUE_LEN (5) ///< number of wordread requests that can be in 'transit' 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | enum gmon_status { 31 | GMON_UNKNOWN, 32 | GMON_IDLE, 33 | GMON_FPGA_DOWN, 34 | GMON_FPGA_READY, 35 | GMON_REQ_META, 36 | GMON_POLL 37 | }; 38 | 39 | struct gmon_lib { 40 | struct katcl_line *server; ///< server 41 | struct katcl_line *log; ///< logging 42 | unsigned int polltime; ///< register polling time 43 | volatile enum gmon_status state; ///< gateware monitor state 44 | unsigned int numsensors; ///< number of sensors in the below list 45 | struct sensor **sensorlist; ///< sensor list 46 | unsigned int readdispatch; ///< 'transit' wordread counter 47 | unsigned int readcollect; ///< 'transit' wordread counter 48 | }; 49 | 50 | int gmon_task(struct gmon_lib *g); 51 | 52 | void gmon_destroy(struct gmon_lib *g); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* _KATCP_GMON_H_ */ 59 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Notes 2 | ----- 3 | 4 | This package provides the katcp library, several utilities and 5 | a control server for the KAT 7 correlator, kcs. For the time 6 | being kcs invokes the corr package (not included) to control 7 | the correlator, but uses its own monitoring subsystem (fmon). 8 | 9 | Build requirements 10 | ------------------ 11 | 12 | To build this you need GCC and GNU Make. Generally the code 13 | doesn't contain that much GCC specific stuff (one or two 14 | __attribute__ ((packed)) statements), but the Makefiles do 15 | use GNU Make features. 16 | 17 | Configuration 18 | ------------- 19 | 20 | There is no configure script. If you wish to change some 21 | build option (eg amount of debug information, floating 22 | point support, version support) edit Makefile.inc. The various 23 | options are documented there. 24 | 25 | Build 26 | ----- 27 | 28 | Type 29 | 30 | make 31 | 32 | at the top level directory. It is also possible to run make in 33 | individual subdirectories. In that case build the content of the 34 | katcp/ subdirectory first, as most other modules depend on it 35 | 36 | Installation 37 | ------------ 38 | 39 | If you are only interested in the library (and maybe kcpcmd 40 | or kcplog), enter the respective subdirectories and run make 41 | install from there, or type 42 | 43 | make -C katcp install 44 | make -C cmd install 45 | 46 | Installing the KAT7 correlator startup logic will no 47 | longer be installed by a global make install, you will 48 | have to do a make install in the scripts and misc directories. 49 | For this to be useful, you also require a configured corr 50 | package, nfs server, dnsmasq, bof files, an exported ppc 51 | filesystem not to mention 16 roach boards. 52 | -------------------------------------------------------------------------------- /wss/server.h: -------------------------------------------------------------------------------- 1 | #ifndef _SERVER_H 2 | #define _SERVER_h 3 | 4 | #include 5 | #include 6 | 7 | #define TLS_CERT "./certs/server.crt" 8 | #define TLS_KEY "./certs/server.key" 9 | 10 | #define C_STATE_NEW 0 11 | #define C_STATE_UPGRADED 1 12 | 13 | #define WSF_FIN 0x80 14 | #define WSF_OPCODE 0x0f 15 | #define WSF_MASK 0x80 16 | #define WSF_PAYLOAD 0x7f 17 | #define WSF_PAYLOAD_16 0x7e 18 | #define WSF_PAYLOAD_64 0x7f 19 | 20 | struct ws_frame { 21 | uint8_t hdr[2]; 22 | uint8_t msk[4]; 23 | uint64_t payload; 24 | }; 25 | 26 | struct ws_client { 27 | int c_fd; 28 | 29 | #if 0 30 | unsigned char *c_rb; 31 | #endif 32 | unsigned char *c_rb_last; 33 | void *c_rb; 34 | int c_rb_len; 35 | 36 | SSL *c_ssl; 37 | int c_state; 38 | 39 | void *c_sb; 40 | int c_sb_len; 41 | 42 | struct ws_frame *c_frame; 43 | }; 44 | 45 | struct ws_server { 46 | int s_fd; 47 | 48 | fd_set s_in; 49 | fd_set s_out; 50 | 51 | int s_hi; 52 | 53 | struct ws_client **s_c; 54 | int s_c_count; 55 | 56 | unsigned long long s_br_count; 57 | 58 | int (*s_cdfn)(struct ws_client *c); 59 | 60 | SSL_CTX *s_tlsctx; 61 | 62 | #if 0 63 | int s_up_count; 64 | 65 | uint8_t *s_sb; 66 | int s_sb_len; 67 | #endif 68 | }; 69 | 70 | 71 | int register_client_handler_server(int (*client_data_fn)(struct ws_client *c), char *port); 72 | 73 | unsigned char *readline_client_ws(struct ws_client *c); 74 | int readdata_client_ws(struct ws_client *c, void *dest, unsigned int n); 75 | void dropdata_client_ws(struct ws_client *c); 76 | 77 | int write_to_client_ws(struct ws_client *c, void *buf, int n); 78 | 79 | int upgrade_client_ws(struct ws_client *c); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /examples/new-client-example.c: -------------------------------------------------------------------------------- 1 | /* new client example to issue arbitrary katcp requests (with no parameters, 2 | * to simplify the example). This uses a simpler api than the client-example 3 | * code 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "katcl.h" 16 | #include "katcp.h" 17 | 18 | int main(int argc, char **argv) 19 | { 20 | struct katcl_line *l; 21 | int result, total, i; 22 | char *ptr; 23 | 24 | if(argc <= 2){ 25 | fprintf(stderr, "usage: %s server-ip[:server-port] command\n", argv[0]); 26 | fprintf(stderr, "example: %s localhost:7147 ?watchdog\n", argv[0]); 27 | return 1; 28 | } 29 | 30 | /* connect to a remote machine, arg is "server:port" where ":port is optional" */ 31 | l = create_name_rpc_katcl(argv[1]); 32 | if(l == NULL){ 33 | fprintf(stderr, "unable to create client connection to server %s: %s\n", argv[1], strerror(errno)); 34 | return 1; 35 | } 36 | 37 | /* send the request, with 5000ms timeout. Here we don't pass any parameters */ 38 | result = send_rpc_katcl(l, 5000, KATCP_FLAG_FIRST | KATCP_FLAG_LAST | KATCP_FLAG_STRING, argv[2], NULL); 39 | 40 | /* result is 0 if the reply returns "ok", 1 if it failed and -1 if things went wrong doing IO or otherwise */ 41 | printf("result of %s request is %d\n", argv[2], result); 42 | 43 | /* you can examine the content of the reply with the following functions */ 44 | total = arg_count_katcl(l); 45 | printf("have %d arguments in reply\n", total); 46 | for(i = 0; i < total; i++){ 47 | /* for binary data use the arg_buffer_katcl, string will stop at the first occurrence of a \0 */ 48 | ptr = arg_string_katcl(l, i); 49 | printf("reply[%d] is <%s>\n", i, ptr); 50 | } 51 | 52 | destroy_rpc_katcl(l); 53 | 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /scripts/capture-start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | source functions.sh 5 | 6 | kcs_arg_check $# 1 7 | stream=$1 8 | status=1 9 | 10 | if kcs_is_beamformer ${KATCP_MODE} ; then 11 | 12 | # bf mode wants a stream parameter 13 | 14 | case "${stream}" in 15 | k7) 16 | target=${KCS_CORR_RX} 17 | if kcpcmd -t 45 -k -m tx-start ${stream} ${target%:*} ${target##*:} ; then 18 | status=0 19 | fi 20 | ;; 21 | bf0|bf1) 22 | 23 | bf_rx=KCS_${stream^^*}META_RX 24 | target=${!bf_rx} 25 | if [ -n "${target}" ] ; then 26 | kcs_info "setting meta target to ${target}" 27 | if ! kcpcmd -t 130 -k -m bf-destination ${stream} meta ${target%:*} ${target##*:} ; then 28 | kcs_error "unable to set meta target to ${target%:*} ${target##*:}" 29 | fi 30 | fi 31 | 32 | bf_rx=KCS_${stream^^*}DATA_RX 33 | target=${!bf_rx} 34 | if [ -n "${target}" ] ; then 35 | kcs_info "setting data target to ${target}" 36 | if ! kcpcmd -t 130 -k -m bf-destination ${stream} data ${target%:*} ${target##*:} ; then 37 | kcs_error "unable to set data target to ${target%:*} ${target##*:}" 38 | fi 39 | fi 40 | 41 | kcs_info "starting tx for ${stream}" 42 | if kcpcmd -t 150 -k -m tx-start ${stream} ; then 43 | status=0 44 | else 45 | kcs_error "tx-start on ${stream} failed" 46 | fi 47 | 48 | ;; 49 | *) 50 | kcs_error "unsupported data stream ${stream}" 51 | ;; 52 | esac 53 | 54 | else 55 | 56 | # corr modes 57 | if [ "$stream" = "k7" ] ; then 58 | target=${KCS_CORR_RX} 59 | if kcpcmd -t 45 -k -m tx-start ${target%:*} ${target##*:} ; then 60 | status=0 61 | fi 62 | else 63 | kcs_error "stream ${stream} not available in this mode" 64 | fi 65 | 66 | fi 67 | 68 | kcs_corr_log 69 | if [ "${status}" -ne "0" ] ; then 70 | kcs_error "corr operations for ${stream} failed" 71 | fi 72 | -------------------------------------------------------------------------------- /katcp/event.c: -------------------------------------------------------------------------------- 1 | #ifdef KATCP_EXPERIMENTAL 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "katcp.h" 8 | #include "katpriv.h" 9 | 10 | struct katcp_event; 11 | 12 | struct katcp_interest{ 13 | struct katcp_flat *i_flat; 14 | void *i_data; 15 | int (*i_call)(struct katcp_dispatch *d, struct katcp_event *e, void *data); 16 | }; 17 | 18 | struct katcp_event{ 19 | char *e_name; 20 | 21 | struct katcp_interest *e_vector; 22 | unsigned int e_count; 23 | 24 | int e_use; 25 | int e_trigger; 26 | 27 | struct katcl_queue *e_queue; 28 | 29 | /* TODO: something to note if we trigger event within this event */ 30 | }; 31 | 32 | void destroy_event_katcp(struct katcp_dispatch *d, struct katcp_event *e) 33 | { 34 | unsigned int i; 35 | struct katcp_interest *ki; 36 | 37 | if(e == NULL){ 38 | return; 39 | } 40 | 41 | #ifdef KATCP_CONSISTENCY_CHECKS 42 | if(e->e_use > 0){ 43 | log_message_katcp(d, KATCP_LEVEL_FATAL, NULL, "internal problem: attempting to destroy an event which is held by some parties"); 44 | abort(); 45 | } 46 | #endif 47 | 48 | for(i = 0; i < e->e_count; i++){ 49 | ki = &(e->e_vector[i]); 50 | /* TODO */ 51 | } 52 | e->e_count = 0; 53 | 54 | if(e->e_name){ 55 | free(e->e_name); 56 | e->e_name = NULL; 57 | } 58 | 59 | if(e->e_vector){ 60 | free(e->e_vector); 61 | e->e_vector = NULL; 62 | } 63 | 64 | if(e->e_queue){ 65 | destroy_queue_katcl(e->e_queue); 66 | e->e_queue = NULL; 67 | } 68 | 69 | e->e_count = 0; 70 | 71 | free(e); 72 | } 73 | 74 | struct katcp_event *create_event_katcp(struct katcp_dispatch *d, char *name) 75 | { 76 | struct katcp_event *e; 77 | 78 | e = malloc(sizeof(struct katcp_event)); 79 | if(e == NULL){ 80 | log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "unable to create event"); 81 | return NULL; 82 | } 83 | 84 | e->e_name = NULL; 85 | 86 | e->e_vector = NULL; 87 | e->e_count = 0; 88 | 89 | e->e_use = 0; 90 | e->e_trigger = 0; 91 | 92 | e->e_queue = NULL; 93 | 94 | return e; 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /scripts/capture-list: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source functions.sh 4 | 5 | list_source() 6 | { 7 | source=$1 8 | host=${2%:*} 9 | port=${2##*:} 10 | 11 | if [ -z "${host}" ] ; then 12 | host=unknown 13 | fi 14 | 15 | if [ -z "${port}" ] ; then 16 | port=unknown 17 | fi 18 | 19 | echo -n "#capture-list ${source} ${host} ${port}" 20 | 21 | if [ -n "$3" ] ; then 22 | host=${3%:*} 23 | port=${3##*:} 24 | 25 | if [ -z "${host}" ] ; then 26 | host=unknown 27 | fi 28 | 29 | if [ -z "${port}" ] ; then 30 | port=unknown 31 | fi 32 | 33 | echo " ${host} ${port}" 34 | else 35 | echo 36 | fi 37 | 38 | } 39 | 40 | if [ -n "${KCS_CORR_RX}" ] ; then 41 | list_source k7 ${KCS_CORR_RX} 42 | else 43 | if [ ! -f ${CORR_CONFIG}/${KATCP_MODE} ] ; then 44 | kcs_warn "no configuration for ${KATCP_MODE}" 45 | else 46 | rxip=$(grep ^rx_udp_ip ${CORR_CONFIG}/${KATCP_MODE} | cut -f2 -d= | tr -d ' ' ) 47 | rxport=$(grep ^rx_udp_port ${CORR_CONFIG}/${KATCP_MODE} | cut -f2 -d= | tr -d ' ' ) 48 | fi 49 | list_source k7 ${rxip}:${rxport} 50 | fi 51 | 52 | if kcs_is_beamformer ${KATCP_MODE} ; then 53 | i=0 54 | while [ "${i}" -lt "2" ] ; do 55 | 56 | bf_rx=KCS_BF${i}DATA_RX 57 | if [ -n "${!bf_rx}" ]; then 58 | data=${!bf_rx} 59 | else 60 | rxip=$(grep ^bf_rx_udp_ip_str_beam${i} ${CORR_CONFIG}/${KATCP_MODE} | cut -f2 -d= | tr -d ' ' ) 61 | rxport=$(grep ^bf_rx_udp_port_beam${i} ${CORR_CONFIG}/${KATCP_MODE} | cut -f2 -d= | tr -d ' ' ) 62 | data=${rxip}:${rxport} 63 | fi 64 | 65 | bf_rx=KCS_BF${i}META_RX 66 | if [ -n "${!bf_rx}" ]; then 67 | meta=${!bf_rx} 68 | else 69 | rxip=$(grep ^bf_rx_meta_ip_str_beam${i} ${CORR_CONFIG}/${KATCP_MODE} | cut -f2 -d= | tr -d ' ' ) 70 | rxport=$(grep ^bf_rx_meta_port_beam${i} ${CORR_CONFIG}/${KATCP_MODE} | cut -f2 -d= | tr -d ' ' ) 71 | meta=${rxip}:${rxport} 72 | fi 73 | 74 | if [ -z "${meta}" ] ; then 75 | meta=${data} 76 | fi 77 | 78 | list_source bf${i} ${data} ${meta} 79 | 80 | i=$[i+1] 81 | done 82 | fi 83 | 84 | exit 0 85 | -------------------------------------------------------------------------------- /kcs/examples/simpleudp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define MTU 9000 13 | #define PORT 10011 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | struct sockaddr_in sar, peer; 18 | unsigned char buffer[MTU]; 19 | int total, fd, run, rb, i, rtn; 20 | socklen_t len; 21 | fd_set ins; 22 | 23 | sar.sin_family = AF_INET; 24 | sar.sin_port = htons(PORT); 25 | sar.sin_addr.s_addr = htonl(INADDR_ANY); 26 | 27 | fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 28 | if (fd < 0){ 29 | fprintf(stderr, "udp: socket err: %s\n", strerror(errno)); 30 | return -1; 31 | } 32 | 33 | if (bind(fd, (struct sockaddr *) &sar, sizeof(struct sockaddr_in)) < 0) { 34 | fprintf(stderr, "udp: bind err: %s\n", strerror(errno)); 35 | return -1; 36 | } 37 | 38 | len = sizeof(struct sockaddr_in); 39 | total = 0; 40 | 41 | for (run = 1; run > 0; ){ 42 | FD_ZERO(&ins); 43 | FD_SET(fd, &ins); 44 | 45 | rtn = select(fd + 1, &ins, NULL, NULL, NULL); 46 | if (rtn < 0){ 47 | run = 0; 48 | } else { 49 | 50 | if (FD_ISSET(fd, &ins)){ 51 | bzero(buffer, MTU); 52 | 53 | rb = recvfrom(fd, buffer, MTU, 0, (struct sockaddr *) &peer, &len); 54 | if (rb == 0 /*|| rb == 24*/){ /*this is bad since recv might read 24bytes in a random case and then exit*/ 55 | fprintf(stderr, "udp: read EOF shutdown\n"); 56 | run = 0; 57 | } else if (rb < 0){ 58 | fprintf(stderr, "upd: error %s\n", strerror(errno)); 59 | } else { 60 | 61 | fprintf(stderr, "udp: got data %d bytes\n", rb); 62 | for (i=0; i 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | 16 | int main(int argc, char *argv[]){ 17 | 18 | int fd,rtn, socerr,socerrlen; 19 | struct sockaddr_in sa; 20 | fd_set wset; 21 | struct timeval tv; 22 | 23 | tv.tv_sec = 0; 24 | tv.tv_usec = 1; 25 | socerrlen = sizeof(int); 26 | 27 | sa.sin_port = htons(80); 28 | sa.sin_family = AF_INET; 29 | if (inet_aton("157.166.226.26",&(sa.sin_addr)) == 0){ 30 | fprintf(stderr,"cannot connect to host\n"); 31 | return -1; 32 | } 33 | 34 | fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK,0); 35 | 36 | FD_ZERO(&wset); 37 | FD_SET(fd,&wset); 38 | 39 | rtn = connect(fd,(struct sockaddr *)&sa,sizeof(struct sockaddr_in)); 40 | if (rtn == 0){ 41 | fprintf(stderr,"connect returned imidiately\n"); 42 | } else if (rtn < 0){ 43 | fprintf(stderr,"there was a connect error: %s\n",strerror(errno)); 44 | if (errno == EINPROGRESS){ 45 | for (;;){ 46 | rtn = select(fd+1,NULL,&wset,NULL,&tv); 47 | if (rtn == 0){ 48 | fprintf(stderr,"."); 49 | FD_ZERO(&wset); 50 | FD_SET(fd,&wset); 51 | } else if (rtn < 0){ 52 | fprintf(stderr,"select error: %s\n",strerror(errno)); 53 | return 0; 54 | } else if (rtn > 0) { 55 | fprintf(stderr,"socket in write set is writable\n"); 56 | rtn = getsockopt(fd, SOL_SOCKET, SO_ERROR, &socerr, &socerrlen); 57 | fprintf(stderr,"getsockopt rtn: %d\n",rtn); 58 | if (socerr > 0){ 59 | fprintf(stderr,"error connecting: %s\n",strerror(socerr)); 60 | return -1; 61 | } else { 62 | fprintf(stderr,"CONNECTED %s\n",strerror(socerr)); 63 | break; 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | close(fd); 71 | fprintf(stderr,"Exiting program\n"); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /katcp/client.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "katpriv.h" 18 | #include "katcl.h" 19 | #include "katcp.h" 20 | #include "netc.h" 21 | 22 | int run_client_katcp(struct katcp_dispatch *d, char *host, int port) 23 | { 24 | int fd, result; 25 | fd_set fsr, fsw; 26 | 27 | fd = net_connect(host, port, 0); 28 | if(fd < 0){ 29 | return terminate_katcp(d, KATCP_EXIT_ABORT); 30 | } 31 | 32 | reset_katcp(d, fd); 33 | name_katcp(d, "%s:%d", host, port); 34 | 35 | while(exited_katcp(d) == KATCP_EXIT_NOTYET){ 36 | 37 | FD_ZERO(&fsr); 38 | FD_ZERO(&fsw); 39 | 40 | FD_SET(fd, &fsr); 41 | if(flushing_katcp(d)){ /* only write data if we have some */ 42 | #ifdef DEBUG 43 | fprintf(stderr, "client: want to flush data\n"); 44 | #endif 45 | FD_SET(fd, &fsw); 46 | } 47 | 48 | result = select(fd + 1, &fsr, &fsw, NULL, NULL); 49 | switch(result){ 50 | case -1 : 51 | switch(errno){ 52 | case EAGAIN : 53 | case EINTR : 54 | continue; /* WARNING */ 55 | default : 56 | return terminate_katcp(d, KATCP_EXIT_ABORT); 57 | } 58 | break; 59 | #if 0 60 | case 0 : 61 | return 0; 62 | #endif 63 | } 64 | 65 | if(FD_ISSET(fd, &fsr)){ 66 | result = read_katcp(d); 67 | if(result){ 68 | if(result < 0){ 69 | return terminate_katcp(d, KATCP_EXIT_ABORT); 70 | } else { 71 | terminate_katcp(d, KATCP_EXIT_HALT); 72 | } 73 | } 74 | } 75 | 76 | result = dispatch_katcp(d); 77 | if(result < 0){ 78 | return terminate_katcp(d, KATCP_EXIT_ABORT); 79 | } 80 | 81 | if(FD_ISSET(fd, &fsw)){ 82 | result = write_katcp(d); 83 | if(result < 0){ 84 | return terminate_katcp(d, KATCP_EXIT_ABORT); 85 | } 86 | } 87 | } 88 | 89 | return 0; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /scripts/beamformer.sh: -------------------------------------------------------------------------------- 1 | kcs_export() { 2 | if [ $# -lt 1 ] ; then 3 | exit 1 4 | fi 5 | 6 | kcpcmd -s localhost:7147 -k -i -r setenv $1 $2 7 | } 8 | 9 | ip_to_hex() { 10 | if [ $# -lt 1 ] ; then 11 | return 1 12 | fi 13 | 14 | ip=$1 15 | 16 | hexip=$(echo $ip | tr '.' \\n | (echo obase=16 ; r=0 ; while read line ; do r=$[256*$r+$line] ; done ; echo $r ) | bc ) 17 | 18 | echo "ip $ip is $hexip" 19 | 20 | export hexip 21 | } 22 | 23 | port_to_hex() { 24 | if [ $# -lt 1 ] ; then 25 | return 1 26 | fi 27 | 28 | port=$1 29 | 30 | hexport=$(echo -e "obase=16\n${port}" | bc ) 31 | 32 | echo "port $port is $hexport" 33 | 34 | export hexport 35 | } 36 | 37 | detect_reg_set () { 38 | if [ $# -lt 2 ] ; then 39 | return 1 40 | fi 41 | 42 | reg=$1 43 | shift 44 | 45 | if kcppar -q -i -s $* -x wordread $reg 0 ; then 46 | return 0 47 | fi 48 | 49 | return 1 50 | } 51 | 52 | disable_bf_count () { 53 | kcpmsg -l info "beamformer logic disabled" 54 | kcs_export KCS_BF_COUNT 0 55 | } 56 | 57 | detect_bf_count () { 58 | if [ $# -lt 1 ] ; then 59 | kcs_export KCS_BF_COUNT 0 60 | return 1 61 | fi 62 | 63 | i=0 64 | 65 | while detect_reg_set bf${i}_dest $*; do 66 | if [ $i -gt 8 ] ; then 67 | kcpmsg -l error "unreasonably large number of beamformers $i" 68 | kcs_export KCS_BF_COUNT 0 69 | return 1; 70 | fi 71 | kcs_export KCS_BF${i}_RX 0.0.0.0:0 72 | i=$[i+1] 73 | done 74 | 75 | kcpmsg -l info "system appears to have ${i} beams" 76 | 77 | kcs_export KCS_BF_COUNT $i 78 | } 79 | 80 | set_bf_rx () { 81 | if [ $# -lt 4 ] ; then 82 | return 1 83 | fi 84 | 85 | if [ "${1:0:2}" != "bf" ] ; then 86 | return 1 87 | fi 88 | 89 | beam=${1:2} 90 | 91 | if [ $beam -ge ${KCS_BF_COUNT} ] ; then 92 | return 1 93 | fi 94 | 95 | ip=$2 96 | port=$3 97 | 98 | ip_to_hex $ip 99 | port_to_hex $port 100 | 101 | shift 3 102 | 103 | if kcppar -i -s $* -x wordwrite bf${beam}_dest 1 0x${hexport} -x wordwrite bf${beam}_dest 0 0x${hexip} ; then 104 | kcs_export KCS_BF${beam}_RX ${ip}:${port} 105 | fi 106 | } 107 | -------------------------------------------------------------------------------- /katcp/Makefile.test: -------------------------------------------------------------------------------- 1 | include ../Makefile.inc 2 | 3 | INC = -I. 4 | 5 | 6 | CFLAGS += -DDEBUG 7 | 8 | TESTS = test-netc test-generic-queue test-parse test-map test-line test-rpc test-job test-queue test-kurl test-ktype test-avl test-bytebit test-dpx-misc 9 | 10 | all: $(TESTS) 11 | 12 | test-generic-queue: generic-queue.c 13 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_GENERIC_QUEUE -o $@ $^ 14 | 15 | test-queue: misc.c queue.c parse.c line.c bytebit.c 16 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_QUEUE -o $@ $^ 17 | 18 | test-map: misc.c parse.c line.c time.c netc.c dispatch.c shared.c ts.c log.c notice.c nonsense.c job.c queue.c map.c kurl.c version.c bytebit.c dbase.c stack.c ktype.c avltree.c dpx.c event.c spointer.c arb.c 19 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_MAP -o $@ $^ 20 | 21 | test-kurl: kurl.c 22 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_KURL -o $@ $^ 23 | 24 | test-avl: misc.c parse.c line.c time.c netc.c dispatch.c shared.c ts.c log.c notice.c nonsense.c job.c queue.c map.c kurl.c version.c avltree.c ktype.c stack.c dbase.c services.c dpx-cmds.c dpx-core.c dpx-forward.c dpx-katcp.c dpx-listen.c dpx-mgmt.c dpx-misc.c arb.c endpoint.c generic-queue.c bytebit.c server.c 25 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_AVL -o $@ $^ 26 | 27 | test-ktype: misc.c parse.c line.c time.c netc.c dispatch.c shared.c ts.c log.c notice.c nonsense.c job.c queue.c map.c kurl.c version.c avltree.c ktype.c 28 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_KTYPE -o $@ $^ 29 | 30 | test-parse: misc.c parse.c bytebit.c 31 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_PARSE -o $@ $^ 32 | 33 | test-line: misc.c parse.c line.c queue.c bytebit.c 34 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_LINE -o $@ $^ 35 | 36 | test-rpc: misc.c parse.c line.c time.c netc.c rpc.c queue.c bytebit.c 37 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_RPC -o $@ $^ 38 | 39 | test-bytebit: bytebit.c 40 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_BYTE_BIT -o $@ $^ 41 | 42 | test-job: misc.c parse.c line.c time.c netc.c dispatch.c shared.c ts.c log.c notice.c nonsense.c job.c queue.c map.c kurl.c version.c 43 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_JOB -o $@ $^ 44 | 45 | test-netc: netc.c 46 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_NETC -o $@ $^ 47 | 48 | test-dpx-misc: dpx-misc.c 49 | $(CC) $(CFLAGS) $(INC) -DUNIT_TEST_DPX_MISC -o $@ $^ 50 | 51 | 52 | clean: 53 | $(RM) *.o core $(TESTS) 54 | -------------------------------------------------------------------------------- /tcpborphserver3/bof.h: -------------------------------------------------------------------------------- 1 | /************************************************** 2 | * $Id: bof.h,v 1.5 2006/10/31 07:28:57 skhay Exp $ 3 | * File : bof.h 4 | * Author: Hayden So 5 | * Date : 01/11/2006 6 | * Description: 7 | * header file for the BOF file format 8 | **************************************************/ 9 | 10 | #ifndef BOF_H_ 11 | #define BOF_H_ 12 | 13 | #include 14 | 15 | /******************** Main BOF header ****************** 16 | * It MUST be at most 52 bytes long. i.e. it MUST be the exact 17 | * same size as a elf header Elf32_EHdr 18 | *******************************************************/ 19 | struct bofhdr { 20 | unsigned char ident[16]; 21 | uint32_t b_version; 22 | uint16_t b_machine; 23 | uint16_t b_elfmachine; 24 | uint32_t b_numchip; 25 | uint32_t b_elfoff; // offset of elf header from beginning of file 26 | uint32_t b_hwoff; // offset of the 1st hwregion from beginning of file 27 | int32_t load_err; 28 | uint32_t b_ekver; // embedded kernel version 29 | uint32_t pad[2]; 30 | }; 31 | 32 | /* position of various misc identifying info within ident */ 33 | #define BI_ENDIAN 5 34 | #define BOFDATA2LSB 1 35 | #define BOFDATA2MSB 2 36 | 37 | /* legal values for b_machine */ 38 | #define BM_BEE2 2 39 | #define BM_ROACH 3 40 | 41 | /*********************** 42 | * header per hw region 43 | ***********************/ 44 | struct hwr_addr { 45 | uint16_t class; 46 | uint16_t addr; 47 | }; 48 | 49 | #define HAC_BEE2FPGA 0x1 50 | #define HAC_PRMOD 0x2 51 | #define HAC_ROACH 0x3 52 | 53 | /* hwrhdr flags */ 54 | #define HFG_PLACED 0x1 55 | #define HFG_NOCONFIG 0x2 56 | struct hwrhdr { 57 | uint32_t flag; 58 | struct hwr_addr addr; /* address of placed */ 59 | uint32_t pl_off; /* payload offset */ 60 | uint32_t pl_len; /* payload len */ 61 | uint32_t nr_symbol; 62 | uint32_t strtab_off; /* string table offset */ 63 | uint32_t next_hwr; /* next hw_region on file */ 64 | // HHH and more info about register mapping, etc 65 | }; 66 | 67 | #define IORM_READ 1 68 | #define IORM_WRITE 2 69 | #define IORM_READWRITE 3 70 | #define IORM_PIPE 4 71 | struct bofioreg { 72 | uint16_t name; //offset into strtab where this name can be found 73 | uint16_t mode; 74 | uint32_t loc; 75 | uint32_t len; 76 | }; 77 | 78 | #endif /* _BOF_H_ */ 79 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | This package contains a C katcp library implementation and selected 3 | applications using it. Unless otherwise noted the code base is released 4 | under the terms described in COPYING 5 | 6 | The Makefile.inc file in this directory contains a number of options, 7 | edit to your needs. Then type make to build it. You probably wish to 8 | do a make install on a per subdirectory basis 9 | 10 | Most executables understand a -h option which provides some (terse) help 11 | 12 | General purpose components: 13 | 14 | katcp - the katcp library itself 15 | cmd - send arbitrary katcp commands to a remote server 16 | log - a utility to monitor a remote katcp server 17 | msg - something to generate katcp log messages (glue logic) 18 | par - similar to cmd, but talk to multiple devices in parallel 19 | con - run concurrent subprocesses 20 | run - simple wrapper to "katcp-ify" output of a program 21 | sq - simple katcp sensor query utility which blocks until 22 | a sensor changes to a specified status 23 | sgw - a serial gateway to proxy katcp requests to a serial port 24 | mpx - a katcp multiplexer allowing a single executable to talk 25 | to multiple servers, one at a turn 26 | examples - simple examples 27 | 28 | Applications for roaches: 29 | 30 | tcpborphserver3 31 | - roach2 server using memory mapped logic. Requires a kernel 32 | with a mmap driver and a roach2 33 | 34 | bulkread - a utlity to perform a ?bulkread request 35 | 36 | fpg - programming utility to load .fpg files. An .fpg file contains 37 | a bitstream and meta information 38 | 39 | Project specific code, requring particular gateware and instruments: 40 | 41 | kcs - a control server using katcp 42 | (incomplete) 43 | scripts - supporting logic to interface kcs to corr 44 | (used by kcs, temporary hack) 45 | tmon - monitor a local ntp server via katcp 46 | (used by kcs) 47 | fmon - fengine monitoring utility to poll gateware status registers 48 | (used by kcs) 49 | smon - monitor common server statistics 50 | 51 | Disregard: 52 | 53 | wops - (incomplete & ignore) 54 | wss - 55 | -------------------------------------------------------------------------------- /Makefile.inc: -------------------------------------------------------------------------------- 1 | # install location 2 | PREFIX=/usr/local 3 | 4 | # where to find the KATCP library (change this in case katcp isn't included locally) 5 | KATCP ?= katcp 6 | 7 | # compiler flags, -Wall is just the right thing to do 8 | CFLAGS += -Wall 9 | #CFLAGS += -O2 10 | 11 | # where the C implementation has diverged from the katcp standard, 12 | # force standard behaviour. Currently only one case: log-level affects 13 | # all connections immediately in standard, otherwise local connection only 14 | CFLAGS += -DKATCP_STRICT_CONFORMANCE 15 | 16 | # how many messages to hold before forcing a flush, only useful 17 | # on memory constrained systems. When this value is unset the 18 | # system buffers as much as needed 19 | #CFLAGS += -DKATCP_FLUSH_THRESHOLD=4 20 | 21 | # enable floating point support (floating point sensor type) 22 | # unless you don't want to use your fpu (or don't have one) enable this 23 | CFLAGS += -DKATCP_USE_FLOATS 24 | 25 | # perform redundant checks, abort if things don't look alright 26 | # enabling this reduces performance and makes the system less 27 | # resistant to failures, but will also notice failures sooner 28 | CFLAGS += -DKATCP_CONSISTENCY_CHECKS 29 | 30 | # log selected noncritical failures to stderr 31 | CFLAGS += -DKATCP_STDERR_ERRORS 32 | 33 | # implement the katcp -T option 34 | #CFLAGS += -DKATCP_ENABLE_TAGS 35 | 36 | # log client messages 37 | CFLAGS += -DKATCP_LOG_REQUESTS 38 | 39 | # enable the ability to manage katcp subprocesses 40 | CFLAGS += -DKATCP_SUBPROCESS 41 | 42 | # enable newer, broken or nonfunctional code 43 | CFLAGS += -DKATCP_EXPERIMENTAL 44 | 45 | # keep older code 46 | CFLAGS += -DKATCP_DEPRECATED 47 | 48 | # respond to trap TERM signal in main loop 49 | CFLAGS += -DKATCP_TRAP_TERM 50 | 51 | # inhibit sensor-{value,list} prefix matching, unless it is on a . boundary 52 | #CFLAGS += -DKATCP_STRICT_SENSOR_MATCH 53 | 54 | # pick a protocol reversion from the list. Making up 55 | # your own major values doesn't work unless you also implement what 56 | # the protocol requires 57 | #CFLAGS += -DKATCP_PROTOCOL_MAJOR_VERSION=5 -DKATCP_PROTOCOL_MINOR_VERSION=0 58 | CFLAGS += -DKATCP_PROTOCOL_MAJOR_VERSION=4 -DKATCP_PROTOCOL_MINOR_VERSION=9 59 | 60 | # amount of debugging logic to enable 61 | #CFLAGS += -DDEBUG=4 62 | #CFLAGS += -DDEBUG 63 | CFLAGS += -ggdb 64 | 65 | # what compiler to use 66 | CC = $(CROSS_COMPILE)gcc 67 | # C++ implements more finicky type checks... so this gives loads of warnings 68 | #CC = g++ -fpermissive 69 | 70 | GITVER = $(shell git describe --always --tags --long --dirty 2> /dev/null || echo unknown) 71 | 72 | INSTALL = install 73 | RM = rm -f 74 | AR = ar 75 | ECHO = echo 76 | 77 | .PHONY: all clean install 78 | -------------------------------------------------------------------------------- /katcp/fork-parent.c: -------------------------------------------------------------------------------- 1 | /* released to the public domain, no warranties, 2 | * no liability, use at your own risk, batteries not included 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include "fork-parent.h" 19 | 20 | #define READ_BUFFER 1024 21 | 22 | int fork_parent() 23 | { 24 | int p[2]; 25 | pid_t pid; 26 | char buffer[READ_BUFFER]; 27 | int rr, status, result; 28 | 29 | if (pipe(p)) { 30 | return -1; 31 | } 32 | 33 | fflush(stderr); 34 | 35 | pid = fork(); 36 | 37 | if(pid < 0){ 38 | return -1; 39 | } 40 | 41 | if(pid == 0){ /* in child - make pipe stderr and detach from terminal */ 42 | close(p[0]); 43 | if (p[1] != STDERR_FILENO) { 44 | if (dup2(p[1], STDERR_FILENO) != STDERR_FILENO) { 45 | exit(EX_OSERR); 46 | } 47 | close(p[1]); 48 | } 49 | 50 | close(STDOUT_FILENO); 51 | close(STDIN_FILENO); 52 | /* TODO: could point STDIN and STDOUT at /dev/null */ 53 | 54 | setsid(); 55 | 56 | return 0; 57 | } 58 | 59 | /* in parent - read from pipe, exit when pipe closes */ 60 | close(p[1]); 61 | 62 | do { 63 | rr = read(p[0], buffer, READ_BUFFER); 64 | switch (rr) { 65 | case -1: 66 | switch (errno) { 67 | case EAGAIN: 68 | case EINTR: 69 | rr = 1; 70 | break; 71 | default: 72 | fprintf(stderr, "unable to read error messages: %s\n", strerror(errno)); 73 | fflush(stderr); 74 | break; 75 | } 76 | break; 77 | case 0: 78 | /* eof */ 79 | break; 80 | default: 81 | write(STDERR_FILENO, buffer, rr); 82 | /* don't care if write fails, can't do anything about it */ 83 | break; 84 | } 85 | } while (rr > 0); 86 | 87 | sched_yield(); 88 | result = 0; 89 | 90 | if (waitpid(pid, &status, WNOHANG) > 0) { /* got a child */ 91 | if (WIFEXITED(status)) { 92 | result = WEXITSTATUS(status); 93 | fprintf(stderr, "exited with code %d\n", result); 94 | } else if (WIFSIGNALED(status)) { 95 | fprintf(stderr, "killed by signal %d\n", WTERMSIG(status)); 96 | fflush(stderr); 97 | result = EX_SOFTWARE; 98 | #if 0 99 | /* mimic child - problematic, it may ovewrite the child core file */ 100 | result = WTERMSIG(status); 101 | raise(result); 102 | #endif 103 | #if 0 104 | } else if (WIFSTOPPED(status)) { /* too clever by half */ 105 | result = WSTOPSIG(status); 106 | fprintf(stderr, "stopped by signal %d, restarting with %d\n", result, SIGCONT); 107 | kill(pid, SIGCONT); 108 | result = 0; 109 | #endif 110 | } 111 | } 112 | 113 | /* else child probably ok */ 114 | exit(result); 115 | /* not reached */ 116 | return -1; 117 | } 118 | -------------------------------------------------------------------------------- /katcp/avltree.h: -------------------------------------------------------------------------------- 1 | #ifndef _AVTREE_H_ 2 | #define _AVTREE_H_ 3 | 4 | #include "katcp.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define AVL_LEFT 0x2 11 | #define AVL_RIGHT 0x1 12 | #define AVL_MASK 0xF 13 | 14 | #define AVL_LEFTRIGHT 0x6 15 | #define AVL_RIGHTLEFT 0x9 16 | #define AVL_LEFTLEFT 0xA 17 | #define AVL_RIGHTRIGHT 0X5 18 | 19 | #define WALK_INIT 0 20 | #define WALK_PUSH 1 21 | #define WALK_POP 2 22 | 23 | struct avl_tree { 24 | struct avl_node *t_root; 25 | }; 26 | 27 | struct avl_node { 28 | struct avl_node *n_parent; 29 | struct avl_node *n_left; 30 | struct avl_node *n_right; 31 | int n_balance; 32 | 33 | char *n_key; 34 | 35 | void *n_data; 36 | }; 37 | 38 | /*this can be used as a set of nodes*/ 39 | struct avl_node_list { 40 | struct avl_node **l_n; 41 | int l_count; 42 | }; 43 | 44 | struct avl_tree *create_avltree(); 45 | struct avl_node *create_node_avltree(char *key, void *data); 46 | int add_node_avltree(struct avl_tree *t, struct avl_node *n); 47 | int del_node_avltree(struct avl_tree *t, struct avl_node *n, void (*d_free)(void *)); 48 | struct avl_node *find_name_node_avltree(struct avl_tree *t, char *key); 49 | void *find_data_avltree(struct avl_tree *t, char *key); 50 | int del_name_node_avltree(struct avl_tree *t, char *key, void (*d_free)(void *)); 51 | void free_node_avltree(struct avl_node *n, void (*d_free)(void *)); 52 | void destroy_avltree(struct avl_tree *t, void (*d_free)(void *)); 53 | 54 | int del_name_node_complex_avltree(struct avl_tree *t, char *key, void *global, void (*complex_free)(void *global, char *key, void *payload)); 55 | int del_node_complex_avltree(struct avl_tree *t, struct avl_node *n, void *global, void (*complex_free)(void *global, char *key, void *payload)); 56 | void destroy_complex_avltree(struct avl_tree *t, void *global, void (*complex_free)(void *global, char *key, void *payload)); 57 | 58 | struct avl_node *walk_inorder_avltree(struct avl_node *n); 59 | void *walk_data_inorder_avltree(struct avl_node *n); 60 | 61 | /*node api*/ 62 | 63 | char *get_node_name_avltree(struct avl_node *n); 64 | void *get_node_data_avltree(struct avl_node *n); 65 | int update_node_data_avltree(struct avl_node *n, void *data); 66 | 67 | int store_named_node_avltree(struct avl_tree *t, char *key, void *data); 68 | struct avl_node *store_exposed_node_avltree(struct avl_tree *t, char *key, void *data); 69 | 70 | /*testing api*/ 71 | void print_avltree(struct katcp_dispatch *d, struct avl_node *n, int depth, void (*fn_print)(struct katcp_dispatch *, char *key, void *)); 72 | void print_inorder_avltree(struct katcp_dispatch *d, struct avl_node *n, void (*fn_print)(struct katcp_dispatch *, char *key, void *), int flags); 73 | 74 | void complex_inorder_traverse_avltree(struct katcp_dispatch *d, struct avl_node *n, void *global, int (*callback)(struct katcp_dispatch *d, void *global, char *key, void *data)); 75 | 76 | 77 | int check_balances_avltree(struct avl_node *n, int depth); 78 | 79 | /*extra*/ 80 | 81 | char *gen_id_avltree(char *prefix); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /katcp/misc.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "katcp.h" 9 | #include "katpriv.h" 10 | 11 | int print_time_delta_katcm(char *buffer, unsigned int len, time_t delta) 12 | { 13 | unsigned long a, r; 14 | char *unit, *minor; 15 | int result; 16 | 17 | if(buffer == NULL){ 18 | return -1; 19 | } 20 | if(len <= 0){ 21 | return -1; 22 | } 23 | 24 | minor = NULL; 25 | 26 | a = delta; 27 | unit = "second"; 28 | minor = NULL; 29 | 30 | if(a > 60){ 31 | r = a % 60; 32 | a = a / 60; 33 | minor = r ? unit : NULL; 34 | unit = "minute"; 35 | if(a > 60){ 36 | r = a % 60; 37 | a = a / 60; 38 | minor = r ? unit : NULL; 39 | unit = "hour"; 40 | if(a > 24){ 41 | r = a % 24; 42 | a = a / 24; 43 | minor = r ? unit : NULL; 44 | unit = "day"; 45 | } 46 | } 47 | } 48 | 49 | if(minor){ 50 | result = snprintf(buffer, len, "%lu %s%s and %lu %s%s", a, unit, (a == 1) ? "" : "s", r, minor, (r == 1) ? "" : "s"); 51 | } else { 52 | result = snprintf(buffer, len, "%lu %s%s", a, unit, (a == 1) ? "" : "s"); 53 | } 54 | 55 | buffer[len - 1] = '\0'; 56 | 57 | return result; 58 | } 59 | 60 | static char *misc_result_table[] = { KATCP_OK, KATCP_FAIL, KATCP_INVALID, KATCP_PARTIAL, NULL }; 61 | 62 | char *code_to_name_katcm(int code) 63 | { 64 | #ifdef DEBUG 65 | if((KATCP_RESULT_OK > 0) || (code < KATCP_RESULT_PARTIAL)){ 66 | return NULL; 67 | } 68 | #endif 69 | return misc_result_table[code * (-1)]; 70 | } 71 | 72 | 73 | char **copy_vector_katcm(char **vector, unsigned int size) 74 | { 75 | char **base; 76 | unsigned int i; 77 | 78 | base = malloc(sizeof(char *) * size); 79 | if(base == NULL){ 80 | return NULL; 81 | } 82 | 83 | for(i = 0; i < size; i++){ 84 | if(vector[i]){ 85 | base[i] = strdup(vector[i]); 86 | if(base[i] == NULL){ 87 | delete_vector_katcm(base, i); 88 | return NULL; 89 | } 90 | } else { 91 | base[i] = NULL; 92 | } 93 | } 94 | 95 | return base; 96 | } 97 | 98 | void delete_vector_katcm(char **vector, unsigned int size) 99 | { 100 | unsigned int i; 101 | 102 | if(vector == NULL){ 103 | return; 104 | } 105 | 106 | for(i = 0; i < size; i++){ 107 | if(vector[i]){ 108 | free(vector[i]); 109 | vector[i] = NULL; 110 | } 111 | } 112 | 113 | free(vector); 114 | } 115 | 116 | char *default_message_type_katcm(char *string, int type) 117 | { 118 | int len; 119 | char *ptr; 120 | 121 | if(string == NULL){ 122 | return NULL; 123 | } 124 | 125 | switch(string[0]){ 126 | case KATCP_REQUEST : 127 | case KATCP_REPLY : 128 | case KATCP_INFORM : 129 | return strdup(string); 130 | } 131 | 132 | len = strlen(string); 133 | 134 | ptr = malloc(len + 2); 135 | if(ptr == NULL){ 136 | return NULL; 137 | } 138 | 139 | ptr[0] = type; 140 | memcpy(ptr + 1, string, len + 1); 141 | 142 | return ptr; 143 | } 144 | -------------------------------------------------------------------------------- /katcp/API: -------------------------------------------------------------------------------- 1 | 2 | To use higher-level api include and link against -lkatcp. 3 | You might also need to include , particularly for lower 4 | layer work. 5 | 6 | You may need to set the include search path with -I and library 7 | search path with -L 8 | 9 | The makefile only generates a static library (.a), but shared 10 | libraries could also be built (but do remember the -fPIC 11 | compiler flag) 12 | 13 | The katcp API has several "layers" 14 | 15 | - A top level where the service main loop is implemented 16 | inside an API function. An example which uses this 17 | API can be found in ../examples/server-example.c code. 18 | The tcpborphserver and kcs source tree also use this 19 | api. 20 | 21 | At this level, the user only provides function and sensor 22 | callbacks. The mainloop is implemented by the library, 23 | as is the logic to handle network connections. 24 | 25 | The API consists of the following functions: 26 | 27 | * A user of this API initialises the system using 28 | startup_katcp. 29 | 30 | * Command callbacks are registered using the 31 | register_katcp call. 32 | 33 | * To register sensors, use one of the 34 | register_*_sensor_katcp functions. 35 | 36 | * After all callbacks are registered, the main loop is started with 37 | functions such as run_server_katcp, run_multi_server_katcp and run_client_katcp. 38 | 39 | * After the main loop completes, final clean ups are done 40 | by invoking the shutdown_katcp function. 41 | 42 | Inside a command function (the one passed to 43 | register_katcp), users can call arg_*_katcp 44 | to access parameters and append_*_katcp, send_katcp 45 | and log_message_katcp to generate output. 46 | 47 | Internally the katcp library implements these 48 | functions in loop.c and netc.c. 49 | 50 | - An intermediate level, where the user implements his 51 | or her own main loop (probably using some select 52 | variant), but still uses a katcp_dispatch structure 53 | to register functions, dispatch them, etc. The 54 | internals of a command function remain similar to 55 | the higher level case (arg_*_katcp, append_*_katcp, etc). 56 | 57 | This logic is implemented inside dispatch.c, but loop.c 58 | may be helpful as a starting point for a users own 59 | main loop. 60 | 61 | This layer is likely to be the least stable. 62 | 63 | - A lower level where only the protocol parsing logic of 64 | the library is used. Here the programmer implements 65 | his or her own main loop and dispatch logic. The functions 66 | used to parse the protocol are defined in line.c and parse and 67 | are distinguished by a *_katcl (*not* a *_katcp) suffix. Thus 68 | it is probably sufficient to include only katcl.h. kcpcmd 69 | and the much simpler kcpmsg use this layer. 70 | 71 | In addition, there is work underway to develop a duplex 72 | routine, where clients can issue and respond to katcp requests, 73 | this is still incomplete and makes reasonably large changes 74 | to the library internals. The lowest layer and the command 75 | registration of the top layer should remain reasonably consistent, 76 | but sensor handling may end up changing. 77 | -------------------------------------------------------------------------------- /misc/init.katcp: -------------------------------------------------------------------------------- 1 | ?setenv PATH /usr/local/lib/kcs/scripts:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/sbin:/usr/sbin 2 | ?chdir /usr/local/lib/kcs 3 | ?define mode ready restart-mode-ready warn 4 | ?define mode bc16n400M1k restart-mode-bc16n400M1k nominal 5 | ?define mode c16n400M1k restart-mode-c16n400M1k nominal 6 | ?define mode c16n400M8k restart-mode-c16n400M8k nominal 7 | ?define mode c16n2M4k restart-mode-c16n2M4k nominal 8 | ?define mode c16n7M4k restart-mode-c16n7M4k nominal 9 | ?define mode c16n25M4k restart-mode-c16n25M4k nominal 10 | ?define mode c16n13M4k restart-mode-c16n13M4k nominal 11 | ?define mode c16n3M8k restart-mode-c16n3M8k nominal 12 | ?define mode bwbc4a restart-mode-bwbc4a nominal 13 | ?define mode twbc4a restart-mode-twbc4a nominal 14 | ?define mode c8n7M4k_top restart-mode-c8n7M4k_top nominal 15 | ?define mode c8n7M4k_bottom restart-mode-c8n7M4k_bottom nominal 16 | ?define mode c8n25M4k_top restart-mode-c8n25M4k_top nominal 17 | ?define mode c8n25M4k_bottom restart-mode-c8n25M4k_bottom nominal 18 | ?define mode bc8n400M1k_top restart-mode-bc8n400M1k_top nominal 19 | ?define mode bc8n400M1k_bottom restart-mode-bc8n400M1k_bottom nominal 20 | ?job process tmon exec://tmon 21 | ?job process smon exec://smon 22 | ?forget ?halt 23 | ?forget ?restart 24 | ?hide ?sensor ?process ?arb ?define ?job ?notice ?dispatch ?watchannounce ?sm ?roach ?search ?set ?get ?dict ?version 25 | ?process ?enable-sensors enable\_roach\_sensors\_(?enable-sensors) 26 | ?process ?label-input alias\_an\_input\_name\_(?label-input\_[input\_[alias]]) 27 | ?process ?label-clear resets\_an\_input\_alias\_(?label-input\_[input]) 28 | ?process ?halt halt\_the\_control\_server_\(?halt) 29 | ?process ?restart restart\_the\_system\_(?restart) 30 | ?process ?sync-now resynchronises\_the\_correlator\_(?sync-now) 31 | ?process ?capture-start start\_a\_capture\_(?capture-start\_stream) 32 | ?process ?capture-stop stop\_a\_capture\_(?capture-stop\_stream) 33 | ?process ?capture-list list\_available\_data\_streams\_(?capture-list) 34 | ?process ?capture-status return\_status\_of\_data\_stream\_(?capture-status\_stream) 35 | ?process ?capture-destination set\_the\_destination\_for\_a\_stream\_(?capture-destination\_stream\_ip\_port) 36 | ?process ?k7-accumulation-length sets\_the\_accumulation\_length\_(?k7-accumlation-length\_accumulation-period) 37 | ?process ?k7-delay set\_the\_delay\_and\_fringe\_correction\_(?k7-delay\_board-input\_time\_delay-value\_delay-rate\_fringe-offset\_fringe-rate) 38 | ?process ?k7-snap-shot retrieve\_a\_processing\_pipeline\_data\_block\_(?k7-snap-shot\_[adc\_board-input|quant\_[count]]) 39 | ?process ?k7-adc-snap-shot retrieve\_an\_adc\_snapshot\_(?k7-adc-snap-shot\_[pps|now]\_threshold\_input+) 40 | ?process ?k7-quant-snap-shot retrieve\_a\_quantiser\_snapshot\_(?k7-quant-snap-shot\_board-input\_[count]) 41 | ?process ?k7-gain sets\_the\_digital\_gain\_(?k7-gain\_board-input\_values) 42 | ?process ?k7-frequency-select select\_a\_frequency\_for\_fine\_channelisation\_(?k7-frequency-select\_center-frequency) 43 | ?process ?k7-beam-weights sets\_a\_vector\_of\_scaling\_factors\_for\_the\_given\_beam\_(?k7-beam-weights\_beam\_input\_values) 44 | ?process ?k7-beam-passband sets\_the\_bandwidth\_and\_centerfrequency\_for\_the\_given\_beam\_(?k7-beam-passband\_beam\_bandwidth\_centerfrequency) 45 | ?process ?xport roach\_start\_and\_stop\_routines 46 | ?process ?test-reload-rf-gain reload\_analog\_gain\_(?test-reload-rf-gain) 47 | ?hide ?test-reload-rf-gain ?enable-sensors ?capture-status 48 | ?xport start 49 | ?mode ready 50 | ?enable-sensors static 51 | ?mode c16n400M1k 52 | ?enable-sensors dynamic 53 | -------------------------------------------------------------------------------- /msg/msg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #define DEFAULT_LEVEL "info" 13 | 14 | void usage(char *app) 15 | { 16 | printf("usage: %s [options] message ...\n", app); 17 | printf("-h this help\n"); 18 | printf("-l level specify level (default is %s)\n", DEFAULT_LEVEL); 19 | printf("-m enable multiple messages\n"); 20 | printf("-s subsystem specify the subsystem (overrides KATCP_LABEL)\n"); 21 | } 22 | 23 | int main(int argc, char **argv) 24 | { 25 | int i, j, c, extra, pos, size; 26 | int multi, level, result; 27 | char *system, *tmp, *buffer; 28 | struct katcl_line *k; 29 | char *app; 30 | 31 | multi = 0; 32 | i = j = 1; 33 | level = KATCP_LEVEL_INFO; 34 | buffer = NULL; 35 | size = 0; 36 | pos = 0; 37 | 38 | system = getenv("KATCP_LABEL"); 39 | if(system == NULL){ 40 | system = "notifier"; 41 | } 42 | 43 | app = argv[0]; 44 | 45 | k = create_katcl(STDOUT_FILENO); 46 | if(k == NULL){ 47 | fprintf(stderr, "%s: unable to create katcp message logic\n", app); 48 | return EX_OSERR; 49 | } 50 | 51 | while (i < argc) { 52 | if (argv[i][0] == '-') { 53 | c = argv[i][j]; 54 | switch (c) { 55 | 56 | case 'h' : 57 | usage(app); 58 | return 0; 59 | 60 | case 'm' : 61 | multi = 1; 62 | j++; 63 | break; 64 | 65 | case 'l' : 66 | case 's' : 67 | 68 | j++; 69 | if (argv[i][j] == '\0') { 70 | j = 0; 71 | i++; 72 | } 73 | 74 | if (i >= argc) { 75 | sync_message_katcl(k, KATCP_LEVEL_ERROR, system, "option -%c needs a parameter"); 76 | return EX_USAGE;; 77 | } 78 | 79 | switch(c){ 80 | case 's' : 81 | system = argv[i] + j; 82 | break; 83 | case 'l' : 84 | tmp = argv[i] + j; 85 | level = log_to_code_katcl(tmp); 86 | if(level < 0){ 87 | sync_message_katcl(k, KATCP_LEVEL_ERROR, system, "unknown log level %s", tmp); 88 | level = KATCP_LEVEL_ERROR; 89 | } 90 | break; 91 | } 92 | 93 | i++; 94 | j = 1; 95 | break; 96 | 97 | case '-' : 98 | j++; 99 | break; 100 | case '\0': 101 | j = 1; 102 | i++; 103 | break; 104 | default: 105 | fprintf(stderr, "%s: unknown option -%c\n", app, argv[i][j]); 106 | return 2; 107 | } 108 | } else { 109 | if(multi){ 110 | log_message_katcl(k, level, system, "%s", argv[i]); 111 | } else { 112 | extra = strlen(argv[i]); 113 | size += extra + 1; 114 | tmp = realloc(buffer, size); 115 | if(tmp == NULL){ 116 | return EX_OSERR; 117 | } 118 | buffer = tmp; 119 | if(pos > 0){ 120 | buffer[pos++] = ' '; 121 | } 122 | strcpy(buffer + pos, argv[i]); 123 | pos += extra; 124 | } 125 | i++; 126 | } 127 | } 128 | 129 | if(buffer){ 130 | log_message_katcl(k, level, system, "%s", buffer); 131 | free(buffer); 132 | } 133 | 134 | while((result = write_katcl(k)) == 0); 135 | 136 | destroy_katcl(k, 0); 137 | 138 | return (result < 0) ? EX_OSERR : EX_OK; 139 | } 140 | -------------------------------------------------------------------------------- /tcpborphserver3/subprocess.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "tcpborphserver3.h" 24 | 25 | void replace_argv(struct katcp_dispatch *d, char *str) 26 | { 27 | struct tbs_raw *tr; 28 | int i, argc; 29 | char **argv; 30 | 31 | tr = get_mode_katcp(d, TBS_MODE_RAW); 32 | 33 | if (tr == NULL) 34 | return; 35 | 36 | argc = tr->r_argc; 37 | argv = tr->r_argv; 38 | 39 | for (i=0; i 0){ 81 | 82 | #ifdef DEBUG 83 | fprintf(stderr, "%s: in parent child has pid: %d\n", __func__, pid); 84 | #endif 85 | 86 | close(fds[0]); 87 | fcntl(fds[1], F_SETFD, FD_CLOEXEC); 88 | 89 | if(pfds[0] >= 0){ 90 | close(pfds[1]); 91 | rr = read(pfds[0], buffer, TINY_BUFFER); 92 | close(pfds[0]); 93 | } 94 | 95 | sched_yield(); 96 | 97 | j = create_job_katcp(d, url, pid, fds[1], 0, n); 98 | if(j == NULL){ 99 | log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "unable to allocate job logic so terminating child process"); 100 | kill(pid, SIGTERM); 101 | close(fds[1]); 102 | /* semantics are that on failure, parent cleans up */ 103 | /* destroy_kurl_katcp(url); */ 104 | } 105 | return j; 106 | } 107 | 108 | /* WARNING: now we are in child - use exit not return */ 109 | #ifdef DEBUG 110 | fprintf(stderr,"%s: in child: %d\n", __func__, getpid()); 111 | #endif 112 | 113 | if(pfds[0] >= 0){ 114 | close(pfds[0]); 115 | } 116 | 117 | xl = create_katcl(fds[0]); 118 | close(fds[1]); 119 | 120 | #if 0 121 | for (i=0; i<1024; i++) 122 | if (i != fds[0]) 123 | close(i); 124 | #endif 125 | 126 | replace_argv(d, url->u_str); 127 | 128 | #if 0 129 | copies = 0; 130 | if (fds[0] != STDOUT_FILENO){ 131 | if (dup2(fds[0], STDOUT_FILENO) != STDOUT_FILENO) { 132 | sync_message_katcl(xl, KATCP_LEVEL_ERROR, NULL, "unable to set up standard output for child process %u (%s)", getpid(), strerror(errno)); 133 | exit(EX_OSERR); 134 | } 135 | copies++; 136 | } 137 | if(fds[0] != STDIN_FILENO){ 138 | if(dup2(fds[0], STDIN_FILENO) != STDIN_FILENO){ 139 | sync_message_katcl(xl, KATCP_LEVEL_ERROR, NULL, "unable to set up standard input for child process %u (%s)", getpid(), strerror(errno)); 140 | exit(EX_OSERR); 141 | } 142 | copies++; 143 | } 144 | if(copies >= 2){ 145 | fcntl(fds[0], F_SETFD, FD_CLOEXEC); 146 | } 147 | #endif 148 | 149 | if(pfds[1] >= 0){ 150 | close(pfds[1]); 151 | } 152 | 153 | result = ((*call)(xl, data)); 154 | 155 | exit((result < 0) ? (result * (-1)) : result); 156 | 157 | return NULL; 158 | #undef TINY_BUFFER 159 | } 160 | -------------------------------------------------------------------------------- /gmon/main.c: -------------------------------------------------------------------------------- 1 | /* This is the main entry point for the Gateware Monitor (GMON) 2 | * application. 3 | * 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "netc.h" 15 | #include "katcp.h" 16 | #include "katcl.h" 17 | 18 | #include "gmon.h" 19 | 20 | static void usage(void); 21 | static void print_version(void); 22 | 23 | static volatile sig_atomic_t monitor = 1; 24 | 25 | static void signalhandler(int signum) 26 | { 27 | switch (signum) { 28 | case SIGTERM: 29 | case SIGINT: 30 | case SIGPIPE: 31 | monitor = 0; 32 | break; 33 | 34 | default: 35 | return; 36 | } 37 | } 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | int opt = 0; 42 | struct sigaction sa; 43 | char *server; 44 | struct gmon_lib gmon = {0}; 45 | int fd; 46 | 47 | /* initialise gmon object */ 48 | gmon.polltime = GMON_POLL_TIME_S; 49 | gmon.state = GMON_UNKNOWN; 50 | 51 | /* initialize the signal handler */ 52 | memset(&sa, 0, sizeof(sa)); 53 | sa.sa_handler = &signalhandler; 54 | sa.sa_flags = SA_RESTART; 55 | sigaction(SIGTERM, &sa, NULL); 56 | sigaction(SIGINT, &sa, NULL); 57 | 58 | server = getenv("KATCP_SERVER"); 59 | if (server == NULL) { 60 | server = "localhost"; 61 | } 62 | 63 | /* process command line arguments */ 64 | while ((opt = getopt(argc, argv, "hs:t:v")) != -1) { 65 | switch (opt) { 66 | case 's': 67 | server = optarg; 68 | break; 69 | case 't': 70 | gmon.polltime = atoi(optarg); 71 | break; 72 | case 'v': 73 | print_version(); 74 | exit(EXIT_SUCCESS); 75 | case 'h': 76 | case '?': 77 | default: 78 | usage(); 79 | exit(EXIT_FAILURE); 80 | break; 81 | } 82 | } 83 | 84 | gmon.log = create_katcl(STDOUT_FILENO); 85 | if (gmon.log == NULL) { 86 | fprintf(stderr, "could not create katcl logger\n"); 87 | return EXIT_FAILURE; 88 | } 89 | 90 | fd = net_connect(server, 0, NETC_VERBOSE_ERRORS | NETC_VERBOSE_STATS); 91 | if (fd < 0) { 92 | fprintf(stderr, "unable to connect to %s\n", server); 93 | return EXIT_FAILURE; 94 | } 95 | 96 | gmon.server = create_katcl(fd); 97 | if (gmon.server == NULL) { 98 | fprintf(stderr, "unable to allocate server state\n"); 99 | /// \todo should we disconnect from server? 100 | return EXIT_FAILURE; 101 | } 102 | 103 | sync_message_katcl(gmon.log, KATCP_LEVEL_INFO, GMON_PROG, 104 | "starting %s on server %s", GMON_PROG, server); 105 | 106 | /* main working loop */ 107 | while (monitor) { 108 | gmon_task(&gmon); 109 | } 110 | 111 | /* perform clean-up */ 112 | sync_message_katcl(gmon.log, KATCP_LEVEL_INFO, GMON_PROG, "gateware monitor shutting down"); 113 | 114 | /* free gmon sensor resources */ 115 | gmon_destroy(&gmon); 116 | 117 | /* free server and logger */ 118 | if (gmon.server) { 119 | destroy_katcl(gmon.server, 1); 120 | gmon.server = NULL; 121 | } 122 | 123 | if (gmon.log) { 124 | destroy_katcl(gmon.log, 1); 125 | gmon.log = NULL; 126 | } 127 | 128 | return EXIT_SUCCESS; 129 | } 130 | 131 | static void usage(void) 132 | { 133 | printf("usage: %s [options]\n", GMON_PROG); 134 | printf("-h\t\t\tthis help\n"); 135 | printf("-s server:port\t\tspecify server:port\n"); 136 | printf("-t polltime\t\tspecify the polltime in seconds [default %d]\n", GMON_POLL_TIME_S); 137 | 138 | printf("\nenvironment variable(s):\n"); 139 | printf("\tKATCP_SERVER\tdefault server (overriden by -s option)\n"); 140 | } 141 | 142 | static void print_version(void) 143 | { 144 | printf("%s version %d.%d.%d\n", GMON_PROG, GMON_VER_MAJOR, GMON_VER_MINOR, 145 | GMON_VER_BUGFIX); 146 | printf("build %s %s\n", __DATE__, __TIME__); 147 | } 148 | 149 | -------------------------------------------------------------------------------- /katcp/time.c: -------------------------------------------------------------------------------- 1 | /* GPLed time comparison code grabbed from libloop */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int string_to_tv_katcp(struct timeval *tv, char *string) 9 | { 10 | char *end, *ptr; 11 | unsigned long v[2]; /* keep tv unchanged in case of parsing failure */ 12 | int digits; 13 | 14 | if(string == NULL){ 15 | return -1; 16 | } 17 | 18 | ptr = string; 19 | 20 | v[0] = strtoul(ptr, &end, 10); 21 | switch(*end){ 22 | case ' ' : 23 | case '\n' : 24 | case '\r' : 25 | case '\t' : 26 | /* WARNING: above chars mean string doesn't only contain a number */ 27 | case '\0' : 28 | if(end == ptr){ /* empty string, fail */ 29 | return -1; 30 | } 31 | 32 | /* had to be something valid, no fractional part */ 33 | tv->tv_sec = v[0]; 34 | tv->tv_usec = 0; 35 | return 0; 36 | 37 | case '.' : 38 | /* move on to fractional handling logic, everything else fails */ 39 | ptr = end + 1; 40 | break; 41 | 42 | default : 43 | return -1; 44 | } 45 | 46 | v[1] = strtoul(ptr, &end, 10); 47 | switch(*end){ 48 | case ' ' : 49 | case '\n' : 50 | case '\r' : 51 | case '\t' : 52 | /* WARNING: above chars mean string doesn't only contain a number */ 53 | case '\0' : 54 | if(end == ptr){ /* empty string, fail */ 55 | return -1; 56 | } 57 | 58 | /* this is rather lame, but avoids floats. Should actually manually parse the string */ 59 | digits = end - ptr; 60 | if(digits < 0){ 61 | return -1; 62 | } 63 | 64 | if(digits > 10){ /* integer overflow on 32 bits */ 65 | return -1; 66 | } 67 | 68 | while(digits > 6){ 69 | v[1] = v[1] / 10; 70 | digits--; 71 | } 72 | while(digits < 6){ 73 | v[1] = v[1] * 10; 74 | digits++; 75 | } 76 | 77 | tv->tv_sec = v[0]; 78 | tv->tv_usec = v[1]; 79 | return 0; 80 | 81 | default : 82 | return -1; 83 | } 84 | 85 | } 86 | 87 | void component_time_katcp(struct timeval *result, unsigned int ms) 88 | { 89 | result->tv_sec = ms / 1000; 90 | result->tv_usec = (ms % 1000) * 1000; 91 | #ifdef DEBUG 92 | fprintf(stderr, "component time: %ums -> %lu.%06lds\n", ms, result->tv_sec, result->tv_usec); 93 | #endif 94 | } 95 | 96 | int cmp_time_katcp(struct timeval *alpha, struct timeval *beta) 97 | { 98 | if(alpha->tv_sec < beta->tv_sec){ 99 | return -1; 100 | } 101 | 102 | if(alpha->tv_sec > beta->tv_sec){ 103 | return 1; 104 | } 105 | 106 | if(alpha->tv_usec < beta->tv_usec){ 107 | return -1; 108 | } 109 | 110 | if(alpha->tv_usec > beta->tv_usec){ 111 | return 1; 112 | } 113 | 114 | return 0; 115 | } 116 | 117 | int add_time_katcp(struct timeval *sigma, struct timeval *alpha, struct timeval *beta) 118 | { 119 | if(alpha->tv_usec + beta->tv_usec >= 1000000){ 120 | sigma->tv_sec = alpha->tv_sec + beta->tv_sec + 1; 121 | sigma->tv_usec = (alpha->tv_usec + beta->tv_usec) - 1000000; 122 | } else { 123 | sigma->tv_sec = alpha->tv_sec + beta->tv_sec; 124 | sigma->tv_usec = alpha->tv_usec + beta->tv_usec; 125 | } 126 | return 0; 127 | } 128 | 129 | int sub_time_katcp(struct timeval *delta, struct timeval *alpha, struct timeval *beta) 130 | { 131 | if(alpha->tv_usec < beta->tv_usec){ 132 | if(alpha->tv_sec <= beta->tv_sec){ 133 | delta->tv_sec = 0; 134 | delta->tv_usec = 0; 135 | return -1; 136 | } 137 | delta->tv_sec = alpha->tv_sec - (beta->tv_sec + 1); 138 | delta->tv_usec = (1000000 + alpha->tv_usec) - beta->tv_usec; 139 | } else { 140 | if(alpha->tv_sec < beta->tv_sec){ 141 | delta->tv_sec = 0; 142 | delta->tv_usec = 0; 143 | return -1; 144 | } 145 | delta->tv_sec = alpha->tv_sec - beta->tv_sec; 146 | delta->tv_usec = alpha->tv_usec - beta->tv_usec; 147 | } 148 | #ifdef DEBUG 149 | if(delta->tv_usec >= 1000000){ 150 | fprintf(stderr, "major logic failure: %lu.%06lu-%lu.%06lu yields %lu.%06lu\n", alpha->tv_sec, alpha->tv_usec, beta->tv_sec, beta->tv_usec, delta->tv_sec, delta->tv_usec); 151 | abort(); 152 | } 153 | #endif 154 | return 0; 155 | } 156 | 157 | -------------------------------------------------------------------------------- /gmon/sensor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sensor.h" 7 | 8 | struct sensor *sensor_create(char *name, char *desc, char *units, char *type, char *status) 9 | { 10 | struct sensor *s = NULL;; 11 | 12 | s = calloc(1, sizeof(struct sensor)); 13 | if (s) { 14 | s->name = strdup(name); 15 | if (s->name == NULL) { 16 | sensor_destroy(s); 17 | return NULL; 18 | } 19 | s->desc = strdup(desc); 20 | if (s->desc == NULL) { 21 | sensor_destroy(s); 22 | return NULL; 23 | } 24 | /* units may be NULL */ 25 | if (units) { 26 | s->units = strdup(units); 27 | if (s->units == NULL) { 28 | sensor_destroy(s); 29 | return NULL; 30 | } 31 | } 32 | s->type = strdup(type); 33 | if (s->type == NULL) { 34 | sensor_destroy(s); 35 | return NULL; 36 | } 37 | s->status = strdup(status); 38 | if (s->status == NULL) { 39 | sensor_destroy(s); 40 | return NULL; 41 | } 42 | } 43 | 44 | return s; 45 | } 46 | 47 | int sensor_destroy(struct sensor *s) 48 | { 49 | if (s) { 50 | if (s->name) { 51 | free(s->name); 52 | } 53 | if (s->desc) { 54 | free(s->desc); 55 | } 56 | if (s->units) { 57 | free(s->units); 58 | } 59 | if (s->type) { 60 | free(s->type); 61 | } 62 | if (s->status) { 63 | free(s->status); 64 | } 65 | free(s); 66 | s = NULL; 67 | return 0; 68 | } else { 69 | return -1; 70 | } 71 | } 72 | 73 | int sensor_katcp_add(struct katcl_line *l, struct sensor *s) 74 | { 75 | int retval = 0; 76 | 77 | if (l == NULL) { 78 | fprintf(stderr, "NULL katcl_line pointer"); 79 | return -1; 80 | } 81 | 82 | if (s == NULL) { 83 | fprintf(stderr, "NULL sensor pointer"); 84 | return -1; 85 | } 86 | 87 | /* register the sensor */ 88 | retval += append_string_katcl(l, KATCP_FLAG_FIRST | KATCP_FLAG_STRING, 89 | KATCP_SENSOR_LIST_INFORM); 90 | retval += append_string_katcl(l, KATCP_FLAG_STRING, s->name); 91 | retval += append_string_katcl(l, KATCP_FLAG_STRING, s->desc); 92 | retval += append_string_katcl(l, KATCP_FLAG_STRING, s->units); 93 | retval += append_string_katcl(l, KATCP_FLAG_LAST | KATCP_FLAG_STRING, 94 | s->type); 95 | 96 | return retval; 97 | } 98 | 99 | int sensor_katcp_update(struct katcl_line *l, struct sensor *s) 100 | { 101 | struct timeval now; 102 | int retval = 0; 103 | //char *valstr = NULL; 104 | 105 | if (l == NULL) { 106 | fprintf(stderr, "NULL katcl_line pointer"); 107 | return -1; 108 | } 109 | 110 | if (s == NULL) { 111 | fprintf(stderr, "NULL sensor pointer"); 112 | return -1; 113 | } 114 | 115 | gettimeofday(&now, NULL); 116 | 117 | /* update the sensor */ 118 | retval += append_string_katcl(l, KATCP_FLAG_FIRST | KATCP_FLAG_STRING, 119 | KATCP_SENSOR_STATUS_INFORM); 120 | #if KATCP_PROTOCOL_MAJOR_VERSION >= 5 121 | retval += append_args_katcl(l, 0, "%lu.%03d", now.tv_sec, 122 | (unsigned int)(now.tv_usec / 1000)); 123 | #else 124 | retval += append_args_katcl(l, 0, "%lu%03d", now.tv_sec, 125 | (unsigned int)(now.tv_usec / 1000)); 126 | #endif 127 | /* only update one sensor */ 128 | retval += append_string_katcl(l, KATCP_FLAG_STRING, "1"); 129 | retval += append_string_katcl(l, KATCP_FLAG_STRING, s->name); 130 | retval += append_string_katcl(l, KATCP_FLAG_STRING, s->status); 131 | 132 | retval += append_unsigned_long_katcl(l, KATCP_FLAG_ULONG | KATCP_FLAG_LAST, s->val); 133 | 134 | /* 135 | if (s->val != 0) { 136 | sprintf(valstr, "%d", s->val); 137 | retval += append_string_katcl(l, KATCP_FLAG_LAST | KATCP_FLAG_STRING, 138 | valstr); 139 | } else { 140 | retval += append_string_katcl(l, KATCP_FLAG_LAST | KATCP_FLAG_STRING, "0"); 141 | } 142 | */ 143 | 144 | return retval; 145 | } 146 | -------------------------------------------------------------------------------- /katcp/spointer.c: -------------------------------------------------------------------------------- 1 | #ifdef KATCP_EXPERIMENTAL 2 | 3 | #include 4 | #include 5 | 6 | #include "katcp.h" 7 | 8 | #define SPOINTER_MAGIC 0x1432fa42 9 | 10 | struct katcp_owner 11 | { 12 | int (*o_exise)(struct katcp_dispatch *d, void *owner, void *pointee); 13 | void *o_owner; 14 | }; 15 | 16 | struct katcp_spointer 17 | { 18 | unsigned int s_magic; 19 | unsigned int s_count; 20 | struct katcp_owner *s_vector; 21 | #if 0 22 | void **s_vector; 23 | int (*s_exise)(struct katcp_dispatch *d, void *owner, void *pointee); 24 | #endif 25 | }; 26 | 27 | /*************************************************************************************/ 28 | 29 | #ifdef KATCP_CONSISTENCY_CHECKS 30 | static void sane_spointer_katcp(struct katcp_spointer *sp) 31 | { 32 | if(sp == NULL){ 33 | fprintf(stderr, "spointer: null structure\n"); 34 | abort(); 35 | } 36 | 37 | if(sp->s_magic != SPOINTER_MAGIC){ 38 | fprintf(stderr, "spointer %p: bad magic 0x%0x, expected 0x%0x\n", sp, sp->s_magic, SPOINTER_MAGIC); 39 | abort(); 40 | } 41 | 42 | } 43 | #else 44 | #define sane_spointer_katcp(sp) 45 | #endif 46 | 47 | /* simple api ************************************************************************/ 48 | 49 | /* owner points to pointee with its own pointer 50 | * pointee contains a spointer structure (setup using create_spointer) 51 | * exise function removes pointee from its owner (triggered when pointee calls release_spointer on its own destruction) 52 | * owner can tell pointee to forget about it by calling forget_spointer, won't trigger exise 53 | */ 54 | 55 | struct katcp_spointer *create_spointer_katcp(struct katcp_dispatch *d) 56 | { 57 | struct katcp_spointer *sp; 58 | 59 | sp = malloc(sizeof(struct katcp_spointer)); 60 | if(sp == NULL){ 61 | log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "unable to allocate pointer handler"); 62 | return NULL; 63 | } 64 | 65 | sp->s_magic = SPOINTER_MAGIC; 66 | sp->s_count = 0; 67 | sp->s_vector = NULL; 68 | 69 | return sp; 70 | } 71 | 72 | int pointat_spointer_katcp(struct katcp_dispatch *d, struct katcp_spointer *sp, void *owner, int (*exise)(struct katcp_dispatch *d, void *owner, void *pointee)) 73 | { 74 | struct katcp_owner *ko, *tmp; 75 | 76 | sane_spointer_katcp(sp); 77 | 78 | tmp = realloc(sp->s_vector, sizeof(struct katcp_owner) * (sp->s_count + 1)); 79 | if(tmp == NULL){ 80 | log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "%p can not hold pointer", owner); 81 | return -1; 82 | } 83 | 84 | sp->s_vector = tmp; 85 | 86 | ko = &(sp->s_vector[sp->s_count]); 87 | 88 | ko->o_owner = owner; 89 | ko->o_exise = exise; 90 | 91 | sp->s_count++; 92 | 93 | return 0; 94 | } 95 | 96 | int forget_spointer_katcp(struct katcp_dispatch *d, struct katcp_spointer *sp, void *owner) 97 | { 98 | unsigned int i; 99 | 100 | sane_spointer_katcp(sp); 101 | 102 | #ifdef KATCP_CONSISTENCY_CHECKS 103 | if(owner == NULL){ 104 | fprintf(stderr, "spointer %p: need a non-null owner", sp); 105 | abort(); 106 | } 107 | #endif 108 | 109 | /* TODO: if this is used in large applications, use bsearch, etc */ 110 | for(i = 0; (i < sp->s_count) && (sp->s_vector[i].o_owner != owner); i++); 111 | 112 | if(i >= sp->s_count){ 113 | fprintf(stderr, "spointer %p: did not find owner %p in vector of %u elements", sp, owner, sp->s_count); 114 | abort(); 115 | return -1; 116 | } 117 | 118 | sp->s_count--; 119 | 120 | /* WARNING: note that the exise function is *NOT* run */ 121 | 122 | if(sp->s_count > 0){ 123 | while(i < sp->s_count){ 124 | sp->s_vector[i].o_owner = sp->s_vector[i + 1].o_owner; 125 | sp->s_vector[i].o_exise = sp->s_vector[i + 1].o_exise; 126 | i++; 127 | } 128 | } else { 129 | free(sp->s_vector); 130 | sp->s_vector = NULL; 131 | } 132 | 133 | return sp->s_count; 134 | } 135 | 136 | void release_spointer_katcp(struct katcp_dispatch *d, struct katcp_spointer *sp, void *pointee) 137 | { 138 | unsigned int i; 139 | struct katcp_owner *ko; 140 | 141 | sane_spointer_katcp(sp); 142 | 143 | for(i = 0; i < sp->s_count; i++){ 144 | ko = &(sp->s_vector[i]); 145 | (*(ko->o_exise))(d, ko->o_owner, pointee); 146 | /* TODO: maybe do something with the return code ? */ 147 | } 148 | 149 | if(sp->s_vector){ 150 | free(sp->s_vector); 151 | sp->s_vector = NULL; 152 | } 153 | 154 | sp->s_count = 0; 155 | sp->s_magic = ~SPOINTER_MAGIC; 156 | 157 | free(sp); 158 | } 159 | 160 | /*************************************************************************************/ 161 | 162 | #endif 163 | -------------------------------------------------------------------------------- /scripts/functions.sh: -------------------------------------------------------------------------------- 1 | export CORR_CONFIG=/etc/corr/ 2 | export CORR_INIT_SCRIPT=/etc/init.d/corr 3 | export KATCP_SERVER=localhost:1235 4 | export CORR_MAPPING=/var/run/corr/antenna_mapping 5 | export MAIN_MAPPING=/var/lib/kcs/mapping 6 | 7 | kcs_check_timeout() 8 | { 9 | if [ $(date +%s) -gt $1 ] ; then 10 | kcpmsg -l error -s script "request to corr timed out" 11 | return 1 12 | fi 13 | } 14 | 15 | kcs_set_frequency () { 16 | # kcpcmd -i -k nb-set-cf $1 | ( while read cmd stat first rest ; do if [ "$cmd" = "!nb-set-cf" -a "${stat}" = "ok" ] ; then echo "#sensor-list .centerfrequency current\_selected\_center\_frequency Hz integer 0 1000000000" ; echo "#sensor-status $(date +%s)000 1 .centerfrequency nominal ${first}" ; fi ; done) 17 | kcpcmd -i -k nb-set-cf $1 | ( while read cmd stat first rest ; do if [ "$cmd" = "!nb-set-cf" ] ; then if [ "${stat}" = "ok" ] ; then echo "#sensor-status $(date +%s)000 1 .centerfrequency nominal ${first}" ; else kcpmsg -l error -s frequency "center frequency update ${stat} ${first}" ; exit 1 ; fi ; else echo ${cmd} ${stat} ${first} ${rest} ; fi ; done) 18 | } 19 | 20 | kcs_set_passband () { 21 | kcpcmd -i -k beam-passband $1 $2 $3 | ( while read cmd stat bw cf rest ; do if [ "$cmd" = "!beam-passband" ] ; then if [ "${stat}" = "ok" ] ; then echo "#sensor-status $(date +%s)000 1 .${1}.bandwidth nominal ${bw}" ; echo "#sensor-status $(date +%s)000 1 .${1}.centerfrequency nominal ${cf}" ; else kcpmsg -l error -s passband "passband update $stat $bw" ; exit 1 ; fi ; else echo ${cmd} ${stat} ${bw} ${cf} ${rest} ; fi ; done) 22 | } 23 | 24 | kcs_input_to_index () { 25 | echo $[$(echo $1 | tr -d -c [:digit:])*2+$(echo $1 | tr -dc xy | tr xy 01)] 26 | } 27 | 28 | kcs_index_to_input () { 29 | echo $[i/2]$(echo $[i%2] | tr 01 xy) 30 | } 31 | 32 | kcs_debug () { 33 | kcpmsg -l debug -s script "$1" 34 | } 35 | 36 | kcs_warn () { 37 | kcpmsg -l warn -s script "$1" 38 | } 39 | 40 | kcs_error () { 41 | kcpmsg -l error -s script "$1" 42 | return 1 43 | } 44 | 45 | kcs_info () { 46 | kcpmsg -l info -s script "$1" 47 | } 48 | 49 | kcs_change_corr() 50 | { 51 | kcs_debug "checking for running corr" 52 | 53 | if ps ax | grep -q corr[_-]katcp[_-]interface ; then 54 | kcs_info "stopping corr" 55 | ${CORR_INIT_SCRIPT} stop 56 | fi 57 | 58 | if [ -n "$1" ] ; then 59 | 60 | kcs_debug "attempting to set config file" 61 | 62 | if [ ! -e ${CORR_CONFIG}/${1} ] ; then 63 | kcs_error "no $1 configuration for corr at ${CORR_CONFIG}/${1}" 64 | return 1 65 | fi 66 | 67 | fi 68 | 69 | kcs_debug "restarting corr" 70 | ${CORR_INIT_SCRIPT} start 71 | 72 | sleep 1 73 | } 74 | 75 | kcs_arg_check () { 76 | if [ $1 -lt $2 ] ; then 77 | kcs_error "insufficient parameters" 78 | return 1 79 | fi 80 | } 81 | 82 | kcs_corr_log () { 83 | kcs_debug "retrieving correlator logs" 84 | if kcpcmd -k -m get-log ; then 85 | kcpcmd -k -r clr-log 86 | fi 87 | kcs_debug "finished getting correlator logs" 88 | return 0 89 | } 90 | 91 | kcs_config_numeric () { 92 | value=$(grep ^${1} ${CORR_CONFIG}/${KATCP_MODE} 2> /dev/null | cut -f2 -d= | tr -d ' ' ) 93 | if [ -z "${value}" ] ; then 94 | kcs_error "unable to locate ${1} in ${CORR_CONFIG}/${KATCP_MODE}" 95 | fi 96 | 97 | kcs_debug "${1} maps to ${value}" 98 | 99 | export $1=${value} 100 | } 101 | 102 | kcs_load_config () { 103 | if [ $# -lt 1 ] ; then 104 | config_file=${CORR_CONFIG}/${KATCP_MODE} 105 | else 106 | config_file=${CORR_CONFIG}/$1 107 | fi 108 | 109 | eval $(grep -v '^ *#' ${config_file} | grep \= | sed -e 's/=/ = /' | (while read label sep value ; do echo var_${label}=${value}\; ; done) ; echo echo ) 110 | } 111 | 112 | 113 | kcs_is_wideband () { 114 | if [ $# -lt 1 ] ; then 115 | return 1 116 | fi 117 | 118 | case "${KATCP_MODE}" in 119 | c16n400M1k|c16n400M8k|bwbc4a|twbc4a|bc16n400M1k|bc8n400M1k_bottom|bc8n400M1k_top) 120 | return 0 121 | ;; 122 | *) 123 | return 1 124 | ;; 125 | esac 126 | 127 | return 1 128 | } 129 | 130 | kcs_is_beamformer () { 131 | if [ $# -lt 1 ] ; then 132 | return 1 133 | fi 134 | 135 | case "${KATCP_MODE}" in 136 | bc16n400M1k|bc8n400M1k_bottom|bc8n400M1k_top) 137 | return 0 138 | ;; 139 | *) 140 | return 1 141 | ;; 142 | esac 143 | 144 | return 1 145 | } 146 | 147 | kcs_is_narrowband () { 148 | if [ $# -lt 1 ] ; then 149 | return 1 150 | fi 151 | 152 | case "${KATCP_MODE}" in 153 | c16n13M4k|c16n25M4k|c16n2M4k|c16n3M8k|c16n7M4k|c8n25M4k_bottom|c8n25M4k_top|c8n7M4k_bottom|c8n7M4k_top) 154 | return 0 155 | ;; 156 | *) 157 | return 1 158 | ;; 159 | esac 160 | 161 | return 1 162 | } 163 | 164 | -------------------------------------------------------------------------------- /gmon/gmon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "gmon.h" 10 | #include "fpga.h" 11 | #include "cmdhandler.h" 12 | #include "reg.h" 13 | 14 | static void gmon_poll_registers(struct gmon_lib *g) 15 | { 16 | while (((g->readdispatch - g->readcollect) < GMON_POLL_QUEUE_LEN) && 17 | (g->readdispatch < g->numsensors)) { 18 | reg_req_wordread(g->server, g->sensorlist[g->readdispatch]->name); 19 | g->readdispatch++; 20 | } 21 | 22 | if (g->readdispatch >= g->numsensors) { 23 | g->readdispatch = 0; 24 | } 25 | } 26 | 27 | static int gmon_state(struct gmon_lib *g) 28 | { 29 | int retval = 0; 30 | 31 | switch (g->state) { 32 | case GMON_UNKNOWN: 33 | fpga_req_cmd(g->server, FPGA_REQ_STATUS); 34 | g->state = GMON_IDLE; 35 | break; 36 | case GMON_IDLE: 37 | case GMON_FPGA_DOWN: 38 | /* do nothing, as one does when idle/down... */ 39 | break; 40 | case GMON_FPGA_READY: 41 | fpga_req_cmd(g->server, FPGA_REQ_LISTDEV); 42 | g->state = GMON_IDLE; 43 | break; 44 | case GMON_REQ_META: 45 | g->state = GMON_POLL; 46 | break; 47 | case GMON_POLL: 48 | gmon_poll_registers(g); 49 | /* only return to IDLE once all the registers have been dispatched */ 50 | if (g->readdispatch == 0) { 51 | g->state = GMON_IDLE; 52 | } 53 | break; 54 | 55 | default: 56 | fprintf(stderr, "gmon in unknown state, setting to initial state"); 57 | g->state = GMON_UNKNOWN; 58 | break; 59 | } 60 | 61 | return retval; 62 | } 63 | 64 | int gmon_task(struct gmon_lib *g) 65 | { 66 | fd_set readfds, writefds; 67 | struct timeval timeout; 68 | int retval, fd, mfd; 69 | 70 | if (g->server == NULL) { 71 | return -1; 72 | } 73 | 74 | /* gmon state machine */ 75 | gmon_state(g); 76 | 77 | FD_ZERO(&readfds); 78 | FD_ZERO(&writefds); 79 | 80 | timeout.tv_sec = g->polltime;; 81 | timeout.tv_usec = 0; 82 | 83 | fd = fileno_katcl(g->server); 84 | mfd = fd; 85 | 86 | /* check if there is server data to process */ 87 | FD_SET(fd, &readfds); 88 | 89 | /* check if there is server data to write out */ 90 | if (flushing_katcl(g->server)) { 91 | FD_SET(fd, &writefds); 92 | } 93 | 94 | /* check if there is log data to write out */ 95 | if (flushing_katcl(g->log)) { 96 | fd = fileno_katcl(g->log); 97 | 98 | FD_SET(fd, &writefds); 99 | 100 | if(mfd < fd){ 101 | mfd = fd; 102 | } 103 | } 104 | 105 | if (g->state == GMON_FPGA_DOWN) { 106 | /* sleep indefinitely if the FPGA is not ready */ 107 | retval = select(mfd + 1, &readfds, &writefds, NULL, NULL); 108 | } else { 109 | retval = select(mfd + 1, &readfds, &writefds, NULL, &timeout); 110 | } 111 | 112 | if(retval < 0){ 113 | switch(errno){ 114 | case EAGAIN : 115 | case EINTR : 116 | return 1; 117 | default : 118 | perror("select()"); 119 | exit(EXIT_FAILURE); 120 | return -1; 121 | } 122 | } 123 | 124 | if (retval) { 125 | /* server data to process */ 126 | if (FD_ISSET(fileno_katcl(g->server), &readfds)) { 127 | retval = read_katcl(g->server); 128 | 129 | if (retval) { 130 | fprintf(stderr, "%s: read failed.", GMON_PROG); 131 | } 132 | 133 | while (have_katcl(g->server) > 0) { 134 | cmdhandler(g); 135 | } 136 | } 137 | 138 | if (FD_ISSET(fileno_katcl(g->server), &writefds)) { 139 | retval = write_katcl(g->server); 140 | } 141 | 142 | if (FD_ISSET(fileno_katcl(g->log), &writefds)) { 143 | retval = write_katcl(g->log); 144 | } 145 | 146 | } else { 147 | log_message_katcl(g->log, KATCP_LEVEL_TRACE, GMON_PROG, 148 | "timeout after %ld seconds, polling...", g->polltime); 149 | g->state = GMON_POLL; 150 | } 151 | 152 | return retval; 153 | } 154 | 155 | void gmon_destroy(struct gmon_lib *g) 156 | { 157 | int i = 0; 158 | int num = g->numsensors; 159 | 160 | /* free sensors */ 161 | for (i = 0; i < num; i++) { 162 | if (g->sensorlist[i]) { 163 | sensor_destroy(g->sensorlist[i]); 164 | g->numsensors--; 165 | } 166 | } 167 | 168 | /* free sensorlist */ 169 | if (g->sensorlist) { 170 | free(g->sensorlist); 171 | g->sensorlist = NULL; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /katcp/dpx-misc.c: -------------------------------------------------------------------------------- 1 | #ifdef KATCP_EXPERIMENTAL 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | static char *scope_table[KATCP_MAX_SCOPE] = { 12 | "individual", "group", "global" 13 | }; 14 | 15 | char *string_from_scope_katcp(unsigned int scope) 16 | { 17 | if(scope >= KATCP_MAX_SCOPE){ 18 | return NULL; 19 | } 20 | 21 | return scope_table[scope]; 22 | } 23 | 24 | int code_from_scope_katcp(char *scope) 25 | { 26 | unsigned int i; 27 | 28 | if(scope == NULL){ 29 | return -1; 30 | } 31 | 32 | for(i = 0; i < KATCP_MAX_SCOPE; i++){ 33 | if(!strcmp(scope_table[i], scope)){ 34 | return i; 35 | } 36 | } 37 | 38 | return -1; 39 | } 40 | 41 | int fixup_timestamp_katcp(char *src, char *dst, int size) 42 | { 43 | char *dot; 44 | int suffix, prefix, total; 45 | 46 | #if KATCP_PROTOCOL_MAJOR_VERSION >= 5 47 | 48 | dot = strchr(src, '.'); 49 | if(dot){ 50 | /* timestamp assumed to be v5, in seconds.fraction */ 51 | 52 | if((src + 10) > dot){ 53 | /* at the time of writing this code, this many seconds had already elapsed */ 54 | return -1; 55 | } 56 | 57 | suffix = strlen(dot); 58 | prefix = dot - src; 59 | 60 | total = prefix + suffix; 61 | 62 | if(suffix >= 4){ /* all ok, no fixup */ 63 | if(total >= size){ 64 | if((prefix + 4) >= size){ 65 | return -1; 66 | } else { 67 | memcpy(dst, src, size - 1); 68 | dst[size - 1] = '\0'; 69 | } 70 | } 71 | 72 | memcpy(dst, src, total + 1); 73 | return 0; 74 | 75 | } else { 76 | /* pad out ... */ 77 | 78 | if(((dot - src) + 4) >= size){ 79 | return -1; 80 | } 81 | memcpy(dst, src, total); 82 | while(suffix < 4){ 83 | dst[total++] = '0'; 84 | suffix++; 85 | } 86 | dst[total] = '\0'; 87 | 88 | return 1; 89 | } 90 | 91 | } else { 92 | /* we are v5 but talking to v4 */ 93 | 94 | total = strlen(src); 95 | if(total < 13){ 96 | /* unreasonable time */ 97 | return -1; 98 | } 99 | 100 | if((total + 1) >= size){ 101 | return -1; 102 | } 103 | 104 | prefix = total - 3; 105 | 106 | memcpy(dst, src, prefix); 107 | dst[prefix] = '.'; 108 | memcpy(dst + prefix + 1, src + prefix, 4); 109 | 110 | return 1; 111 | } 112 | 113 | #else 114 | 115 | /* we are configured to be old-style ... */ 116 | 117 | dot = strchr(src, '.'); 118 | if(dot){ 119 | /* a new message, with seconds and fractions */ 120 | 121 | prefix = dot - src; 122 | if(prefix < 10){ 123 | return -1; 124 | } 125 | 126 | if((prefix + 3) >= size){ 127 | return -1; 128 | } 129 | 130 | memcpy(dst, src, prefix); 131 | 132 | total = strlen(src); 133 | 134 | suffix = total - (prefix + 1); 135 | if(suffix > 3){ 136 | suffix = 3; 137 | } 138 | 139 | if(suffix > 0){ 140 | memcpy(dst + prefix, dot + 1, suffix); 141 | } 142 | while(suffix < 3){ 143 | dst[prefix + suffix] = '0'; 144 | suffix++; 145 | } 146 | 147 | dst[prefix + suffix] = '\0'; 148 | 149 | return 1; 150 | 151 | } else { 152 | /* old style, no change other than length checks */ 153 | 154 | total = strlen(src); 155 | if(total < 13){ 156 | return -1; 157 | } 158 | 159 | if(total >= size){ 160 | return -1; 161 | } 162 | 163 | strcpy(dst, src); 164 | 165 | return 0; 166 | } 167 | 168 | #endif 169 | 170 | } 171 | 172 | int is_ver_sensor_katcp(struct katcp_dispatch *d, struct katcp_vrbl *vx) 173 | { 174 | struct katcp_vrbl_payload *py; 175 | 176 | if(vx == NULL){ 177 | return -1; 178 | } 179 | 180 | if((vx->v_flags & KATCP_VRF_VER) == 0){ 181 | return 0; 182 | } 183 | 184 | py = find_payload_katcp(d, vx, KATCP_VRC_VERSION_VERSION); 185 | if(py == NULL){ 186 | return 0; 187 | } 188 | 189 | return 1; 190 | } 191 | 192 | #endif 193 | 194 | #ifdef UNIT_TEST_DPX_MISC 195 | 196 | int main(int argc, char **argv) 197 | { 198 | #define BUFFER 32 199 | struct timeval tv; 200 | unsigned int milli; 201 | char in[BUFFER], out[BUFFER]; 202 | 203 | gettimeofday(&tv, NULL); 204 | milli = tv.tv_usec / 1000; 205 | 206 | snprintf(in, BUFFER, "%lu.%03u", tv.tv_sec, milli); 207 | fixup_timestamp_katcp(in, out, BUFFER); 208 | printf("%s \t-> %s\n", in, out); 209 | 210 | snprintf(in, BUFFER, "%lu.%01u", tv.tv_sec, milli / 100); 211 | fixup_timestamp_katcp(in, out, BUFFER); 212 | printf("%s \t-> %s\n", in, out); 213 | 214 | snprintf(in, BUFFER, "%lu%03u", tv.tv_sec, milli); 215 | fixup_timestamp_katcp(in, out, BUFFER); 216 | printf("%s \t-> %s\n", in, out); 217 | 218 | snprintf(in, BUFFER, "%lu.", tv.tv_sec); 219 | fixup_timestamp_katcp(in, out, BUFFER); 220 | printf("%s \t-> %s\n", in, out); 221 | 222 | snprintf(in, BUFFER, "%lu.%03u", tv.tv_sec, milli); 223 | if(fixup_timestamp_katcp(in + 1, out, BUFFER) >= 0){ 224 | fprintf(stderr, "fail: %s \t-> %s\n", in, out); 225 | return 1; 226 | } 227 | 228 | return 0; 229 | 230 | #undef BUFFER 231 | } 232 | 233 | #endif 234 | 235 | -------------------------------------------------------------------------------- /tcpborphserver3/main.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include "tcpborphserver3.h" 28 | 29 | void usage(char *app) 30 | { 31 | printf("Usage: %s" 32 | " [-b bof-dir] [-f] [-h] [-i init-script] [-l log-file] [-m mode] [-p network-port]\n", app); 33 | 34 | printf("-b dir directory containing bof files\n"); 35 | printf("-f run in foreground (default is background)\n"); 36 | printf("-h this help\n"); 37 | printf("-i file run the specified startup script\n"); 38 | printf("-l file log file name\n"); 39 | printf("-m mode mode to enter at startup\n"); 40 | printf("-p port network port to listen on\n"); 41 | 42 | } 43 | 44 | int main(int argc, char **argv) 45 | { 46 | struct katcp_dispatch *d; 47 | int status; 48 | int i, j, c, foreground, lfd; 49 | char *port, *mode, *init, *lfile, *bofdir; 50 | time_t now; 51 | 52 | port = "7147"; 53 | mode = TBS_MODE_RAW_NAME; 54 | init = NULL; 55 | lfile = TBS_LOGFILE; 56 | foreground = 0; 57 | bofdir = NULL; 58 | 59 | i = 1; 60 | j = 1; 61 | while (i < argc) { 62 | if (argv[i][0] == '-') { 63 | c = argv[i][j]; 64 | switch (c) { 65 | case '\0': 66 | j = 1; 67 | i++; 68 | break; 69 | case '-': 70 | j++; 71 | break; 72 | case 'h' : 73 | usage(argv[0]); 74 | return EX_OK; 75 | 76 | case 'f' : 77 | j++; 78 | foreground = 1 - foreground; 79 | break; 80 | 81 | case 'b' : 82 | case 'i' : 83 | case 'l' : 84 | case 'm' : 85 | case 'p' : 86 | j++; 87 | if (argv[i][j] == '\0') { 88 | j = 0; 89 | i++; 90 | } 91 | if (i >= argc) { 92 | fprintf(stderr, "%s: option -%c requires a parameter\n", argv[0], c); 93 | } 94 | switch(c){ 95 | case 'b' : 96 | bofdir = argv[i] + j; 97 | break; 98 | case 'i' : 99 | init = argv[i] + j; 100 | break; 101 | case 'l': 102 | lfile = argv[i] + j; 103 | break; 104 | case 'm' : 105 | mode = argv[i] + j; 106 | break; 107 | case 'p' : 108 | port = argv[i] + j; 109 | break; 110 | } 111 | i++; 112 | j = 1; 113 | break; 114 | default: 115 | fprintf(stderr, "%s: unknown option -%c\n", argv[0], c); 116 | return 1; 117 | break; 118 | } 119 | } else { 120 | fprintf(stderr, "%s: extra argument %s\n", argv[0], argv[i]); 121 | return 1; 122 | } 123 | } 124 | 125 | if (!foreground){ 126 | fprintf(stderr,"%s: about to go into background\n", argv[0]); 127 | if(fork_parent() < 0){ 128 | fprintf(stderr, "%s: unable to fork_parent\n", argv[0]); 129 | return 1; 130 | } 131 | } 132 | 133 | /* create a state handle */ 134 | d = startup_katcp(); 135 | if(d == NULL){ 136 | fprintf(stderr, "%s: unable to allocate state\n", argv[0]); 137 | return 1; 138 | } 139 | 140 | if(setup_raw_tbs(d, bofdir, argc, argv) < 0){ 141 | fprintf(stderr, "%s: unable to initialise logic for raw mode\n", argv[0]); 142 | return 1; 143 | } 144 | 145 | /* mode from command line */ 146 | if(mode){ 147 | if(enter_name_mode_katcp(d, mode, NULL) < 0){ 148 | fprintf(stderr, "%s: unable to enter mode %s\n", argv[0], mode); 149 | return 1; 150 | } 151 | } 152 | 153 | signal(SIGPIPE, SIG_DFL); 154 | 155 | if (!foreground){ 156 | lfd = open(lfile, O_WRONLY | O_APPEND | O_CREAT | O_NOCTTY, S_IWUSR | S_IRUSR | S_IRGRP | S_IWGRP); 157 | 158 | if (lfd < 0){ 159 | fprintf(stderr,"%s: unable to open %s: %s\n",argv[0], TBS_LOGFILE, strerror(errno)); 160 | return 1; 161 | } else { 162 | fflush(stderr); 163 | if (dup2(lfd, STDERR_FILENO) >= STDERR_FILENO){ 164 | now = time(NULL); 165 | fprintf(stderr ,"Logging to file started at %s\n",ctime(&now)); 166 | } 167 | close(lfd); 168 | } 169 | } 170 | 171 | #ifdef DEBUG 172 | fprintf(stderr, "server: about to run config server\n"); 173 | #endif 174 | 175 | if(run_config_server_katcp(d, init, TBS_MAX_CLIENTS, port, 0) < 0){ 176 | fprintf(stderr, "server: run failed\n"); 177 | return 1; 178 | } 179 | 180 | status = exited_katcp(d); 181 | 182 | shutdown_katcp(d); 183 | 184 | #ifdef DEBUG 185 | fprintf(stderr, "server: exit with status %d\n", status); 186 | #endif 187 | 188 | return status; 189 | } 190 | -------------------------------------------------------------------------------- /modules/mod_dsorcer.c: -------------------------------------------------------------------------------- 1 | #define _XOPEN_SOURCE 500 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #define INOTIFY_ADD_WATCH_DIR "add_watch_dir" 20 | #define KATCP_OP_IMPORT_DIR "import_dir" 21 | 22 | #define DELIMS "/ []()-_.&#@!%^*+={}'\"" 23 | #define NCOUNT 1000 24 | 25 | static struct katcp_stack *__tempstack; 26 | 27 | static int see_file(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) 28 | { 29 | char *buffer, *token, *fnkey; 30 | int i, err, j; 31 | struct katcl_parse *p; 32 | 33 | err = 0; 34 | 35 | if (tflag == FTW_F){ 36 | 37 | fnkey = fpath + ftwbuf->base;//crypt(fpath + ftwbuf->base, "$5$") + 4; 38 | 39 | #if 0 40 | def DEBUG 41 | fprintf(stderr, "see_file: %s\nkey: %s\n", fpath, fnkey); 42 | #endif 43 | 44 | buffer = strdup(fpath); 45 | if (buffer == NULL) 46 | return -1; 47 | 48 | p = create_parse_katcl(); 49 | if (p == NULL) 50 | return -1; 51 | 52 | err += add_string_parse_katcl(p, KATCP_FLAG_FIRST | KATCP_FLAG_STRING, KATCP_SET_REQUEST); 53 | err += add_string_parse_katcl(p, KATCP_FLAG_STRING, fnkey); 54 | err += add_string_parse_katcl(p, KATCP_FLAG_STRING, "schema"); 55 | err += add_string_parse_katcl(p, KATCP_FLAG_STRING, "location"); 56 | //err += add_string_parse_katcl(p, KATCP_FLAG_STRING | KATCP_FLAG_LAST, fpath); 57 | //err += add_string_parse_katcl(p, KATCP_FLAG_STRING, fnkey); 58 | err += add_string_parse_katcl(p, KATCP_FLAG_STRING, fpath); 59 | err += add_string_parse_katcl(p, KATCP_FLAG_STRING, "tags"); 60 | 61 | for (i=0; (token = strtok((i>0) ? NULL : buffer, DELIMS)) != NULL; i++){ 62 | 63 | for (j=0; token[j] != '\0'; j++) 64 | token[j] = tolower(token[j]); 65 | 66 | err += add_string_parse_katcl(p, KATCP_FLAG_STRING, token); 67 | 68 | #if 0 69 | def DEBUG 70 | fprintf(stderr, "<%s> ", token); 71 | #endif 72 | 73 | } 74 | 75 | err += finalize_parse_katcl(p); 76 | 77 | free(buffer); 78 | 79 | if (err < 0){ 80 | destroy_parse_katcl(p); 81 | return -1; 82 | } 83 | 84 | if (push_stack_katcp(__tempstack, p, NULL) < 0){ 85 | destroy_parse_katcl(p); 86 | return -1; 87 | } 88 | 89 | #if 0 90 | def DEBUG 91 | fprintf(stderr, "\n"); 92 | #endif 93 | 94 | } 95 | 96 | return 0; 97 | } 98 | 99 | 100 | int import_dir_mod(struct katcp_dispatch *d, struct katcp_stack *stack, struct katcp_tobject *to) 101 | { 102 | struct katcl_parse *p; 103 | char *dir; 104 | 105 | __tempstack = create_stack_katcp(); 106 | 107 | dir = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_STRING); 108 | if (dir == NULL) 109 | return -1; 110 | 111 | if (nftw(dir, &see_file, NCOUNT, FTW_PHYS) == -1){ 112 | log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "ftw encountered error"); 113 | return -1; 114 | } 115 | 116 | while ((p = pop_data_stack_katcp(__tempstack)) != NULL){ 117 | 118 | if (set_dbase_katcp(d, p) < 0){ 119 | log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "cannot ?set"); 120 | } 121 | 122 | /*TODO: this could be included into the parse logic*/ 123 | destroy_parse_katcl(p); 124 | 125 | } 126 | 127 | if (__tempstack != NULL) 128 | destroy_stack_katcp(__tempstack); 129 | 130 | __tempstack = NULL; 131 | 132 | return 0; 133 | } 134 | 135 | struct kcs_sm_op *import_dir_setup_mod(struct katcp_dispatch *d, struct kcs_sm_state *s) 136 | { 137 | return create_sm_op_kcs(&import_dir_mod, NULL); 138 | } 139 | 140 | int add_watch_dir_mod(struct katcp_dispatch *d, struct katcp_stack *stack, struct katcp_tobject *to) 141 | { 142 | char *dir; 143 | 144 | dir = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_STRING); 145 | if (dir == NULL) 146 | return -1; 147 | 148 | #ifdef DEBUG 149 | fprintf(stderr, "mod_inotify: add watch for dir <%s>\n", dir); 150 | #endif 151 | 152 | 153 | 154 | return 0; 155 | } 156 | 157 | struct kcs_sm_op *add_watch_dir_setup_mod(struct katcp_dispatch *d, struct kcs_sm_state *s) 158 | { 159 | return create_sm_op_kcs(&add_watch_dir_mod, NULL); 160 | } 161 | 162 | int init_mod(struct katcp_dispatch *d) 163 | { 164 | int rtn; 165 | 166 | rtn = 0; 167 | 168 | if (check_code_version_katcp(d) != 0){ 169 | #ifdef DEBUG 170 | fprintf(stderr, "mod: ERROR was build against an incompatible katcp lib\n"); 171 | #endif 172 | log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "cannot load module katcp version mismatch"); 173 | return -1; 174 | } 175 | 176 | log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "successfully loaded mod_dsorcer"); 177 | 178 | 179 | rtn += store_data_type_katcp(d, KATCP_TYPE_OPERATION, KATCP_DEP_BASE, KATCP_OP_IMPORT_DIR, import_dir_setup_mod, NULL, NULL, NULL, NULL, NULL, NULL); 180 | 181 | rtn += store_data_type_katcp(d, KATCP_TYPE_OPERATION, KATCP_DEP_BASE, INOTIFY_ADD_WATCH_DIR, &add_watch_dir_setup_mod, NULL, NULL, NULL, NULL, NULL, NULL); 182 | 183 | return rtn; 184 | } 185 | -------------------------------------------------------------------------------- /tcpborphserver3/README: -------------------------------------------------------------------------------- 1 | 2 | This is tcpborphserver, version 3. A server designed to control 3 | roach2s. It speaks katcp over port 7147. You should be able to 4 | connect to a roach2 and type ?help to see the list of commands. 5 | 6 | tcpborphserver links in the mainloop of the katcp library which 7 | can and does implement commands which are not directly relevant 8 | to users who simply wish to interact with the fpga. In addition 9 | tcpborphserver itself may contain commands which are still under 10 | development, and not guaranteed to be retained. 11 | 12 | The following commands are implemented by tcpborphserver3: 13 | 14 | ?listbof 15 | 16 | Lists gateware image files stored on the roach 17 | 18 | ?delbof filename 19 | 20 | Removes a gateware image file 21 | 22 | ?progdev filename 23 | 24 | Programs a gateware image already stored on the roach in 25 | the image directory (paths not permitted) 26 | 27 | ?upload port 28 | 29 | Upload and program a local gateware image file to the roach. Send 30 | the local image to the tcp port on the roach, as specified. No 31 | escaping of the image file required as it has its own stream, 32 | which should be closed when upload has completed. Still a bit 33 | experimental and subject to revision (there was an uploadbof command 34 | which was different). 35 | 36 | Example 37 | 38 | ?upload 3000 39 | !upload ok 3000 40 | 41 | Then from a local terminal type 42 | 43 | nc -w 2 -q 2 192.168.40.57 3000 < some-image.bof 44 | 45 | Which will give you 46 | 47 | #fpga loaded 48 | #fpga ready 49 | 50 | ?fpgastatus 51 | 52 | Checks if the fpga is programmed. Will return fail in case the 53 | fpga is not programmed. In earlier versions this command was 54 | called ?status 55 | 56 | ?listdev [size] 57 | 58 | Lists the register names provided by the currently programmed 59 | gateware image. The optional "size" keyword will include a size 60 | field in the output 61 | 62 | ?register name position bit-offset length 63 | 64 | Assign a name to an fpga memory location explicitly, instead 65 | of having it set in the bof (gateware image) file. Experimental 66 | 67 | ?wordwrite register word-offset word 68 | 69 | Writes a 32bit word to the given register at the word-offset. The 70 | word should be given as a hexadecimal value. Example 71 | 72 | ?wordwrite sys_scratchpad 0 0x74657374 73 | 74 | ?wordread register word-offset [word-count] 75 | 76 | Reads a 32bit word from the given offset in the named register. 77 | The word offset is counted in words, not bytes. The value returned 78 | is given in hexadecimal. Example 79 | 80 | ?wordread sys_scratchpad 0 81 | !wordread ok 0x74657374 82 | 83 | ?read register byte-offset count 84 | 85 | Reads data from the given register. Reads start at the specified 86 | byte-offset and attempt to read count bytes. Data is returned 87 | in binary form (with escapes as per katcp specification). Not 88 | all offsets and sizes are supported, as there are alignment 89 | alignment constraints. Example 90 | 91 | ?read sys_scratchpad 0 4 92 | !read ok test 93 | 94 | ?write register byte-offset data 95 | 96 | Write the given binary data to the position byte-offset to the 97 | named register, subject to alignment constraints 98 | 99 | ?chassis-led led-name state 100 | 101 | Allows you to toggle an LED on the roach chassis. Example 102 | 103 | ?chassis-led red on 104 | 105 | Currently the only useful led name is "red" (there is a "green" 106 | too, but it gets toggled automatically). chassis-start is not 107 | needed during normal operation as it should happen automatically 108 | 109 | ?tap-info 110 | 111 | displays some freeform information about running tap instances 112 | 113 | ?tap-stop register-name 114 | 115 | Stop a running tap instance 116 | 117 | ?tap-start tap-device register-name ip-address [port [mac]] 118 | 119 | Start a tap instance with name tap-device, which opens an fpga 120 | register at register-name to loop traffic to the kernel. The kernel 121 | interface is given ip-address (netmask fixed to 255.255.255.0). Port 122 | is a udp port on which gateware collects data 123 | 124 | The following commands are part of the katcp library, and with the exception 125 | of log-record and system-info also part of the katcp specification 126 | 127 | ?client-list 128 | 129 | Lists current connections to the server 130 | 131 | ?version-list 132 | 133 | Display some version information 134 | 135 | ?sensor-list 136 | 137 | Display available sensors 138 | 139 | ?sensor-value sensor 140 | 141 | Retrieve a sensor value (rather use sensor-sampling if you 142 | wish to see periodic data) 143 | 144 | ?sensor-sampling sensor strategy parameter 145 | 146 | Example 147 | 148 | ?sensor-sampling raw.temp.fpga event 149 | 150 | ?watchdog 151 | 152 | No-op, used as a ping 153 | 154 | ?log-level 155 | 156 | Sets the log level 157 | 158 | Example to enable lots of debug messages 159 | 160 | ?log-level trace 161 | 162 | ?help 163 | 164 | List available, nonhidden commands 165 | 166 | ?restart 167 | 168 | Reboot the roach 169 | 170 | ?halt 171 | 172 | Turn off the roach 173 | 174 | ?log-record [priority] message 175 | 176 | Write a log message, goes to all client connections 177 | 178 | ?system-info 179 | 180 | Prints some unstructed information about the system. 181 | Mostly useful to debug server internals 182 | 183 | -------------------------------------------------------------------------------- /delay/delay.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include "katcl.h" 15 | #include "katcp.h" 16 | #include "katpriv.h" 17 | 18 | #if 0 19 | #define FORGIVE_LATE 20 | #endif 21 | #define FORGIVE_LARGE 22 | 23 | /* cribbed from math.h, it wants __GNU to be defined and who knows what else that does */ 24 | #define OVERPI 0.3183098861837906715377675267450287L 25 | #define BUFFER 64 26 | 27 | #define NAME "k7-delay" 28 | 29 | int complete_with_log(struct katcl_line *l, struct timeval *until, struct katcl_line *k) 30 | { 31 | struct katcl_parse *px; 32 | int result; 33 | char *ptr; 34 | 35 | while((result = complete_rpc_katcl(l, 0, until)) == 0){ 36 | px = ready_katcl(l); 37 | if(px){ 38 | if(is_inform_parse_katcl(px)){ 39 | ptr = get_string_parse_katcl(px, 0); 40 | if(!strcmp("#log", ptr)){ 41 | append_parse_katcl(k, px); 42 | } 43 | } 44 | } 45 | } 46 | 47 | return result; 48 | } 49 | 50 | int main(int argc, char **argv) 51 | { 52 | struct katcl_line *l, *k; 53 | struct timeval start, ready, done, until, delta, request, elapsed, lead, local; 54 | int result, code; 55 | char *server, *end, *ptr; 56 | long double value, tmp; 57 | 58 | gettimeofday(&start, NULL); 59 | 60 | /* preparation */ 61 | 62 | k = create_katcl(STDOUT_FILENO); 63 | if(k == NULL){ 64 | fprintf(stderr, "unable to create katcp message logic\n"); 65 | return 2; 66 | } 67 | 68 | if(argc <= 6){ 69 | sync_message_katcl(k, KATCP_LEVEL_ERROR, NAME, "expect parameters: antpol loadtime delay delayrate fringe fringerate"); 70 | return 1; 71 | } 72 | 73 | #if 0 74 | server = getenv("KATCP_SERVER"); 75 | #endif 76 | server = "localhost:1235"; 77 | 78 | l = create_name_rpc_katcl(server ? server : "localhost:7147"); 79 | if(l == NULL){ 80 | sync_message_katcl(k, KATCP_LEVEL_ERROR, NAME, "unable to connect to %s", server ? server : "localhost:7147"); 81 | return 1; 82 | } 83 | 84 | append_string_katcl(l, KATCP_FLAG_STRING | KATCP_FLAG_FIRST, "?fr-delay-set"); 85 | 86 | append_string_katcl(l, KATCP_FLAG_STRING, argv[1]); /* antenna */ 87 | 88 | value = strtold(argv[5], &end); /* fringe */ 89 | tmp = value * 180.0 * OVERPI; 90 | #ifdef FORGIVE_LARGE 91 | tmp = fmodl(tmp, 360.0); 92 | #endif 93 | 94 | append_args_katcl(l, KATCP_FLAG_STRING , "%.16Lf", tmp); 95 | log_message_katcl(k, KATCP_LEVEL_DEBUG, NAME, "fringe offset %srad mapped to %.16Lfdeg", argv[5], tmp); 96 | 97 | value = strtold(argv[6], &end); /* fringe rate */ 98 | tmp = value * 500.0 * OVERPI; 99 | append_args_katcl(l, KATCP_FLAG_STRING, "%.16Lf", tmp); 100 | log_message_katcl(k, KATCP_LEVEL_DEBUG, NAME, "fringe rate %srads/ms mapped to %.16Lfrotations/s", argv[6], tmp); 101 | 102 | value = strtold(argv[3], &end); /* delay */ 103 | append_args_katcl(l, KATCP_FLAG_STRING , "%.16Lf", value / 1000.0); 104 | 105 | log_message_katcl(k, KATCP_LEVEL_DEBUG, NAME, "delay %sms mapped to %.16Lfs", argv[3], value / 1000.0); 106 | 107 | value = strtold(argv[4], &end); /* delay rate */ 108 | append_args_katcl(l, KATCP_FLAG_STRING , "%.16Lf", value); 109 | 110 | log_message_katcl(k, KATCP_LEVEL_DEBUG, NAME, "delay rate is %.16Lfs/s or ms/ms", value); 111 | 112 | value = strtold(argv[2], &end) / 1000.0; /* time */ 113 | append_args_katcl(l, KATCP_FLAG_STRING , "%Lf", value); 114 | 115 | log_message_katcl(k, KATCP_LEVEL_DEBUG, NAME, "%s load time %sms mapped to %Lfs", argv[1], argv[2], value); 116 | 117 | tmp = truncl(value); 118 | request.tv_sec = tmp; 119 | request.tv_usec = (value - tmp) * 1000000; 120 | 121 | append_string_katcl(l, KATCP_FLAG_STRING | KATCP_FLAG_LAST, "now"); 122 | 123 | gettimeofday(&ready, NULL); 124 | 125 | if(cmp_time_katcp(&request, &ready) <= 0){ 126 | sub_time_katcp(&delta, &ready, &request); 127 | 128 | sync_message_katcl(k, KATCP_LEVEL_ERROR, NAME, "requested time %lu.%06lus is %lu.%06lus in the past", request.tv_sec, request.tv_usec, delta.tv_sec, delta.tv_usec); 129 | code = 1; 130 | 131 | #ifdef FORGIVE_LATE 132 | } 133 | #else 134 | } else { 135 | #endif 136 | 137 | /* the send part */ 138 | 139 | delta.tv_sec = 20; 140 | delta.tv_usec = 0; 141 | 142 | add_time_katcp(&until, &ready, &delta); 143 | 144 | result = complete_with_log(l, &until, k); 145 | 146 | if(result < 0){ 147 | sync_message_katcl(k, KATCP_LEVEL_ERROR, NAME, "unable to complete request"); 148 | code = 2; 149 | } else { 150 | ptr = arg_string_katcl(l, 1); 151 | if(ptr){ 152 | if(strcmp(ptr, KATCP_OK)){ 153 | code = 1; 154 | } else { 155 | code = 0; 156 | } 157 | append_string_katcl(l, KATCP_FLAG_STRING | KATCP_FLAG_FIRST | KATCP_FLAG_LAST, "?get-log"); 158 | complete_with_log(l, &until, k); 159 | 160 | append_string_katcl(l, KATCP_FLAG_STRING | KATCP_FLAG_FIRST | KATCP_FLAG_LAST, "?clr-log"); 161 | complete_with_log(l, &until, k); 162 | } else { 163 | code = 2; 164 | } 165 | } 166 | #ifndef FORGIVE_LATE 167 | } 168 | #endif 169 | 170 | gettimeofday(&done, NULL); 171 | 172 | destroy_rpc_katcl(l); 173 | 174 | sub_time_katcp(&lead, &request, &start); 175 | sub_time_katcp(&elapsed, &done, &start); 176 | sub_time_katcp(&local, &ready, &start); 177 | 178 | sync_message_katcl(k, KATCP_LEVEL_DEBUG, NAME, "delay stats: lead=%lu.%06lus taken=%lu.%06lus setup=%lu.%06lus code=%d", lead.tv_sec, lead.tv_usec, elapsed.tv_sec, elapsed.tv_usec, local.tv_sec, local.tv_usec, code); 179 | 180 | destroy_rpc_katcl(k); 181 | 182 | return code; 183 | } 184 | 185 | -------------------------------------------------------------------------------- /kcs/subprocess.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "kcs.h" 21 | 22 | void replace_argv(struct katcp_dispatch *d, char *str) 23 | { 24 | struct kcs_basic *kb; 25 | int i, argc; 26 | char **argv; 27 | 28 | kb = get_mode_katcp(d, KCS_MODE_BASIC); 29 | 30 | if (kb == NULL) 31 | return; 32 | 33 | argc = kb->b_argc; 34 | argv = kb->b_argv; 35 | 36 | for (i=0; i 0){ 63 | close(fds[0]); 64 | fcntl(fds[1], F_SETFD, FD_CLOEXEC); 65 | #ifdef DEBUG 66 | fprintf(stderr,"subprocess: in parent child has pid: %d\n",pid); 67 | #endif 68 | j = create_job_katcp(d, url, pid, fds[1], 0, n); 69 | if (j == NULL){ 70 | log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "unable to allocate job logic so terminating child process"); 71 | kill(pid, SIGTERM); 72 | close(fds[1]); 73 | destroy_kurl_katcp(url); 74 | } 75 | return j; 76 | } 77 | #ifdef DEBUG 78 | fprintf(stderr,"subprocess: in child: %d\n",getpid()); 79 | #endif 80 | /*in child use exit not return*/ 81 | xl = create_katcl(fds[0]); 82 | close(fds[1]); 83 | 84 | for (i=0; i<1024; i++) 85 | if (i != fds[0]) 86 | close(i); 87 | 88 | replace_argv(d, url->u_str); 89 | 90 | #if 0 91 | copies = 0; 92 | if (fds[0] != STDOUT_FILENO){ 93 | if (dup2(fds[0], STDOUT_FILENO) != STDOUT_FILENO) { 94 | sync_message_katcl(xl, KATCP_LEVEL_ERROR, NULL, "unable to set up standard output for child process %u (%s)", getpid(), strerror(errno)); 95 | exit(EX_OSERR); 96 | } 97 | copies++; 98 | } 99 | if(fds[0] != STDIN_FILENO){ 100 | if(dup2(fds[0], STDIN_FILENO) != STDIN_FILENO){ 101 | sync_message_katcl(xl, KATCP_LEVEL_ERROR, NULL, "unable to set up standard input for child process %u (%s)", getpid(), strerror(errno)); 102 | exit(EX_OSERR); 103 | } 104 | copies++; 105 | } 106 | if(copies >= 2){ 107 | fcntl(fds[0], F_SETFD, FD_CLOEXEC); 108 | } 109 | #endif 110 | 111 | if ((*call)(xl,data) < 0) 112 | sync_message_katcl(xl, KATCP_LEVEL_ERROR, NULL, "run child process kcs fail"); 113 | 114 | exit(EX_OK); 115 | return NULL; 116 | } 117 | 118 | 119 | int xport_sync_connect_and_start_subprocess_kcs(struct katcl_line *l, void *data) 120 | { 121 | #define ARRAYSIZE 5 122 | struct katcp_url *url; 123 | int fd, wb; 124 | unsigned char onstring[ARRAYSIZE] = { 0002, 0201, 0002, 0377, 0377 }; 125 | 126 | url = data; 127 | if (url == NULL) 128 | return -1; 129 | 130 | fd = net_connect(url->u_host, url->u_port, 0); 131 | 132 | if (fd < 0) 133 | return -1; 134 | 135 | wb = write(fd, onstring, ARRAYSIZE); 136 | 137 | sync_message_katcl(l, KATCP_LEVEL_INFO, NULL, "poweron %s wrote %d bytes", url->u_str ,wb); 138 | 139 | close(fd); 140 | return 0; 141 | #undef ARRAYSIZE 142 | } 143 | 144 | int xport_sync_connect_and_stop_subprocess_kcs(struct katcl_line *l, void *data) 145 | { 146 | #define ARRAYSIZE 5 147 | struct katcp_url *url; 148 | int fd, wb; 149 | unsigned char onstring[ARRAYSIZE] = { 0002, 0202, 0002, 0377, 0377 }; 150 | 151 | url = data; 152 | if (url == NULL) 153 | return -1; 154 | 155 | fd = net_connect(url->u_host, url->u_port, 0); 156 | 157 | if (fd < 0) 158 | return -1; 159 | 160 | wb = write(fd, onstring, ARRAYSIZE); 161 | 162 | sync_message_katcl(l, KATCP_LEVEL_INFO, NULL, "poweroff %s wrote %d bytes", url->u_str ,wb); 163 | 164 | close(fd); 165 | return 0; 166 | #undef ARRAYSIZE 167 | } 168 | 169 | int xport_sync_connect_and_soft_restart_subprocess_kcs(struct katcl_line *l, void *data) 170 | { 171 | #define ARRAYSIZE 5 172 | struct katcp_url *url; 173 | int fd, wb; 174 | unsigned char onstring[ARRAYSIZE] = { 0002, 0202, 0002, 00, 00 }; 175 | 176 | url = data; 177 | if (url == NULL) 178 | return -1; 179 | 180 | fd = net_connect(url->u_host, url->u_port, 0); 181 | 182 | if (fd < 0) 183 | return -1; 184 | 185 | wb = write(fd, onstring, ARRAYSIZE); 186 | 187 | sync_message_katcl(l, KATCP_LEVEL_INFO, NULL, "powersoft %s wrote %d bytes", url->u_str ,wb); 188 | 189 | close(fd); 190 | return 0; 191 | #undef ARRAYSIZE 192 | } 193 | 194 | #if 0 195 | void process(void *data) { 196 | #ifdef DEBUG 197 | fprintf(stdout,"subprocess: This is a sub process with data: %p\n",data); 198 | #endif 199 | } 200 | 201 | int main(int argc, char **argv) { 202 | 203 | int rtn; 204 | char data = "hello world"; 205 | 206 | 207 | rtn = run_child_process_kcs(NULL, NULL, &process, data, NULL) 208 | 209 | if (rtn < 0){ 210 | #ifdef DEBUG 211 | fprintf(stderr,"subprocess: fail\n"); 212 | #endif 213 | } else { 214 | #ifdef DEBUG 215 | fprintf(stderr,"subprocess: ok\n"); 216 | #endif 217 | } 218 | 219 | 220 | return 0; 221 | } 222 | #endif 223 | -------------------------------------------------------------------------------- /gmon/cmdhandler.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "gmon.h" 8 | #include "cmdhandler.h" 9 | #include "katpriv.h" 10 | #include "katcl.h" 11 | #include "sensor.h" 12 | 13 | struct message { 14 | char *cmd; 15 | void (*action)(struct gmon_lib *g); 16 | }; 17 | 18 | static void cmd_fpga(struct gmon_lib *g) 19 | { 20 | char *arg = NULL; 21 | 22 | arg = arg_string_katcl(g->server, 1); 23 | 24 | if (arg) { 25 | if (!strcmp("down", arg)) { 26 | g->state = GMON_FPGA_DOWN; 27 | /* free sensor resources */ 28 | gmon_destroy(g); 29 | log_message_katcl(g->log, KATCP_LEVEL_INFO, GMON_PROG, 30 | "fpga down", NULL); 31 | } else if (!strcmp("ready", arg)) { 32 | g->state = GMON_FPGA_READY; 33 | log_message_katcl(g->log, KATCP_LEVEL_INFO, GMON_PROG, 34 | "fpga ready", NULL); 35 | } 36 | //log_message_katcl(g->log, KATCP_LEVEL_INFO, GMON_PROG, 37 | // "fpga status is %s", fpga_status_string(g->f_status)); 38 | } 39 | } 40 | 41 | static void cmd_log(struct gmon_lib *g) 42 | { 43 | struct katcl_parse *p = NULL; 44 | 45 | /* route output to STDOUT */ 46 | p = ready_katcl(g->server); 47 | if (p) { 48 | append_parse_katcl(g->log, p); 49 | } 50 | } 51 | 52 | static void cmd_listdev(struct gmon_lib *g) 53 | { 54 | char *reg = NULL; 55 | char *description = "Temporary description"; 56 | struct sensor *regsensor = NULL; 57 | struct sensor **tmpsensorlist = NULL; 58 | 59 | /* obtain the register name */ 60 | reg = arg_string_katcl(g->server, 1); 61 | if (reg) { 62 | /* create the sensor using the register name */ 63 | regsensor = sensor_create(reg, description, NULL, "integer", "nominal"); 64 | if (regsensor) { 65 | /* increase the size of the sensorlist */ 66 | tmpsensorlist = realloc(g->sensorlist, (g->numsensors + 1) * sizeof(regsensor)); 67 | if (tmpsensorlist) { 68 | /* add the sensor to the sensorlist */ 69 | g->sensorlist = tmpsensorlist; 70 | g->sensorlist[g->numsensors] = regsensor; 71 | g->numsensors++; 72 | log_message_katcl(g->log, KATCP_LEVEL_INFO, GMON_PROG, 73 | "added %s register to sensorlist, total = %d", reg, g->numsensors); 74 | /* register the katcp sensor for ?sensor-list */ 75 | sensor_katcp_add(g->log, regsensor); 76 | } else { 77 | /* sensorlist size could not be increased, destroy the sensor */ 78 | sensor_destroy(regsensor); 79 | log_message_katcl(g->log, KATCP_LEVEL_WARN, GMON_PROG, 80 | "could not add %s registers to the sensorlist", reg); 81 | } 82 | } 83 | } 84 | } 85 | 86 | static void cmd_meta(struct gmon_lib *g) 87 | { 88 | unsigned int argcount = 0; 89 | unsigned int i = 0; 90 | char *arg = NULL; 91 | 92 | argcount = arg_count_katcl(g->server); 93 | 94 | printf("\n"); 95 | for (i = 1; i < argcount; i++) { 96 | arg = arg_string_katcl(g->server, i); 97 | printf("arg %d : %s ", i, arg); 98 | } 99 | } 100 | 101 | static void cmd_wordread(struct gmon_lib *g) 102 | { 103 | char *arg = NULL; 104 | uint32_t val = 0; 105 | char *endptr; 106 | bool parse = true; 107 | 108 | arg = arg_string_katcl(g->server, 1); 109 | if (!strcmp("ok", arg)) { 110 | arg = arg_string_katcl(g->server, 2); 111 | /* convert ascii hex string to int, also refer to 'man strtol' */ 112 | errno = 0; 113 | val = strtol(arg, &endptr, 16); 114 | /* check for various strtol errors */ 115 | if ((errno == ERANGE) || (errno != 0 && val == 0)) { 116 | log_message_katcl(g->log, KATCP_LEVEL_WARN, GMON_PROG, 117 | "could not convert ascii string %s", arg); 118 | parse = false; 119 | } 120 | if (endptr == arg) { 121 | log_message_katcl(g->log, KATCP_LEVEL_WARN, GMON_PROG, 122 | "no digits found %s", arg); 123 | parse = false; 124 | } 125 | if (parse) { 126 | g->sensorlist[g->readcollect]->val = val; 127 | #if 0 128 | printf("reg %s, value = %s\n", g->sensorlist[g->readcollect]->name, arg); 129 | #endif 130 | /* update the katcp sensorlist */ 131 | sensor_katcp_update(g->log, g->sensorlist[g->readcollect]); 132 | } 133 | } else { 134 | log_message_katcl(g->log, KATCP_LEVEL_WARN, GMON_PROG, 135 | "could not read reg %s", g->sensorlist[g->readcollect]->name); 136 | } 137 | 138 | g->readcollect++; 139 | if (g->readcollect >= g->numsensors) { 140 | g->readcollect = 0; 141 | } 142 | } 143 | 144 | static struct message messageLookup[] = { 145 | {KATCP_LOG_INFORM, cmd_log}, 146 | {"#fpga", cmd_fpga}, 147 | {"#listdev", cmd_listdev}, 148 | {"#meta", cmd_meta}, 149 | {"!wordread", cmd_wordread}, 150 | {NULL, NULL} 151 | }; 152 | 153 | int cmdhandler(struct gmon_lib *g) 154 | { 155 | char *cmd; 156 | int i = 0; 157 | 158 | /* get the command */ 159 | cmd = arg_string_katcl(g->server, 0); 160 | if (cmd) { 161 | /* itterate through the message lookup list */ 162 | while (messageLookup[i].cmd != NULL) { 163 | if (!strcmp(messageLookup[i].cmd, cmd)) { 164 | messageLookup[i].action(g); 165 | } 166 | i++; 167 | } 168 | } 169 | 170 | return 0; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /scripts/sensors.sh: -------------------------------------------------------------------------------- 1 | await_mode_sensors() { 2 | echo "#sensor-status $(date +%s)000 1 .channels unknown 0" 3 | echo "#sensor-status $(date +%s)000 1 .centerfrequency unknown 0" 4 | echo "#sensor-status $(date +%s)000 1 .bandwidth unknown 0" 5 | 6 | for name in bf0 bf1 ; do 7 | echo "#sensor-status $(date +%s)000 1 .${name}.bandwidth unknown 0" 8 | echo "#sensor-status $(date +%s)000 1 .${name}.centerfrequency unknown 0" 9 | done 10 | } 11 | 12 | fetch_config_sensors() { 13 | 14 | config_file="$1" 15 | status="$2" 16 | # prefix="$3" 17 | 18 | if [ ! -f "${config_file}" ] ; then 19 | kcpmsg -s mode -l warn "no configuration in ${config_file}" 20 | return 0 21 | fi 22 | 23 | if [ -z "${status}" ] ; then 24 | kcpmsg -s mode -l warn "bad status field ${status}" 25 | return 0 26 | fi 27 | 28 | # if [ -n "${prefix}" ] ; then 29 | # if [ "${prefix:0:1}" != '.' ] ; then 30 | # kcpmsg -s mode -l warn "mode prefix ${prefix} probably malformed" 31 | # fi 32 | # fi 33 | 34 | channels=$(grep ^n_chans ${config_file} 2> /dev/null | cut -f2 -d= | tr -d ' ' ) 35 | if [ -n "${channels}" ] ; then 36 | 37 | adc_clock=$(grep ^adc_clk ${config_file} 2> /dev/null | cut -f2 -d= | tr -d ' ' ) 38 | coarse_channels=$(grep ^coarse_chans ${config_file} 2> /dev/null | cut -f2 -d= | tr -d ' ' ) 39 | 40 | bandwidth=$(echo "${adc_clock:-800}/(${coarse_channels:-1}*2)" | bc -l | cut -f1 -d. ) 41 | if [ -n "${coarse_channels}" ] ; then 42 | centerfrequency=0 43 | else 44 | centerfrequency=$(echo "${bandwidth}/2" | bc -l | cut -f1 -d.) 45 | fi 46 | 47 | echo "#sensor-status $(date +%s)000 1 .channels ${status} ${channels}" 48 | echo "#sensor-status $(date +%s)000 1 .centerfrequency ${status} ${centerfrequency}" 49 | echo "#sensor-status $(date +%s)000 1 .bandwidth ${status} ${bandwidth}" 50 | 51 | fi 52 | 53 | } 54 | 55 | setup_static_sensors () { 56 | echo "#sensor-list .channels number\_of\_channels none integer 0 65536" 57 | 58 | echo "#sensor-list .centerfrequency current\_center\_frequency Hz integer 0 500000000" 59 | echo "#sensor-list .bandwidth bandwidth\_of\_current\_mode Hz integer 0 1000000000" 60 | 61 | for name in bf0 bf1 ; do 62 | echo "#sensor-list .${name}.centerfrequency selected\_center\_frequency\_of\_beam Hz integer 0 500000000" 63 | echo "#sensor-list .${name}.bandwidth selected\_bandwidth\_of\_beam Hz integer 0 1000000000" 64 | done 65 | } 66 | 67 | change_mode_sensors () { 68 | from="$1" 69 | to="$2" 70 | 71 | if [ -z "${from}" -o -z "${to}" ] ; then 72 | kcpmsg -s mode -l warn "no static sensors to update" 73 | exit 0 74 | fi 75 | 76 | # if [ -f ${CORR_CONFIG}/${from} ] ; then 77 | # echo "#sensor-status $(date +%s)000 1 .${from}.centerfrequency unknown \@" 78 | # echo "#sensor-status $(date +%s)000 1 .${from}.channels unknown \@" 79 | # echo "#sensor-status $(date +%s)000 1 .${from}.bandwidth unknown \@" 80 | # fi 81 | # 82 | # if [ -f ${CORR_CONFIG}/${to} ] ; then 83 | # echo "#sensor-status $(date +%s)000 1 .${to}.centerfrequency nominal \@" 84 | # echo "#sensor-status $(date +%s)000 1 .${to}.channels nominal \@" 85 | # echo "#sensor-status $(date +%s)000 1 .${to}.bandwidth nominal \@" 86 | # fi 87 | 88 | fetch_config_sensors ${CORR_CONFIG}/${to} nominal 89 | } 90 | 91 | 92 | # change_mode_sensors () { 93 | # if [ -n "${2}" ] ; then 94 | # matching_mode=${2} 95 | # else 96 | # kcs_error "mode sensors needs to be invoked with sensor parameter" 97 | # fi 98 | # 99 | # sensor_suffixes=("number\_of\_channels none integer 0 65536" "number\_of\_chanels none integer 0 65536" "current\_selected\_center\_frequency Hz integer 0 1000000000" "number\_of\_channels none integer 0 65536" "number\_of\_channels none integer 0 65536" "number\_of\_channels none integer 0 65536") 100 | # sensor_names=(".nbc.channels.coarse" ".nbc.channels" ".nbc.centerfrequency" ".wbc.channels" ".wbc8k.channels" ".bwbc4a.channels") 101 | # sensor_keys=(coarse_chans n_chans "" n_chans n_chans n_chans) 102 | # sensor_values=("" "" "0" "" "" "") 103 | # sensor_stata=("" "" "unknown" "" "" "") 104 | # 105 | # i=0 106 | # while [ $i -lt ${#sensor_names[*]} ] ; do 107 | # 108 | # sensor_name=${sensor_names[$i]} 109 | # sensor_key=${sensor_keys[$i]} 110 | # sensor_suffix=${sensor_suffixes[$i]} 111 | # sensor_value=${sensor_values[$i]} 112 | # 113 | # if [ "${sensor_name:0:1}" = "." ] ; then 114 | # relative=${sensor_name:1} 115 | # mode=${relative%%.*} 116 | # else 117 | # mode=${sensor_name%%.*} 118 | # fi 119 | # 120 | # config=${CORR_CONFIG}/${mode} 121 | # 122 | # kcs_debug "attempting to locate $sensor_key in ${config} (mode ${mode}) for ${sensor_name}" 123 | # 124 | # if [ "${mode}" = "${matching_mode}" ] ; then 125 | # sensor_status="nominal" 126 | # else 127 | # sensor_status="unknown" 128 | # fi 129 | # 130 | # temp=${sensor_stata[$i]} 131 | # if [ -n "${temp}" ] ; then 132 | # sensor_status=${temp} 133 | # fi 134 | # 135 | # # try to look up a value in file, clobbering what is set statically above 136 | # if [ -e ${config} ] ; then 137 | # if [ -n "${sensor_key}" ] ; then 138 | # temp=$(grep ^${sensor_key} ${config} 2> /dev/null | cut -f2 -d= | tr -d ' ' ) 139 | # if [ -n "${temp}" ] ; then 140 | # sensor_value=${temp} 141 | # fi 142 | # fi 143 | # fi 144 | # 145 | # # if we have a value, print the sensor 146 | # if [ -n "${sensor_value}" ] ; then 147 | # echo "#sensor-list ${sensor_name} ${sensor_suffix}" 148 | # echo "#sensor-status $(date +%s)000 1 ${sensor_name} ${sensor_status} ${sensor_value}" 149 | # fi 150 | # 151 | # i=$[i+1] 152 | # done 153 | # } 154 | -------------------------------------------------------------------------------- /kcs/kcserver.c: -------------------------------------------------------------------------------- 1 | /* (c) 2010,2011 SKA SA */ 2 | /* Released under the GNU GPLv3 - see COPYING */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include "kcs.h" 28 | 29 | void usage(char *app) 30 | { 31 | printf("Usage: %s" 32 | " [-m mode] [-p network-port] [-s script-directory]\n", app); 33 | 34 | printf("-m mode mode to enter at startup\n"); 35 | printf("-p network-port network port to listen on\n"); 36 | printf("-s script-dir directory to load scripts from\n"); 37 | printf("-i init-file file containing commands to run at startup\n"); 38 | printf("-l log-file log file name\n"); 39 | printf("-d detach and run in background\n"); 40 | printf("-f run in foreground\n"); 41 | 42 | } 43 | 44 | #define UNAME_BUFFER 128 45 | int main(int argc, char **argv) 46 | { 47 | struct katcp_dispatch *d; 48 | struct utsname un; 49 | int status; 50 | int i, j, c, foreground, lfd; 51 | char *port, *scripts, *mode, *init, *lfile; 52 | char uname_buffer[UNAME_BUFFER]; 53 | time_t now; 54 | 55 | scripts = "."; 56 | port = "7147"; 57 | mode = KCS_MODE_BASIC_NAME; 58 | init = NULL; 59 | lfile = KCS_LOGFILE; 60 | foreground = KCS_FOREGROUND; 61 | 62 | i = 1; 63 | j = 1; 64 | while (i < argc) { 65 | if (argv[i][0] == '-') { 66 | c = argv[i][j]; 67 | switch (c) { 68 | case '\0': 69 | j = 1; 70 | i++; 71 | break; 72 | case '-': 73 | j++; 74 | break; 75 | case 'h' : 76 | usage(argv[0]); 77 | return EX_OK; 78 | 79 | case 'f' : 80 | j++; 81 | foreground = 1; 82 | break; 83 | 84 | case 'd' : 85 | j++; 86 | foreground = 0; 87 | break; 88 | 89 | case 'l' : 90 | case 'm' : 91 | case 's' : 92 | case 'p' : 93 | case 'i' : 94 | j++; 95 | if (argv[i][j] == '\0') { 96 | j = 0; 97 | i++; 98 | } 99 | if (i >= argc) { 100 | fprintf(stderr, "%s: option -%c requires a parameter\n", argv[0], c); 101 | return EX_USAGE; 102 | 103 | } 104 | switch(c){ 105 | case 's' : 106 | scripts = argv[i] + j; 107 | break; 108 | case 'm' : 109 | mode = argv[i] + j; 110 | break; 111 | case 'p' : 112 | port = argv[i] + j; 113 | break; 114 | case 'i' : 115 | init = argv[i] + j; 116 | break; 117 | case 'l': 118 | lfile = argv[i] + j; 119 | break; 120 | } 121 | i++; 122 | j = 1; 123 | break; 124 | default: 125 | fprintf(stderr, "%s: unknown option -%c\n", argv[0], c); 126 | return 1; 127 | break; 128 | } 129 | } else { 130 | fprintf(stderr, "%s: extra argument %s\n", argv[0], argv[i]); 131 | return 1; 132 | } 133 | } 134 | 135 | if (!foreground){ 136 | fprintf(stderr,"%s: about to go into background\n", argv[0]); 137 | if(fork_parent() < 0){ 138 | fprintf(stderr, "%s: unable to fork_parent\n", argv[0]); 139 | return 1; 140 | } 141 | } 142 | 143 | /* create a state handle */ 144 | d = startup_katcp(); 145 | if(d == NULL){ 146 | fprintf(stderr, "%s: unable to allocate state\n", argv[0]); 147 | return 1; 148 | } 149 | 150 | #ifdef TCPBORPHSERVER_BUILD 151 | add_build_katcp(d, TCPBORPHSERVER_BUILD); 152 | #endif 153 | 154 | if(uname(&un) == 0){ 155 | snprintf(uname_buffer, UNAME_BUFFER, "%s-%s", un.sysname, un.release); 156 | uname_buffer[UNAME_BUFFER - 1] = '\0'; 157 | #if 0 158 | add_build_katcp(d, uname_buffer); 159 | #endif 160 | } 161 | 162 | if(setup_basic_kcs(d, scripts, argv, argc) < 0){ 163 | #ifdef DEBUG 164 | fprintf(stderr, "%s: unable to set up basic logic\n", argv[0]); 165 | #endif 166 | return 1; 167 | } 168 | 169 | /* mode from command line */ 170 | if(mode){ 171 | if(enter_name_mode_katcp(d, mode, NULL) < 0){ 172 | fprintf(stderr, "%s: unable to enter mode %s\n", argv[0], mode); 173 | return 1; 174 | } 175 | } 176 | 177 | signal(SIGPIPE, SIG_DFL); 178 | 179 | if (!foreground){ 180 | lfd = open(lfile, O_WRONLY | O_APPEND | O_CREAT | O_NOCTTY, S_IWUSR | S_IRUSR | S_IRGRP | S_IWGRP); 181 | 182 | if (lfd < 0){ 183 | fprintf(stderr,"%s: unable to open %s: %s\n",argv[0], KCS_LOGFILE,strerror(errno)); 184 | return 1; 185 | } else { 186 | fflush(stderr); 187 | if (dup2(lfd,STDERR_FILENO) >= 0){ 188 | now = time(NULL); 189 | fprintf(stderr,"Logging to file started at %s\n",ctime(&now)); 190 | } 191 | close(lfd); 192 | } 193 | } 194 | 195 | #ifdef DEBUG 196 | fprintf(stderr, "server: about to run config server\n"); 197 | #endif 198 | 199 | if(run_config_server_katcp(d, init, KCS_MAX_CLIENTS, port, 0) < 0){ 200 | fprintf(stderr, "server: run failed\n"); 201 | return 1; 202 | } 203 | 204 | status = exited_katcp(d); 205 | 206 | shutdown_katcp(d); 207 | 208 | #ifdef DEBUG 209 | fprintf(stderr, "server: exit with status %d\n", status); 210 | #endif 211 | 212 | return status; 213 | } 214 | --------------------------------------------------------------------------------