Using WINC1500 with a PIC32, scan not working properly - wifi

I'm currently working on a project using a PIC32 and the wifi module ATWINC1500. I won't be able to give all the code but I'm on a test function that I can share.
First, here is some settings and configuration I'm using:
Processor : PIC32MZ1024EFE064
IDE : MPLAB IDE 5.45
Harmony version : 2.06
Wifi Module : ATWINC1500
Real Time OS : FreeRTOS
What I'm trying to do is to connect the Wifi module to an existing Access Point using the Infrastructure mode. I'm able to get the number of access point around me but when I try to read information from those access points, information are empty, void or incorrect.
Here is my code:
bool WIFI_Test_Infrastructure(void)
{
//Example: https://www.microchip.com/forums/m906568.aspx
//Wait for WINC1500 to be initialized
if(isWdrvExtReady() == false)
return false;
//Start a scan or wait for result
IWPRIV_PARAM_SCAN scanner;
IWPRIV_GET_PARAM param_scan = {
.scan = scanner
};
iwpriv_get(SCANSTATUS_GET, &param_scan);
IWPRIV_SCAN_STATUS status = param_scan.scan.scanStatus;
IWPRIV_EXECUTE_PARAM dummy_param;
//Process StateMachine while scanning
if(status == IWPRIV_SCAN_IDLE)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
//Disconnect wifi from everything
WDRV_Disconnect();
vTaskDelay(1000 / portTICK_PERIOD_MS);
while(WDRV_ConnectionState_Get() != WDRV_CONNECTION_STATE_NOT_CONNECTED)
vTaskDelay(10 / portTICK_PERIOD_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
WDRV_EXT_CmdScanStart();
return false;
}
else if(status == IWPRIV_SCAN_IN_PROGRESS)
{
return false;
}
else if(status == IWPRIV_SCAN_NO_AP_FOUND)
{
iwpriv_execute(SCAN_START, &dummy_param);
return false;
}
else if(status == IWPRIV_SCAN_SUCCESSFUL)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
//Read liste of wifi access point
uint16_t wifi_number_AP;
wifi_number_AP = m2m_wifi_get_num_ap_found();
WDRV_SCAN_RESULT scanResult;
tstrM2mWifiscanResult result;
int i;
for(i=0; i<wifi_number_AP; i++)
{
m2m_wifi_req_scan_result(i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
winc1500_scan_result_read(&result); //ISSUE HAPPENED HERE
vTaskDelay(1000 / portTICK_PERIOD_MS);
memcpy((void *)scanResult.bssid, (void *)result.au8BSSID, sizeof(scanResult.bssid));
}
//SUCCESS
return true;
}
else
{
return false;
}
}
So what happened here:
First, you need to know that this function is called by a Thread Manager, that's why it returns false or true. I'm checking the state in which the scan is.
I'm able to reach the SCAN_SUCCESSFUL part and the number of access point detected is correct.
I labeled the line where the issue is happening. When I'm reading the result information of an access point, it is quite empty. Here is what I see in Debug Session (and it is the same result for all of access points):
I have been waiting for weeks before asking this. Hope someone can help or at least give me hints on things to check.
If I missed information, do not hesitate to ask me.
Thanks in advance!
Adrien

The solution was simply a story of stack. I have two other tasks: SYS and TCP/IP. I needed to increase the size of their stack because they were managing several functions about scanning. So there was an overriding somewhere.

Related

Why do builds for various projects fail with ‘Operation not permitted’ using iOS on-device compiler/toolchain?

