When I analysis sgx process by using strace, ioctl function is called so many times after mmap function like below.
1424 11:18:56 mmap(NULL, 4194304, PROT_NONE, MAP_SHARED, 4, 0) = 0x7f7e6a800000
1424 11:18:56 ioctl(4, _IOC(_IOC_WRITE, 0xa4, 0x00, 0x08), 0x7ffdadb760b0) = 0
1424 11:18:56 ioctl(4, _IOC(_IOC_WRITE, 0xa4, 0x01, 0x1a), 0x7ffdadb76f00) = 0
1424 11:18:56 ioctl(4, _IOC(_IOC_WRITE, 0xa4, 0x01, 0x1a), 0x7ffdadb76f00) = 0
1424 11:18:56 ioctl(4, _IOC(_IOC_WRITE, 0xa4, 0x01, 0x1a), 0x7ffdadb76f00) = 0
1424 11:18:56 ioctl(4, _IOC(_IOC_WRITE, 0xa4, 0x01, 0x1a), 0x7ffdadb76f00) = 0
Is there anyone who knows why this function is called so many times?
What means this function?
Instead of adding a custom system call, a lot of things use ioctl on a "device" FD as a way for user-space to communicate with the kernel. Think of it as a device-specific system call.
In this specific case of SGX I don't know specifically what it's doing, but it's not rare to see lots of ioctls. e.g. sound card drivers use a lot of ioctl, too.
Originally ioctl was mostly for terminal I/O settings on TTY file descriptors, like canonical vs. raw, and which special characters did what, and serial port speeds. But as I said, other kinds of device drivers have used it as an alternative to adding new system calls.
Related
After Philips has discontinued their health app, I had an idea of connecting subj to the raspberry pi. What I got so far (quick and dirty bluepy solution) is
from bluepy import btle
from bluepy.btle import AssignedNumbers
addr = 'CF:0C:XX:XX:XX:XX'
scales = btle.Peripheral(addr, btle.ADDR_TYPE_RANDOM)
class MyDelegate(btle.DefaultDelegate):
def handleNotification(self, cHandle, data):
print(f"Notification: {cHandle} {data}")
scales.setDelegate(MyDelegate())
svc = scales.getServiceByUUID('000078d2-0000-1000-8000-00805f9b34fb')
for ch in svc.getCharacteristics():
if ch.propertiesToString().strip() == 'INDICATE':
print(f"Subscribing to {ch.uuid} {ch.valHandle}")
scales.writeCharacteristic(ch.valHandle + 1, (2).to_bytes(2, byteorder='little'))
elif ch.propertiesToString().strip() == 'WRITE':
# print(f"Writting magic to {ch.uuid} {ch.valHandle}")
# scales.writeCharacteristic(ch.valHandle + 1, bytes([0x02, 0x00, 0x00, 0x00, 0x00]))
else:
print(f"{ch.uuid} {ch.propertiesToString()}")
print(scales.readCharacteristic(ch.valHandle))
while True:
if scales.waitForNotifications(1.0):
continue
print("Waiting...")
The code is far from being ideal, but at least, I'm receiving notification for characteristic 00008a82-0000-1000-8000-00805f9b34fb (which has nothing to do with weight).
My understanding (after reading documentation on how they handle Medisana BS444 ) is that some magic number needs to be written to 00008a81-0000-1000-8000-00805f9b34fb (commented lines).The one used for Medisana scales doesn't (obviously?) work.
Any suggestions on what can be done next?
I am developing a project where I have to read the holding registers data. I check everything using this http://www.freemodbus.com/ and it is working and get a proper response. While trying with the developed program I am not getting the proper response.
Software Response: 0x01 0x03 0x04 0x1a 0xa0 0x42 0x48 0xcd 0x9f
Arduino response: 0x01 0x04 0x83 0x43 0xff 0xff 0xff 0xff 0xff
note that in Arduino response there is no 0x03 after 0x01 I don't know why it is happening can anyone please help me with this.
please find attached Arduino code below.
static union
{
unsigned long a;
byte b[4];
float f;
}vr;
void readregister(unsigned int address)
{
byte rxbuf[]={0,0,0,0,0,0,0,0,0,0,0};
byte data[] = {0x01,0x03,0x00,0xab,0x00,0x02,0xb5,0xeb};
Serial3.flush();
for(int i=0;i<8;i++)
{
Serial3.write(data[i]);
}
delay(250);
while(Serial3.available()>0)
{
for(int v=0; v<=10;v++)
{
rxbuf[v]=Serial3.read();
Serial.println(rxbuf[v],HEX);
}
}
Serial3.flush();
vr.b[3]=rxbuf[3];
vr.b[2]=rxbuf[2];
vr.b[1]=rxbuf[5];
vr.b[0]=rxbuf[4];
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial3.begin(9600,SERIAL_8E1);
}
void loop() {
// put your main code here, to run repeatedly:
readregister(99);
Serial.print("\n");
delay(3000);
}
Yes, I think you're getting an Error code 4 back from the device. See http://www.simplymodbus.ca/exceptions.htm
On this line, where you prep your request:
byte data[] = {0x01,0x03,0x00,0xab,0x00,0x02,0xb5,0xeb};
You're saying, device 1, function 3, 0x00 is space, then register address 0xAB. Not sure about the extra zero then, then length 2, and then CRC. So I vote that either the CRC is wrong, or the extra zero is wrong.
Also, note that modbus fails on ocassion for no reason, even when you do everything right, so retry after a few seconds and see what happens
I've been reading a lot of questions and answers regarding nrf24l01 and Arduinos while I was trying to figure out my problem. I'm fairly sure no one had this issue yet but I might be wrong. Here is my problem:
If I upload the sending code to the UNO and the receiving code to the NANO I keep getting errors. And nothing gets transmitted. However, if I do the opposite and I upload the sending code to the NANO and the receiving code to the UNO, everything is fine... I've been scratching my head for a couple days without any idea and I would like to get input from other people because I ran out of ideas...
I tried different nrf24l01 modules (I got about 20) to see if one was fried. Still the same thing. Tried changing to different pins... still the same thing. Changed the code to get it simpler and simpler to narrow down.. still the same thing. Maybe it requires more power to scan than send a package and the 3.3v from the Nano is not enough? I highly doubt..
I'm really curious if you guys can figure this one out. I think I provided a lot of info. If you need more feel free to ask.
Here is my set-up:
Arduino Nano:
And here is the log from the printDetails() function:
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xb01dfacece 0xb01dfacece
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xb01dfacece
RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x02
RF_CH = 0x73
RF_SETUP = 0x07
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX
Arduino Uno:
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xb01dfacece 0xb01dfacece
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xb01dfacece
RX_PW_P0-6 = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x02
RF_CH = 0x73
RF_SETUP = 0x07
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX
Here is the Receiver code:
#include <SPI.h>
#include "RF24.h"
#include "nRF24L01.h"
#include "printf.h"
RF24 myRadio (7,8);
const uint64_t pipe = 0xB01DFACECEL;
struct package
{
int id=0;
int code = 0;
char text[100] = "";
};
typedef struct package Package;
Package data;
void setup() {
Serial.begin(115200);
printf_begin();
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.openReadingPipe(1,pipe);
myRadio.printDetails();
myRadio.startListening();
Serial.println("Set-Up Done");
delay(1000);
}
void loop() {
if(myRadio.available())
{
while(myRadio.available())
{
myRadio.read(&data, sizeof(data));
Serial.print("\nPackage");
Serial.println(data.id);
Serial.println(data.code);
Serial.println(data.text);
}
}
delay(500);
}
Here is the Sending code:
#include <SPI.h>
#include "RF24.h"
#include "nRF24L01.h"
#include "printf.h"
RF24 myRadio (7,8);
const uint64_t pipe = 0xB01DFACECEL;
struct package
{
int id=1;
int code = 2;
char text[100] = "text";
};
typedef struct package Package;
Package data;
void setup() {
Serial.begin(9600);
printf_begin();
delay(1000);
myRadio.begin();
myRadio.setChannel(115);
myRadio.openWritingPipe(pipe);
myRadio.setRetries(15,15);
myRadio.printDetails();
myRadio.stopListening();
Serial.println("Set-Up Done");
delay(1000);
}
void loop() {
if(!myRadio.write(&data, sizeof(data)))
{
Serial.println("error!!");
myRadio.printDetails();
}
Serial.print("\nPackage");
Serial.println(data.id);
Serial.println(data.code);
Serial.println(data.text);
data.id += 1;
data.code += 1;
delay(3000);
}
Try putting a 10uf capacitor across the +3.3v and gnd of each of the nRF24L01 module.
These modules need a lot of sending power which the capacitor helps with. I hope it works for you.
Try putting a 10uf capacitor across the +3.3v and gnd of each of the nRF24L01 module.
If that dosen't work, run the nrf24l01 off its own supply, 3.3v but have seen these peak at 1A! sending bursts. and the poor Nano's 3.3V comes from the FT232 chip, only 50mA is available.
I'm trying to send HEX values via XBee from a Arduino to digi's Xbee program XCTU. But i have some problems with some bytes that i cant send
The list of bytes i cant send:
0x11
0x13
0x7D
0x7E
0x81
0xEC
0xEE
If i use any other bytes i can see it in the XCTU console window and i get a response back to the Arduino
I have enabled API mode (AP=1) on both of the Xbee's. Im using the XBee lib linked from Arduino web site (https://www.arduino.cc/en/Reference/Libraries)
My code looks like this:
#define XBEE_RX_PIN 8
#define XBEE_TX_PIN 9
SoftwareSerial xbeeSerial(XBEE_RX_PIN, XBEE_TX_PIN);
void setup()
{
Serial.begin(9600);
xbeeSerial.begin(9600);
xbee.begin(xbeeSerial);
}
void loop()
{
Serial.println("Send next 255 msg:");
uint8_t testMsg[1] = { 0x0 };
for (uint8_t i = 0; i <= 0xFF; i++)
{
test2[0] = i;
Tx16Request testTx = Tx16Request(0xFFFF, testMsg, sizeof(testMsg));
xbee.send(testTx);
Serial.print("Message send: ");
Serial.println(test2[0], HEX);
if (xbee.readPacket(5000)) {
Serial.println("SUCCESS");
}
else if (xbee.getResponse().isError()) {
Serial.println("isError");
}
else {
Serial.println("No Response");
}
}
Serial.println("");
delay(3000);
}
With AP=1, you can't send some special bytes like:
0x7E (start of frame)
0x11/0x13 (XOn XOff)
...
As mentioned in the XBee documentation (XBee®XBee-PRO® ZB RF Modules manual 90000976_W.pdf, starting page 112), you should use AP=2 mode which allows you to transmit these special bytes by escaping them:
Escape characters.
When sending or receiving a UART data frame, specific data values must be
escaped (flagged) so they do not interfere with the data frame sequencing.
To escape an interfering data byte, insert 0x7D and follow it with the byte to be escaped XOR’d with 0x20.
Note that, if not escaped, 0x11 and 0x13 is sent as is.
Data bytes that need to be escaped:
- 0x7E – Frame Delimiter
- 0x7D – Escape
- 0x11 – XON
- 0x13 – XOFF
Example - Raw UART Data Frame (before escaping interfering bytes):
- 0x7E 0x00 0x02 0x23 0x11 0xCB
0x11 needs to be escaped which results in the following frame:
- 0x7E 0x00 0x02 0x23 0x7D 0x31 0xCB
Note In the above example, the length of the raw data (excluding the checksum) is 0x0002 and the checksum of the non-escaped data (excluding frame delimiter and length) is calculated as:
0xFF - (0x23 + 0x11) = (0xFF - 0x34) = 0xCB.
Hope this helps
Could anyone tell me how to format the serialport.write method in c# for the following get memory command of a digital multimeter?
DLE
STX
Command
arg1
arg2
arg3
DLE
ETX
10h
02h
4Eh
00h
00h
00h
10h
03h
Many thanks
Try creating a byte array, and writing this to the port.
byte[] data = new byte[] {0x10, 0x02, 0x4E, 0x0, 0x0, 0x0, 0x10, 0x03};
port.Write(data, 0, data.Length);