New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for raspyrfm hardware with unittest #434
base: rewrite
Are you sure you want to change the base?
Conversation
fddae90
to
4e18e36
Compare
While doing some tests concerning the topic https://forum.pilight.org/showthread.php?tid=3522 I got an issue; the hwtype was set too late so that pilight can handle multiple hardware. I forced push and will bring it also to the staging branch. |
What actually changed? |
Also here, the setting of hwtype |
7d94531
to
e198e7c
Compare
I'm currently porting the hardware module to lua, but i noticed that the unittest doesn't yet cover everything. What i countered till this far:
|
What i also don't get is how you set a rawlen of 32 pulses on line 202, while you expect a rawlen of 50 pulses on line 114. Ok, the send unittest now works in lua. Next step is the receiving end. |
This is because the rfm69 module transforms pulselengths to a contineous bitstream. For every 31 µS a bit is generated. A value of 248 in txtestpulses generates 248/31 = 8 bits. The last value in txtestpulses (5952) results in 5952/31 = 192 bits to be generated, in this case represented by the last 24 bytes in txtestraw array. |
How can I test for correct speed? I think if the SPI can not be opened with the requested speed it should return an error. Which test is missing? The frequency is checked in setFrequency, if SPI channel is not provided, raspyrfmHwInit would return an error. |
Here various parameters are set, but the test doesn't check if they are all set with the correct values:
This one is set.
This is what i did in the new serial unittest: int tcgetattr(int fildes, struct termios *termios_p) {
memset(termios_p, 0, sizeof(struct termios));
return 0;
}
int tcsetattr(int fildes, int optional_actions, const struct termios *termios_p) {
char buffer[1024];
int l = 0;
l += snprintf(buffer, 1024,
"%4u",
optional_actions);
l += snprintf(&buffer[l], 1024-l,
"%8u",
termios_p->c_iflag);
l += snprintf(&buffer[l], 1024-l,
"%8u",
termios_p->c_oflag);
l += snprintf(&buffer[l], 1024-l,
"%8u",
termios_p->c_cflag);
l += snprintf(&buffer[l], 1024-l,
"%8u",
termios_p->c_lflag);
int i = 0;
for(i=0;i<NCCS;i++) {
l += snprintf(&buffer[l], 1024-l,
"%4u",
termios_p->c_cc[i]);
}
l += snprintf(&buffer[l], 1024-l,
"%8u",
termios_p->c_ispeed);
l += snprintf(&buffer[l], 1024-l,
"%8u",
termios_p->c_ospeed);
write(fildes, buffer, l);
return 0;
} And the other side: static void callback(uv_fs_t *req) {
unsigned int len = req->result;
uv_fs_req_cleanup(req);
FREE(req);
if(len > 0) {
if(strcmp(rbuffer, " 2 0 0 6321 0 0 0 0 0 0 150 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4097 4097") == 0) {
pthread_attr_t attrs;
pthread_attr_init(&attrs);
pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
pthread_create(&pthread, NULL, thread, &fd);
return;
}
}
if(run == 1) {
uv_fs_t *read_req = NULL;
if((read_req = MALLOC(sizeof(uv_fs_t))) == NULL) {
OUT_OF_MEMORY /*LCOV_EXCL_LINE*/
}
memset(rbuffer, '\0', BUFFER_SIZE);
uv_buf_t buf = uv_buf_init(rbuffer, BUFFER_SIZE);
uv_fs_read(uv_default_loop(), read_req, fd, &buf, 1, -1, callback);
}
} So, you could change the wiringXSPISetup to write the SPI parameters to the /dev/spidev0.0 file as just file content and then you check the parameters written to that file in a file read callback at the unittest side. That's at least what i did. |
The rfmcfg are hardcoded values for the RFM69 IC. Is it really needed to check for it? When the SPI is working, which is checked implicitely with RX/TX tests, it can not fail. |
How can i be sure about that when porint the whole thing to lua and not having the device itself. |
Good point. I added checking of rfmcfg. |
So what happens when i do the following:
instead of
Does the unittest work or fail and why? |
It will fail. You are writing wrong values in wrong registers. In the unittest all register writes are catched, and if a register/value pair there matches with rfmcfg, I set a flag in rfmcfgcheck. When everything is flagged in the rfmcfgcheck, the test will pass. |
But where are those values defined at the unit test side? I only see that empty struct.
|
Those values are defined here: pilight/libs/pilight/hardware/raspyrfm.c Line 84 in cbd9a35
|
That's what I said. At the hardware side not at the unit test side.
Also, the new implementation will be in lua so the c defined struct of the module can't be used anymore .
|
Ok, this means the rfmcfg needs to be defined redundant also in the unittest. Then of course if a value in rfmcfg has to be changed it will also have to be changed in the unittest. |
Welcome to the world of unittesting 😉 |
I've ported the whole module to lua and all unittest succeed. You can check the work done in the I also believe nobody has ever got a more thorough review than you got. I see that as a compliment 😄 There are a few things i also want to see fixed before i finally merge:
Lastly:
|
I'm back after a busy period. |
pilight programs are not supported in the rewrite branch. That's why i removed them in the latest commits. |
Also, welcome back 👍 |
No description provided.