I am an intermediately skilled Linux/Unix user trying to compile software for an iPad on a (jailbroken) iPad.
Many builds (for example, make and tex-live) fail with some Operation not permitted error. This will either look like Can't exec "blah": Operation not permitted or execvp: blah: Operation not permitted where blah is aclocal, a configure script, libtool, or just about anything. Curiously, finding the offending line in a Makefile or configure script and prefixing it with sudo -u mobile -E will solve the error for that line, only for it to reappear for on a later line or in another file. Since I am running the build scripts as mobile, I do not understand how this could possibly fix the issue, yet it does. I have confirmed that making these changes does actually allow for the script to work successfully up to that point. Running the build script with sudo or sudo -u mobile -E and/or running the entire build as root does not solve the issue; with either, I still must edit build scripts to add sudo’s.
I would like to know why this is happening, and if possible how I could address the issue without editing build scripts. Any information about these types of errors would be interesting to me even if they do not solve my problem. I am aware that the permissions/security/entitlements system is unusual on iOS and would like to learn more about how it works.
I am using an iPad Pro 4 on jailbroken iOS 13.5 with the build tools from sbingner’s and MCApollo’s repos (repo.bingner.com and mcapollo.github.io/Public). In particular, I am using a build of LLVM 5 (manually installed from sbingner’s old debs), Clang 10, Darwin CC tools 927 and GNU Make 4.2.1. I have set CC, CXX, CFLAGS, etc. to point to clang-10 and my iOS 13.5 SDK with -isysroot and have confirmed that these settings are working. I would like to replace these with updated versions, but I cannot yet build these tools for myself due to this issue and a few others. I do have access to a Mac for cross-compilation if necessary, but I would rather use only my iPad because I like the challenge.
I can attach any logs necessary or provide more information if that would be useful; I do not know enough about this issue to know what information is useful. Thanks in advance for helping me!
For anyone who ends up needing to address this issue on a jailbreak that does not have a fix for this issue, I have written (pasted below) a userland hook based on the posix_spawn implementation from the source of Apple’s xnu kernel.
Compile it with Theos, and inject it into all processes spawned by your shell by setting environment variable DYLD_INSERT_LIBRARIES to the path of the resulting dylib. Note: some tweak injectors (namely libhooker, see here) reset DYLD_INSERT_LIBRARIES, so if you notice this behavior, be sure to inject only your library.
Because the implementation of the exec syscalls in iOS call out to posix_spawn, this hook fixes all of the exec-related issue’s I’ve run into so far.
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <spawn.h>
// Copied from bsd/kern/kern_exec.c
#define IS_WHITESPACE(ch) ((ch == ' ') || (ch == '\t'))
#define IS_EOL(ch) ((ch == '#') || (ch == '\n'))
// Copied from bsd/sys/imgact.h
#define IMG_SHSIZE 512
// Here, we provide an alternate implementation of posix_spawn which correctly handles #!.
// This is based on the implementation of posix_spawn in bsd/kern/kern_exec.c from Apple's xnu source.
// Thus, I am fairly confident that this posix_spawn has correct behavior relative to macOS.
%hookf(int, posix_spawn, pid_t *pid, const char *orig_path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t *attrp, char *const orig_argv[], char *const envp[]) {
// Call orig before checking for anything.
// This mirrors the standard implementation of posix_spawn because it first checks if we are spawning a binary.
int err = %orig;
// %orig returns EPERM when spawning a script.
// Thus, if err is anything other than EPERM, we can just return like normal.
if (err != EPERM)
return err;
// At this point, we do not need to check for exec permissions or anything like that.
// because posix_spawn would have returned that error instead of EPERM.
// Now we open the file for reading so that we can check if it's a script.
// If it turns out not to be a script, the EPERM must be from something else
// so we just return err.
FILE *file = fopen(orig_path, "r");
if (file == NULL) {
return err;
}
if (fseek(file, 0, SEEK_SET)) {
return err;
}
// In exec_activate_image, the data buffer is filled with the first PAGE_SIZE bytes of the file.
// However, in exec_shell_imgact, only the first IMG_SHSIZE bytes are used.
// Thus, we read IMG_SHSIZE bytes out of our file.
// The buffer is filled with newlines so that if the file is not IMG_SHSIZE bytes,
// the logic reads an IS_EOL.
char vdata[IMG_SHSIZE] = {'\n'};
if (fread(vdata, 1, IMG_SHSIZE, file) < 2) { // If we couldn't read at least two bytes, it's not a script.
fclose(file);
return err;
}
// Now that we've filled the buffer, we don't need the file anymore.
fclose(file);
// Now we follow exec_shell_imgact.
// The point of this is to confirm we have a script
// and extract the usable part of the interpreter+arg string.
// Where they return -1, we don't have a shell script, so we return err.
// Where they return an error, we return that same error.
// We don't bother doing any SUID stuff because SUID scripts should be disabled anyway.
char *ihp;
char *line_startp, *line_endp;
// Make sure we have a shell script.
if (vdata[0] != '#' || vdata[1] != '!') {
return err;
}
// Try to find the first non-whitespace character
for (ihp = &vdata[2]; ihp < &vdata[IMG_SHSIZE]; ihp++) {
if (IS_EOL(*ihp)) {
// Did not find interpreter, "#!\n"
return ENOEXEC;
} else if (IS_WHITESPACE(*ihp)) {
// Whitespace, like "#! /bin/sh\n", keep going.
} else {
// Found start of interpreter
break;
}
}
if (ihp == &vdata[IMG_SHSIZE]) {
// All whitespace, like "#! "
return ENOEXEC;
}
line_startp = ihp;
// Try to find the end of the interpreter+args string
for (; ihp < &vdata[IMG_SHSIZE]; ihp++) {
if (IS_EOL(*ihp)) {
// Got it
break;
} else {
// Still part of interpreter or args
}
}
if (ihp == &vdata[IMG_SHSIZE]) {
// A long line, like "#! blah blah blah" without end
return ENOEXEC;
}
// Backtrack until we find the last non-whitespace
while (IS_EOL(*ihp) || IS_WHITESPACE(*ihp)) {
ihp--;
}
// The character after the last non-whitespace is our logical end of line
line_endp = ihp + 1;
/*
* Now we have pointers to the usable part of:
*
* "#! /usr/bin/int first second third \n"
* ^ line_startp ^ line_endp
*/
// Now, exec_shell_imgact copies the interpreter into another buffer and then null-terminates it.
// Then, it copies the entire interpreter+args into another buffer and null-terminates it for later processing into argv.
// This processing is done in exec_extract_strings, which goes through and null-terminates each argument.
// We will just do this all at once since that's much easier.
// Keep track of how many arguments we have.
int i_argc = 0;
ihp = line_startp;
while (true) {
// ihp is on the start of an argument.
i_argc++;
// Scan to the end of the argument.
for (; ihp < line_endp; ihp++) {
if (IS_WHITESPACE(*ihp)) {
// Found the end of the argument
break;
} else {
// Keep going
}
}
// Null terminate the argument
*ihp = '\0';
// Scan to the beginning of the next argument.
for (; ihp < line_endp; ihp++) {
if (!IS_WHITESPACE(*ihp)) {
// Found the next argument
break;
} else {
// Keep going
}
}
if (ihp == line_endp) {
// We've reached the end of the arg string
break;
}
// If we are here, ihp is the start of an argument.
}
// Now line_startp is a bunch of null-terminated arguments possibly padded by whitespace.
// i_argc is now the count of the interpreter arguments.
// Our new argv should look like i_argv[0], i_argv[1], i_argv[2], ..., orig_path, orig_argv[1], orig_argv[2], ..., NULL
// where i_argv is the arguments to be extracted from line_startp;
// To allocate our new argv, we need to know orig_argc.
int orig_argc = 0;
while (orig_argv[orig_argc] != NULL) {
orig_argc++;
}
// We need space for i_argc + 1 + (orig_argc - 1) + 1 char*'s
char *argv[i_argc + orig_argc + 1];
// Copy i_argv into argv
int i = 0;
ihp = line_startp;
for (; i < i_argc; i++) {
// ihp is on the start of an argument
argv[i] = ihp;
// Scan to the next null-terminator
for (; ihp < line_endp; ihp++) {
if (*ihp == '\0') {
// Found it
break;
} else {
// Keep going
}
}
// Go to the next character
ihp++;
// Then scan to the next argument.
// There must be another argument because we already counted i_argc.
for (; ihp < line_endp; ihp++) {
if (!IS_WHITESPACE(*ihp)) {
// Found it
break;
} else {
// Keep going
}
}
// ihp is on the start of an argument.
}
// Then, copy orig_path into into argv.
// We need to make a copy of orig_path to avoid issues with const.
char orig_path_copy[strlen(orig_path)+1];
strcpy(orig_path_copy, orig_path);
argv[i] = orig_path_copy;
i++;
// Now, copy orig_argv[1...] into argv.
for (int j = 1; j < orig_argc; i++, j++) {
argv[i] = orig_argv[j];
}
// Finally, add the null.
argv[i] = NULL;
// Now, our argv is setup correctly.
// Now, we can call out to posix_spawn again.
// The interpeter is in argv[0], so we use that for the path.
return %orig(pid, argv[0], file_actions, attrp, argv, envp);
}

