u/Scary_Competition_11

fs::read_dir can locate a file but fs::read_to_str can't open it

I have some code where I need to parse a file to generate a character tree. However, the main access point is supposed to be through the directory.

Essentially, when I perform a read_dir on the directory, the correct file is found. Then the path of this new file is passed into a different function, and the new function tries to perform a read_to_string of the path.

At this point, the code panics with the error message "No such OS or Directory found". I checked the source code for read_to_string, and it appears that it uses File::open()? under the hood. Any ideas why this may be failing? I'm running ubuntu on a WSL system, btw.

Edit: I forgot to say before that the file and directory both have read permission for all users

Edit: Here is what I'm trying right now:

impl SharDirectory {
   pub fn new(dir_path: &str) -> Result<Self> {
        let entries = std::fs::read_dir(dir_path);

             for entry in entries {
                    let entry = entry?;
                    let entry_type = entry.file_type()?;
                    .
                    .
                    .
                    } else if entry_type.is_file() {
                        let file = SharFile::new(entry.path().to_str().unwrap())?;
                    }
    }
}

impl SharFile {
    pub fn new(file_path: &str) -> Result<Self> {
        println!("file path: {}", file_path); // prints proper file path from home directory
        let file = std::fs::read_to_string(file_path);
        .
        .
        .
    }
}        
reddit.com
u/Scary_Competition_11 — 13 hours ago
▲ 26 r/NEU

Finding a co-op was never supposed to be easy

Co-ops never have and never will be guaranteed. That doesn’t even make sense.

A co-op is an internship that last half a year. That’s half a year’s worth of salary, and half a year’s worth of time where full timers spend a significant amount of time training instead of working.

When I was deciding to come here, Northeastern - or at least khoury college - emphasized that it will be up to the student to be qualified enough to find a co-op. No company wants someone that doesn’t have the skill to perform or the attitude to be trainable.

What northeastern provides is the scaffolding. The employer relationships that shrink the scope of competition to just your school instead of the country or world. The co-op class that teaches resume writing and interview prep. The culture centered around co-ops that everybody knows are difficult to get - which in turn creates a culture where everyone is working extra to make sure they get one.

93% of people get a co-op. The remaining 7% is dominated by those who weren’t looking for one and instead went for the research route or some other experiential learning option. Northeastern’s strategy works.

If co-ops were guaranteed, nobody would see the point in trying to excel, since the immediate payoff no longer exists. This would ironically probably push down the quality of graduates from the school.

I feel for the people who couldn’t get co-ops, but the process was never designed to be guaranteed. Northeastern’s job is a to facilitate the job search, not replace it.

reddit.com
u/Scary_Competition_11 — 16 hours ago

STM32 HAL_CRC_Calculate HardFault

I would like to preface this by saying that I am new to embedded engineering.

I'm trying to calculate a CRC using the crc peripheral on the STM32. The input data is about 56 bytes long and mostly zeros with really only about 8 bytes being actual data (quirk in the codebase that we're using, as well as a desire to support larger data partitions made this sound).

The thing that really loses me is that it fails inconsistently, and yet I can always predict when it fails. The very first time - during a data migration - it will work perfectly fine. The second time - updating said data after the migration - causes a Hardware Fault and kills the board I'm using.

Also we have a bunch of different boards that we're running this code on, but for some reason if fails on some but not others, even though they are all using the STM32g4xxx.

I'm thinking that it might be because of something I'm doing wrong in initialization, but I have no idea. Here is the code from which HAL_CRC_Calculate is being called (I can provide more higher-level code for more of an idea of what could be going on, but it's all the same regardless of scenario):

void MX_CRC_Init(void) {
    __HAL_RCC_CRC_CLK_ENABLE();
    hcrc.Instance = CRC;
    hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
    hcrc.Init.GeneratingPolynomial = 0x1021;
    hcrc.Init.CRCLength = CRC_POLYLENGTH_16B;
    hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;
    hcrc.Init.InitValue = 0xFFFF;
    hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_BYTE;
    hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_ENABLE;
    hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
    if (HAL_CRC_Init(&hcrc) != HAL_OK) {
        Error_Handler();
    }
}

uint16_t crc16_compute(const uint8_t* data, uint8_t length) {
    return ~HAL_CRC_Calculate(&hcrc, (uint32_t*)data, length);
}

Any help would be much appreciated.

EDIT: A lot of the comments have been talking about word-alignment. I tried implementing it, and word-alignmed data yields the same results.

reddit.com
▲ 0 r/NEU

Guys I know this isn’t MIT, but how good is would you say this pipeline is here. That is to say, how much “easier” is it because you go to northeastern / how much more frictionless?

reddit.com
u/Scary_Competition_11 — 15 days ago