void setup() { //Initialize serial and wait for port to open: Serial1.begin(9600); SPI.begin(); while (!Serial1) { ; // wait for serial port to connect. Needed for Leonardo only } delay(1200); // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { Serial1.println("WiFi shield not present"); // don't continue: while (true); } String fv = WiFi.firmwareVersion(); if ( fv != "1.1.0" ) Serial1.println("Please upgrade the firmware"); // Print WiFi MAC address: printMacAddress(); // scan for existing networks: Serial1.println("Scanning available networks..."); listNetworks(); }
void printFrame(ODRFrame receivedFrame){ char hostname[1024],sourceHost[1024],destHost[1024]; memset(hostname,'\0',1024); memset(sourceHost, '\0', 1024); memset(destHost, '\0', 1024); gethostname(hostname,1023); getDomainName(receivedFrame.data.source, sourceHost); getDomainName(receivedFrame.data.destination, destHost); printf("ODR at node %s : sending frame hdr src %s dest ",hostname, hostname); printMacAddress(receivedFrame.header.destAddress); printf("\t\tODR msg type %d src %s dest %s \n",receivedFrame.header.packetType, sourceHost, destHost); }
void printFrame(char *Frame) { struct ethhdr *eth = (struct ethhdr *)Frame; printf("Ethernet Source Mac : "); printMacAddress(eth->h_source); printf("\t"); printf("Ethernet Destination Mac : "); printMacAddress(eth->h_dest); printf("\t"); printf("ethernet type %d \n", ntohs(eth->h_proto)); arp_hdr* arpHeader = (arp_hdr*)(eth+1); printf("ARP Source Mac :"); printMacAddress(arpHeader->sender_mac); printf("\t"); printf("ARP Dest Mac :"); printMacAddress(arpHeader->target_mac); printf("\n"); struct in_addr sinAddr1; struct in_addr sinAddr2; sinAddr1.s_addr = getSaddr(arpHeader->sender_ip); sinAddr2.s_addr = getSaddr(arpHeader->target_ip); //printf("ARP Destination ip : %s \n",inet_ntoa(sinAddr2)); //printf("Advertisement Number : %d \t",arpHeader->advNumber); //printf("Hardware Length : %d \t",arpHeader->hlen); //printf("Hardware Type : %d \n",arpHeader->htype); //printf("Protocol Length : %d \t",arpHeader->plen); //printf("Protocol Type : %d \t",arpHeader->ptype); //printf("Operation Code : %d \n",arpHeader->opcode); if(arpHeader->opcode == 1) { printf("%s requested %s for MacAddress \n", getDomainNameFromIpAddress(sinAddr1), getDomainNameFromIpAddress(sinAddr2)); }else { printf("%s replied %s with MacAddress \n", getDomainNameFromIpAddress(sinAddr1), getDomainNameFromIpAddress(sinAddr2)); } }
int areq (struct sockaddr *IPaddr, socklen_t sockaddrlen, struct hwaddr *HWaddr) { int clientSocket = getARPclientBindedsocket(); connectToARP(clientSocket); struct sockaddr_in* ipAddress = (struct sockaddr_in *)IPaddr; char* ipAddressString = inet_ntoa(ipAddress->sin_addr); printf("MAC ADDRESS Requested for destination : %s \n ",ipAddressString); char* message = marshallMessage(ipAddressString,BRODCAST_MAC); struct timeval tv; int maxfd=0; fd_set readSet; FD_ZERO (&readSet); maxfd = clientSocket + 1; FD_SET(clientSocket,&readSet); tv.tv_sec = ARP_TIME_OUT_SECS; tv.tv_usec = ARP_TIME_OUT_USECS; sendUDSMessage(clientSocket,message); if((select(maxfd,&readSet,NULL,NULL,&tv))<0) { perror("ARPAPI.c : Select in the client Failed :"); } char recvMessage[UDS_PACKET_MAX_LEN]; if(FD_ISSET(clientSocket,&readSet)) { recvUDSMessage(clientSocket,recvMessage); unMarshallMessage(recvMessage,ipAddressString, HWaddr->sll_addr ); HWaddr->sll_halen = HADDR_LEN; HWaddr->sll_ifindex = getEth0Index(); HWaddr->sll_hatype = ETHERNET; printf("MAC ADDRESS for destination : %s is ",ipAddressString); printMacAddress(HWaddr->sll_addr ); printf("\n"); return 1; } else { printf("ARPAPI.c : MAC ADDRESS retrieval failed"); return -1; } unLinkSocket(clientSocket); return 1; }
void main(void){ //============================================================================== // Main Program // // Description: This function contains the while loop that runs continuously // to act for the operating system. It also calls all the functions to // initialize the system. // // Passed : no variables passed // Locals: no variables declared // Returned: no values returned // Globals: volatile unsigned int Time_Sequence; // volatile char one_time; // char* display_1 // char* display_2 // char* display_3 // char* display_4 // slow_input_down // control_state[CNTL_STATE_INDEX] // char big // char size_count; // char posL1 // char posL2 // char posL3 // char posL4 // // Author: David Pryor // Date: Feb 2016 // Compiler: Built with IAR Embedded Workbench Version: V4.10A/W32 (6.4.1) //============================================================================== Init_Ports(); // Initialize Ports Init_Clocks(); // Initialize Clock System Init_Conditions(); Time_Sequence = SWITCH_OFF; // Init_Timers(); // Initialize Timers Init_LEDs(); // Initialize LEDs Init_LCD(); // Initialize LCD Init_ADC(); // Initialize ADC Init_Serial_UCA1(0); // BAUD rate 9600 Init_Serial_UCA0(1); // BAUD rate 9600 Five_msec_Delay(1); PJOUT |= IOT_STA_MINIAP; //turning on miniap (only works this way) IR_LED_OFF(); lcd_BIG_mid(); display_1 = " David "; display_2 = "Project 8"; display_3 = " Pryor "; display_4 = ""; Display_Process(); //------------------------------------------------------------------------------ // Begining of the "While" Operating System //------------------------------------------------------------------------------ while(ALWAYS) { // Can the Operating system run ADC_Process(); // call sampling function if(MainFG){ Menu_Process(); } else if(BaudMenuFG==TRUE){ Baud_Menu(); } else if(IOTMenuFG==TRUE){ IOT_Menu(); } if(StartCommandFG){ //StartCommandFG is true once "." has been received commandTree(); } printMacAddress(); //prints mac address to screen macFG=FALSE; //turn off command to print mac address clearReceiveBuffer(); parseIOTData(); } //------------------------------------------------------------------------------ }
void setup() { pinMode(13, OUTPUT); Serial.begin(74880); Serial.println("Initializing..."); WiFi.mode(WIFI_AP_STA); WiFi.softAP("foobar", "12345678", 1, 0); if (startWifi(30)) { } else { Serial.println("failed to start wifi"); ESP.restart(); } uint8_t macaddr[6]; wifi_get_macaddr(STATION_IF, macaddr); Serial.print("mac address (STATION_IF): "); printMacAddress(macaddr); wifi_get_macaddr(SOFTAP_IF, macaddr); Serial.print("mac address (SOFTAP_IF): "); printMacAddress(macaddr); if (esp_now_init() == 0) { Serial.println("init"); } else { Serial.println("init failed"); ESP.restart(); return; } esp_now_set_self_role(ESP_NOW_ROLE_SLAVE); esp_now_register_recv_cb([](uint8_t *macaddr, uint8_t *data, uint8_t len) { // Serial.print("data: "); // for (int i = 0; i < len; i++) { // Serial.print(" 0x"); // Serial.print(data[i], HEX); // } // // Serial.println(""); // Serial.print("recv_cb length="); // Serial.print(len); // Serial.print(" from mac address: "); // printMacAddress(macaddr); // // exception... //send_data_t* send_data = static_cast<send_data_t*>(static_cast<void*>(data)); send_data_t send_data; memcpy(&send_data, data, sizeof(send_data)); // uint8_t data_len = (len - sizeof(send_data.chipId) - sizeof(send_data.battery)) / sizeof(uint32_t); // Serial.print("data_len: "); // Serial.println(data_len); data_queue.push_back(send_data); }); esp_now_register_send_cb([](uint8_t* macaddr, uint8_t status) { Serial.println("send_cb"); Serial.print("mac address: "); printMacAddress(macaddr); Serial.print("status = "); Serial.println(status); }); int res = esp_now_add_peer(mac, (uint8_t)ESP_NOW_ROLE_CONTROLLER,(uint8_t)WIFI_DEFAULT_CHANNEL, NULL, 0); // esp_now_unregister_recv_cb(); // esp_now_deinit(); }
void printUdsPacket(char *packet) { printf("MAC ADDRESS : "); printMacAddress(packet); printf("\t"); printf("IP ADDRESS : %s\n",packet+HADDR_LEN); }