Saxon-C CentOS8 Compile

I am trying to evaluate Saxon-C 1.2.1 HE on CentOS8 and installation seems to have gone ok. Trying out the samples by cd samples/cppTests && build64-linux.sh though leads to a myriad of compilation errors to the tune of the following:
../../Saxon.C.API/SaxonProcessor.h:599:32: error: division ‘sizeof (JNINativeMethod*) / sizeof (JNINativeMethod)’ does not compute the number of array elements [-Werror=sizeof-pointer-div]
gMethods, sizeof(gMethods) / sizeof(gMethods[0]));
Before I summarily and trustfully switched off -Werror=sizeof-pointer-div i checked the source code and what's going on there do seem dubious.
bool registerCPPFunction(char * libName, JNINativeMethod * gMethods=NULL){
if(libName != NULL) {
setConfigurationProperty("extc", libName);
}
if(gMethods == NULL && nativeMethodVect.size()==0) {
return false;
} else {
if(gMethods == NULL) {
//copy vector to gMethods
gMethods = new JNINativeMethod[nativeMethodVect.size()];
}
return registerNativeMethods(sxn_environ->env, "com/saxonica/functions/>
gMethods, sizeof(gMethods) / sizeof(gMethods[0]));
}
return false;
}
more specifically sizeof(gMethods) / sizeof(gMethods[0]) would not seem to calculate anything useful by any margin. The intention was probably rather to output some code that would arrive at the same value as nativeMethodVect.size() but seeing this project's source for the very first time i might be mistaking and the division is in fact intentional ?
I am inclined to guess the intention was in fact closer to b than to a in the following example:
#include <cstdio>
struct test
{
int x, y, z;
};
int main()
{
test *a = new test[32], b[32];
printf("%d %d\n", sizeof(a)/sizeof(a[0]), sizeof(b)/sizeof(b[0]));
return 0;
}
which output 0 32 which is expected as the sizeof(a) gives the size of a pointer not the size of an array's memory region.
That bit of code is to support the feature of user defined extension functions in XSLT stylesheets and XQuery queries. If a user is not using these features then they don't need that bit of code. In fact User defined extension functions is only available in Saxon-PE/C and Saxon-EE/C so it should not be in the Saxon-HE/C code base. I have created the following bug issue to investigate the error above and to https://saxonica.plan.io/issues/4477
I would think the workaround would be to either remove the code in question if the extension function feature is not used or remove the compile flag -Werror=sizeof-pointer-div.
The intent was code is as follows:
jobject JNICALL cppNativeCall(jstring funcName, jobjectArray arguments, jobjectArray argTypes){
//native call code here
}
JNINativeMethod cppMethods[] =
{
{
fname,
funcParameters,
(void *)&cppNativeCall
}
};
bool nativeFound = processor->registerNativeMethods(env, "NativeCall",
cppMethods, sizeof(cppMethods) / sizeof(cppMethods[0]));

