2017 2학기 - goofcode/UR GitHub Wiki

10월 28일

  • Windows용 FTDI driver 설치 가이드를 보면서 driver 설치

  • Contiki OS tutorial을 따라VMware에서 instant Contiki를 사용하여 cooja실행 및 체험

  • [Solved] cooja 실행중

     BUILD FAILED /home/user/contiki-3.0/tools/cooja/build.xml:199: 
     The following error occurred while executing this line:
     /home/user/contiki-3.0/tools/cooja/apps/mspsim/build.xml:29: 
     - Could not find the MSPSim build file. Did you run "git submodule update --init"?
    

    $git submodule update --init

     혹은 tools/mspsim$git clone https://github.com/contiki-os/mspsim

  • kmote sky에 example/hello-world를 실행

     $ make TARGET=sky hello-world		# compile
     $ make TARGET=sky savetarget		# save taget
     $ make hello-world.upload		# compile + upload
     $ make login				# connect
    
  • [Solved] msp430-gcc 미설치

     make: msp430-gcc: Command not found
    

    sudo apt-get install msp430-gcc

  • reset버튼을 찾지 못해(kmote에는 없는건가??) hello world 출력을 볼 수 없었음 upload login at once

    • 그 대신 timer를 살짝 공부, "sys/timer.h"clock_second()을 이용, 30초 동안 출력하게 하고, 그 사이 $make login

       #include "contiki.h"
       #include "sys/timer.h"
       #include <stdio.h> 
       
       PROCESS(hello_world_process, "Hello world process");
       AUTOSTART_PROCESSES(&hello_world_process);
       
       PROCESS_THREAD(hello_world_process, ev, data)
       {
       	PROCESS_BEGIN();
       	unsigned long start = clock_seconds();
      
       	while(clock_seconds()-start < 30)
       		printf("Hello, world\n");
      
       	PROCESS_END();
       }
  • Contiki OS github

  • IoT in 5 days

  • anrg.usc.edu Contiki Tutorial

10월 31일

  • Cooja simulation w/ 5 examples/ipv6/simple-udp-rpl/broadcasting-ex.c motes

  • make - target, dependency, command macro

     CC = gcc
     target1 : dependency1 dependency2
     	command1
     	command2
    
     CC = gcc
     CFLAGS = -W -WALL
     TARGET = my.exe
     OBJECTS = a.o b.o c.o
     
     all : $(TARGET)
     
     $(TARGET) : $(OBJECTS) 
     	$(CC) $(CFLAGS) -o $@ $^	# $@: current target
     					# $^: dep list of current target
     								
     clean : 				# for $make clean
     	rm *.o my.exe	
    
  • upload and login at once

      make TARGET=sky MOTES=/dev/ttyUSB0 hello-world.upload login
    

11월 1일

  • broadcast-name

     # Makefile
     CONTIKI_PROJECT = broadcast-name
     all: $(CONTIKI_PROJECT)
    
     CONTIKI = ../..
     CONTIKI_WITH_RIME = 1			# for broadcast_open, ...
     include $(CONTIKI)/Makefile.include
     // broadcast-name.c
     #include "contiki.h"
     #include "net/rime/rime.h"
     #include "random.h"
    
     #include <stdio.h>
    
     PROCESS(example_broadcast_process, "Broadcast example");		// process def
     AUTOSTART_PROCESSES(&example_broadcast_process);			// start process(es)
    
     static void broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)	// recieve callback
     {
     	printf("broadcast message received from %d.%d: '%s'\n",
     	from->u8[0], from->u8[1], (char *)packetbuf_dataptr());
     }
    
    
     static const struct broadcast_callbacks broadcast_call = {broadcast_recv};
     static struct broadcast_conn broadcast;
    
    
     PROCESS_THREAD(example_broadcast_process, ev, data)	// process thread for ex_broadcast_process
     {
       static struct etimer et;					// event timer
    
       PROCESS_EXITHANDLER(broadcast_close(&broadcast));		// set process exit handler
    
       PROCESS_BEGIN();
    
       broadcast_open(&broadcast, 129, &broadcast_call);		// open broadcast specifying conn,
       								// register callback
    
       while(1) {
    
     	etimer_set(&et, CLOCK_SECOND * 4);			// delay 4 sec
    
     	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));		// wait etimer to be expired
    
     	packetbuf_copyfrom("Mookeun", 8);			// set packetbuf
     	broadcast_send(&broadcast);				// broadcast
     	printf("broadcast message sent\n");			// print log
       }
    
       PROCESS_END();
     }

11월 3일

  • blink

     #include "contiki.h"
     #include "sys/timer.h"
     #include "dev/leds.h"
     #include <stdio.h>
    
     PROCESS(blink_ex, "blink example");
     AUTOSTART_PROCESSES(&blink_ex);
    
     PROCESS_THREAD(blink_ex, ev, data){
    
         PROCESS_EXITHANDLER(goto exit;)
         PROCESS_BEGIN();
    
         static struct etimer et;
         while(1){
     	printf("turning on all led\n");
     	leds_on(LEDS_ALL);
     	etimer_set(&et, CLOCK_SECOND);
     	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));		// wait for a second
    
     	printf("turning off all led\n");
     	leds_off(LEDS_ALL);
     	etimer_set(&et, CLOCK_SECOND);
     	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));		// wait for a second
         }
    
    
     exit:
         leds_off(LEDS_ALL);
         PROCESS_END();
     }

11월 5일

  • Process contexts

    • cooperative: sequential
    • preemptive: temporarily stop cooperative
    • process -> cooperative
    • interrupt, real time timers -> preemptive
  • start on system boots & when module is loaded into system

  • protothreads - way to structure code in a way that allows the system to run other activities when the code is waiting for something to happen.

     PROCESS_BEGIN(); // Declares the beginning of a process' protothread. 
     PROCESS_END(); // Declares the end of a process' protothread. 
     PROCESS_EXIT(); // Exit the process. 
     PROCESS_WAIT_EVENT(); // Wait for any event. 
     PROCESS_WAIT_EVENT_UNTIL(); // Wait for an event, but with a condition.
     PROCESS_YIELD(); // Wait for any event, equivalent to PROCESS_WAIT_EVENT().
     PROCESS_WAIT_UNTIL(); // Wait for a given condition; may not yield the process.
     PROCESS_PAUSE(); // Temporarily yield the process.
  • asynchronous event -> to event queue -> to receiver (by kernel)

    • delivered to the receiving process some time after they have been posted
    • if receiver is specific process, invoke the process
    • if receiver is all processes, sequentially deliver
  • synchronous event -> directly deliver

    • only to specific process
    • functionally equivalent to a function call: the process to which the event is delivered is directly invoked, and the process that posted the event is blocked until the receiving process has finished processing the event.
⚠️ **GitHub.com Fallback** ⚠️