-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#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(""); | ||
|
||
//Setting PowerSaveMode | ||
uint8_t ret; | ||
Serial.print("Set PowerSaveMode to "); | ||
Serial.println(POWER_SAVE_MODE_AUTO_SLEEP); | ||
ret = sakuraio.setPowerSaveMode(POWER_SAVE_MODE_AUTO_SLEEP); | ||
if (ret != 0x01) { | ||
Serial.print(" FAILED ret="); | ||
Serial.println(ret); | ||
} | ||
ret = sakuraio.getPowerSaveMode(); | ||
Serial.print("getPowerSaveMode(): "); | ||
Serial.println(ret); | ||
} | ||
|
||
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); | ||
|
||
// 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); | ||
} |