Popravljen sprejemnik za linux (monitor mode)
parent
9948e344d5
commit
93cf9f9e72
Binary file not shown.
|
@ -20,7 +20,7 @@ $ sudo ifconfig wlp5s0 down
|
|||
$ sudo iwconfig wlp5s0 mode monitor
|
||||
$ sudo ifconfig wlp5s0 up
|
||||
|
||||
3/Run this code as root
|
||||
3/Run this code as root or regular user!
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -45,18 +45,34 @@ $ sudo ifconfig wlp5s0 up
|
|||
#include "lo/lo_lowlevel.h"
|
||||
#include "lo/lo_osc_types.h"
|
||||
|
||||
#define PACKET_LENGTH 400 //Approximate
|
||||
// OSC destination; localhost supercollider running @ default port (57121)
|
||||
// @TODO get this from argv?
|
||||
lo_address osc_dest;
|
||||
|
||||
//Approximate
|
||||
#define PACKET_LENGTH 400
|
||||
#define MAX_PACKET_LEN 1000
|
||||
|
||||
// ESPNOW data payload starts at byte 60
|
||||
#define ESP_DATA_OFFSET 57
|
||||
|
||||
// Sensor message
|
||||
#include "../src/sensor_msg.h"
|
||||
|
||||
// Maksimalno stevilo
|
||||
#define ST_SPREJEMNIKOV 10
|
||||
|
||||
// Receiver MAC start at byte 52
|
||||
#define WLAN_DA_OFFSET 52
|
||||
/*our MAC address*/
|
||||
uint8_t sprejemnikMac[] = { 0x9c, 0xb6, 0xd0, 0xc4, 0xe8, 0xb9 };
|
||||
uint8_t wlan_da[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
|
||||
|
||||
// ESPNOW packet identifier
|
||||
#define ESP_ID_OFFSET 82
|
||||
uint8_t esp_id[] = { 0x18, 0xfe, 0x34, 0x04 };
|
||||
uint8_t pkg_header[] = { 0x0, 0x0, 0x0, 0x0 };
|
||||
|
||||
// ESPNOW data payload starts at byte 87
|
||||
#define ESP_DATA_OFFSET 87
|
||||
|
||||
// Sensor message
|
||||
#include "../src/sensor_msg.h"
|
||||
|
||||
uint8_t odcitekId;
|
||||
sensor_msg odcitki[ST_SPREJEMNIKOV];
|
||||
bool poslji[ST_SPREJEMNIKOV];
|
||||
|
@ -66,9 +82,6 @@ struct timeval cas;
|
|||
struct timeval zdaj;
|
||||
int eps = 0;
|
||||
|
||||
/*our MAC address*/
|
||||
//{0xF8, 0x1A, 0x67, 0xB7, 0xeB, 0x0B};
|
||||
|
||||
/*ESP8266 host MAC address*/
|
||||
//{0x84,0xF3,0xEB,0x73,0x55,0x0D};
|
||||
|
||||
|
@ -102,17 +115,52 @@ static struct sock_filter bpfcode[FILTER_LENGTH] = {
|
|||
};
|
||||
|
||||
void print_packet(uint8_t *data, int len) {
|
||||
/*
|
||||
char macNaslov[18];
|
||||
snprintf(macNaslov, sizeof(macNaslov), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
||||
// Beri samo primerne pakete!
|
||||
memcpy(&wlan_da, data + WLAN_DA_OFFSET, 6);
|
||||
#ifdef DEBUG
|
||||
printf("Dest MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", wlan_da[0],wlan_da[1],wlan_da[2],wlan_da[3],wlan_da[4],wlan_da[5]);
|
||||
#endif
|
||||
|
||||
/* DEBUG - print whole raw packet */
|
||||
#ifdef DEBUG
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf("0x%02x ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
// Ignoriraj pakete, ki so namenjeni drugam
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (wlan_da[i] != sprejemnikMac[i]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignoriraj pakete, ki niso ESP paketi!
|
||||
memcpy(&pkg_header, data + ESP_ID_OFFSET, 4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (pkg_header[i] != esp_id[i]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Stetje paketov na sekundo
|
||||
eps += 1;
|
||||
gettimeofday(&zdaj, NULL);
|
||||
|
||||
if (zdaj.tv_sec != cas.tv_sec) {
|
||||
printf("Paketov na sekundo: %i\n", eps);
|
||||
eps = 0;
|
||||
gettimeofday(&cas, NULL);
|
||||
}
|
||||
|
||||
printf("%s\n", macNaslov);
|
||||
*/
|
||||
//printf("Prejel podatke dolzine %i \n", len);
|
||||
|
||||
// ID senzorja
|
||||
odcitekId = (uint8_t) data[ESP_DATA_OFFSET];
|
||||
memcpy(&odcitekId, data + ESP_DATA_OFFSET, 1);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Odcitek ID: %i\n", odcitekId);
|
||||
#endif
|
||||
|
||||
// Vrednosti
|
||||
memcpy(&odcitki[odcitekId], data + ESP_DATA_OFFSET, sizeof(sensor_msg));
|
||||
|
@ -130,18 +178,6 @@ void print_packet(uint8_t *data, int len) {
|
|||
printf("bat: %f \n", odcitki[odcitekId].bat);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
eps += 1;
|
||||
gettimeofday(&zdaj, NULL);
|
||||
|
||||
if (zdaj.tv_sec != cas.tv_sec) {
|
||||
printf("Paketov na sekundo: %i\n", eps);
|
||||
eps = 0;
|
||||
gettimeofday(&cas, NULL);
|
||||
}
|
||||
return;
|
||||
|
||||
// @TODO locen thread za posiljanje?
|
||||
char glava[32];
|
||||
|
@ -176,6 +212,7 @@ void print_packet(uint8_t *data, int len) {
|
|||
|
||||
sporocilo = lo_bundle_serialise(svezenj, NULL, &dolzina);
|
||||
lo_bundle_pp(svezenj);
|
||||
lo_send_bundle(osc_dest, svezenj);
|
||||
printf("%s\n", sporocilo);
|
||||
lo_bundle_free(svezenj);
|
||||
|
||||
|
@ -183,12 +220,6 @@ void print_packet(uint8_t *data, int len) {
|
|||
//free(sporocilo);
|
||||
}
|
||||
}
|
||||
/* DEBUG - print whole raw packet
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf("0x%02x ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
*/
|
||||
}
|
||||
|
||||
int create_raw_socket(char *dev, struct sock_fprog *bpf)
|
||||
|
@ -221,33 +252,33 @@ int create_raw_socket(char *dev, struct sock_fprog *bpf)
|
|||
return fd;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
assert(argc == 2);
|
||||
int main(int argc, char **argv) {
|
||||
assert(argc == 2);
|
||||
|
||||
uint8_t buff[MAX_PACKET_LEN] = {0};
|
||||
int sock_fd;
|
||||
char *dev = argv[1];
|
||||
struct sock_fprog bpf = {FILTER_LENGTH, bpfcode};
|
||||
uint8_t buff[MAX_PACKET_LEN] = {0};
|
||||
int sock_fd;
|
||||
char *dev = argv[1];
|
||||
struct sock_fprog bpf = {FILTER_LENGTH, bpfcode};
|
||||
|
||||
sock_fd = create_raw_socket(dev, &bpf); /* Creating the raw socket */
|
||||
sock_fd = create_raw_socket(dev, &bpf); /* Creating the raw socket */
|
||||
|
||||
printf("\n Waiting to receive packets ........ \n");
|
||||
// @TODO get this from args?
|
||||
osc_dest = lo_address_new("localhost", "57121");
|
||||
|
||||
gettimeofday(&cas, NULL);
|
||||
printf("\n Waiting to receive packets ........ \n");
|
||||
gettimeofday(&cas, NULL);
|
||||
|
||||
while (1)
|
||||
{
|
||||
int len = recvfrom(sock_fd, buff, MAX_PACKET_LEN, MSG_TRUNC, NULL, 0);
|
||||
while (1) {
|
||||
int len = recvfrom(sock_fd, buff, MAX_PACKET_LEN, MSG_TRUNC, NULL, 0);
|
||||
|
||||
if (len < 0) {
|
||||
perror("Socket receive failed or error");
|
||||
break;
|
||||
} else {
|
||||
//printf("len:%d\n", len);
|
||||
print_packet(buff, len);
|
||||
}
|
||||
if (len < 0) {
|
||||
perror("Socket receive failed or error");
|
||||
break;
|
||||
} else {
|
||||
//printf("len:%d\n", len);
|
||||
print_packet(buff, len);
|
||||
}
|
||||
close(sock_fd);
|
||||
return 0;
|
||||
}
|
||||
close(sock_fd);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
rmmod ath10k_pci
|
||||
rmmod ath10k_core
|
||||
|
||||
modprobe ath10k_core
|
||||
modprobe ath10k_pci
|
||||
|
||||
systemctl start NetworkManager
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
dev=${1:-wlp3s0}
|
||||
chan=${2:-1}
|
||||
|
||||
rmmod ath10k_pci
|
||||
rmmod ath10k_core
|
||||
|
||||
systemctl stop NetworkManager
|
||||
|
||||
sleep 1
|
||||
|
||||
modprobe ath10k_core awmode=1 cryptmode=1
|
||||
sleep 1
|
||||
modprobe ath10k_pci
|
||||
sleep 1
|
||||
|
||||
ifconfig $dev down
|
||||
iwconfig $dev mode monitor
|
||||
ifconfig $dev up
|
||||
iwconfig $dev channel $chan
|
|
@ -1,3 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
sudo ./bin/receiver wlxd0aeec558360
|
||||
dev=${1:-wlp3s0}
|
||||
|
||||
sudo ./bin/receiver $dev
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
dev="wlxd0aeec558360"
|
||||
chan="1"
|
||||
# sudo bash prep.sh *iface* *channel*
|
||||
# sudo bash prep.sh wlp1s0 8
|
||||
ifconfig $dev down
|
||||
iwconfig $dev mode monitor
|
||||
ifconfig $dev up
|
||||
iwconfig $dev channel $chan
|
Loading…
Reference in New Issue