forked from sakuraio/SakuraIOArduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Standard.ino
130 lines (109 loc) · 2.88 KB
/
Standard.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <SakuraIO.h>
//SakuraIO_SPI sakuraio(10);
SakuraIO_I2C sakuraio;
void setup() {
Serial.begin(9600);
Serial.print("Waiting to come online");
for(;;){
if( (sakuraio.getConnectionStatus() & 0x80) == 0x80 ) break;
Serial.print(".");
delay(1000);
}
Serial.println("");
}
uint8_t counter = 0;
void loop() {
counter++;
Serial.println("");
Serial.println(counter);
uint8_t request[33] = {};
uint8_t response[33] = {};
// Echoback
request[0] = counter;
sakuraio.echoback(1, request, response);
Serial.print(request[0]);
Serial.print(" -> ");
Serial.println(response[0]);
// Unixtime
uint32_t unixtime = (uint32_t)(sakuraio.getUnixtime()/1000UL);
Serial.print("Unixtime ");
Serial.println(unixtime);
// ADC
uint16_t adc;
adc = sakuraio.getADC(0);
Serial.print("ADC0 ");
Serial.println(adc);
adc = sakuraio.getADC(1);
Serial.print("ADC1 ");
Serial.println(adc);
// ProductID
uint16_t pid = sakuraio.getProductID();
Serial.print("PID ");
Serial.println(pid);
// UniqueID
sakuraio.getUniqueID((char *)response);
Serial.print("UID ");
Serial.println((char *)response);
// Version
sakuraio.getFirmwareVersion((char *)response);
Serial.print("Ver ");
Serial.println((char *)response);
// Connection Status
uint8_t connectionStatus = sakuraio.getConnectionStatus();
Serial.print("Status ");
Serial.println(connectionStatus);
//getSignalQuality
uint8_t signalQuality = sakuraio.getSignalQuality();
Serial.print("Quality ");
Serial.println(signalQuality);
// Tx Queue
uint8_t ret;
ret = sakuraio.enqueueTx((uint8_t)0, (int32_t)counter);
Serial.print("Enqueue ");
Serial.println(ret);
uint8_t avail;
uint8_t queued;
sakuraio.getTxQueueLength(&avail, &queued);
Serial.print("Tx Available=");
Serial.print(avail);
Serial.print(" Queued=");
Serial.println(queued);
if(queued >= 30){
ret = sakuraio.clearTx();
Serial.print("Clear ");
Serial.println(ret);
}else if(queued >= 5){
ret = sakuraio.send();
Serial.print("Send ");
Serial.println(ret);
}
// Rx Queue
sakuraio.getRxQueueLength(&avail, &queued);
Serial.print("Rx Available=");
Serial.print(avail);
Serial.print(" Queued=");
Serial.println(queued);
for(uint8_t i=0; i<queued; i++){
uint8_t channel;
uint8_t type;
uint8_t values[8];
int64_t offset;
ret = sakuraio.dequeueRx(&channel, &type, values, &offset);
Serial.print("Dequeue ");
Serial.print(ret);
if(ret == 0x01){
Serial.print(" ch="); Serial.print(channel);
Serial.print(" type="); Serial.print((char)type);
Serial.print(" values=[");
for(uint8_t b=0; b<7; b++){
Serial.print(values[b]);
Serial.print(" ");
}
Serial.print(values[7]);
Serial.print("] offset="); Serial.println((int32_t)offset);
}else{
Serial.println(" ERROR");
}
}
delay(5000);
}