Contiki 3.x
serial-dumper.c
Go to the documentation of this file.
1 /**
2  * \file
3  * adapted from Battery and Temperature IPv6 Demo for Zolertia Z1
4  * \author
5  * Dan Playle <djap1g12@soton.ac.uk>
6  */
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "contiki.h"
11 #include "store.h"
12 #include "net/ipv6/uip-ds6.h"
13 #include "readings.pb.h"
14 #include "settings.pb.h"
15 
16 PROCESS(serial_dumper_process, "Serial Dumper");
17 
18 AUTOSTART_PROCESSES(&serial_dumper_process);
19 
20 /**
21  * Dump a binary buffer over serial as a hex line.
22  * @param buffer The buffer to print
23  * @param len The length of the buffer
24  */
25 static void dump_buffer(uint8_t *buffer, uint8_t len);
26 
27 PROCESS_THREAD(serial_dumper_process, ev, data) {
28  PROCESS_BEGIN();
29 
30  // Initialize the store before anything else
31  store_init();
32 
33  printf("+++SERIALDUMP+++NODEID+++\n");
34  {
35  uip_ds6_addr_t *lladdr = uip_ds6_get_link_local(-1);
36  printf("%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
37  lladdr->ipaddr.u8[8],
38  lladdr->ipaddr.u8[9],
39  lladdr->ipaddr.u8[10],
40  lladdr->ipaddr.u8[11],
41  lladdr->ipaddr.u8[12],
42  lladdr->ipaddr.u8[13],
43  lladdr->ipaddr.u8[14],
44  lladdr->ipaddr.u8[15]
45  );
46  }
47 
48  printf("+++SERIALDUMP+++SAMPLE+++START+++\n");
49  {
50  uint8_t buffer[Sample_size];
51  uint8_t buffer_len;
52  uint16_t id;
53 
54  // Keep going as long as the ID is valid
55  for (id = store_get_latest_sample_id(); id > 0; id--) {
56  if ((buffer_len = store_get_raw_sample(id, buffer))) {
57  dump_buffer(buffer, buffer_len);
58  }
59  }
60 
61  }
62  printf("+++SERIALDUMP+++SAMPLE+++END+++\n");
63 
64  printf("+++SERIALDUMP+++CONFIG+++START+++\n");
65  {
66  uint8_t buffer[SensorConfig_size];
67  uint8_t buffer_len;
68 
69  if ((buffer_len = store_get_raw_config(buffer))) {
70  dump_buffer(buffer, buffer_len);
71  }
72 
73  }
74  printf("+++SERIALDUMP+++CONFIG+++END+++\n");
75 
76  PROCESS_END();
77 }
78 
79 void dump_buffer(uint8_t *buffer, uint8_t len) {
80  int i;
81  for (i = 0; i < len; i++) {
82  printf("%02x", buffer[i]);
83  }
84  printf("\n");
85 }
Header file for IPv6-related data structures.
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
uint8_t store_get_raw_sample(uint16_t id, uint8_t buffer[Sample_size])
Get a given sample from the flash, in the form of an encoded protocol buffer.
Definition: store.c:155
Convenience layer for storing readings and the config.
Unicast address structure.
Definition: uip-ds6.h:202
static void dump_buffer(uint8_t *buffer, uint8_t len)
Dump a binary buffer over serial as a hex line.
Definition: serial-dumper.c:79
void store_init(void)
Initialize the data store.
Definition: store.c:339
uint8_t store_get_raw_config(uint8_t buffer[SensorConfig_size])
Get the configuration from the flash.
Definition: store.c:262
uint16_t store_get_latest_sample_id(void)
Get the identifer of the most recent sample stored.
Definition: store.c:170
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120