How to implement pjsip video call in ios

Implement audio call using pjsip working proper but not working video call.
i applied following changes :
//Sip init
pj_status_t sip_startup(app_config_t *app_config)
{
pjsua_config cfg;
pjsua_config_default (&cfg);
cfg.cb.on_incoming_call = &on_incoming_call;
cfg.cb.on_call_media_state = &on_call_media_state;
cfg.cb.on_call_state = &on_call_state;
cfg.cb.on_reg_state2 = &on_reg_state2;
cfg.cb.on_call_media_event = &on_call_media_event;
// Init the logging config structure
pjsua_logging_config log_cfg;
pjsua_logging_config_default(&log_cfg);
log_cfg.console_level = 4;
// Init PJ Media
pjsua_media_config me_cfg;
pjsua_media_config_default(&me_cfg);
// Init the pjsua
status = pjsua_init(&cfg, &log_cfg, &me_cfg);
if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
}
//following code add when apply sip connection
pjsua_call_setting _call_setting;
pjsua_call_setting_default(&_call_setting);
_call_setting.aud_cnt = 1;
_call_setting.vid_cnt = 1;
//when press call button from app call this funtion for video call.
pj_status_t sip_dial(pjsua_acc_id acc_id, const char *number,
pjsua_call_id *call_id)
{
pj_status_t status;
pj_str_t uri = pj_str(destUri);
status = pjsua_call_make_call(_acc_id, &uri, &(_call_setting),
NULL, NULL, NULL);
if (status != PJ_SUCCESS)
error_exit("Error making call", status);
}
//Apply changes related to video code
static void on_call_media_state(pjsua_call_id call_id)
{
pjsua_call_info ci;
unsigned mi;
pjsua_call_get_info(call_id, &ci);
sip_ring_stop([SharedAppDelegate.aVoipManager pjsipConfig]);
if(ci.media_status == PJMEDIA_TYPE_VIDEO)
{
NSLog(#"windows id : %d",ci.media[mi].stream.vid.win_in);
NSLog(#"media id : %d",mi);
if (ci.media_status != PJSUA_CALL_MEDIA_ACTIVE)
return;
[[XCPjsua sharedXCPjsua]
displayWindow:ci.media[mi].stream.vid.win_in];
}
}
i applied above code but not place video call using pjsip.
Any one have idea or steps related to video call then please help me.
Thank you
This subject is too large, I think you need to refine your questions to a smaller more specific question if you wish to get a good answer.
Make sure you have read and understood the pjsip video support:
PJSip Video_Users_Guide
PJSIP IOS Video Support
I would look for what other people have done (even if it's on another platform, e.g. Android, Windows, etc.) and the look into the pjsip pjsua sample which I believe has video support but I'm not sure if it support ios video.
Get a known good examples of pjsip video calls going so you know that it looks like and what the logs look like when it works.
Then try against your ios code against the known good example clients to see where they differ. If you can't figure it out at least you should have enough info to be able to ask a more specific question about a specific situation that is not working for you.

PIC32MZ2048ECH144 USART- Junk characters transmitted

I am new to MPLAB X Harmony framework and also in working with microcontrollers. I am working on PIC32MZ2048ECH144. I wanted to transmit a simple string using USART and see it displayed in RealTerm terminal.(I have tried HyperTerminal also.) Whatever string I send, I see only junk characters being displayed. When I browsed for the solution for this problem of junk characters being displayed, there were suggestions to check for the baud rate. I have set the baud rate to be 9600 in MPLab Harmony Configurator(Options -> Harmony Framework configuration -> Drivers -> USART -> USART Driver Instance 0 -> Baud Rate -> 9600). So I used the following line in app.c to explicitly set the baud rate.(PBCLK is 100MHz). But no luck!
PLIB_USART_BaudRateSet(USART_ID_2, 100000000 ,9600);
The code for app.c file:
/*******************************************************************************
Start of File
*/
const char *string1 = "*** UART Interrupt-driven Application Example ***\r\n";
const char *string2 = "*** Type some characters and observe the LED turn ON ***\r\n";
APP_DATA appData =
{
};
APP_DRV_OBJECTS appDrvObject;
void APP_Initialize ( void )
{
appData.state = USART_ENABLE;
appData.InterruptFlag = false;
}
bool WriteString(void)
{
if(*appData.stringPointer == '\0')
{
return true;
}
while (PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
PLIB_USART_TransmitterByteSend(USART_ID_1, *appData.stringPointer);
appData.stringPointer++;
if(*appData.stringPointer == '\0')
{
return true;
}
}
return false;
}
bool PutCharacter(const char character)
{
if(PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
PLIB_USART_TransmitterByteSend(USART_ID_1, character);
return true;
}
else
return false;
}
void APP_Tasks ( void )
{
/* check the application state*/
switch ( appData.state )
{
case USART_ENABLE:
/* Enable the UART module*/
PLIB_USART_BaudRateSet(USART_ID_1, 100000000 ,9600);
PLIB_USART_Enable(USART_ID_1);
appData.stringPointer = string1;
appData.state = USART_TRANSMIT_FIRST_STRING;
break;
case USART_TRANSMIT_FIRST_STRING:
if(true == WriteString())
{
appData.state = USART_TRANSMIT_SECOND_STRING;
appData.stringPointer = string2;
}
break;
case USART_TRANSMIT_SECOND_STRING:
if(true == WriteString())
{
appData.state = USART_RECEIVE_DONE;
}
break;
case USART_RECEIVE_DONE:
if (appData.InterruptFlag)
{
if(true == PutCharacter(appData.data))
{
appData.InterruptFlag = false;
}
}
break;
default:
while (1);
}
}
/*******************************************************************************
End of File
*/
I am sorry that I cannot attach the image of the output I receive in RealTerm as I do not have enough points.
I have no clue where else the problem could be that gives the mismatch of baud rate. Any hints or help would be of great help. Thanks in advance.
Kindly apologize me for any mistakes in the post.
you are correct that it is most likely BAUD rate, but just to be sure how is the USART hooked to the computer? Do you have a translator chip since the computer is expecting +-5V? As for the BAUD, check your clocking scheme and know that PBCLK is sometimes DIV_2 of the SYSCLOCK. There is a great clocking schematic in the Harmony framework to double check your clocking and CONFIG pragmas.

Thread handling in TCP server in C

This is my first post here, so I'd like to say hello to everyone.
I am facing some problems with writing a TCP, I want to have a separate thread that allows user to type quit instruction to terminate process. The problem is that it doesn't seem to be running. The programme pauses on accept and I am unable to pass anything to the thread function.
The thread function:
void *loop_stop()
{
while(progr_control != 'q')
progr_control = getchar();
return NULL;
}
And the main (I ommited some code I think is not causing problems):
pthread_t thread_id;
pthread_create(&thread_id, NULL, loop_stop, NULL);
do
{
listen(sock_fd, 5);
int addr_len = sizeof(client_addr);
if( (new_sock_fd = accept(sock_fd, (struct sockaddr *) &client_addr, &addr_len)) < 0)
{
perror("Problems with incoming connection");
return -1;
}
else
//here is the ommited part-as I've said this loop stops at accept
}while(progr_control != 'q');
If anyone could please find the bug, or suggest other way of handling with the task, I'd be grateful
As Brian mentioned:
'accept' will make the thread wait for incomming connection, so no "quit check" is possible. The alternative is to use ctrl+c to quit instead.

Resources