SHARE
TWEET

Untitled

a guest Dec 9th, 2018 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Include ASSP library for code
  2. #include "ASSP.h"
  3.  
  4. //Array with names which symulate network
  5. #define NUMNAMES 29
  6. const char* names[NUMNAMES] = {
  7.   "Art", "Hal", "Mel", "Vic",
  8.   "Bob", "Ivy", "Ned", "Wes",
  9.   "Bee", "Jan", "Nia", "Xao",
  10.   "Bev", "Jem", "Obe", "Yao",
  11.   "Coy", "Del", "Eva", "Fey",
  12.   "Jen", "Ken", "Leo", "Lee",
  13.   "Pam", "Ron", "Sam", "Tom",
  14.   "Zoe"
  15. };
  16.  
  17. //Function isDeviceOnPort returns true or false
  18. boolean isDeviceOnPort(const char* name, int port) {
  19.   //Configurate Message
  20.   SerialShield.setMessageSender("raw32");
  21.   SerialShield.setMessageContent("ping");
  22.   SerialShield.setMessageDestination(name);
  23.  
  24.   //Send message to the typed port
  25.   SerialShield.sendASSPMessage(port);
  26.  
  27.   boolean state = false;
  28.  
  29.   for (int i = 0; i < 50; i++) {
  30.  
  31.     //Assign fetch boolean status to state variable
  32.     state = SerialShield.fetchASSPMessage();
  33.  
  34.     //If state equals "true" break the loop
  35.     if (state) {
  36.       break;
  37.     } else {
  38.       continue;
  39.     }
  40.   }
  41.  
  42.   //Return status of state
  43.   return state;
  44. }
  45.  
  46. //Task0 Test function
  47. void task0() {
  48.   Serial.println("Device     Port1?");
  49.  
  50.   //Iterate array of "devices"
  51.   for (int n = 0; n < 29; n++) {
  52.     Serial.print(names[n]);
  53.  
  54.     //Check status of connection of devices and ports
  55.     if (isDeviceOnPort(names[n], 1)) {
  56.       Serial.println("        Y");
  57.     } else {
  58.       Serial.println("        N");
  59.     }
  60.   }
  61. }
  62.  
  63. void setup() {
  64.   Serial.begin(9600);
  65.   task0();
  66. }
  67.  
  68. void loop() {
  69.  
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top